Skip to content

Commit 239b106

Browse files
committed
Clean up inconsistent naming in Flight implementation, part 2
After `ReactModel` has been renamed to `ReactClientValue` in facebook#26351, I think we should also rename the params, variables and functions that handle this type accordingly from `model` to `value`.
1 parent e5a69af commit 239b106

23 files changed

+212
-209
lines changed

fixtures/flight-browser/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ <h1>Flight Example</h1>
5555
return 'Title';
5656
}
5757

58-
let model = {
58+
let value = {
5959
title: <Title />,
6060
content: <HTML />,
6161
};
6262

63-
let stream = ReactServerDOMServer.renderToReadableStream(model);
63+
let stream = ReactServerDOMServer.renderToReadableStream(value);
6464
let response = new Response(stream, {
6565
headers: {'Content-Type': 'text/html'},
6666
});
@@ -83,12 +83,12 @@ <h1>Flight Example</h1>
8383
}
8484

8585
function Shell({ data }) {
86-
let model = React.use(data);
86+
let value = React.use(data);
8787
return <div>
8888
<Suspense fallback="...">
89-
<h1>{model.title}</h1>
89+
<h1>{value.title}</h1>
9090
</Suspense>
91-
{model.content}
91+
{value.content}
9292
</div>;
9393
}
9494

packages/react-client/src/ReactFlightClient.js

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {LazyComponent} from 'react/src/ReactLazy';
1313
import type {
1414
ClientReference,
1515
ClientReferenceMetadata,
16-
UninitializedModel,
16+
UninitializedValue,
1717
Response,
1818
SSRManifest,
1919
} from './ReactFlightClientHostConfig';
@@ -22,7 +22,7 @@ import {
2222
resolveClientReference,
2323
preloadModule,
2424
requireModule,
25-
parseModel,
25+
parseValue,
2626
} from './ReactFlightClientHostConfig';
2727

2828
import {REACT_LAZY_TYPE, REACT_ELEMENT_TYPE} from 'shared/ReactSymbols';
@@ -41,7 +41,7 @@ export type JSONValue =
4141

