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