初窥React-5(unbatchedUpdate方法)

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方法)

上一篇:Centos模板机配置


下一篇:Centos7 编译安装openssl和openssh