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

Function reconcileChildrenArray

code/communication/public/app.js:9285–9422  ·  view source on GitHub ↗
(returnFiber, currentFirstChild, newChildren, expirationTime)

Source from the content-addressed store, hash-verified

9283 }
9284
9285 function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, expirationTime) {
9286 // This algorithm can't optimize by searching from boths ends since we
9287 // don't have backpointers on fibers. I'm trying to see how far we can get
9288 // with that model. If it ends up not being worth the tradeoffs, we can
9289 // add it later.
9290
9291 // Even with a two ended optimization, we'd want to optimize for the case
9292 // where there are few changes and brute force the comparison instead of
9293 // going for the Map. It'd like to explore hitting that path first in
9294 // forward-only mode and only go for the Map once we notice that we need
9295 // lots of look ahead. This doesn't handle reversal as well as two ended
9296 // search but that's unusual. Besides, for the two ended optimization to
9297 // work on Iterables, we'd need to copy the whole set.
9298
9299 // In this first iteration, we'll just live with hitting the bad case
9300 // (adding everything to a Map) in for every insert/move.
9301
9302 // If you change this code, also update reconcileChildrenIterator() which
9303 // uses the same algorithm.
9304
9305 {
9306 // First, validate keys.
9307 var knownKeys = null;
9308 for (var i = 0; i < newChildren.length; i++) {
9309 var child = newChildren[i];
9310 knownKeys = warnOnInvalidKey(child, knownKeys);
9311 }
9312 }
9313
9314 var resultingFirstChild = null;
9315 var previousNewFiber = null;
9316
9317 var oldFiber = currentFirstChild;
9318 var lastPlacedIndex = 0;
9319 var newIdx = 0;
9320 var nextOldFiber = null;
9321 for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {
9322 if (oldFiber.index > newIdx) {
9323 nextOldFiber = oldFiber;
9324 oldFiber = null;
9325 } else {
9326 nextOldFiber = oldFiber.sibling;
9327 }
9328 var newFiber = updateSlot(returnFiber, oldFiber, newChildren[newIdx], expirationTime);
9329 if (newFiber === null) {
9330 // TODO: This breaks on empty slots like null children. That's
9331 // unfortunate because it triggers the slow path all the time. We need
9332 // a better way to communicate whether this was a miss or null,
9333 // boolean, undefined, etc.
9334 if (oldFiber === null) {
9335 oldFiber = nextOldFiber;
9336 }
9337 break;
9338 }
9339 if (shouldTrackSideEffects) {
9340 if (oldFiber && newFiber.alternate === null) {
9341 // We matched the slot, but we didn't reuse the existing fiber, so we
9342 // 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