2019-10-30 05:45:47 +08:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
|
|
|
*
|
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
|
*
|
|
|
|
|
* @flow
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This is a renderer of React that doesn't have a render target output.
|
|
|
|
|
* It is useful to demonstrate the internals of the reconciler in isolation
|
|
|
|
|
* and for testing semantics of reconciliation separate from the host
|
|
|
|
|
* environment.
|
|
|
|
|
*/
|
|
|
|
|
|
2020-03-24 08:53:45 +08:00
|
|
|
import {readModule} from 'react-noop-renderer/flight-modules';
|
|
|
|
|
|
2020-03-08 03:23:30 +08:00
|
|
|
import ReactFlightClient from 'react-client/flight';
|
2019-10-30 05:45:47 +08:00
|
|
|
|
2019-11-02 07:05:07 +08:00
|
|
|
type Source = Array<string>;
|
2019-10-30 05:45:47 +08:00
|
|
|
|
2020-03-26 02:47:55 +08:00
|
|
|
const {createResponse, processStringChunk, close} = ReactFlightClient({
|
2019-11-02 07:05:07 +08:00
|
|
|
supportsBinaryStreams: false,
|
2020-03-24 08:53:45 +08:00
|
|
|
resolveModuleReference(idx: string) {
|
|
|
|
|
return idx;
|
2020-03-22 13:28:36 +08:00
|
|
|
},
|
2020-03-24 08:53:45 +08:00
|
|
|
preloadModule(idx: string) {},
|
|
|
|
|
requireModule(idx: string) {
|
|
|
|
|
return readModule(idx);
|
2020-03-22 13:28:36 +08:00
|
|
|
},
|
2020-04-04 05:58:02 +08:00
|
|
|
parseModel(response: Response, json) {
|
|
|
|
|
return JSON.parse(json, response._fromJSON);
|
|
|
|
|
},
|
2019-10-30 05:45:47 +08:00
|
|
|
});
|
|
|
|
|
|
2020-03-26 02:47:55 +08:00
|
|
|
function read<T>(source: Source): T {
|
2020-04-02 03:35:52 +08:00
|
|
|
const response = createResponse(source);
|
2019-11-02 07:05:07 +08:00
|
|
|
for (let i = 0; i < source.length; i++) {
|
|
|
|
|
processStringChunk(response, source[i], 0);
|
|
|
|
|
}
|
2020-03-11 05:55:04 +08:00
|
|
|
close(response);
|
2020-03-26 02:47:55 +08:00
|
|
|
return response.readRoot();
|
2019-10-30 05:45:47 +08:00
|
|
|
}
|
|
|
|
|
|
2020-02-28 09:18:55 +08:00
|
|
|
export {read};
|