react-dom-unstable-fizz.browser.development.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /** @license React v16.13.1
  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. 'use strict';
  10. if (process.env.NODE_ENV !== "production") {
  11. (function() {
  12. 'use strict';
  13. function scheduleWork(callback) {
  14. callback();
  15. }
  16. function flushBuffered(destination) {// WHATWG Streams do not yet have a way to flush the underlying
  17. // transform streams. https://github.com/whatwg/streams/issues/960
  18. }
  19. function writeChunk(destination, buffer) {
  20. destination.enqueue(buffer);
  21. return destination.desiredSize > 0;
  22. }
  23. function close(destination) {
  24. destination.close();
  25. }
  26. var textEncoder = new TextEncoder();
  27. function convertStringToBuffer(content) {
  28. return textEncoder.encode(content);
  29. }
  30. function formatChunkAsString(type, props) {
  31. var str = '<' + type + '>';
  32. if (typeof props.children === 'string') {
  33. str += props.children;
  34. }
  35. str += '</' + type + '>';
  36. return str;
  37. }
  38. function formatChunk(type, props) {
  39. return convertStringToBuffer(formatChunkAsString(type, props));
  40. }
  41. // The Symbol used to tag the ReactElement-like types. If there is no native Symbol
  42. // nor polyfill, then a plain number is used for performance.
  43. var hasSymbol = typeof Symbol === 'function' && Symbol.for;
  44. var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
  45. function createRequest(children, destination) {
  46. return {
  47. destination: destination,
  48. children: children,
  49. completedChunks: [],
  50. flowing: false
  51. };
  52. }
  53. function performWork(request) {
  54. var element = request.children;
  55. request.children = null;
  56. if (element && element.$$typeof !== REACT_ELEMENT_TYPE) {
  57. return;
  58. }
  59. var type = element.type;
  60. var props = element.props;
  61. if (typeof type !== 'string') {
  62. return;
  63. }
  64. request.completedChunks.push(formatChunk(type, props));
  65. if (request.flowing) {
  66. flushCompletedChunks(request);
  67. }
  68. flushBuffered(request.destination);
  69. }
  70. function flushCompletedChunks(request) {
  71. var destination = request.destination;
  72. var chunks = request.completedChunks;
  73. request.completedChunks = [];
  74. try {
  75. for (var i = 0; i < chunks.length; i++) {
  76. var chunk = chunks[i];
  77. writeChunk(destination, chunk);
  78. }
  79. } finally {
  80. }
  81. close(destination);
  82. }
  83. function startWork(request) {
  84. request.flowing = true;
  85. scheduleWork(function () {
  86. return performWork(request);
  87. });
  88. }
  89. function startFlowing(request) {
  90. request.flowing = false;
  91. flushCompletedChunks(request);
  92. }
  93. function renderToReadableStream(children) {
  94. var request;
  95. return new ReadableStream({
  96. start: function (controller) {
  97. request = createRequest(children, controller);
  98. startWork(request);
  99. },
  100. pull: function (controller) {
  101. startFlowing(request);
  102. },
  103. cancel: function (reason) {}
  104. });
  105. }
  106. var ReactDOMFizzServerBrowser = {
  107. renderToReadableStream: renderToReadableStream
  108. };
  109. // TODO: decide on the top-level export form.
  110. // This is hacky but makes it work with both Rollup and Jest
  111. var unstableFizz_browser = ReactDOMFizzServerBrowser.default || ReactDOMFizzServerBrowser;
  112. module.exports = unstableFizz_browser;
  113. })();
  114. }