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

Function reconcileChildrenArray

code/styling/public/app.js:9250–9387  ·  view source on GitHub ↗
(returnFiber, currentFirstChild, newChildren, expirationTime)

Source from the content-addressed store, hash-verified

9248 }
9249
9250 function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, expirationTime) {
9251 // This algorithm can't optimize by searching from boths ends since we
9252 // don't have backpointers on fibers. I'm trying to see how far we can get
9253 // with that model. If it ends up not being worth the tradeoffs, we can
9254 // add it later.
9255
9256 // Even with a two ended optimization, we'd want to optimize for the case
9257 // where there are few changes and brute force the comparison instead of
9258 // going for the Map. It'd like to explore hitting that path first in
9259 // forward-only mode and only go for the Map once we notice that we need
9260 // lots of look ahead. This doesn't handle reversal as well as two ended
9261 // search but that's unusual. Besides, for the two ended optimization to
9262 // work on Iterables, we'd need to copy the whole set.
9263
9264 // In this first iteration, we'll just live with hitting the bad case
9265 // (adding everything to a Map) in for every insert/move.
9266
9267 // If you change this code, also update reconcileChildrenIterator() which
9268 // uses the same algorithm.
9269
9270 {
9271 // First, validate keys.
9272 var knownKeys = null;
9273 for (var i = 0; i < newChildren.length; i++) {
9274 var child = newChildren[i];
9275 knownKeys = warnOnInvalidKey(child, knownKeys);
9276 }
9277 }
9278
9279 var resultingFirstChild = null;
9280 var previousNewFiber = null;
9281
9282 var oldFiber = currentFirstChild;
9283 var lastPlacedIndex = 0;
9284 var newIdx = 0;
9285 var nextOldFiber = null;
9286 for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {
9287 if (oldFiber.index > newIdx) {
9288 nextOldFiber = oldFiber;
9289 oldFiber = null;
9290 } else {
9291 nextOldFiber = oldFiber.sibling;
9292 }
9293 var newFiber = updateSlot(returnFiber, oldFiber, newChildren[newIdx], expirationTime);
9294 if (newFiber === null) {
9295 // TODO: This breaks on empty slots like null children. That's
9296 // unfortunate because it triggers the slow path all the time. We need
9297 // a better way to communicate whether this was a miss or null,
9298 // boolean, undefined, etc.
9299 if (oldFiber === null) {
9300 oldFiber = nextOldFiber;
9301 }
9302 break;
9303 }
9304 if (shouldTrackSideEffects) {
9305 if (oldFiber && newFiber.alternate === null) {
9306 // We matched the slot, but we didn't reuse the existing fiber, so we
9307 // 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