/
githubmr
/
facebook-react
Обзор
Документация
Войти
/
githubmr
/
facebook-react
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
v16.13.1
packages/react-server/src/ReactFizzStreamer.js
83 строки
2 KB
Dan Abramov
Update Flow to 0.84 (#17805)
09 янв 2020, 17:50
Не верифицирован
09 янв 2020, 17:50
e706721
Код
Авторство
О чём код?
/** * 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 {Destination} from './ReactServerHostConfig'; import type {ReactNodeList} from 'shared/ReactTypes'; import { scheduleWork, beginWriting, writeChunk, completeWriting, flushBuffered, close, } from './ReactServerHostConfig'; import {formatChunk} from './ReactServerFormatConfig'; import {REACT_ELEMENT_TYPE} from 'shared/ReactSymbols'; type OpaqueRequest = { destination: Destination, children: ReactNodeList, completedChunks: Array<Uint8Array>, flowing: boolean, ... }; export function createRequest( children: ReactNodeList, destination: Destination, ): OpaqueRequest { return {destination, children, completedChunks: [], flowing: false}; } function performWork(request: OpaqueRequest): void { let element = (request.children: any); request.children = null; if (element && element.$$typeof !== REACT_ELEMENT_TYPE) { return; } let type = element.type; let props = element.props; if (typeof type !== 'string') { return; } request.completedChunks.push(formatChunk(type, props)); if (request.flowing) { flushCompletedChunks(request); } flushBuffered(request.destination); } function flushCompletedChunks(request: OpaqueRequest) { let destination = request.destination; let chunks = request.completedChunks; request.completedChunks = []; beginWriting(destination); try { for (let i = 0; i < chunks.length; i++) { let chunk = chunks[i]; writeChunk(destination, chunk); } } finally { completeWriting(destination); } close(destination); } export function startWork(request: OpaqueRequest): void { request.flowing = true; scheduleWork(() => performWork(request)); } export function startFlowing(request: OpaqueRequest): void { request.flowing = false; flushCompletedChunks(request); }