|
|
@ -161,46 +161,13 @@ switch 中的 case 逻辑太多了,全部都写出来会让笔记显得特别 |
|
|
|
|
|
|
|
|
|
|
|
### updateHostRoot |
|
|
|
### updateHostRoot |
|
|
|
|
|
|
|
|
|
|
|
首先会执行 pushHostRootContext 函数,这个函数与 context 有关 |
|
|
|
首先会执行 pushHostRootContext 函数,这个函数与 context 有关,暂且不谈 |
|
|
|
|
|
|
|
|
|
|
|
**pushHostRootContext** |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```javascript |
|
|
|
|
|
|
|
function pushHostRootContext(workInProgress) { |
|
|
|
|
|
|
|
var root = workInProgress.stateNode; |
|
|
|
|
|
|
|
if (root.pendingContext) { |
|
|
|
|
|
|
|
pushTopLevelContextObject( |
|
|
|
|
|
|
|
workInProgress, |
|
|
|
|
|
|
|
root.pendingContext, |
|
|
|
|
|
|
|
root.pendingContext !== root.context |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} else if (root.context) { |
|
|
|
|
|
|
|
// Should always be set |
|
|
|
|
|
|
|
pushTopLevelContextObject(workInProgress, root.context, false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pushHostContainer(workInProgress, root.containerInfo); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
**pushTopLevelContextObject** |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```javascript |
|
|
|
|
|
|
|
function pushTopLevelContextObject(fiber, context, didChange) { |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (contextStackCursor.current !== emptyContextObject) { |
|
|
|
|
|
|
|
throw new Error("..."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
push(contextStackCursor, context, fiber); |
|
|
|
|
|
|
|
push(didPerformWorkStackCursor, didChange, fiber); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```javascript |
|
|
|
```javascript |
|
|
|
function updateHostRoot(current, workInProgress, renderLanes) { |
|
|
|
function updateHostRoot(current, workInProgress, renderLanes) { |
|
|
|
|
|
|
|
// context 相关 |
|
|
|
pushHostRootContext(workInProgress); |
|
|
|
pushHostRootContext(workInProgress); |
|
|
|
|
|
|
|
// 取出 updateQueue |
|
|
|
var updateQueue = workInProgress.updateQueue; |
|
|
|
var updateQueue = workInProgress.updateQueue; |
|
|
|
if (current === null || updateQueue === null) { |
|
|
|
if (current === null || updateQueue === null) { |
|
|
|
throw new Error("..."); |
|
|
|
throw new Error("..."); |
|
|
|