Skip to content

Commit fe1d427

Browse files
committed
Not sure if I'll add this.
1 parent b048550 commit fe1d427

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
/**
11+
* This is a renderer of React that doesn't have a render target output.
12+
* It is useful to demonstrate the internals of the reconciler in isolation
13+
* and for testing semantics of reconciliation separate from the host
14+
* environment.
15+
*/
16+
17+
import ReactFlightHooks from 'react-client/flight-hooks';
18+
19+
type Source = Array<string>;
20+
21+
const {createResponse, processStringChunk, close} = ReactFlightClient({
22+
supportsBinaryStreams: false,
23+
resolveModuleReference(idx: string) {
24+
return idx;
25+
},
26+
preloadModule(idx: string) {},
27+
requireModule(idx: string) {
28+
return readModule(idx);
29+
},
30+
parseModel(response: Response, json) {
31+
return JSON.parse(json, response._fromJSON);
32+
},
33+
});
34+
35+
function read<T>(source: Source): T {
36+
const response = createResponse(source);
37+
for (let i = 0; i < source.length; i++) {
38+
processStringChunk(response, source[i], 0);
39+
}
40+
close(response);
41+
return response.readRoot();
42+
}
43+
44+
export {read};
45+

0 commit comments

Comments
 (0)