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

Function reconcileChildrenArray

code/new-context-api/public/app.js:8611–8748  ·  view source on GitHub ↗
(returnFiber, currentFirstChild, newChildren, expirationTime)

Source from the content-addressed store, hash-verified

8609 }
8610
8611 function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, expirationTime) {
8612 // This algorithm can't optimize by searching from boths ends since we
8613 // don't have backpointers on fibers. I'm trying to see how far we can get
8614 // with that model. If it ends up not being worth the tradeoffs, we can
8615 // add it later.
8616
8617 // Even with a two ended optimization, we'd want to optimize for the case
8618 // where there are few changes and brute force the comparison instead of
8619 // going for the Map. It'd like to explore hitting that path first in
8620 // forward-only mode and only go for the Map once we notice that we need
8621 // lots of look ahead. This doesn't handle reversal as well as two ended
8622 // search but that's unusual. Besides, for the two ended optimization to
8623 // work on Iterables, we'd need to copy the whole set.
8624
8625 // In this first iteration, we'll just live with hitting the bad case
8626 // (adding everything to a Map) in for every insert/move.
8627
8628 // If you change this code, also update reconcileChildrenIterator() which
8629 // uses the same algorithm.
8630
8631 {
8632 // First, validate keys.
8633 var knownKeys = null;
8634 for (var i = 0; i < newChildren.length; i++) {
8635 var child = newChildren[i];
8636 knownKeys = warnOnInvalidKey(child, knownKeys);
8637 }
8638 }
8639
8640 var resultingFirstChild = null;
8641 var previousNewFiber = null;
8642
8643 var oldFiber = currentFirstChild;
8644 var lastPlacedIndex = 0;
8645 var newIdx = 0;
8646 var nextOldFiber = null;
8647 for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {
8648 if (oldFiber.index > newIdx) {
8649 nextOldFiber = oldFiber;
8650 oldFiber = null;
8651 } else {
8652 nextOldFiber = oldFiber.sibling;
8653 }
8654 var newFiber = updateSlot(returnFiber, oldFiber, newChildren[newIdx], expirationTime);
8655 if (newFiber === null) {
8656 // TODO: This breaks on empty slots like null children. That's
8657 // unfortunate because it triggers the slow path all the time. We need
8658 // a better way to communicate whether this was a miss or null,
8659 // boolean, undefined, etc.
8660 if (oldFiber === null) {
8661 oldFiber = nextOldFiber;
8662 }
8663 break;
8664 }
8665 if (shouldTrackSideEffects) {
8666 if (oldFiber && newFiber.alternate === null) {
8667 // We matched the slot, but we didn't reuse the existing fiber, so we
8668 // 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