react-dom-unstable-fizz.node.development.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. 'use strict';
  10. if (process.env.NODE_ENV !== "production") {
  11. (function() {
  12. 'use strict';
  13. function scheduleWork(callback) {
  14. setImmediate(callback);
  15. }
  16. function flushBuffered(destination) {
  17. // If we don't have any more data to send right now.
  18. // Flush whatever is in the buffer to the wire.
  19. if (typeof destination.flush === 'function') {
  20. // http.createServer response have flush(), but it has a different meaning and
  21. // is deprecated in favor of flushHeaders(). Detect to avoid a warning.
  22. if (typeof destination.flushHeaders !== 'function') {
  23. // By convention the Zlib streams provide a flush function for this purpose.
  24. destination.flush();
  25. }
  26. }
  27. }
  28. function beginWriting(destination) {
  29. // Older Node streams like http.createServer don't have this.
  30. if (typeof destination.cork === 'function') {
  31. destination.cork();
  32. }
  33. }
  34. function writeChunk(destination, buffer) {
  35. var nodeBuffer = buffer; // close enough
  36. return destination.write(nodeBuffer);
  37. }
  38. function completeWriting(destination) {
  39. // Older Node streams like http.createServer don't have this.
  40. if (typeof destination.uncork === 'function') {
  41. destination.uncork();
  42. }
  43. }
  44. function close(destination) {
  45. destination.end();
  46. }
  47. function convertStringToBuffer(content) {
  48. return Buffer.from(content, 'utf8');
  49. }
  50. function formatChunkAsString(type, props) {
  51. var str = '<' + type + '>';
  52. if (typeof props.children === 'string') {
  53. str += props.children;
  54. }
  55. str += '</' + type + '>';
  56. return str;
  57. }
  58. function formatChunk(type, props) {
  59. return convertStringToBuffer(formatChunkAsString(type, props));
  60. }
  61. // The Symbol used to tag the ReactElement-like types. If there is no native Symbol
  62. // nor polyfill, then a plain number is used for performance.
  63. var hasSymbol = typeof Symbol === 'function' && Symbol.for;
  64. var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
  65. function createRequest(children, destination) {
  66. return {
  67. destination: destination,
  68. children: children,
  69. completedChunks: [],
  70. flowing: false
  71. };
  72. }
  73. function performWork(request) {
  74. var element = request.children;
  75. request.children = null;
  76. if (element && element.$$typeof !== REACT_ELEMENT_TYPE) {
  77. return;
  78. }
  79. var type = element.type;
  80. var props = element.props;
  81. if (typeof type !== 'string') {
  82. return;
  83. }
  84. request.completedChunks.push(formatChunk(type, props));
  85. if (request.flowing) {
  86. flushCompletedChunks(request);
  87. }
  88. flushBuffered(request.destination);
  89. }
  90. function flushCompletedChunks(request) {
  91. var destination = request.destination;
  92. var chunks = request.completedChunks;
  93. request.completedChunks = [];
  94. beginWriting(destination);
  95. try {
  96. for (var i = 0; i < chunks.length; i++) {
  97. var chunk = chunks[i];
  98. writeChunk(destination, chunk);
  99. }
  100. } finally {
  101. completeWriting(destination);
  102. }
  103. close(destination);
  104. }
  105. function startWork(request) {
  106. request.flowing = true;
  107. scheduleWork(function () {
  108. return performWork(request);
  109. });
  110. }
  111. function startFlowing(request) {
  112. request.flowing = false;
  113. flushCompletedChunks(request);
  114. }
  115. function createDrainHandler(destination, request) {
  116. return function () {
  117. return startFlowing(request);
  118. };
  119. }
  120. function pipeToNodeWritable(children, destination) {
  121. var request = createRequest(children, destination);
  122. destination.on('drain', createDrainHandler(destination, request));
  123. startWork(request);
  124. }
  125. var ReactDOMFizzServerNode = {
  126. pipeToNodeWritable: pipeToNodeWritable
  127. };
  128. // TODO: decide on the top-level export form.
  129. // This is hacky but makes it work with both Rollup and Jest
  130. var unstableFizz_node = ReactDOMFizzServerNode.default || ReactDOMFizzServerNode;
  131. module.exports = unstableFizz_node;
  132. })();
  133. }