/
githubmr
/
facebook-react
Обзор
Документация
Войти
/
githubmr
/
facebook-react
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
main
packages/react-reconciler/src/ReactFiberAsyncDispatcher.js
42 строки
1 KB
Sebastian Markbåge
Expose cacheSignal() alongside cache() (#33557)
18 июн 2025, 00:04
Не верифицирован
18 июн 2025, 00:04
e1dc034
Код
Авторство
О чём код?
/** * Copyright (c) Meta Platforms, Inc. and 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 {AsyncDispatcher, Fiber} from './ReactInternalTypes'; import type {Cache} from './ReactFiberCacheComponent'; import {readContext} from './ReactFiberNewContext'; import {CacheContext} from './ReactFiberCacheComponent'; import {current as currentOwner} from './ReactCurrentFiber'; function getCacheForType<T>(resourceType: () => T): T { const cache: Cache = readContext(CacheContext); let cacheForType: T | void = (cache.data.get(resourceType): any); if (cacheForType === undefined) { cacheForType = resourceType(); cache.data.set(resourceType, cacheForType); } return cacheForType; } function cacheSignal(): null | AbortSignal { const cache: Cache = readContext(CacheContext); return cache.controller.signal; } export const DefaultAsyncDispatcher: AsyncDispatcher = ({ getCacheForType, cacheSignal, }: any); if (__DEV__) { DefaultAsyncDispatcher.getOwner = (): null | Fiber => { return currentOwner; }; }