(
returnFiber: Fiber,
currentFirstChild: Fiber | null,
newChildren: ?Iterator<mixed>,
lanes: Lanes,
)
| 1430 | } |
| 1431 | |
| 1432 | function reconcileChildrenIterator( |
| 1433 | returnFiber: Fiber, |
| 1434 | currentFirstChild: Fiber | null, |
| 1435 | newChildren: ?Iterator<mixed>, |
| 1436 | lanes: Lanes, |
| 1437 | ): Fiber | null { |
| 1438 | if (newChildren == null) { |
| 1439 | throw new Error('An iterable object provided no iterator.'); |
| 1440 | } |
| 1441 | |
| 1442 | let resultingFirstChild: Fiber | null = null; |
| 1443 | let previousNewFiber: Fiber | null = null; |
| 1444 | |
| 1445 | let oldFiber = currentFirstChild; |
| 1446 | let lastPlacedIndex = 0; |
| 1447 | let newIdx = 0; |
| 1448 | let nextOldFiber = null; |
| 1449 | |
| 1450 | let knownKeys: Set<string> | null = null; |
| 1451 | |
| 1452 | let step = newChildren.next(); |
| 1453 | for ( |
| 1454 | ; |
| 1455 | oldFiber !== null && !step.done; |
| 1456 | newIdx++, step = newChildren.next() |
| 1457 | ) { |
| 1458 | if (oldFiber.index > newIdx) { |
| 1459 | nextOldFiber = oldFiber; |
| 1460 | oldFiber = null; |
| 1461 | } else { |
| 1462 | nextOldFiber = oldFiber.sibling; |
| 1463 | } |
| 1464 | const newFiber = updateSlot(returnFiber, oldFiber, step.value, lanes); |
| 1465 | if (newFiber === null) { |
| 1466 | // TODO: This breaks on empty slots like null children. That's |
| 1467 | // unfortunate because it triggers the slow path all the time. We need |
| 1468 | // a better way to communicate whether this was a miss or null, |
| 1469 | // boolean, undefined, etc. |
| 1470 | if (oldFiber === null) { |
| 1471 | oldFiber = nextOldFiber; |
| 1472 | } |
| 1473 | break; |
| 1474 | } |
| 1475 | |
| 1476 | if (__DEV__) { |
| 1477 | knownKeys = warnOnInvalidKey( |
| 1478 | returnFiber, |
| 1479 | newFiber, |
| 1480 | step.value, |
| 1481 | knownKeys, |
| 1482 | ); |
| 1483 | } |
| 1484 | |
| 1485 | if (shouldTrackSideEffects) { |
| 1486 | if (oldFiber && newFiber.alternate === null) { |
| 1487 | // We matched the slot, but we didn't reuse the existing fiber, so we |
| 1488 | // need to delete the existing child. |
| 1489 | deleteChild(returnFiber, oldFiber); |
no test coverage detected