1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | 'use strict';
|
11 |
|
12 |
|
13 |
|
14 | if (process.env.NODE_ENV !== "production") {
|
15 | (function() {
|
16 | 'use strict';
|
17 |
|
18 | function scheduleWork(callback) {
|
19 | setImmediate(callback);
|
20 | }
|
21 | function flushBuffered(destination) {
|
22 |
|
23 |
|
24 | if (typeof destination.flush === 'function') {
|
25 |
|
26 |
|
27 | if (typeof destination.flushHeaders !== 'function') {
|
28 |
|
29 | destination.flush();
|
30 | }
|
31 | }
|
32 | }
|
33 | function beginWriting(destination) {
|
34 |
|
35 | if (typeof destination.cork === 'function') {
|
36 | destination.cork();
|
37 | }
|
38 | }
|
39 | function writeChunk(destination, buffer) {
|
40 | var nodeBuffer = buffer;
|
41 |
|
42 | return destination.write(nodeBuffer);
|
43 | }
|
44 | function completeWriting(destination) {
|
45 |
|
46 | if (typeof destination.uncork === 'function') {
|
47 | destination.uncork();
|
48 | }
|
49 | }
|
50 | function close(destination) {
|
51 | destination.end();
|
52 | }
|
53 | function convertStringToBuffer(content) {
|
54 | return Buffer.from(content, 'utf8');
|
55 | }
|
56 |
|
57 | function formatChunkAsString(type, props) {
|
58 | var str = '<' + type + '>';
|
59 |
|
60 | if (typeof props.children === 'string') {
|
61 | str += props.children;
|
62 | }
|
63 |
|
64 | str += '</' + type + '>';
|
65 | return str;
|
66 | }
|
67 | function formatChunk(type, props) {
|
68 | return convertStringToBuffer(formatChunkAsString(type, props));
|
69 | }
|
70 |
|
71 |
|
72 |
|
73 | var hasSymbol = typeof Symbol === 'function' && Symbol.for;
|
74 | var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
|
75 |
|
76 | function createRequest(children, destination) {
|
77 | return {
|
78 | destination: destination,
|
79 | children: children,
|
80 | completedChunks: [],
|
81 | flowing: false
|
82 | };
|
83 | }
|
84 |
|
85 | function performWork(request) {
|
86 | var element = request.children;
|
87 | request.children = null;
|
88 |
|
89 | if (element && element.$$typeof !== REACT_ELEMENT_TYPE) {
|
90 | return;
|
91 | }
|
92 |
|
93 | var type = element.type;
|
94 | var props = element.props;
|
95 |
|
96 | if (typeof type !== 'string') {
|
97 | return;
|
98 | }
|
99 |
|
100 | request.completedChunks.push(formatChunk(type, props));
|
101 |
|
102 | if (request.flowing) {
|
103 | flushCompletedChunks(request);
|
104 | }
|
105 |
|
106 | flushBuffered(request.destination);
|
107 | }
|
108 |
|
109 | function flushCompletedChunks(request) {
|
110 | var destination = request.destination;
|
111 | var chunks = request.completedChunks;
|
112 | request.completedChunks = [];
|
113 | beginWriting(destination);
|
114 |
|
115 | try {
|
116 | for (var i = 0; i < chunks.length; i++) {
|
117 | var chunk = chunks[i];
|
118 | writeChunk(destination, chunk);
|
119 | }
|
120 | } finally {
|
121 | completeWriting(destination);
|
122 | }
|
123 |
|
124 | close(destination);
|
125 | }
|
126 |
|
127 | function startWork(request) {
|
128 | request.flowing = true;
|
129 | scheduleWork(function () {
|
130 | return performWork(request);
|
131 | });
|
132 | }
|
133 | function startFlowing(request) {
|
134 | request.flowing = false;
|
135 | flushCompletedChunks(request);
|
136 | }
|
137 |
|
138 | function createDrainHandler(destination, request) {
|
139 | return function () {
|
140 | return startFlowing(request);
|
141 | };
|
142 | }
|
143 |
|
144 | function pipeToNodeWritable(children, destination) {
|
145 | var request = createRequest(children, destination);
|
146 | destination.on('drain', createDrainHandler(destination, request));
|
147 | startWork(request);
|
148 | }
|
149 |
|
150 | var ReactDOMFizzServerNode = {
|
151 | pipeToNodeWritable: pipeToNodeWritable
|
152 | };
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 | var unstableFizz_node = ReactDOMFizzServerNode.default || ReactDOMFizzServerNode;
|
159 |
|
160 | module.exports = unstableFizz_node;
|
161 | })();
|
162 | }
|