Dashboard sipadu mbip
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

react-dom-unstable-flight-client.development.js 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. /** @license React v16.12.0
  2. * react-dom-unstable-flight-client.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. var supportsBinaryStreams = true;
  14. function createStringDecoder() {
  15. return new TextDecoder();
  16. }
  17. var decoderOptions = {
  18. stream: true
  19. };
  20. function readPartialStringChunk(decoder, buffer) {
  21. return decoder.decode(buffer, decoderOptions);
  22. }
  23. function readFinalStringChunk(decoder, buffer) {
  24. return decoder.decode(buffer);
  25. }
  26. var PENDING = 0;
  27. var RESOLVED = 1;
  28. var ERRORED = 2;
  29. function createResponse(source) {
  30. var modelRoot = {};
  31. var rootChunk = createPendingChunk();
  32. definePendingProperty(modelRoot, 'model', rootChunk);
  33. var chunks = new Map();
  34. chunks.set(0, rootChunk);
  35. var response = {
  36. source: source,
  37. partialRow: '',
  38. modelRoot: modelRoot,
  39. chunks: chunks,
  40. fromJSON: function (key, value) {
  41. return parseFromJSON(response, this, key, value);
  42. }
  43. };
  44. if (supportsBinaryStreams) {
  45. response.stringDecoder = createStringDecoder();
  46. }
  47. return response;
  48. }
  49. function createPendingChunk() {
  50. var resolve = null;
  51. var promise = new Promise(function (r) {
  52. return resolve = r;
  53. });
  54. return {
  55. status: PENDING,
  56. value: promise,
  57. resolve: resolve
  58. };
  59. }
  60. function createErrorChunk(error) {
  61. return {
  62. status: ERRORED,
  63. value: error,
  64. resolve: null
  65. };
  66. }
  67. function triggerErrorOnChunk(chunk, error) {
  68. if (chunk.status !== PENDING) {
  69. // We already resolved. We didn't expect to see this.
  70. return;
  71. }
  72. var resolve = chunk.resolve;
  73. var erroredChunk = chunk;
  74. erroredChunk.status = ERRORED;
  75. erroredChunk.value = error;
  76. erroredChunk.resolve = null;
  77. resolve();
  78. }
  79. function createResolvedChunk(value) {
  80. return {
  81. status: RESOLVED,
  82. value: value,
  83. resolve: null
  84. };
  85. }
  86. function resolveChunk(chunk, value) {
  87. if (chunk.status !== PENDING) {
  88. // We already resolved. We didn't expect to see this.
  89. return;
  90. }
  91. var resolve = chunk.resolve;
  92. var resolvedChunk = chunk;
  93. resolvedChunk.status = RESOLVED;
  94. resolvedChunk.value = value;
  95. resolvedChunk.resolve = null;
  96. resolve();
  97. } // Report that any missing chunks in the model is now going to throw this
  98. // error upon read. Also notify any pending promises.
  99. function reportGlobalError(response, error) {
  100. response.chunks.forEach(function (chunk) {
  101. // If this chunk was already resolved or errored, it won't
  102. // trigger an error but if it wasn't then we need to
  103. // because we won't be getting any new data to resolve it.
  104. triggerErrorOnChunk(chunk, error);
  105. });
  106. }
  107. function definePendingProperty(object, key, chunk) {
  108. Object.defineProperty(object, key, {
  109. configurable: false,
  110. enumerable: true,
  111. get: function () {
  112. if (chunk.status === RESOLVED) {
  113. return chunk.value;
  114. } else {
  115. throw chunk.value;
  116. }
  117. }
  118. });
  119. }
  120. function parseFromJSON(response, targetObj, key, value) {
  121. if (typeof value === 'string' && value[0] === '$') {
  122. if (value[1] === '$') {
  123. // This was an escaped string value.
  124. return value.substring(1);
  125. } else {
  126. var id = parseInt(value.substring(1), 16);
  127. var chunks = response.chunks;
  128. var chunk = chunks.get(id);
  129. if (!chunk) {
  130. chunk = createPendingChunk();
  131. chunks.set(id, chunk);
  132. } else if (chunk.status === RESOLVED) {
  133. return chunk.value;
  134. }
  135. definePendingProperty(targetObj, key, chunk);
  136. return undefined;
  137. }
  138. }
  139. return value;
  140. }
  141. function resolveJSONRow(response, id, json) {
  142. var model = JSON.parse(json, response.fromJSON);
  143. var chunks = response.chunks;
  144. var chunk = chunks.get(id);
  145. if (!chunk) {
  146. chunks.set(id, createResolvedChunk(model));
  147. } else {
  148. resolveChunk(chunk, model);
  149. }
  150. }
  151. function processFullRow(response, row) {
  152. if (row === '') {
  153. return;
  154. }
  155. var tag = row[0];
  156. switch (tag) {
  157. case 'J':
  158. {
  159. var colon = row.indexOf(':', 1);
  160. var id = parseInt(row.substring(1, colon), 16);
  161. var json = row.substring(colon + 1);
  162. resolveJSONRow(response, id, json);
  163. return;
  164. }
  165. case 'E':
  166. {
  167. var _colon = row.indexOf(':', 1);
  168. var _id = parseInt(row.substring(1, _colon), 16);
  169. var _json = row.substring(_colon + 1);
  170. var errorInfo = JSON.parse(_json);
  171. var error = new Error(errorInfo.message);
  172. error.stack = errorInfo.stack;
  173. var chunks = response.chunks;
  174. var chunk = chunks.get(_id);
  175. if (!chunk) {
  176. chunks.set(_id, createErrorChunk(error));
  177. } else {
  178. triggerErrorOnChunk(chunk, error);
  179. }
  180. return;
  181. }
  182. default:
  183. {
  184. // Assume this is the root model.
  185. resolveJSONRow(response, 0, row);
  186. return;
  187. }
  188. }
  189. }
  190. function processStringChunk(response, chunk, offset) {
  191. var linebreak = chunk.indexOf('\n', offset);
  192. while (linebreak > -1) {
  193. var fullrow = response.partialRow + chunk.substring(offset, linebreak);
  194. processFullRow(response, fullrow);
  195. response.partialRow = '';
  196. offset = linebreak + 1;
  197. linebreak = chunk.indexOf('\n', offset);
  198. }
  199. response.partialRow += chunk.substring(offset);
  200. }
  201. function processBinaryChunk(response, chunk) {
  202. if (!supportsBinaryStreams) {
  203. throw new Error("This environment don't support binary chunks.");
  204. }
  205. var stringDecoder = response.stringDecoder;
  206. var linebreak = chunk.indexOf(10); // newline
  207. while (linebreak > -1) {
  208. var fullrow = response.partialRow + readFinalStringChunk(stringDecoder, chunk.subarray(0, linebreak));
  209. processFullRow(response, fullrow);
  210. response.partialRow = '';
  211. chunk = chunk.subarray(linebreak + 1);
  212. linebreak = chunk.indexOf(10); // newline
  213. }
  214. response.partialRow += readPartialStringChunk(stringDecoder, chunk);
  215. }
  216. function complete(response) {
  217. // In case there are any remaining unresolved chunks, they won't
  218. // be resolved now. So we need to issue an error to those.
  219. // Ideally we should be able to early bail out if we kept a
  220. // ref count of pending chunks.
  221. reportGlobalError(response, new Error('Connection closed.'));
  222. }
  223. function getModelRoot(response) {
  224. return response.modelRoot;
  225. }
  226. // This file intentionally does *not* have the Flow annotation.
  227. // Don't add it. See `./inline-typed.js` for an explanation.
  228. function startReadingFromStream(response, stream) {
  229. var reader = stream.getReader();
  230. function progress(_ref) {
  231. var done = _ref.done,
  232. value = _ref.value;
  233. if (done) {
  234. complete(response);
  235. return;
  236. }
  237. var buffer = value;
  238. processBinaryChunk(response, buffer);
  239. return reader.read().then(progress, error);
  240. }
  241. function error(e) {
  242. reportGlobalError(response, e);
  243. }
  244. reader.read().then(progress, error);
  245. }
  246. function readFromReadableStream(stream) {
  247. var response = createResponse(stream);
  248. startReadingFromStream(response, stream);
  249. return getModelRoot(response);
  250. }
  251. function readFromFetch(promiseForResponse) {
  252. var response = createResponse(promiseForResponse);
  253. promiseForResponse.then(function (r) {
  254. startReadingFromStream(response, r.body);
  255. }, function (e) {
  256. reportGlobalError(response, e);
  257. });
  258. return getModelRoot(response);
  259. }
  260. function readFromXHR(request) {
  261. var response = createResponse(request);
  262. var processedLength = 0;
  263. function progress(e) {
  264. var chunk = request.responseText;
  265. processStringChunk(response, chunk, processedLength);
  266. processedLength = chunk.length;
  267. }
  268. function load(e) {
  269. progress(e);
  270. complete(response);
  271. }
  272. function error(e) {
  273. reportGlobalError(response, new TypeError('Network error'));
  274. }
  275. request.addEventListener('progress', progress);
  276. request.addEventListener('load', load);
  277. request.addEventListener('error', error);
  278. request.addEventListener('abort', error);
  279. request.addEventListener('timeout', error);
  280. return getModelRoot(response);
  281. }
  282. var ReactFlightDOMClient = {
  283. readFromXHR: readFromXHR,
  284. readFromFetch: readFromFetch,
  285. readFromReadableStream: readFromReadableStream
  286. };
  287. var ReactFlightDOMClient$1 = Object.freeze({
  288. default: ReactFlightDOMClient
  289. });
  290. var ReactFlightDOMClient$2 = ( ReactFlightDOMClient$1 && ReactFlightDOMClient ) || ReactFlightDOMClient$1;
  291. // TODO: decide on the top-level export form.
  292. // This is hacky but makes it work with both Rollup and Jest
  293. var unstableFlightClient = ReactFlightDOMClient$2.default || ReactFlightDOMClient$2;
  294. module.exports = unstableFlightClient;
  295. })();
  296. }