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

Function reconcileChildrenIterator

code/styling/public/app.js:9389–9532  ·  view source on GitHub ↗
(returnFiber, currentFirstChild, newChildrenIterable, expirationTime)

Source from the content-addressed store, hash-verified

9387 }
9388
9389 function reconcileChildrenIterator(returnFiber, currentFirstChild, newChildrenIterable, expirationTime) {
9390 // This is the same implementation as reconcileChildrenArray(),
9391 // but using the iterator instead.
9392
9393 var iteratorFn = getIteratorFn(newChildrenIterable);
9394 !(typeof iteratorFn === 'function') ? invariant(false, 'An object is not an iterable. This error is likely caused by a bug in React. Please file an issue.') : void 0;
9395
9396 {
9397 // Warn about using Maps as children
9398 if (typeof newChildrenIterable.entries === 'function') {
9399 var possibleMap = newChildrenIterable;
9400 if (possibleMap.entries === iteratorFn) {
9401 warning(didWarnAboutMaps, 'Using Maps as children is unsupported and will likely yield ' + 'unexpected results. Convert it to a sequence/iterable of keyed ' + 'ReactElements instead.%s', getCurrentFiberStackAddendum$2());
9402 didWarnAboutMaps = true;
9403 }
9404 }
9405
9406 // First, validate keys.
9407 // We'll get a different iterator later for the main pass.
9408 var _newChildren = iteratorFn.call(newChildrenIterable);
9409 if (_newChildren) {
9410 var knownKeys = null;
9411 var _step = _newChildren.next();
9412 for (; !_step.done; _step = _newChildren.next()) {
9413 var child = _step.value;
9414 knownKeys = warnOnInvalidKey(child, knownKeys);
9415 }
9416 }
9417 }
9418
9419 var newChildren = iteratorFn.call(newChildrenIterable);
9420 !(newChildren != null) ? invariant(false, 'An iterable object provided no iterator.') : void 0;
9421
9422 var resultingFirstChild = null;
9423 var previousNewFiber = null;
9424
9425 var oldFiber = currentFirstChild;
9426 var lastPlacedIndex = 0;
9427 var newIdx = 0;
9428 var nextOldFiber = null;
9429
9430 var step = newChildren.next();
9431 for (; oldFiber !== null && !step.done; newIdx++, step = newChildren.next()) {
9432 if (oldFiber.index > newIdx) {
9433 nextOldFiber = oldFiber;
9434 oldFiber = null;
9435 } else {
9436 nextOldFiber = oldFiber.sibling;
9437 }
9438 var newFiber = updateSlot(returnFiber, oldFiber, step.value, expirationTime);
9439 if (newFiber === null) {
9440 // TODO: This breaks on empty slots like null children. That's
9441 // unfortunate because it triggers the slow path all the time. We need
9442 // a better way to communicate whether this was a miss or null,
9443 // boolean, undefined, etc.
9444 if (!oldFiber) {
9445 oldFiber = nextOldFiber;
9446 }

Callers 1

reconcileChildFibersFunction · 0.70

Calls 11

warningFunction · 0.85
getIteratorFnFunction · 0.70
invariantFunction · 0.70
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