UNPKG

3.78 kBJavaScriptView Raw
1/** @license React v16.12.0
2 * react-dom-unstable-fizz.browser.development.js
3 *
4 * Copyright (c) Facebook, Inc. and its affiliates.
5 *
6 * This source code is licensed under the MIT license found in the
7 * LICENSE file in the root directory of this source tree.
8 */
9
10'use strict';
11
12
13
14if (process.env.NODE_ENV !== "production") {
15 (function() {
16'use strict';
17
18function scheduleWork(callback) {
19 callback();
20}
21function flushBuffered(destination) {// WHATWG Streams do not yet have a way to flush the underlying
22 // transform streams. https://github.com/whatwg/streams/issues/960
23}
24
25function writeChunk(destination, buffer) {
26 destination.enqueue(buffer);
27 return destination.desiredSize > 0;
28}
29
30function close(destination) {
31 destination.close();
32}
33var textEncoder = new TextEncoder();
34function convertStringToBuffer(content) {
35 return textEncoder.encode(content);
36}
37
38function formatChunkAsString(type, props) {
39 var str = '<' + type + '>';
40
41 if (typeof props.children === 'string') {
42 str += props.children;
43 }
44
45 str += '</' + type + '>';
46 return str;
47}
48function formatChunk(type, props) {
49 return convertStringToBuffer(formatChunkAsString(type, props));
50}
51
52// The Symbol used to tag the ReactElement-like types. If there is no native Symbol
53// nor polyfill, then a plain number is used for performance.
54var hasSymbol = typeof Symbol === 'function' && Symbol.for;
55var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
56
57
58
59
60
61 // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary
62// (unstable) APIs that have been removed. Can we remove the symbols?
63
64function createRequest(children, destination) {
65 return {
66 destination: destination,
67 children: children,
68 completedChunks: [],
69 flowing: false
70 };
71}
72
73function performWork(request) {
74 var element = request.children;
75 request.children = null;
76
77 if (element && element.$$typeof !== REACT_ELEMENT_TYPE) {
78 return;
79 }
80
81 var type = element.type;
82 var props = element.props;
83
84 if (typeof type !== 'string') {
85 return;
86 }
87
88 request.completedChunks.push(formatChunk(type, props));
89
90 if (request.flowing) {
91 flushCompletedChunks(request);
92 }
93
94 flushBuffered(request.destination);
95}
96
97function flushCompletedChunks(request) {
98 var destination = request.destination;
99 var chunks = request.completedChunks;
100 request.completedChunks = [];
101 try {
102 for (var i = 0; i < chunks.length; i++) {
103 var chunk = chunks[i];
104 writeChunk(destination, chunk);
105 }
106 } finally {
107
108 }
109
110 close(destination);
111}
112
113function startWork(request) {
114 request.flowing = true;
115 scheduleWork(function () {
116 return performWork(request);
117 });
118}
119function startFlowing(request) {
120 request.flowing = false;
121 flushCompletedChunks(request);
122}
123
124// This file intentionally does *not* have the Flow annotation.
125// Don't add it. See `./inline-typed.js` for an explanation.
126
127function renderToReadableStream(children) {
128 var request;
129 return new ReadableStream({
130 start: function (controller) {
131 request = createRequest(children, controller);
132 startWork(request);
133 },
134 pull: function (controller) {
135 startFlowing(request);
136 },
137 cancel: function (reason) {}
138 });
139}
140
141var ReactDOMFizzServerBrowser = {
142 renderToReadableStream: renderToReadableStream
143};
144
145var ReactDOMFizzServerBrowser$1 = Object.freeze({
146 default: ReactDOMFizzServerBrowser
147});
148
149var ReactDOMFizzServerBrowser$2 = ( ReactDOMFizzServerBrowser$1 && ReactDOMFizzServerBrowser ) || ReactDOMFizzServerBrowser$1;
150
151// TODO: decide on the top-level export form.
152// This is hacky but makes it work with both Rollup and Jest
153
154
155var unstableFizz_browser = ReactDOMFizzServerBrowser$2.default || ReactDOMFizzServerBrowser$2;
156
157module.exports = unstableFizz_browser;
158 })();
159}