|
|
|
@ -4,11 +4,18 @@
@@ -4,11 +4,18 @@
|
|
|
|
|
|
|
|
|
|
```javascript |
|
|
|
|
function beginWork(current, workInProgress, renderLanes) { |
|
|
|
|
|
|
|
|
|
// 前 beginWork 阶段 |
|
|
|
|
if (current !== null) { |
|
|
|
|
...... |
|
|
|
|
} else { |
|
|
|
|
...... |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 正式 beginWork 阶段 |
|
|
|
|
switch (workInProgress.tag) { |
|
|
|
|
...... |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
@ -16,12 +23,22 @@ beginWork 函数接受三个参数,分别是 current 节点,workInProgress
@@ -16,12 +23,22 @@ beginWork 函数接受三个参数,分别是 current 节点,workInProgress
|
|
|
|
|
|
|
|
|
|
## 前 beginWork 阶段 |
|
|
|
|
|
|
|
|
|
在进入正式 beginWork 阶段之前,会先对 current 节点进行空值判断,如果 current 节点不存在则表示在上一次的渲染当中不存在当前节点,会进入相对应的 current 为空的逻辑:didReceiveUpdate 赋值为 false |
|
|
|
|
```javascript |
|
|
|
|
if (current !== null) { |
|
|
|
|
...... |
|
|
|
|
} else { |
|
|
|
|
didReceiveUpdate = false; |
|
|
|
|
} |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
在进入正式 beginWork 阶段之前,会先对传入的 current 节点进行空值判断,根据 current 是否为空进入不同的处理逻辑,这一段代码的主要目的是为了赋值 didReceiveUpdate 变量 |
|
|
|
|
|
|
|
|
|
### current 不为空 |
|
|
|
|
|
|
|
|
|
### current 为空 |
|
|
|
|
|
|
|
|
|
didReceiveUpdate 赋值为 false |
|
|
|
|
|
|
|
|
|
## 正式 beginWork 阶段 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|