mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Rename CacheDispatcher to AsyncDispatcher
This commit is contained in:
committed by
Rick Hanlon
parent
446aa9a632
commit
d5d6023a01
+2
-2
@@ -7,7 +7,7 @@
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import type {CacheDispatcher} from './ReactInternalTypes';
|
||||
import type {AsyncDispatcher} from './ReactInternalTypes';
|
||||
import type {Cache} from './ReactFiberCacheComponent';
|
||||
|
||||
import {enableCache} from 'shared/ReactFeatureFlags';
|
||||
@@ -27,6 +27,6 @@ function getCacheForType<T>(resourceType: () => T): T {
|
||||
return cacheForType;
|
||||
}
|
||||
|
||||
export const DefaultCacheDispatcher: CacheDispatcher = {
|
||||
export const DefaultAsyncDispatcher: AsyncDispatcher = {
|
||||
getCacheForType,
|
||||
};
|
||||
|
||||
+11
-11
@@ -203,7 +203,7 @@ import {
|
||||
resetHooksOnUnwind,
|
||||
ContextOnlyDispatcher,
|
||||
} from './ReactFiberHooks';
|
||||
import {DefaultCacheDispatcher} from './ReactFiberCache';
|
||||
import {DefaultAsyncDispatcher} from './ReactFiberCache';
|
||||
import {
|
||||
createCapturedValueAtFiber,
|
||||
type CapturedValue,
|
||||
@@ -1874,19 +1874,19 @@ function popDispatcher(prevDispatcher: any) {
|
||||
ReactSharedInternals.H = prevDispatcher;
|
||||
}
|
||||
|
||||
function pushCacheDispatcher() {
|
||||
function pushAsyncDispatcher() {
|
||||
if (enableCache) {
|
||||
const prevCacheDispatcher = ReactSharedInternals.C;
|
||||
ReactSharedInternals.C = DefaultCacheDispatcher;
|
||||
return prevCacheDispatcher;
|
||||
const prevAsyncDispatcher = ReactSharedInternals.A;
|
||||
ReactSharedInternals.A = DefaultAsyncDispatcher;
|
||||
return prevAsyncDispatcher;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function popCacheDispatcher(prevCacheDispatcher: any) {
|
||||
function popAsyncDispatcher(prevAsyncDispatcher: any) {
|
||||
if (enableCache) {
|
||||
ReactSharedInternals.C = prevCacheDispatcher;
|
||||
ReactSharedInternals.A = prevAsyncDispatcher;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1963,7 +1963,7 @@ function renderRootSync(root: FiberRoot, lanes: Lanes) {
|
||||
const prevExecutionContext = executionContext;
|
||||
executionContext |= RenderContext;
|
||||
const prevDispatcher = pushDispatcher(root.containerInfo);
|
||||
const prevCacheDispatcher = pushCacheDispatcher();
|
||||
const prevAsyncDispatcher = pushAsyncDispatcher();
|
||||
|
||||
// If the root or lanes have changed, throw out the existing stack
|
||||
// and prepare a fresh one. Otherwise we'll continue where we left off.
|
||||
@@ -2061,7 +2061,7 @@ function renderRootSync(root: FiberRoot, lanes: Lanes) {
|
||||
|
||||
executionContext = prevExecutionContext;
|
||||
popDispatcher(prevDispatcher);
|
||||
popCacheDispatcher(prevCacheDispatcher);
|
||||
popAsyncDispatcher(prevAsyncDispatcher);
|
||||
|
||||
if (workInProgress !== null) {
|
||||
// This is a sync render, so we should have finished the whole tree.
|
||||
@@ -2104,7 +2104,7 @@ function renderRootConcurrent(root: FiberRoot, lanes: Lanes) {
|
||||
const prevExecutionContext = executionContext;
|
||||
executionContext |= RenderContext;
|
||||
const prevDispatcher = pushDispatcher(root.containerInfo);
|
||||
const prevCacheDispatcher = pushCacheDispatcher();
|
||||
const prevAsyncDispatcher = pushAsyncDispatcher();
|
||||
|
||||
// If the root or lanes have changed, throw out the existing stack
|
||||
// and prepare a fresh one. Otherwise we'll continue where we left off.
|
||||
@@ -2317,7 +2317,7 @@ function renderRootConcurrent(root: FiberRoot, lanes: Lanes) {
|
||||
resetContextDependencies();
|
||||
|
||||
popDispatcher(prevDispatcher);
|
||||
popCacheDispatcher(prevCacheDispatcher);
|
||||
popAsyncDispatcher(prevAsyncDispatcher);
|
||||
executionContext = prevExecutionContext;
|
||||
|
||||
if (__DEV__) {
|
||||
|
||||
+1
-1
@@ -434,6 +434,6 @@ export type Dispatcher = {
|
||||
) => [Awaited<S>, (P) => void, boolean],
|
||||
};
|
||||
|
||||
export type CacheDispatcher = {
|
||||
export type AsyncDispatcher = {
|
||||
getCacheForType: <T>(resourceType: () => T) => T,
|
||||
};
|
||||
|
||||
+2
-2
@@ -7,12 +7,12 @@
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import type {CacheDispatcher} from 'react-reconciler/src/ReactInternalTypes';
|
||||
import type {AsyncDispatcher} from 'react-reconciler/src/ReactInternalTypes';
|
||||
|
||||
function getCacheForType<T>(resourceType: () => T): T {
|
||||
throw new Error('Not implemented.');
|
||||
}
|
||||
|
||||
export const DefaultCacheDispatcher: CacheDispatcher = {
|
||||
export const DefaultAsyncDispatcher: AsyncDispatcher = {
|
||||
getCacheForType,
|
||||
};
|
||||
|
||||
+5
-5
@@ -109,7 +109,7 @@ import {
|
||||
getActionStateCount,
|
||||
getActionStateMatchingIndex,
|
||||
} from './ReactFizzHooks';
|
||||
import {DefaultCacheDispatcher} from './ReactFizzCache';
|
||||
import {DefaultAsyncDispatcher} from './ReactFizzCache';
|
||||
import {getStackByComponentStackNode} from './ReactFizzComponentStack';
|
||||
import {emptyTreeContext, pushTreeContext} from './ReactFizzTreeContext';
|
||||
|
||||
@@ -3663,10 +3663,10 @@ export function performWork(request: Request): void {
|
||||
const prevContext = getActiveContext();
|
||||
const prevDispatcher = ReactSharedInternals.H;
|
||||
ReactSharedInternals.H = HooksDispatcher;
|
||||
let prevCacheDispatcher = null;
|
||||
let prevAsyncDispatcher = null;
|
||||
if (enableCache) {
|
||||
prevCacheDispatcher = ReactSharedInternals.C;
|
||||
ReactSharedInternals.C = DefaultCacheDispatcher;
|
||||
prevAsyncDispatcher = ReactSharedInternals.A;
|
||||
ReactSharedInternals.A = DefaultAsyncDispatcher;
|
||||
}
|
||||
|
||||
const prevRequest = currentRequest;
|
||||
@@ -3698,7 +3698,7 @@ export function performWork(request: Request): void {
|
||||
setCurrentResumableState(prevResumableState);
|
||||
ReactSharedInternals.H = prevDispatcher;
|
||||
if (enableCache) {
|
||||
ReactSharedInternals.C = prevCacheDispatcher;
|
||||
ReactSharedInternals.A = prevAsyncDispatcher;
|
||||
}
|
||||
|
||||
if (__DEV__) {
|
||||
|
||||
+4
-4
@@ -89,7 +89,7 @@ import {
|
||||
getThenableStateAfterSuspending,
|
||||
resetHooksForRequest,
|
||||
} from './ReactFlightHooks';
|
||||
import {DefaultCacheDispatcher} from './flight/ReactFlightServerCache';
|
||||
import {DefaultAsyncDispatcher} from './flight/ReactFlightServerCache';
|
||||
|
||||
import {
|
||||
getIteratorFn,
|
||||
@@ -358,14 +358,14 @@ export function createRequest(
|
||||
environmentName: void | string,
|
||||
): Request {
|
||||
if (
|
||||
ReactSharedInternals.C !== null &&
|
||||
ReactSharedInternals.C !== DefaultCacheDispatcher
|
||||
ReactSharedInternals.A !== null &&
|
||||
ReactSharedInternals.A !== DefaultAsyncDispatcher
|
||||
) {
|
||||
throw new Error(
|
||||
'Currently React only supports one RSC renderer at a time.',
|
||||
);
|
||||
}
|
||||
ReactSharedInternals.C = DefaultCacheDispatcher;
|
||||
ReactSharedInternals.A = DefaultAsyncDispatcher;
|
||||
|
||||
const abortSet: Set<Task> = new Set();
|
||||
const pingedTasks: Array<Task> = [];
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import type {CacheDispatcher} from 'react-reconciler/src/ReactInternalTypes';
|
||||
import type {AsyncDispatcher} from 'react-reconciler/src/ReactInternalTypes';
|
||||
|
||||
import {resolveRequest, getCache} from '../ReactFlightServer';
|
||||
|
||||
@@ -19,7 +19,7 @@ function resolveCache(): Map<Function, mixed> {
|
||||
return new Map();
|
||||
}
|
||||
|
||||
export const DefaultCacheDispatcher: CacheDispatcher = {
|
||||
export const DefaultAsyncDispatcher: AsyncDispatcher = {
|
||||
getCacheForType<T>(resourceType: () => T): T {
|
||||
const cache = resolveCache();
|
||||
let entry: T | void = (cache.get(resourceType): any);
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import type {CacheDispatcher} from 'react-reconciler/src/ReactInternalTypes';
|
||||
import type {AsyncDispatcher} from 'react-reconciler/src/ReactInternalTypes';
|
||||
import ReactSharedInternals from 'shared/ReactSharedInternals';
|
||||
|
||||
export function waitForSuspense<T>(fn: () => T): Promise<T> {
|
||||
const cache: Map<Function, mixed> = new Map();
|
||||
const testDispatcher: CacheDispatcher = {
|
||||
const testDispatcher: AsyncDispatcher = {
|
||||
getCacheForType<R>(resourceType: () => R): R {
|
||||
let entry: R | void = (cache.get(resourceType): any);
|
||||
if (entry === undefined) {
|
||||
@@ -26,8 +26,8 @@ export function waitForSuspense<T>(fn: () => T): Promise<T> {
|
||||
// Not using async/await because we don't compile it.
|
||||
return new Promise((resolve, reject) => {
|
||||
function retry() {
|
||||
const prevDispatcher = ReactSharedInternals.C;
|
||||
ReactSharedInternals.C = testDispatcher;
|
||||
const prevDispatcher = ReactSharedInternals.A;
|
||||
ReactSharedInternals.A = testDispatcher;
|
||||
try {
|
||||
const result = fn();
|
||||
resolve(result);
|
||||
@@ -38,7 +38,7 @@ export function waitForSuspense<T>(fn: () => T): Promise<T> {
|
||||
reject(thrownValue);
|
||||
}
|
||||
} finally {
|
||||
ReactSharedInternals.C = prevDispatcher;
|
||||
ReactSharedInternals.A = prevDispatcher;
|
||||
}
|
||||
}
|
||||
retry();
|
||||
|
||||
@@ -54,7 +54,7 @@ function createCacheNode<T>(): CacheNode<T> {
|
||||
|
||||
export function cache<A: Iterable<mixed>, T>(fn: (...A) => T): (...A) => T {
|
||||
return function () {
|
||||
const dispatcher = ReactSharedInternals.C;
|
||||
const dispatcher = ReactSharedInternals.A;
|
||||
if (!dispatcher) {
|
||||
// If there is no dispatcher, then we treat this as not being cached.
|
||||
// $FlowFixMe[incompatible-call]: We don't want to use rest arguments since we transpile the code.
|
||||
|
||||
@@ -46,7 +46,7 @@ if (enableCache && enableFetchInstrumentation) {
|
||||
resource: URL | RequestInfo,
|
||||
options?: RequestOptions,
|
||||
) {
|
||||
const dispatcher = ReactSharedInternals.C;
|
||||
const dispatcher = ReactSharedInternals.A;
|
||||
if (!dispatcher) {
|
||||
// We're outside a cached scope.
|
||||
return originalFetch(resource, options);
|
||||
|
||||
@@ -44,7 +44,7 @@ function resolveDispatcher() {
|
||||
}
|
||||
|
||||
export function getCacheForType<T>(resourceType: () => T): T {
|
||||
const dispatcher = ReactSharedInternals.C;
|
||||
const dispatcher = ReactSharedInternals.A;
|
||||
if (!dispatcher) {
|
||||
// If there is no dispatcher, then we treat this as not being cached.
|
||||
return resourceType();
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
import type {Dispatcher} from 'react-reconciler/src/ReactInternalTypes';
|
||||
import type {CacheDispatcher} from 'react-reconciler/src/ReactInternalTypes';
|
||||
import type {AsyncDispatcher} from 'react-reconciler/src/ReactInternalTypes';
|
||||
import type {BatchConfigTransition} from 'react-reconciler/src/ReactFiberTracingMarkerComponent';
|
||||
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
|
||||
|
||||
@@ -16,7 +16,7 @@ import {disableStringRefs} from 'shared/ReactFeatureFlags';
|
||||
|
||||
export type SharedStateClient = {
|
||||
H: null | Dispatcher, // ReactCurrentDispatcher for Hooks
|
||||
C: null | CacheDispatcher, // ReactCurrentCache for Cache
|
||||
A: null | AsyncDispatcher, // ReactCurrentCache for Cache
|
||||
T: null | BatchConfigTransition, // ReactCurrentBatchConfig for Transitions
|
||||
|
||||
// DEV-only-ish
|
||||
@@ -47,7 +47,7 @@ export type RendererTask = boolean => RendererTask | null;
|
||||
|
||||
const ReactSharedInternals: SharedStateClient = ({
|
||||
H: null,
|
||||
C: null,
|
||||
A: null,
|
||||
T: null,
|
||||
}: any);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
import type {Dispatcher} from 'react-reconciler/src/ReactInternalTypes';
|
||||
import type {CacheDispatcher} from 'react-reconciler/src/ReactInternalTypes';
|
||||
import type {AsyncDispatcher} from 'react-reconciler/src/ReactInternalTypes';
|
||||
import type {ReactComponentInfo} from 'shared/ReactTypes';
|
||||
|
||||
import type {
|
||||
@@ -28,7 +28,7 @@ import {disableStringRefs, enableTaint} from 'shared/ReactFeatureFlags';
|
||||
|
||||
export type SharedStateServer = {
|
||||
H: null | Dispatcher, // ReactCurrentDispatcher for Hooks
|
||||
C: null | CacheDispatcher, // ReactCurrentCache for Cache
|
||||
A: null | AsyncDispatcher, // ReactCurrentCache for Cache
|
||||
|
||||
// enableTaint
|
||||
TaintRegistryObjects: WeakMap<Reference, string>,
|
||||
@@ -49,7 +49,7 @@ export type RendererTask = boolean => RendererTask | null;
|
||||
|
||||
const ReactSharedInternals: SharedStateServer = ({
|
||||
H: null,
|
||||
C: null,
|
||||
A: null,
|
||||
}: any);
|
||||
|
||||
if (enableTaint) {
|
||||
|
||||
Reference in New Issue
Block a user