1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
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 = global || self, global.ReactDOMFizzServer = factory());
|
16 | }(this, (function () { 'use strict';
|
17 |
|
18 | function scheduleWork(callback) {
|
19 | callback();
|
20 | }
|
21 | function flushBuffered(destination) {
|
22 |
|
23 | }
|
24 | function writeChunk(destination, buffer) {
|
25 | destination.enqueue(buffer);
|
26 | return destination.desiredSize > 0;
|
27 | }
|
28 | function close(destination) {
|
29 | destination.close();
|
30 | }
|
31 | var textEncoder = new TextEncoder();
|
32 | function convertStringToBuffer(content) {
|
33 | return textEncoder.encode(content);
|
34 | }
|
35 |
|
36 | function formatChunkAsString(type, props) {
|
37 | var str = '<' + type + '>';
|
38 |
|
39 | if (typeof props.children === 'string') {
|
40 | str += props.children;
|
41 | }
|
42 |
|
43 | str += '</' + type + '>';
|
44 | return str;
|
45 | }
|
46 | function formatChunk(type, props) {
|
47 | return convertStringToBuffer(formatChunkAsString(type, props));
|
48 | }
|
49 |
|
50 |
|
51 |
|
52 | var hasSymbol = typeof Symbol === 'function' && Symbol.for;
|
53 | var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
|
54 |
|
55 | function createRequest(children, destination) {
|
56 | return {
|
57 | destination: destination,
|
58 | children: children,
|
59 | completedChunks: [],
|
60 | flowing: false
|
61 | };
|
62 | }
|
63 |
|
64 | function performWork(request) {
|
65 | var element = request.children;
|
66 | request.children = null;
|
67 |
|
68 | if (element && element.$$typeof !== REACT_ELEMENT_TYPE) {
|
69 | return;
|
70 | }
|
71 |
|
72 | var type = element.type;
|
73 | var props = element.props;
|
74 |
|
75 | if (typeof type !== 'string') {
|
76 | return;
|
77 | }
|
78 |
|
79 | request.completedChunks.push(formatChunk(type, props));
|
80 |
|
81 | if (request.flowing) {
|
82 | flushCompletedChunks(request);
|
83 | }
|
84 |
|
85 | flushBuffered(request.destination);
|
86 | }
|
87 |
|
88 | function flushCompletedChunks(request) {
|
89 | var destination = request.destination;
|
90 | var chunks = request.completedChunks;
|
91 | request.completedChunks = [];
|
92 |
|
93 | try {
|
94 | for (var i = 0; i < chunks.length; i++) {
|
95 | var chunk = chunks[i];
|
96 | writeChunk(destination, chunk);
|
97 | }
|
98 | } finally {
|
99 | }
|
100 |
|
101 | close(destination);
|
102 | }
|
103 |
|
104 | function startWork(request) {
|
105 | request.flowing = true;
|
106 | scheduleWork(function () {
|
107 | return performWork(request);
|
108 | });
|
109 | }
|
110 | function startFlowing(request) {
|
111 | request.flowing = false;
|
112 | flushCompletedChunks(request);
|
113 | }
|
114 |
|
115 | function renderToReadableStream(children) {
|
116 | var request;
|
117 | return new ReadableStream({
|
118 | start: function (controller) {
|
119 | request = createRequest(children, controller);
|
120 | startWork(request);
|
121 | },
|
122 | pull: function (controller) {
|
123 | startFlowing(request);
|
124 | },
|
125 | cancel: function (reason) {}
|
126 | });
|
127 | }
|
128 |
|
129 | var ReactDOMFizzServerBrowser = {
|
130 | renderToReadableStream: renderToReadableStream
|
131 | };
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 | var unstableFizz_browser = ReactDOMFizzServerBrowser.default || ReactDOMFizzServerBrowser;
|
138 |
|
139 | return unstableFizz_browser;
|
140 |
|
141 | })));
|