MCPcopy Create free account
hub / github.com/reactjs/react-rails / reconcileChildrenArray

Function reconcileChildrenArray

lib/assets/react-source/development/react.js:17505–17654  ·  view source on GitHub ↗
(returnFiber, currentFirstChild, newChildren, expirationTime)

Source from the content-addressed store, hash-verified

17503 }
17504
17505 function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, expirationTime) {
17506 // This algorithm can't optimize by searching from both ends since we
17507 // don't have backpointers on fibers. I'm trying to see how far we can get
17508 // with that model. If it ends up not being worth the tradeoffs, we can
17509 // add it later.
17510 // Even with a two ended optimization, we'd want to optimize for the case
17511 // where there are few changes and brute force the comparison instead of
17512 // going for the Map. It'd like to explore hitting that path first in
17513 // forward-only mode and only go for the Map once we notice that we need
17514 // lots of look ahead. This doesn't handle reversal as well as two ended
17515 // search but that's unusual. Besides, for the two ended optimization to
17516 // work on Iterables, we'd need to copy the whole set.
17517 // In this first iteration, we'll just live with hitting the bad case
17518 // (adding everything to a Map) in for every insert/move.
17519 // If you change this code, also update reconcileChildrenIterator() which
17520 // uses the same algorithm.
17521 {
17522 // First, validate keys.
17523 var knownKeys = null;
17524
17525 for (var i = 0; i < newChildren.length; i++) {
17526 var child = newChildren[i];
17527 knownKeys = warnOnInvalidKey(child, knownKeys);
17528 }
17529 }
17530
17531 var resultingFirstChild = null;
17532 var previousNewFiber = null;
17533 var oldFiber = currentFirstChild;
17534 var lastPlacedIndex = 0;
17535 var newIdx = 0;
17536 var nextOldFiber = null;
17537
17538 for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {
17539 if (oldFiber.index > newIdx) {
17540 nextOldFiber = oldFiber;
17541 oldFiber = null;
17542 } else {
17543 nextOldFiber = oldFiber.sibling;
17544 }
17545
17546 var newFiber = updateSlot(returnFiber, oldFiber, newChildren[newIdx], expirationTime);
17547
17548 if (newFiber === null) {
17549 // TODO: This breaks on empty slots like null children. That's
17550 // unfortunate because it triggers the slow path all the time. We need
17551 // a better way to communicate whether this was a miss or null,
17552 // boolean, undefined, etc.
17553 if (oldFiber === null) {
17554 oldFiber = nextOldFiber;
17555 }
17556
17557 break;
17558 }
17559
17560 if (shouldTrackSideEffects) {
17561 if (oldFiber && newFiber.alternate === null) {
17562 // We matched the slot, but we didn't reuse the existing fiber, so we

Callers 1

reconcileChildFibersFunction · 0.85

Calls 8

warnOnInvalidKeyFunction · 0.85
updateSlotFunction · 0.85
deleteChildFunction · 0.85
placeChildFunction · 0.85
deleteRemainingChildrenFunction · 0.85
createChildFunction · 0.85
mapRemainingChildrenFunction · 0.85
updateFromMapFunction · 0.85

Tested by

no test coverage detected