跳到主要内容

React 共享内部客户端

type onStartTransitionFinish = (transition: Transition, mixed: mixed) => void;
type onStartGestureTransitionFinish = (
transition: Transition,
gestureProvider: GestureProvider,
gestureOptions?: GestureOptions,
) => () => void;

export type SharedStateClient = {
H: null | Dispatcher; // ReactCurrentDispatcher for Hooks
A: null | AsyncDispatcher; // ReactCurrentCache for Cache
T: null | Transition; // ReactCurrentBatchConfig for Transitions
S: null | onStartTransitionFinish;
G: null | onStartGestureTransitionFinish;

// DEV-only

// ReactCurrentActQueue
actQueue: null | Array<RendererTask>;

// When zero this means we're outside an async startTransition.
asyncTransitions: number;

// Used to reproduce behavior of `batchedUpdates` in legacy mode.
isBatchingLegacy: boolean;
didScheduleLegacyUpdate: boolean;

// Tracks whether something called `use` during the current batch of work.
// Determines whether we should yield to microtasks to unwrap already resolved
// promises without suspending.
//
// 跟踪当前工作批次中是否调用了名为 `use` 的东西。 决定我们是否应该让出给微任务,以便在不挂起的
// 情况下获取已解析的 promise 的结果。
didUsePromise: boolean;

// Track first uncaught error within this act
// 跟踪此行为中的第一个未捕获错误
thrownErrors: Array<mixed>;

// ReactDebugCurrentFrame
// React 调试当前帧
getCurrentStack: null | (() => string);

// ReactOwnerStackReset
// React 所有者堆栈重置
recentlyCreatedOwnerStacks: 0;
};

export type RendererTask = (boolean) => RendererTask | null;

const ReactSharedInternals: SharedStateClient = {
H: null,
A: null,
T: null,
S: null,
} as any;
if (enableGestureTransition) {
ReactSharedInternals.G = null;
}

if (__DEV__) {
ReactSharedInternals.actQueue = null;
ReactSharedInternals.asyncTransitions = 0;
ReactSharedInternals.isBatchingLegacy = false;
ReactSharedInternals.didScheduleLegacyUpdate = false;
ReactSharedInternals.didUsePromise = false;
ReactSharedInternals.thrownErrors = [];
// Stack implementation injected by the current renderer.
// 当前渲染器注入的堆栈实现。
ReactSharedInternals.getCurrentStack = null as null | (() => string);
ReactSharedInternals.recentlyCreatedOwnerStacks = 0;
}

export default ReactSharedInternals;