7kms/react-illustration-series

hook-state 一节中 baseQueue拼接后的链表顺序好像有误

Closed this issue · 0 comments

pbgf commented

hook-state 一节中 baseQueue拼接后的链表顺序好像有误,和给到的demo中的dispatch顺序不符
dispatch
baseQueue拼接后

我理解应该为1、3、2
132

具体代码为:

 // 2. 链表拼接: 将 hook.queue.pending 拼接到 current.baseQueue
  const pendingQueue = queue.pending;
  if (pendingQueue !== null) {
    if (baseQueue !== null) {
      const baseFirst = baseQueue.next; // 假设为空 baseQueue.next则指向自己
      const pendingFirst = pendingQueue.next; // pendingQueue 为2 ,pendingQueue.next 则为1
      baseQueue.next = pendingFirst; // baseQueue 指向 1
      pendingQueue.next = baseFirst; // pendingQueue(2) 指向 baseQueue
     // 所以最后是 baseQueue => 1 => 3 => 2( 2指向baseQueue )
    }
    current.baseQueue = baseQueue = pendingQueue;
    queue.pending = null;
  }