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

Function reconcileChildrenIterator

code/communication/public/app.js:9424–9567  ·  view source on GitHub ↗
(returnFiber, currentFirstChild, newChildrenIterable, expirationTime)

Source from the content-addressed store, hash-verified

9422 }
9423
9424 function reconcileChildrenIterator(returnFiber, currentFirstChild, newChildrenIterable, expirationTime) {
9425 // This is the same implementation as reconcileChildrenArray(),
9426 // but using the iterator instead.
9427
9428 var iteratorFn = getIteratorFn(newChildrenIterable);
9429 !(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;
9430
9431 {
9432 // Warn about using Maps as children
9433 if (typeof newChildrenIterable.entries === 'function') {
9434 var possibleMap = newChildrenIterable;
9435 if (possibleMap.entries === iteratorFn) {
9436 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());
9437 didWarnAboutMaps = true;
9438 }
9439 }
9440
9441 // First, validate keys.
9442 // We'll get a different iterator later for the main pass.
9443 var _newChildren = iteratorFn.call(newChildrenIterable);
9444 if (_newChildren) {
9445 var knownKeys = null;
9446 var _step = _newChildren.next();
9447 for (; !_step.done; _step = _newChildren.next()) {
9448 var child = _step.value;
9449 knownKeys = warnOnInvalidKey(child, knownKeys);
9450 }
9451 }
9452 }
9453
9454 var newChildren = iteratorFn.call(newChildrenIterable);
9455 !(newChildren != null) ? invariant(false, 'An iterable object provided no iterator.') : void 0;
9456
9457 var resultingFirstChild = null;
9458 var previousNewFiber = null;
9459
9460 var oldFiber = currentFirstChild;
9461 var lastPlacedIndex = 0;
9462 var newIdx = 0;
9463 var nextOldFiber = null;
9464
9465 var step = newChildren.next();
9466 for (; oldFiber !== null && !step.done; newIdx++, step = newChildren.next()) {
9467 if (oldFiber.index > newIdx) {
9468 nextOldFiber = oldFiber;
9469 oldFiber = null;
9470 } else {
9471 nextOldFiber = oldFiber.sibling;
9472 }
9473 var newFiber = updateSlot(returnFiber, oldFiber, step.value, expirationTime);
9474 if (newFiber === null) {
9475 // TODO: This breaks on empty slots like null children. That's
9476 // unfortunate because it triggers the slow path all the time. We need
9477 // a better way to communicate whether this was a miss or null,
9478 // boolean, undefined, etc.
9479 if (!oldFiber) {
9480 oldFiber = nextOldFiber;
9481 }

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