全局变量isUnbatchingUpdates是什么意思啊

来源:4-4 batchedUpdates

慕前端2324083

2020-08-04

在学习 requestwork时,用到全局变量中2个变量
isBatchingUpdates
isUnbatchingUpdates

我理解isBatchingUpdates 是表明当前更新是否为批量更新的意思。
那isUnbatchingUpdates的意思呢?
源码中判断如下:

function requestWork(root: FiberRoot, expirationTime: ExpirationTime) {
  addRootToSchedule(root, expirationTime);
  if (isRendering) {
    // Prevent reentrancy. Remaining work will be scheduled at the end of
    // the currently rendering batch.
    return;
  }
  //
  if (isBatchingUpdates) {
    // Flush work at the end of the batch.
    if (isUnbatchingUpdates) {
      // ...unless we're inside unbatchedUpdates, in which case we should
      // flush it now.
      nextFlushedRoot = root;
      nextFlushedExpirationTime = Sync;
      performWorkOnRoot(root, Sync, true);
    }
    return;
  }
}

以上在isUnbatchingUpdates判断的地方,是基于判断isBatchingUpdates=true的情况下。说明,这2个变量并不是互斥的。也就是说isUnbatchingUpdates并不代表就是非批量更新。

另外,老师提供的在线文档是这样的

图片描述
什么解释都没有,也是得不到任何帮助。

学习过程中有很多困惑,有些地方实在难受。麻烦老师帮忙解答下

写回答

1回答

Jokcy

2020-08-04

isUnbatchingUpdates就是非批量更新啊。。。在某些特定情况下需要指定不用批量跟新的。你可以全局搜索一下isUnbatchingUpdates,应该不只是在这一个地方用到

0
2
Jokcy
回复
慕前端2324083
不冲突的,设置isUnbatchingUpdates和isBatchingUpdates设置的地方不一样,两个都为true的情况也会存在
2020-08-09
共2条回复

React源码深度解析 高级前端工程师必备技能

掌握React源码,让你的开发水平没有上限,更不惧前端未来的到来

1749 学习 · 336 问题

查看课程