Projekt

Obecné

Profil

Stáhnout (3.92 KB) Statistiky
| Větev: | Revize:
1
/** @license React v16.13.1
2
 * react-dom-unstable-fizz.node.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

    
14
if (process.env.NODE_ENV !== "production") {
15
  (function() {
16
'use strict';
17

    
18
function scheduleWork(callback) {
19
  setImmediate(callback);
20
}
21
function flushBuffered(destination) {
22
  // If we don't have any more data to send right now.
23
  // Flush whatever is in the buffer to the wire.
24
  if (typeof destination.flush === 'function') {
25
    // http.createServer response have flush(), but it has a different meaning and
26
    // is deprecated in favor of flushHeaders(). Detect to avoid a warning.
27
    if (typeof destination.flushHeaders !== 'function') {
28
      // By convention the Zlib streams provide a flush function for this purpose.
29
      destination.flush();
30
    }
31
  }
32
}
33
function beginWriting(destination) {
34
  // Older Node streams like http.createServer don't have this.
35
  if (typeof destination.cork === 'function') {
36
    destination.cork();
37
  }
38
}
39
function writeChunk(destination, buffer) {
40
  var nodeBuffer = buffer; // close enough
41

    
42
  return destination.write(nodeBuffer);
43
}
44
function completeWriting(destination) {
45
  // Older Node streams like http.createServer don't have this.
46
  if (typeof destination.uncork === 'function') {
47
    destination.uncork();
48
  }
49
}
50
function close(destination) {
51
  destination.end();
52
}
53
function convertStringToBuffer(content) {
54
  return Buffer.from(content, 'utf8');
55
}
56

    
57
function formatChunkAsString(type, props) {
58
  var str = '<' + type + '>';
59

    
60
  if (typeof props.children === 'string') {
61
    str += props.children;
62
  }
63

    
64
  str += '</' + type + '>';
65
  return str;
66
}
67
function formatChunk(type, props) {
68
  return convertStringToBuffer(formatChunkAsString(type, props));
69
}
70

    
71
// The Symbol used to tag the ReactElement-like types. If there is no native Symbol
72
// nor polyfill, then a plain number is used for performance.
73
var hasSymbol = typeof Symbol === 'function' && Symbol.for;
74
var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
75

    
76
function createRequest(children, destination) {
77
  return {
78
    destination: destination,
79
    children: children,
80
    completedChunks: [],
81
    flowing: false
82
  };
83
}
84

    
85
function performWork(request) {
86
  var element = request.children;
87
  request.children = null;
88

    
89
  if (element && element.$$typeof !== REACT_ELEMENT_TYPE) {
90
    return;
91
  }
92

    
93
  var type = element.type;
94
  var props = element.props;
95

    
96
  if (typeof type !== 'string') {
97
    return;
98
  }
99

    
100
  request.completedChunks.push(formatChunk(type, props));
101

    
102
  if (request.flowing) {
103
    flushCompletedChunks(request);
104
  }
105

    
106
  flushBuffered(request.destination);
107
}
108

    
109
function flushCompletedChunks(request) {
110
  var destination = request.destination;
111
  var chunks = request.completedChunks;
112
  request.completedChunks = [];
113
  beginWriting(destination);
114

    
115
  try {
116
    for (var i = 0; i < chunks.length; i++) {
117
      var chunk = chunks[i];
118
      writeChunk(destination, chunk);
119
    }
120
  } finally {
121
    completeWriting(destination);
122
  }
123

    
124
  close(destination);
125
}
126

    
127
function startWork(request) {
128
  request.flowing = true;
129
  scheduleWork(function () {
130
    return performWork(request);
131
  });
132
}
133
function startFlowing(request) {
134
  request.flowing = false;
135
  flushCompletedChunks(request);
136
}
137

    
138
function createDrainHandler(destination, request) {
139
  return function () {
140
    return startFlowing(request);
141
  };
142
}
143

    
144
function pipeToNodeWritable(children, destination) {
145
  var request = createRequest(children, destination);
146
  destination.on('drain', createDrainHandler(destination, request));
147
  startWork(request);
148
}
149

    
150
var ReactDOMFizzServerNode = {
151
  pipeToNodeWritable: pipeToNodeWritable
152
};
153

    
154
// TODO: decide on the top-level export form.
155
// This is hacky but makes it work with both Rollup and Jest
156

    
157

    
158
var unstableFizz_node = ReactDOMFizzServerNode.default || ReactDOMFizzServerNode;
159

    
160
module.exports = unstableFizz_node;
161
  })();
162
}
(9-9/15)