初窥React-7(updateContainer方法-p2)

来到了update入栈了 enqueueUpdate(current$1, update);
function enqueueUpdate(fiber, update) { 
    var updateQueue = fiber.updateQueue; //取出当前的updateQueue

    if (updateQueue === null) {
      // Only occurs if the fiber has been unmounted.
      return;
    }

    var sharedQueue = updateQueue.shared;
    var pending = sharedQueue.pending;                

    //update插入到fiber的updateQueue.shared队列当中...
    if (pending === null) {
      // This is the first update. Create a circular list.
      update.next = update;
    } else {
      //入队 c- > a b之间
      update.next = pending.next;
      pending.next = update;
    }

    sharedQueue.pending = update;

    {
      if (currentlyProcessingQueue === sharedQueue && !didWarnUpdateInsideUpdate) {
        error('An update (setState, replaceState, or forceUpdate) was scheduled ' + 'from inside an update function. Update functions should be pure, ' + 'with zero side-effects. Consider using componentDidUpdate or a ' + 'callback.');

        didWarnUpdateInsideUpdate = true;
      }
    }
  }

 

上一篇:React源码——diff算法揭秘


下一篇:react源码解析12.状态更新流程