(childToDelete: FiberNode, root: FiberRootNode)
| 362 | } |
| 363 | |
| 364 | function commitDeletion(childToDelete: FiberNode, root: FiberRootNode) { |
| 365 | const rootChildrenToDelete: FiberNode[] = []; |
| 366 | |
| 367 | // 递归子树 |
| 368 | commitNestedComponent(childToDelete, (unmountFiber) => { |
| 369 | switch (unmountFiber.tag) { |
| 370 | case HostComponent: |
| 371 | recordHostChildrenToDelete(rootChildrenToDelete, unmountFiber); |
| 372 | safelyDetachRef(unmountFiber); |
| 373 | return; |
| 374 | case HostText: |
| 375 | recordHostChildrenToDelete(rootChildrenToDelete, unmountFiber); |
| 376 | return; |
| 377 | case FunctionComponent: |
| 378 | commitPassiveEffect(unmountFiber, root, 'unmount'); |
| 379 | return; |
| 380 | default: |
| 381 | if (__DEV__) { |
| 382 | console.warn('未处理的unmount类型', unmountFiber); |
| 383 | } |
| 384 | } |
| 385 | }); |
| 386 | |
| 387 | // 移除rootHostComponent的DOM |
| 388 | if (rootChildrenToDelete.length) { |
| 389 | const hostParent = getHostParent(childToDelete); |
| 390 | if (hostParent !== null) { |
| 391 | rootChildrenToDelete.forEach((node) => { |
| 392 | removeChild(node.stateNode, hostParent); |
| 393 | }); |
| 394 | } |
| 395 | } |
| 396 | childToDelete.return = null; |
| 397 | childToDelete.child = null; |
| 398 | } |
| 399 | |
| 400 | function commitNestedComponent( |
| 401 | root: FiberNode, |
no test coverage detected