@@ -191,7 +191,12 @@ type SomeChunk<T> =
191
191
| ErroredChunk<T>;
192
192
193
193
// $FlowFixMe[missing-this-annot]
194
- function Chunk(status: any, value: any, reason: any, response: Response) {
194
+ function ReactPromise(
195
+ status: any,
196
+ value: any,
197
+ reason: any,
198
+ response: Response,
199
+ ) {
195
200
this.status = status;
196
201
this.value = value;
197
202
this.reason = reason;
@@ -201,9 +206,9 @@ function Chunk(status: any, value: any, reason: any, response: Response) {
201
206
}
202
207
}
203
208
// We subclass Promise.prototype so that we get other methods like .catch
204
- Chunk .prototype = (Object.create(Promise.prototype): any);
209
+ ReactPromise .prototype = (Object.create(Promise.prototype): any);
205
210
// TODO: This doesn't return a new Promise chain unlike the real .then
206
- Chunk .prototype.then = function <T>(
211
+ ReactPromise .prototype.then = function <T>(
207
212
this: SomeChunk<T>,
208
213
resolve: (value: T) => mixed,
209
214
reject?: (reason: mixed) => mixed,
@@ -304,20 +309,20 @@ export function getRoot<T>(response: Response): Thenable<T> {
304
309
305
310
function createPendingChunk<T>(response: Response): PendingChunk<T> {
306
311
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
307
- return new Chunk (PENDING, null, null, response);
312
+ return new ReactPromise (PENDING, null, null, response);
308
313
}
309
314
310
315
function createBlockedChunk<T>(response: Response): BlockedChunk<T> {
311
316
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
312
- return new Chunk (BLOCKED, null, null, response);
317
+ return new ReactPromise (BLOCKED, null, null, response);
313
318
}
314
319
315
320
function createErrorChunk<T>(
316
321
response: Response,
317
322
error: Error | Postpone,
318
323
): ErroredChunk<T> {
319
324
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
320
- return new Chunk (ERRORED, null, error, response);
325
+ return new ReactPromise (ERRORED, null, error, response);
321
326
}
322
327
323
328
function wakeChunk<T>(listeners: Array<(T) => mixed>, value: T): void {
@@ -391,31 +396,31 @@ function createResolvedModelChunk<T>(
391
396
value: UninitializedModel,
392
397
): ResolvedModelChunk<T> {
393
398
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
394
- return new Chunk (RESOLVED_MODEL, value, null, response);
399
+ return new ReactPromise (RESOLVED_MODEL, value, null, response);
395
400
}
396
401
397
402
function createResolvedModuleChunk<T>(
398
403
response: Response,
399
404
value: ClientReference<T>,
400
405
): ResolvedModuleChunk<T> {
401
406
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
402
- return new Chunk (RESOLVED_MODULE, value, null, response);
407
+ return new ReactPromise (RESOLVED_MODULE, value, null, response);
403
408
}
404
409
405
410
function createInitializedTextChunk(
406
411
response: Response,
407
412
value: string,
408
413
): InitializedChunk<string> {
409
414
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
410
- return new Chunk (INITIALIZED, value, null, response);
415
+ return new ReactPromise (INITIALIZED, value, null, response);
411
416
}
412
417
413
418
function createInitializedBufferChunk(
414
419
response: Response,
415
420
value: $ArrayBufferView | ArrayBuffer,
416
421
): InitializedChunk<Uint8Array> {
417
422
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
418
- return new Chunk (INITIALIZED, value, null, response);
423
+ return new ReactPromise (INITIALIZED, value, null, response);
419
424
}
420
425
421
426
function createInitializedIteratorResultChunk<T>(
@@ -424,7 +429,12 @@ function createInitializedIteratorResultChunk<T>(
424
429
done: boolean,
425
430
): InitializedChunk<IteratorResult<T, T>> {
426
431
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
427
- return new Chunk(INITIALIZED, {done: done, value: value}, null, response);
432
+ return new ReactPromise(
433
+ INITIALIZED,
434
+ {done: done, value: value},
435
+ null,
436
+ response,
437
+ );
428
438
}
429
439
430
440
function createInitializedStreamChunk<
@@ -437,7 +447,7 @@ function createInitializedStreamChunk<
437
447
// We use the reason field to stash the controller since we already have that
438
448
// field. It's a bit of a hack but efficient.
439
449
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
440
- return new Chunk (INITIALIZED, value, controller, response);
450
+ return new ReactPromise (INITIALIZED, value, controller, response);
441
451
}
442
452
443
453
function createResolvedIteratorResultChunk<T>(
@@ -449,7 +459,7 @@ function createResolvedIteratorResultChunk<T>(
449
459
const iteratorResultJSON =
450
460
(done ? '{"done":true,"value":' : '{"done":false,"value":') + value + '}';
451
461
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
452
- return new Chunk (RESOLVED_MODEL, iteratorResultJSON, null, response);
462
+ return new ReactPromise (RESOLVED_MODEL, iteratorResultJSON, null, response);
453
463
}
454
464
455
465
function resolveIteratorResultChunk<T>(
@@ -1761,7 +1771,7 @@ function startAsyncIterable<T>(
1761
1771
if (nextReadIndex === buffer.length) {
1762
1772
if (closed) {
1763
1773
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
1764
- return new Chunk (
1774
+ return new ReactPromise (
1765
1775
INITIALIZED,
1766
1776
{done: true, value: undefined},
1767
1777
null,
0 commit comments