MCPcopy Create free account
hub / github.com/krasimir/react-in-patterns / reconcileChildrenArray

Function reconcileChildrenArray

code/redux/public/app.js:9501–9638  ·  view source on GitHub ↗
(returnFiber, currentFirstChild, newChildren, expirationTime)

Source from the content-addressed store, hash-verified

9499 }
9500
9501 function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, expirationTime) {
9502 // This algorithm can't optimize by searching from boths ends since we
9503 // don't have backpointers on fibers. I'm trying to see how far we can get
9504 // with that model. If it ends up not being worth the tradeoffs, we can
9505 // add it later.
9506
9507 // Even with a two ended optimization, we'd want to optimize for the case
9508 // where there are few changes and brute force the comparison instead of
9509 // going for the Map. It'd like to explore hitting that path first in
9510 // forward-only mode and only go for the Map once we notice that we need
9511 // lots of look ahead. This doesn't handle reversal as well as two ended
9512 // search but that's unusual. Besides, for the two ended optimization to
9513 // work on Iterables, we'd need to copy the whole set.
9514
9515 // In this first iteration, we'll just live with hitting the bad case
9516 // (adding everything to a Map) in for every insert/move.
9517
9518 // If you change this code, also update reconcileChildrenIterator() which
9519 // uses the same algorithm.
9520
9521 {
9522 // First, validate keys.
9523 var knownKeys = null;
9524 for (var i = 0; i < newChildren.length; i++) {
9525 var child = newChildren[i];
9526 knownKeys = warnOnInvalidKey(child, knownKeys);
9527 }
9528 }
9529
9530 var resultingFirstChild = null;
9531 var previousNewFiber = null;
9532
9533 var oldFiber = currentFirstChild;
9534 var lastPlacedIndex = 0;
9535 var newIdx = 0;
9536 var nextOldFiber = null;
9537 for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {
9538 if (oldFiber.index > newIdx) {
9539 nextOldFiber = oldFiber;
9540 oldFiber = null;
9541 } else {
9542 nextOldFiber = oldFiber.sibling;
9543 }
9544 var newFiber = updateSlot(returnFiber, oldFiber, newChildren[newIdx], expirationTime);
9545 if (newFiber === null) {
9546 // TODO: This breaks on empty slots like null children. That's
9547 // unfortunate because it triggers the slow path all the time. We need
9548 // a better way to communicate whether this was a miss or null,
9549 // boolean, undefined, etc.
9550 if (oldFiber === null) {
9551 oldFiber = nextOldFiber;
9552 }
9553 break;
9554 }
9555 if (shouldTrackSideEffects) {
9556 if (oldFiber && newFiber.alternate === null) {
9557 // We matched the slot, but we didn't reuse the existing fiber, so we
9558 // need to delete the existing child.

Callers 1

reconcileChildFibersFunction · 0.70

Calls 8

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

Tested by

no test coverage detected