forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathReactNoopFlightServer.js
75 lines (66 loc) · 2.07 KB
/
ReactNoopFlightServer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* 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.
*/
import type {ReactModel} from 'react-server/src/ReactFlightServer';
import {saveModule} from 'react-noop-renderer/flight-modules';
import ReactFlightServer from 'react-server/flight';
type Destination = Array<string>;
const ReactNoopFlightServer = ReactFlightServer({
scheduleWork(callback: () => void) {
callback();
},
beginWriting(destination: Destination): void {},
writeChunk(destination: Destination, chunk: string): void {
destination.push(chunk);
},
completeWriting(destination: Destination): void {},
close(destination: Destination): void {},
closeWithError(destination: Destination, error: mixed): void {},
flushBuffered(destination: Destination): void {},
stringToChunk(content: string): string {
return content;
},
stringToPrecomputedChunk(content: string): string {
return content;
},
isModuleReference(reference: Object): boolean {
return reference.$$typeof === Symbol.for('react.module.reference');
},
getModuleKey(reference: Object): Object {
return reference;
},
resolveModuleMetaData(
config: void,
reference: {$$typeof: Symbol, value: any},
) {
return saveModule(reference.value);
},
});
type Options = {
onError?: (error: mixed) => void,
};
function render(model: ReactModel, options?: Options): Destination {
const destination: Destination = [];
const bundlerConfig = undefined;
const request = ReactNoopFlightServer.createRequest(
model,
destination,
bundlerConfig,
options ? options.onError : undefined,
);
ReactNoopFlightServer.startWork(request);
ReactNoopFlightServer.startFlowing(request);
return destination;
}
export {render};