UNPKG

3.7 kBJavaScriptView Raw
1/** @license React v16.8.5
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}
21
22function flushBuffered(destination) {
23 // WHATWG Streams do not yet have a way to flush the underlying
24 // transform streams. https://github.com/whatwg/streams/issues/960
25}
26
27
28
29function writeChunk(destination, buffer) {
30 destination.enqueue(buffer);
31}
32
33
34
35function close(destination) {
36 destination.close();
37}
38
39var textEncoder = new TextEncoder();
40
41function convertStringToBuffer(content) {
42 return textEncoder.encode(content);
43}
44
45function formatChunk(type, props) {
46 var str = '<' + type + '>';
47 if (typeof props.children === 'string') {
48 str += props.children;
49 }
50 str += '</' + type + '>';
51 return convertStringToBuffer(str);
52}
53
54// The Symbol used to tag the ReactElement-like types. If there is no native Symbol
55// nor polyfill, then a plain number is used for performance.
56var hasSymbol = typeof Symbol === 'function' && Symbol.for;
57
58var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
59
60function createRequest(children, destination) {
61 return { destination: destination, children: children, completedChunks: [], flowing: false };
62}
63
64function performWork(request) {
65 var element = request.children;
66 request.children = null;
67 if (element && element.$$typeof !== REACT_ELEMENT_TYPE) {
68 return;
69 }
70 var type = element.type;
71 var props = element.props;
72 if (typeof type !== 'string') {
73 return;
74 }
75 request.completedChunks.push(formatChunk(type, props));
76 if (request.flowing) {
77 flushCompletedChunks(request);
78 }
79
80 flushBuffered(request.destination);
81}
82
83function flushCompletedChunks(request) {
84 var destination = request.destination;
85 var chunks = request.completedChunks;
86 request.completedChunks = [];
87
88 try {
89 for (var i = 0; i < chunks.length; i++) {
90 var chunk = chunks[i];
91 writeChunk(destination, chunk);
92 }
93 } finally {
94
95 }
96 close(destination);
97}
98
99function startWork(request) {
100 request.flowing = true;
101 scheduleWork(function () {
102 return performWork(request);
103 });
104}
105
106function startFlowing(request, desiredBytes) {
107 request.flowing = false;
108 flushCompletedChunks(request);
109}
110
111// This file intentionally does *not* have the Flow annotation.
112// Don't add it. See `./inline-typed.js` for an explanation.
113
114function renderToReadableStream(children) {
115 var request = void 0;
116 return new ReadableStream({
117 start: function (controller) {
118 request = createRequest(children, controller);
119 startWork(request);
120 },
121 pull: function (controller) {
122 startFlowing(request, controller.desiredSize);
123 },
124 cancel: function (reason) {}
125 });
126}
127
128var ReactDOMFizzServerBrowser = {
129 renderToReadableStream: renderToReadableStream
130};
131
132var ReactDOMFizzServerBrowser$1 = Object.freeze({
133 default: ReactDOMFizzServerBrowser
134});
135
136var ReactDOMFizzServerBrowser$2 = ( ReactDOMFizzServerBrowser$1 && ReactDOMFizzServerBrowser ) || ReactDOMFizzServerBrowser$1;
137
138// TODO: decide on the top-level export form.
139// This is hacky but makes it work with both Rollup and Jest
140var unstableFizz_browser = ReactDOMFizzServerBrowser$2.default || ReactDOMFizzServerBrowser$2;
141
142return unstableFizz_browser;
143
144})));