跳到主要内容

React Fiber 异步调度器

导出的常量

1. 默认异步调度器

export const DefaultAsyncDispatcher: AsyncDispatcher = {
getCacheForType,
cacheSignal,
} as any;

if (__DEV__) {
DefaultAsyncDispatcher.getOwner = (): null | Fiber => {
return currentOwner;
};
}

工具

1. 获取类型缓存

备注
function getCacheForType<T>(resourceType: () => T): T {
const cache: Cache = readContext(CacheContext);
let cacheForType: T | void = cache.data.get(resourceType) as any;
if (cacheForType === undefined) {
cacheForType = resourceType();
cache.data.set(resourceType, cacheForType);
}
return cacheForType;
}

2. 缓存信号

备注
function cacheSignal(): null | AbortSignal {
const cache: Cache = readContext(CacheContext);
return cache.controller.signal;
}