首页 > 其他 > 详细

初窥React-5(unbatchedUpdate方法)

时间:2021-07-07 10:21:10      阅读:17      评论:0      收藏:0      [点我收藏+]
React按照事件的紧急程度,把它们划分成三个等级:
  • 离散事件(DiscreteEvent):click、keydown、focusin等,这些事件的触发不是连续的,优先级为0。
  • 用户阻塞事件(UserBlockingEvent):drag、scroll、mouseover等,特点是连续触发,阻塞渲染,优先级为1。
  • 连续事件(ContinuousEvent):canplay、error、audio标签的timeupdate和canplay,优先级最高,为2。

 

unbatchedUpdates(function () {
  updateContainer(children, fiberRoot, parentComponent, callback);
});
function unbatchedUpdates(fn, a) {         //非常有趣的设计,类似锁、释放内存的设计
    var prevExecutionContext = executionContext; //0
    executionContext &= ~BatchedContext;         //1
    executionContext |= LegacyUnbatchedContext;  //8

    try {
      return fn(a); //执行updateContainer....
    } finally {
      executionContext = prevExecutionContext; //重置....

      if (executionContext === NoContext) {
        // Flush the immediate callbacks that were scheduled during this batch
        resetRenderTimer();
        flushSyncCallbackQueue();
      }
    }
  }

 

初窥React-5(unbatchedUpdate方法)

原文:https://www.cnblogs.com/allenliu0927/p/14979622.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!