| 38 | let nextEffect: FiberNode | null = null; |
| 39 | |
| 40 | export const commitEffects = ( |
| 41 | phrase: 'mutation' | 'layout', |
| 42 | mask: Flags, |
| 43 | callback: (fiber: FiberNode, root: FiberRootNode) => void |
| 44 | ) => { |
| 45 | return (finishedWork: FiberNode, root: FiberRootNode) => { |
| 46 | nextEffect = finishedWork; |
| 47 | while (nextEffect !== null) { |
| 48 | // 向下遍历 |
| 49 | const child: FiberNode | null = nextEffect.child; |
| 50 | |
| 51 | if ((nextEffect.subtreeFlags & mask) !== NoFlags && child !== null) { |
| 52 | nextEffect = child; |
| 53 | } else { |
| 54 | // 向上遍历 DFS |
| 55 | up: while (nextEffect !== null) { |
| 56 | callback(nextEffect, root); |
| 57 | const sibling: FiberNode | null = nextEffect.sibling; |
| 58 | |
| 59 | if (sibling !== null) { |
| 60 | nextEffect = sibling; |
| 61 | break up; |
| 62 | } |
| 63 | nextEffect = nextEffect.return; |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | }; |
| 68 | }; |
| 69 | |
| 70 | const commitMutationEffectsOnFiber = ( |
| 71 | finishedWork: FiberNode, |