Skip to content

Commit f6f99fd

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 10ce129 commit f6f99fd

26 files changed

+268
-265
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: 50 additions & 50 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 {knownServerReferences} from './ReactFlightServerReferenceRegistry';
@@ -43,7 +43,7 @@ export type JSONValue =
4343

4444
const PENDING = 'pending';
4545
const BLOCKED = 'blocked';
46-
const RESOLVED_MODEL = 'resolved_model';
46+
const RESOLVED_VALUE = 'resolved_value';
4747
const RESOLVED_MODULE = 'resolved_module';
4848
const INITIALIZED = 'fulfilled';
4949
const ERRORED = 'rejected';
@@ -62,9 +62,9 @@ type BlockedChunk<T> = {
6262
_response: Response,
6363
then(resolve: (T) => mixed, reject: (mixed) => mixed): void,
6464
};
65-
type ResolvedModelChunk<T> = {
66-
status: 'resolved_model',
67-
value: UninitializedModel,
65+
type ResolvedValueChunk<T> = {
66+
status: 'resolved_value',
67+
value: UninitializedValue,
6868
reason: null,
6969
_response: Response,
7070
then(resolve: (T) => mixed, reject: (mixed) => mixed): void,
@@ -93,7 +93,7 @@ type ErroredChunk<T> = {
9393
type SomeChunk<T> =
9494
| PendingChunk<T>
9595
| BlockedChunk<T>
96-
| ResolvedModelChunk<T>
96+
| ResolvedValueChunk<T>
9797
| ResolvedModuleChunk<T>
9898
| InitializedChunk<T>
9999
| ErroredChunk<T>;
@@ -117,8 +117,8 @@ Chunk.prototype.then = function <T>(
117117
// If we have resolved content, we try to initialize it first which
118118
// might put us back into one of the other states.
119119
switch (chunk.status) {
120-
case RESOLVED_MODEL:
121-
initializeModelChunk(chunk);
120+
case RESOLVED_VALUE:
121+
initializeValueChunk(chunk);
122122
break;
123123
case RESOLVED_MODULE:
124124
initializeModuleChunk(chunk);
@@ -163,8 +163,8 @@ function readChunk<T>(chunk: SomeChunk<T>): T {
163163
// If we have resolved content, we try to initialize it first which
164164
// might put us back into one of the other states.
165165
switch (chunk.status) {
166-
case RESOLVED_MODEL:
167-
initializeModelChunk(chunk);
166+
case RESOLVED_VALUE:
167+
initializeValueChunk(chunk);
168168
break;
169169
case RESOLVED_MODULE:
170170
initializeModuleChunk(chunk);
@@ -249,12 +249,12 @@ function triggerErrorOnChunk<T>(chunk: SomeChunk<T>, error: mixed): void {
249249
}
250250
}
251251

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

260260
function createResolvedModuleChunk<T>(
@@ -265,24 +265,24 @@ function createResolvedModuleChunk<T>(
265265
return new Chunk(RESOLVED_MODULE, value, null, response);
266266
}
267267

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

310-
let initializingChunk: ResolvedModelChunk<any> = (null: any);
311-
let initializingChunkBlockedModel: null | {deps: number, value: any} = null;
312-
function initializeModelChunk<T>(chunk: ResolvedModelChunk<T>): void {
310+
let initializingChunk: ResolvedValueChunk<any> = (null: any);
311+
let initializingChunkBlockedValue: null | {deps: number, value: any} = null;
312+
function initializeValueChunk<T>(chunk: ResolvedValueChunk<T>): void {
313313
const prevChunk = initializingChunk;
314-
const prevBlocked = initializingChunkBlockedModel;
314+
const prevBlocked = initializingChunkBlockedValue;
315315
initializingChunk = chunk;
316-
initializingChunkBlockedModel = null;
316+
initializingChunkBlockedValue = null;
317317
try {
318-
const value: T = parseModel(chunk._response, chunk.value);
318+
const value: T = parseValue(chunk._response, chunk.value);
319319
if (
320-
initializingChunkBlockedModel !== null &&
321-
initializingChunkBlockedModel.deps > 0
320+
initializingChunkBlockedValue !== null &&
321+
initializingChunkBlockedValue.deps > 0
322322
) {
323-
initializingChunkBlockedModel.value = value;
323+
initializingChunkBlockedValue.value = value;
324324
// We discovered new dependencies on modules that are not yet resolved.
325325
// We have to go the BLOCKED state until they're resolved.
326326
const blockedChunk: BlockedChunk<T> = (chunk: any);
@@ -338,7 +338,7 @@ function initializeModelChunk<T>(chunk: ResolvedModelChunk<T>): void {
338338
erroredChunk.reason = error;
339339
} finally {
340340
initializingChunk = prevChunk;
341-
initializingChunkBlockedModel = prevBlocked;
341+
initializingChunkBlockedValue = prevBlocked;
342342
}
343343
}
344344

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

439-
function createModelResolver<T>(
439+
function createValueResolver<T>(
440440
chunk: SomeChunk<T>,
441441
parentObject: Object,
442442
key: string,
443443
): (value: any) => void {
444444
let blocked;
445-
if (initializingChunkBlockedModel) {
446-
blocked = initializingChunkBlockedModel;
445+
if (initializingChunkBlockedValue) {
446+
blocked = initializingChunkBlockedValue;
447447
blocked.deps++;
448448
} else {
449-
blocked = initializingChunkBlockedModel = {
449+
blocked = initializingChunkBlockedValue = {
450450
deps: 1,
451451
value: null,
452452
};
@@ -469,7 +469,7 @@ function createModelResolver<T>(
469469
};
470470
}
471471

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

@@ -501,7 +501,7 @@ function createServerReferenceProxy<A: Iterable<any>, T>(
501501
return proxy;
502502
}
503503

504-
export function parseModelString(
504+
export function parseValueString(
505505
response: Response,
506506
parentObject: Object,
507507
key: string,
@@ -544,8 +544,8 @@ export function parseModelString(
544544
const id = parseInt(value.substring(2), 16);
545545
const chunk = getChunk(response, id);
546546
switch (chunk.status) {
547-
case RESOLVED_MODEL:
548-
initializeModelChunk(chunk);
547+
case RESOLVED_VALUE:
548+
initializeValueChunk(chunk);
549549
break;
550550
}
551551
// The status might have changed after initialization.
@@ -569,8 +569,8 @@ export function parseModelString(
569569
const id = parseInt(value.substring(1), 16);
570570
const chunk = getChunk(response, id);
571571
switch (chunk.status) {
572-
case RESOLVED_MODEL:
573-
initializeModelChunk(chunk);
572+
case RESOLVED_VALUE:
573+
initializeValueChunk(chunk);
574574
break;
575575
case RESOLVED_MODULE:
576576
initializeModuleChunk(chunk);
@@ -584,8 +584,8 @@ export function parseModelString(
584584
case BLOCKED:
585585
const parentChunk = initializingChunk;
586586
chunk.then(
587-
createModelResolver(parentChunk, parentObject, key),
588-
createModelReject(parentChunk),
587+
createValueResolver(parentChunk, parentObject, key),
588+
createValueReject(parentChunk),
589589
);
590590
return null;
591591
default:
@@ -597,7 +597,7 @@ export function parseModelString(
597597
return value;
598598
}
599599

600-
export function parseModelTuple(
600+
export function parseValueTuple(
601601
response: Response,
602602
value: {+[key: string]: JSONValue} | $ReadOnlyArray<JSONValue>,
603603
): any {
@@ -631,30 +631,30 @@ export function createResponse(
631631
return response;
632632
}
633633

634-
export function resolveModel(
634+
export function resolveValue(
635635
response: Response,
636636
id: number,
637-
model: UninitializedModel,
637+
value: UninitializedValue,
638638
): void {
639639
const chunks = response._chunks;
640640
const chunk = chunks.get(id);
641641
if (!chunk) {
642-
chunks.set(id, createResolvedModelChunk(response, model));
642+
chunks.set(id, createResolvedValueChunk(response, value));
643643
} else {
644-
resolveModelChunk(chunk, model);
644+
resolveValueChunk(chunk, value);
645645
}
646646
}
647647

648648
export function resolveModule(
649649
response: Response,
650650
id: number,
651-
model: UninitializedModel,
651+
value: UninitializedValue,
652652
): void {
653653
const chunks = response._chunks;
654654
const chunk = chunks.get(id);
655-
const clientReferenceMetadata: ClientReferenceMetadata = parseModel(
655+
const clientReferenceMetadata: ClientReferenceMetadata = parseValue(
656656
response,
657-
model,
657+
value,
658658
);
659659
const clientReference = resolveClientReference<$FlowFixMe>(
660660
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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import type {SSRManifest} from './ReactFlightClientHostConfig';
1313

1414
import {
1515
resolveModule,
16-
resolveModel,
16+
resolveValue,
1717
resolveErrorProd,
1818
resolveErrorDev,
1919
createResponse as createResponseBase,
20-
parseModelString,
21-
parseModelTuple,
20+
parseValueString,
21+
parseValueTuple,
2222
} from './ReactFlightClient';
2323

2424
import {
@@ -63,7 +63,7 @@ function processFullRow(response: Response, row: string): void {
6363
}
6464
default: {
6565
// We assume anything else is JSON.
66-
resolveModel(response, id, row.substring(colon + 1));
66+
resolveValue(response, id, row.substring(colon + 1));
6767
return;
6868
}
6969
}
@@ -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)