/
githubmr
/
facebook-react
Обзор
Документация
Войти
/
githubmr
/
facebook-react
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
v18.1.0
packages/react-server-native-relay/src/ReactFlightNativeRelayClientHostConfig.js
69 строк
2 KB
Sebastian Markbåge
Reland Remove redundant initial of isArray (#21188)
07 апр 2021, 17:57
Не верифицирован
07 апр 2021, 17:57
172e89b
Код
Авторство
О чём код?
/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @flow */ import type {JSONValue, ResponseBase} from 'react-client/src/ReactFlightClient'; import type JSResourceReference from 'JSResourceReference'; export type ModuleReference<T> = JSResourceReference<T>; import { parseModelString, parseModelTuple, } from 'react-client/src/ReactFlightClient'; export { resolveModuleReference, preloadModule, requireModule, } from 'ReactFlightNativeRelayClientIntegration'; import isArray from 'shared/isArray'; export type {ModuleMetaData} from 'ReactFlightNativeRelayClientIntegration'; export type UninitializedModel = JSONValue; export type Response = ResponseBase; function parseModelRecursively(response: Response, parentObj, value) { if (typeof value === 'string') { return parseModelString(response, parentObj, value); } if (typeof value === 'object' && value !== null) { if (isArray(value)) { const parsedValue = []; for (let i = 0; i < value.length; i++) { (parsedValue: any)[i] = parseModelRecursively( response, value, value[i], ); } return parseModelTuple(response, parsedValue); } else { const parsedValue = {}; for (const innerKey in value) { (parsedValue: any)[innerKey] = parseModelRecursively( response, value, value[innerKey], ); } return parsedValue; } } return value; } const dummy = {}; export function parseModel<T>(response: Response, json: UninitializedModel): T { return (parseModelRecursively(response, dummy, json): any); }