165
status: 'pending',
166
value: null | Array<(T) => mixed>,
167
reason: null | Array<(mixed) => mixed>,
168
- _response: Response,
168
_children: Array<SomeChunk<any>> | ProfilingResult, // Profiling-only
169
_debugInfo?: null | ReactDebugInfo, // DEV-only
170
then(resolve: (T) => mixed, reject?: (mixed) => mixed): void,
173
status: 'blocked',
174
value: null | Array<(T) => mixed>,
175
reason: null | Array<(mixed) => mixed>,
177
- _response: Response,
176
_children: Array<SomeChunk<any>> | ProfilingResult, // Profiling-only
177
_debugInfo?: null | ReactDebugInfo, // DEV-only
178
then(resolve: (T) => mixed, reject?: (mixed) => mixed): void,
180
type ResolvedModelChunk<T> = {
181
status: 'resolved_model',
182
value: UninitializedModel,
185
- reason: null,
186
- _response: Response,
183
+ reason: Response,
184
_children: Array<SomeChunk<any>> | ProfilingResult, // Profiling-only
185
_debugInfo?: null | ReactDebugInfo, // DEV-only
186
then(resolve: (T) => mixed, reject?: (mixed) => mixed): void,
189
status: 'resolved_module',
190
value: ClientReference<T>,
191
reason: null,
195
- _response: Response,
192
_children: Array<SomeChunk<any>> | ProfilingResult, // Profiling-only
193
_debugInfo?: null | ReactDebugInfo, // DEV-only
194
then(resolve: (T) => mixed, reject?: (mixed) => mixed): void,
197
status: 'fulfilled',
198
value: T,
199
reason: null | FlightStreamController,
204
- _response: Response,
200
_children: Array<SomeChunk<any>> | ProfilingResult, // Profiling-only
201
_debugInfo?: null | ReactDebugInfo, // DEV-only
202
then(resolve: (T) => mixed, reject?: (mixed) => mixed): void,
207
status: 'fulfilled',
208
value: T,
209
reason: FlightStreamController,
215
- _response: Response,
210
_children: Array<SomeChunk<any>> | ProfilingResult, // Profiling-only
211
_debugInfo?: null | ReactDebugInfo, // DEV-only
212
then(resolve: (ReadableStream) => mixed, reject?: (mixed) => mixed): void,
215
status: 'rejected',
216
value: null,
217
reason: mixed,
224
- _response: Response,
218
_children: Array<SomeChunk<any>> | ProfilingResult, // Profiling-only
219
_debugInfo?: null | ReactDebugInfo, // DEV-only
220
then(resolve: (T) => mixed, reject?: (mixed) => mixed): void,
223
status: 'halted',
224
value: null,
225
reason: null,
233
- _response: Response,
226
_children: Array<SomeChunk<any>> | ProfilingResult, // Profiling-only
227
_debugInfo?: null | ReactDebugInfo, // DEV-only
228
then(resolve: (T) => mixed, reject?: (mixed) => mixed): void,
237
| HaltedChunk<T>;
238
239
// $FlowFixMe[missing-this-annot]
248
-function ReactPromise(
249
- status: any,
250
- value: any,
251
- reason: any,
252
- response: Response,
253
-) {
240
+function ReactPromise(status: any, value: any, reason: any) {
241
this.status = status;
242
this.value = value;
243
this.reason = reason;
257
- this._response = response;
244
if (enableProfilerTimer && enableComponentPerformanceTrack) {
245
this._children = [];
246
}
387
388
function createPendingChunk<T>(response: Response): PendingChunk<T> {
389
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
404
- return new ReactPromise(PENDING, null, null, response);
390
+ return new ReactPromise(PENDING, null, null);
391
}
392
393
function createBlockedChunk<T>(response: Response): BlockedChunk<T> {
394
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
409
- return new ReactPromise(BLOCKED, null, null, response);
395
+ return new ReactPromise(BLOCKED, null, null);
396
}
397
398
function createErrorChunk<T>(
400
error: mixed,
401
): ErroredChunk<T> {
402
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
417
- return new ReactPromise(ERRORED, null, error, response);
403
+ return new ReactPromise(ERRORED, null, error);
404
}
405
406
function wakeChunk<T>(listeners: Array<(T) => mixed>, value: T): void {
472
value: UninitializedModel,
473
): ResolvedModelChunk<T> {
474
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
489
- return new ReactPromise(RESOLVED_MODEL, value, null, response);
475
+ return new ReactPromise(RESOLVED_MODEL, value, response);
476
}
477
478
function createResolvedModuleChunk<T>(
480
value: ClientReference<T>,
481
): ResolvedModuleChunk<T> {
482
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
497
- return new ReactPromise(RESOLVED_MODULE, value, null, response);
483
+ return new ReactPromise(RESOLVED_MODULE, value, null);
484
}
485
486
function createInitializedTextChunk(
488
value: string,
489
): InitializedChunk<string> {
490
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
505
- return new ReactPromise(INITIALIZED, value, null, response);
491
+ return new ReactPromise(INITIALIZED, value, null);
492
}
493
494
function createInitializedBufferChunk(
496
value: $ArrayBufferView | ArrayBuffer,
497
): InitializedChunk<Uint8Array> {
498
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
513
- return new ReactPromise(INITIALIZED, value, null, response);
499
+ return new ReactPromise(INITIALIZED, value, null);
500
}
501
502
function createInitializedIteratorResultChunk<T>(
505
done: boolean,
506
): InitializedChunk<IteratorResult<T, T>> {
507
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
522
- return new ReactPromise(
523
- INITIALIZED,
524
- {done: done, value: value},
525
- null,
526
- response,
527
- );
508
+ return new ReactPromise(INITIALIZED, {done: done, value: value}, null);
509
}
510
511
function createInitializedStreamChunk<
518
// We use the reason field to stash the controller since we already have that
519
// field. It's a bit of a hack but efficient.
520
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
540
- return new ReactPromise(INITIALIZED, value, controller, response);
521
+ return new ReactPromise(INITIALIZED, value, controller);
522
}
523
524
function createResolvedIteratorResultChunk<T>(
530
const iteratorResultJSON =
531
(done ? '{"done":true,"value":' : '{"done":false,"value":') + value + '}';
532
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
552
- return new ReactPromise(RESOLVED_MODEL, iteratorResultJSON, null, response);
533
+ return new ReactPromise(RESOLVED_MODEL, iteratorResultJSON, response);
534
}
535
536
function resolveIteratorResultChunk<T>(
537
+ response: Response,
538
chunk: SomeChunk<IteratorResult<T, T>>,
539
value: UninitializedModel,
540
done: boolean,
542
// To reuse code as much code as possible we add the wrapper element as part of the JSON.
543
const iteratorResultJSON =
544
(done ? '{"done":true,"value":' : '{"done":false,"value":') + value + '}';
563
- resolveModelChunk(chunk, iteratorResultJSON);
545
+ resolveModelChunk(response, chunk, iteratorResultJSON);
546
}
547
548
function resolveModelChunk<T>(
549
+ response: Response,
550
chunk: SomeChunk<T>,
551
value: UninitializedModel,
552
): void {
563
const resolvedChunk: ResolvedModelChunk<T> = (chunk: any);
564
resolvedChunk.status = RESOLVED_MODEL;
565
resolvedChunk.value = value;
566
+ resolvedChunk.reason = response;
567
if (resolveListeners !== null) {
568
// This is unfortunate that we're reading this eagerly if
569
// we already have listeners attached since they might no
609
initializingHandler = null;
610
611
const resolvedModel = chunk.value;
612
+ const response = chunk.reason;
613
614
// We go to the BLOCKED state until we've fully resolved this.
615
// We do this before parsing in case we try to initialize the same chunk
624
}
625
626
try {
642
- const value: T = parseModel(chunk._response, resolvedModel);
627
+ const value: T = parseModel(response, resolvedModel);
628
// Invoke any listeners added while resolving this model. I.e. cyclic
629
// references. This may or may not fully resolve the model depending on
630
// if they were blocked.
1847
if (!chunk) {
1848
chunks.set(id, createResolvedModelChunk(response, model));
1849
} else {
1865
- resolveModelChunk(chunk, model);
1850
+ resolveModelChunk(response, chunk, model);
1851
}
1852
}
1853
2021
// to synchronous emitting.
2022
previousBlockedChunk = null;
2023
}
2039
- resolveModelChunk(chunk, json);
2024
+ resolveModelChunk(response, chunk, json);
2025
});
2026
}
2027
},
2109
false,
2110
);
2111
} else {
2127
- resolveIteratorResultChunk(buffer[nextWriteIndex], value, false);
2112
+ resolveIteratorResultChunk(
2113
+ response,
2114
+ buffer[nextWriteIndex],
2115
+ value,
2116
+ false,
2117
+ );
2118
}
2119
nextWriteIndex++;
2120
},
2127
true,
2128
);
2129
} else {
2140
- resolveIteratorResultChunk(buffer[nextWriteIndex], value, true);
2130
+ resolveIteratorResultChunk(
2131
+ response,
2132
+ buffer[nextWriteIndex],
2133
+ value,
2134
+ true,
2135
+ );
2136
}
2137
nextWriteIndex++;
2138
while (nextWriteIndex < buffer.length) {
2139
// In generators, any extra reads from the iterator have the value undefined.
2140
resolveIteratorResultChunk(
2141
+ response,
2142
buffer[nextWriteIndex++],
2143
'"$undefined"',
2144
true,
2174
INITIALIZED,
2175
{done: true, value: undefined},
2176
null,
2181
- response,
2177
);
2178
}
2179
buffer[nextReadIndex] =
2941
chunks.set(id, chunk);
2942
initializeModelChunk(chunk);
2943
} else {
2949
- resolveModelChunk(chunk, model);
2944
+ resolveModelChunk(response, chunk, model);
2945
if (chunk.status === RESOLVED_MODEL) {
2946
initializeModelChunk(chunk);
2947
}