4242
const PENDING = 'pending';
4343
const BLOCKED = 'blocked';
44-
const RESOLVED_MODEL = 'resolved_model';
44+
const RESOLVED_VALUE = 'resolved_value';
4545
const RESOLVED_MODULE = 'resolved_module';
4646
const INITIALIZED = 'fulfilled';
4747
const ERRORED = 'rejected';
@@ -60,9 +60,9 @@ type BlockedChunk<T> = {
6060
_response: Response,
6161
then(resolve: (T) => mixed, reject: (mixed) => mixed): void,
6262
};
63-
type ResolvedModelChunk<T> = {
64-
status: 'resolved_model',
65-
value: UninitializedModel,
63+
type ResolvedValueChunk<T> = {
64+
status: 'resolved_value',
65+
value: UninitializedValue,
6666
reason: null,
6767
_response: Response,
6868
then(resolve: (T) => mixed, reject: (mixed) => mixed): void,
@@ -91,7 +91,7 @@ type ErroredChunk<T> = {
9191
type SomeChunk<T> =
9292
| PendingChunk<T>
9393
| BlockedChunk<T>
94-
| ResolvedModelChunk<T>
94+
| ResolvedValueChunk<T>
9595
| ResolvedModuleChunk<T>
9696
| InitializedChunk<T>
9797
| ErroredChunk<T>;
@@ -115,8 +115,8 @@ Chunk.prototype.then = function <T>(
115115
// If we have resolved content, we try to initialize it first which
116116
// might put us back into one of the other states.
117117
switch (chunk.status) {
118-
case RESOLVED_MODEL:
119-
initializeModelChunk(chunk);
118+
case RESOLVED_VALUE:
119+
initializeValueChunk(chunk);
120120
break;
121121
case RESOLVED_MODULE:
122122
initializeModuleChunk(chunk);
@@ -161,8 +161,8 @@ function readChunk<T>(chunk: SomeChunk<T>): T {
161161
// If we have resolved content, we try to initialize it first which
162162
// might put us back into one of the other states.
163163
switch (chunk.status) {
164-
case RESOLVED_MODEL:
165-
initializeModelChunk(chunk);
164+
case RESOLVED_VALUE:
165+
initializeValueChunk(chunk);
166166
break;
167167
case RESOLVED_MODULE:
168168
initializeModuleChunk(chunk);
@@ -247,12 +247,12 @@ function triggerErrorOnChunk<T>(chunk: SomeChunk<T>, error: mixed): void {
247247
}
248248
}
249249

250-
function createResolvedModelChunk<T>(
250+
function createResolvedValueChunk<T>(
251251
response: Response,
252-
value: UninitializedModel,
253-
): ResolvedModelChunk<T> {
252+
value: UninitializedValue,
253+
): ResolvedValueChunk<T> {
254254
// $FlowFixMe Flow doesn't support functions as constructors
255-
return new Chunk(RESOLVED_MODEL, value, null, response);
255+
return new Chunk(RESOLVED_VALUE, value, null, response);
256256
}
257257

258258
function createResolvedModuleChunk<T>(
@@ -263,24 +263,24 @@ function createResolvedModuleChunk<T>(
263263
return new Chunk(RESOLVED_MODULE, value, null, response);
264264
}
265265

266-
function resolveModelChunk<T>(
266+
function resolveValueChunk<T>(
267267
chunk: SomeChunk<T>,
268-
value: UninitializedModel,
268+
value: UninitializedValue,
269269
): void {
270270
if (chunk.status !== PENDING) {
271271
// We already resolved. We didn't expect to see this.
272272
return;
273273
}
274274
const resolveListeners = chunk.value;
275275
const rejectListeners = chunk.reason;
276-
const resolvedChunk: ResolvedModelChunk<T> = (chunk: any);
277-
resolvedChunk.status = RESOLVED_MODEL;
276+
const resolvedChunk: ResolvedValueChunk<T> = (chunk: any);
277+
resolvedChunk.status = RESOLVED_VALUE;
278278
resolvedChunk.value = value;
279279
if (resolveListeners !== null) {
280280
// This is unfortunate that we're reading this eagerly if
281281
// we already have listeners attached since they might no
282282
// longer be rendered or might not be the highest pri.
283-
initializeModelChunk(resolvedChunk);
283+
initializeValueChunk(resolvedChunk);
284284
// The status might have changed after initialization.
285285
wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners);
286286
}
@@ -305,20 +305,20 @@ function resolveModuleChunk<T>(
305305
}
306306
}
307307

308-
let initializingChunk: ResolvedModelChunk<any> = (null: any);
309-
let initializingChunkBlockedModel: null | {deps: number, value: any} = null;
310-
function initializeModelChunk<T>(chunk: ResolvedModelChunk<T>): void {
308+
let initializingChunk: ResolvedValueChunk<any> = (null: any);
309+
let initializingChunkBlockedValue: null | {deps: number, value: any} = null;
310+
function initializeValueChunk<T>(chunk: ResolvedValueChunk<T>): void {
311311
const prevChunk = initializingChunk;
312-
const prevBlocked = initializingChunkBlockedModel;
312+
const prevBlocked = initializingChunkBlockedValue;
313313
initializingChunk = chunk;
314-
initializingChunkBlockedModel = null;
314+
initializingChunkBlockedValue = null;
315315
try {
316-
const value: T = parseModel(chunk._response, chunk.value);
316+
const value: T = parseValue(chunk._response, chunk.value);
317317
if (
318-
initializingChunkBlockedModel !== null &&
319-
initializingChunkBlockedModel.deps > 0
318+
initializingChunkBlockedValue !== null &&
319+
initializingChunkBlockedValue.deps > 0
320320
) {
321-
initializingChunkBlockedModel.value = value;
321+
initializingChunkBlockedValue.value = value;
322322
// We discovered new dependencies on modules that are not yet resolved.
323323
// We have to go the BLOCKED state until they're resolved.
324324
const blockedChunk: BlockedChunk<T> = (chunk: any);
@@ -336,7 +336,7 @@ function initializeModelChunk<T>(chunk: ResolvedModelChunk<T>): void {
336336
erroredChunk.reason = error;
337337
} finally {
338338
initializingChunk = prevChunk;
339-
initializingChunkBlockedModel = prevBlocked;
339+
initializingChunkBlockedValue = prevBlocked;
340340
}
341341
}
342342

@@ -434,17 +434,17 @@ function getChunk(response: Response, id: number): SomeChunk<any> {
434434
return chunk;
435435
}
436436

437-
function createModelResolver<T>(
437+
function createValueResolver<T>(
438438
chunk: SomeChunk<T>,
439439
parentObject: Object,
440440
key: string,
441441
): (value: any) => void {
442442
let blocked;
443-
if (initializingChunkBlockedModel) {
444-
blocked = initializingChunkBlockedModel;
443+
if (initializingChunkBlockedValue) {
444+
blocked = initializingChunkBlockedValue;
445445
blocked.deps++;
446446
} else {
447-
blocked = initializingChunkBlockedModel = {
447+
blocked = initializingChunkBlockedValue = {
448448
deps: 1,
449449
value: null,
450450
};
@@ -467,7 +467,7 @@ function createModelResolver<T>(
467467
};
468468
}
469469

470-
function createModelReject<T>(chunk: SomeChunk<T>): (error: mixed) => void {
470+
function createValueReject<T>(chunk: SomeChunk<T>): (error: mixed) => void {
471471
return (error: mixed) => triggerErrorOnChunk(chunk, error);
472472
}
473473

@@ -498,7 +498,7 @@ function createServerReferenceProxy<A: Iterable<any>, T>(
498498
return proxy;
499499
}
500500

501-
export function parseModelString(
501+
export function parseValueString(
502502
response: Response,
503503
parentObject: Object,
504504
key: string,
@@ -541,8 +541,8 @@ export function parseModelString(
541541
const id = parseInt(value.substring(2), 16);
542542
const chunk = getChunk(response, id);
543543
switch (chunk.status) {
544-
case RESOLVED_MODEL:
545-
initializeModelChunk(chunk);
544+
case RESOLVED_VALUE:
545+
initializeValueChunk(chunk);
546546
break;
547547
}
548548
// The status might have changed after initialization.
@@ -561,8 +561,8 @@ export function parseModelString(
561561
const id = parseInt(value.substring(1), 16);
562562
const chunk = getChunk(response, id);
563563
switch (chunk.status) {
564-
case RESOLVED_MODEL:
565-
initializeModelChunk(chunk);
564+
case RESOLVED_VALUE:
565+
initializeValueChunk(chunk);
566566
break;
567567
case RESOLVED_MODULE:
568568
initializeModuleChunk(chunk);
@@ -576,8 +576,8 @@ export function parseModelString(
576576
case BLOCKED:
577577
const parentChunk = initializingChunk;
578578
chunk.then(
579-
createModelResolver(parentChunk, parentObject, key),
580-
createModelReject(parentChunk),
579+
createValueResolver(parentChunk, parentObject, key),
580+
createValueReject(parentChunk),
581581
);
582582
return null;
583583
default:
@@ -589,7 +589,7 @@ export function parseModelString(
589589
return value;
590590
}
591591

592-
export function parseModelTuple(
592+
export function parseValueTuple(
593593
response: Response,
594594
value: {+[key: string]: JSONValue} | $ReadOnlyArray<JSONValue>,
595595
): any {
@@ -626,27 +626,27 @@ export function createResponse(
626626
export function resolveModel(
627627
response: Response,
628628
id: number,
629-
model: UninitializedModel,
629+
value: UninitializedValue,
630630
): void {
631631
const chunks = response._chunks;
632632
const chunk = chunks.get(id);
633633
if (!chunk) {
634-
chunks.set(id, createResolvedModelChunk(response, model));
634+
chunks.set(id, createResolvedValueChunk(response, value));
635635
} else {
636-
resolveModelChunk(chunk, model);
636+
resolveValueChunk(chunk, value);
637637
}
638638
}
639639

640640
export function resolveModule(
641641
response: Response,
642642
id: number,
643-
model: UninitializedModel,
643+
value: UninitializedValue,
644644
): void {
645645
const chunks = response._chunks;
646646
const chunk = chunks.get(id);
647-
const clientReferenceMetadata: ClientReferenceMetadata = parseModel(
647+
const clientReferenceMetadata: ClientReferenceMetadata = parseValue(
648648
response,
649-
model,
649+
value,
650650
);
651651
const clientReference = resolveClientReference<$FlowFixMe>(
652652
response._ssrManifest,

packages/react-client/src/ReactFlightClientHostConfigStream.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export type Response = ResponseBase & {
1616
_stringDecoder: StringDecoder,
1717
};
1818

19-
export type UninitializedModel = string;
19+
export type UninitializedValue = string;
2020

21-
export function parseModel<T>(response: Response, json: UninitializedModel): T {
21+
export function parseValue<T>(response: Response, json: UninitializedValue): T {
2222
return JSON.parse(json, response._fromJSON);
2323
}

packages/react-client/src/ReactFlightClientStream.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import {
1717
resolveErrorProd,
1818
resolveErrorDev,
1919
createResponse as createResponseBase,
20-
parseModelString,
21-
parseModelTuple,
20+
parseValueString,
21+
parseValueTuple,
2222
} from './ReactFlightClient';
2323

2424
import {
@@ -111,10 +111,10 @@ function createFromJSONCallback(response: Response) {
111111
return function (key: string, value: JSONValue) {
112112
if (typeof value === 'string') {
113113
// We can't use .bind here because we need the "this" value.
114-
return parseModelString(response, this, key, value);
114+
return parseValueString(response, this, key, value);
115115
}
116116
if (typeof value === 'object' && value !== null) {
117-
return parseModelTuple(response, value);
117+
return parseValueTuple(response, value);
118118
}
119119
return value;
120120
};

0 commit comments

Comments
 (0)