React 源码解析 - renderRoot 完成节点更新任务

2019-06-21  本文已影响0人  coolheadedY

completeUnitOfWork

当 beginWork 遍历到 fiber 树的单侧最下方时 next 为 null,这时候就会调用 completeUnitOfWork 完成节点并按遍历顺序设置新的 next 进行操作

performUnitOfWork 遍历 fiber 树的顺序

核心功能

completeUnitOfWork 没有报错的处理流程

if ((workInProgress.effectTag & Incomplete) === NoEffect) { //.. }

resetChildExpirationTime 重置 workInProgress.childExpirationTime

completeWork 完成节点更新

核心功能

HostComponent tag 的更新

tag 为 HostComponent 表示普通 dom 节点,如: div

核心功能

初始更新

createInstance 创建 dom

appendAllChildren 构建 dom 树

构建 dom 树, 都是 append 第一层 child 和 child.sibling,不会 append 嵌套的,嵌套的会在他自己是 workInProgress 时 append

finalizeInitialChildren 初始化属性,初始化事件监听

// ...
  setInitialDOMProperties(
    tag,
    domElement,
    rootContainerElement,
    props,
    isCustomComponentTag,
  );

HostComponent 更新 DOM 时进行的 diff 判断

updateHostComponent

diffProperties

completeWork 对于 HostText 的更新

renderRoot 错误处理

核心

onUncaughtError

throwException

throwException 处理错误节点

completeUnitOfWork 处理报错节点

unwindWork 的处理

当前报错组件能处理错误重新标记 effect

上一篇 下一篇

猜你喜欢

热点阅读