UNPKG

3.87 kBJavaScriptView Raw
1/** @license React v16.10.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(function (global, factory) {
13 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
14 typeof define === 'function' && define.amd ? define(factory) :
15 (global.ReactDOMFizzServer = factory());
16}(this, (function () { '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}
28
29function close(destination) {
30 destination.close();
31}
32var textEncoder = new TextEncoder();
33function convertStringToBuffer(content) {
34 return textEncoder.encode(content);
35}
36
37function formatChunk(type, props) {
38 var str = '<' + type + '>';
39
40 if (typeof props.children === 'string') {
41 str += props.children;
42 }
43
44 str += '</' + type + '>';
45 return convertStringToBuffer(str);
46}
47
48// The Symbol used to tag the ReactElement-like types. If there is no native Symbol
49// nor polyfill, then a plain number is used for performance.
50var hasSymbol = typeof Symbol === 'function' && Symbol.for;
51var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
52
53
54
55
56
57 // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary
58// (unstable) APIs that have been removed. Can we remove the symbols?
59
60function createRequest(children, destination) {
61 return {
62 destination: destination,
63 children: children,
64 completedChunks: [],
65 flowing: false
66 };
67}
68
69function performWork(request) {
70 var element = request.children;
71 request.children = null;
72
73 if (element && element.$$typeof !== REACT_ELEMENT_TYPE) {
74 return;
75 }
76
77 var type = element.type;
78 var props = element.props;
79
80 if (typeof type !== 'string') {
81 return;
82 }
83
84 request.completedChunks.push(formatChunk(type, props));
85
86 if (request.flowing) {
87 flushCompletedChunks(request);
88 }
89
90 flushBuffered(request.destination);
91}
92
93function flushCompletedChunks(request) {
94 var destination = request.destination;
95 var chunks = request.completedChunks;
96 request.completedChunks = [];
97 try {
98 for (var i = 0; i < chunks.length; i++) {
99 var chunk = chunks[i];
100 writeChunk(destination, chunk);
101 }
102 } finally {
103
104 }
105
106 close(destination);
107}
108
109function startWork(request) {
110 request.flowing = true;
111 scheduleWork(function () {
112 return performWork(request);
113 });
114}
115function startFlowing(request, desiredBytes) {
116 request.flowing = false;
117 flushCompletedChunks(request);
118}
119
120// This file intentionally does *not* have the Flow annotation.
121// Don't add it. See `./inline-typed.js` for an explanation.
122
123function renderToReadableStream(children) {
124 var request;
125 return new ReadableStream({
126 start: function (controller) {
127 request = createRequest(children, controller);
128 startWork(request);
129 },
130 pull: function (controller) {
131 startFlowing(request, controller.desiredSize);
132 },
133 cancel: function (reason) {}
134 });
135}
136
137var ReactDOMFizzServerBrowser = {
138 renderToReadableStream: renderToReadableStream
139};
140
141var ReactDOMFizzServerBrowser$1 = Object.freeze({
142 default: ReactDOMFizzServerBrowser
143});
144
145var ReactDOMFizzServerBrowser$2 = ( ReactDOMFizzServerBrowser$1 && ReactDOMFizzServerBrowser ) || ReactDOMFizzServerBrowser$1;
146
147// TODO: decide on the top-level export form.
148// This is hacky but makes it work with both Rollup and Jest
149
150
151var unstableFizz_browser = ReactDOMFizzServerBrowser$2.default || ReactDOMFizzServerBrowser$2;
152
153return unstableFizz_browser;
154
155})));