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

Function reconcileChildrenIterator

code/new-context-api/public/app.js:8750–8893  ·  view source on GitHub ↗
(returnFiber, currentFirstChild, newChildrenIterable, expirationTime)

Source from the content-addressed store, hash-verified

8748 }
8749
8750 function reconcileChildrenIterator(returnFiber, currentFirstChild, newChildrenIterable, expirationTime) {
8751 // This is the same implementation as reconcileChildrenArray(),
8752 // but using the iterator instead.
8753
8754 var iteratorFn = getIteratorFn(newChildrenIterable);
8755 !(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;
8756
8757 {
8758 // Warn about using Maps as children
8759 if (typeof newChildrenIterable.entries === 'function') {
8760 var possibleMap = newChildrenIterable;
8761 if (possibleMap.entries === iteratorFn) {
8762 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());
8763 didWarnAboutMaps = true;
8764 }
8765 }
8766
8767 // First, validate keys.
8768 // We'll get a different iterator later for the main pass.
8769 var _newChildren = iteratorFn.call(newChildrenIterable);
8770 if (_newChildren) {
8771 var knownKeys = null;
8772 var _step = _newChildren.next();
8773 for (; !_step.done; _step = _newChildren.next()) {
8774 var child = _step.value;
8775 knownKeys = warnOnInvalidKey(child, knownKeys);
8776 }
8777 }
8778 }
8779
8780 var newChildren = iteratorFn.call(newChildrenIterable);
8781 !(newChildren != null) ? invariant(false, 'An iterable object provided no iterator.') : void 0;
8782
8783 var resultingFirstChild = null;
8784 var previousNewFiber = null;
8785
8786 var oldFiber = currentFirstChild;
8787 var lastPlacedIndex = 0;
8788 var newIdx = 0;
8789 var nextOldFiber = null;
8790
8791 var step = newChildren.next();
8792 for (; oldFiber !== null && !step.done; newIdx++, step = newChildren.next()) {
8793 if (oldFiber.index > newIdx) {
8794 nextOldFiber = oldFiber;
8795 oldFiber = null;
8796 } else {
8797 nextOldFiber = oldFiber.sibling;
8798 }
8799 var newFiber = updateSlot(returnFiber, oldFiber, step.value, expirationTime);
8800 if (newFiber === null) {
8801 // TODO: This breaks on empty slots like null children. That's
8802 // unfortunate because it triggers the slow path all the time. We need
8803 // a better way to communicate whether this was a miss or null,
8804 // boolean, undefined, etc.
8805 if (!oldFiber) {
8806 oldFiber = nextOldFiber;
8807 }

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