MCPcopy Index your code
hub / github.com/krasimir/react-in-patterns / reconcileChildrenArray

Function reconcileChildrenArray

code/composition/public/app.js:9388–9525  ·  view source on GitHub ↗
(returnFiber, currentFirstChild, newChildren, expirationTime)

Source from the content-addressed store, hash-verified

9386 }
9387
9388 function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, expirationTime) {
9389 // This algorithm can't optimize by searching from boths ends since we
9390 // don't have backpointers on fibers. I'm trying to see how far we can get
9391 // with that model. If it ends up not being worth the tradeoffs, we can
9392 // add it later.
9393
9394 // Even with a two ended optimization, we'd want to optimize for the case
9395 // where there are few changes and brute force the comparison instead of
9396 // going for the Map. It'd like to explore hitting that path first in
9397 // forward-only mode and only go for the Map once we notice that we need
9398 // lots of look ahead. This doesn't handle reversal as well as two ended
9399 // search but that's unusual. Besides, for the two ended optimization to
9400 // work on Iterables, we'd need to copy the whole set.
9401
9402 // In this first iteration, we'll just live with hitting the bad case
9403 // (adding everything to a Map) in for every insert/move.
9404
9405 // If you change this code, also update reconcileChildrenIterator() which
9406 // uses the same algorithm.
9407
9408 {
9409 // First, validate keys.
9410 var knownKeys = null;
9411 for (var i = 0; i < newChildren.length; i++) {
9412 var child = newChildren[i];
9413 knownKeys = warnOnInvalidKey(child, knownKeys);
9414 }
9415 }
9416
9417 var resultingFirstChild = null;
9418 var previousNewFiber = null;
9419
9420 var oldFiber = currentFirstChild;
9421 var lastPlacedIndex = 0;
9422 var newIdx = 0;
9423 var nextOldFiber = null;
9424 for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {
9425 if (oldFiber.index > newIdx) {
9426 nextOldFiber = oldFiber;
9427 oldFiber = null;
9428 } else {
9429 nextOldFiber = oldFiber.sibling;
9430 }
9431 var newFiber = updateSlot(returnFiber, oldFiber, newChildren[newIdx], expirationTime);
9432 if (newFiber === null) {
9433 // TODO: This breaks on empty slots like null children. That's
9434 // unfortunate because it triggers the slow path all the time. We need
9435 // a better way to communicate whether this was a miss or null,
9436 // boolean, undefined, etc.
9437 if (oldFiber === null) {
9438 oldFiber = nextOldFiber;
9439 }
9440 break;
9441 }
9442 if (shouldTrackSideEffects) {
9443 if (oldFiber && newFiber.alternate === null) {
9444 // We matched the slot, but we didn't reuse the existing fiber, so we
9445 // 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