export function unbatchedUpdates<A, R>(fn: (a: A) => R, a: A): R {
const prevExecutionContext = executionContext;
executionContext &= ~BatchedContext;
executionContext |= LegacyUnbatchedContext;
try {
return fn(a);
} finally {
executionContext = prevExecutionContext;
if (executionContext === NoContext) {
// Flush the immediate callbacks that were scheduled during this batch
flushSyncCallbackQueue();
}
}
}
请问unbatchedUpdates中的这段代码起了什么作用?
const prevExecutionContext = executionContext;
executionContext &= ~BatchedContext;
executionContext |= LegacyUnbatchedContext;
在将
upbatchedUpdates
前,我们看一下一些常量和变量上面的一些常量都是定义的React中对应的执行栈。变量
executionContext
则记录当前的执行栈.现在,我们回到
upbatchedUpdates
方法中