UNPKG

3.75 kBJavaScriptView Raw
1/** @license React v16.9.0-alpha.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}
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74// React event targets
75
76function createRequest(children, destination) {
77 return { destination: destination, children: children, completedChunks: [], flowing: false };
78}
79
80function performWork(request) {
81 var element = request.children;
82 request.children = null;
83 if (element && element.$$typeof !== REACT_ELEMENT_TYPE) {
84 return;
85 }
86 var type = element.type;
87 var props = element.props;
88 if (typeof type !== 'string') {
89 return;
90 }
91 request.completedChunks.push(formatChunk(type, props));
92 if (request.flowing) {
93 flushCompletedChunks(request);
94 }
95
96 flushBuffered(request.destination);
97}
98
99function flushCompletedChunks(request) {
100 var destination = request.destination;
101 var chunks = request.completedChunks;
102 request.completedChunks = [];
103
104 try {
105 for (var i = 0; i < chunks.length; i++) {
106 var chunk = chunks[i];
107 writeChunk(destination, chunk);
108 }
109 } finally {
110
111 }
112 close(destination);
113}
114
115function startWork(request) {
116 request.flowing = true;
117 scheduleWork(function () {
118 return performWork(request);
119 });
120}
121
122function startFlowing(request, desiredBytes) {
123 request.flowing = false;
124 flushCompletedChunks(request);
125}
126
127// This file intentionally does *not* have the Flow annotation.
128// Don't add it. See `./inline-typed.js` for an explanation.
129
130function renderToReadableStream(children) {
131 var request = void 0;
132 return new ReadableStream({
133 start: function (controller) {
134 request = createRequest(children, controller);
135 startWork(request);
136 },
137 pull: function (controller) {
138 startFlowing(request, controller.desiredSize);
139 },
140 cancel: function (reason) {}
141 });
142}
143
144var ReactDOMFizzServerBrowser = {
145 renderToReadableStream: renderToReadableStream
146};
147
148var ReactDOMFizzServerBrowser$1 = Object.freeze({
149 default: ReactDOMFizzServerBrowser
150});
151
152var ReactDOMFizzServerBrowser$2 = ( ReactDOMFizzServerBrowser$1 && ReactDOMFizzServerBrowser ) || ReactDOMFizzServerBrowser$1;
153
154// TODO: decide on the top-level export form.
155// This is hacky but makes it work with both Rollup and Jest
156var unstableFizz_browser = ReactDOMFizzServerBrowser$2.default || ReactDOMFizzServerBrowser$2;
157
158return unstableFizz_browser;
159
160})));