MCPcopy Create free account
hub / github.com/danielstocks/react-sortable / reconcileChildrenIterator

Function reconcileChildrenIterator

bundle.js:7168–7196  ·  view source on GitHub ↗
(returnFiber,currentFirstChild,newChildrenIterable,priority)

Source from the content-addressed store, hash-verified

7166existingChildren['delete'](_newFiber2.key===null?newIdx:_newFiber2.key);}}lastPlacedIndex=placeChild(_newFiber2,lastPlacedIndex,newIdx);if(previousNewFiber===null){resultingFirstChild=_newFiber2;}else{previousNewFiber.sibling=_newFiber2;}previousNewFiber=_newFiber2;}}if(shouldTrackSideEffects){// Any existing children that weren't consumed above were deleted. We need
7167// to add them to the deletion list.
7168existingChildren.forEach(function(child){return deleteChild(returnFiber,child);});}return resultingFirstChild;}function reconcileChildrenIterator(returnFiber,currentFirstChild,newChildrenIterable,priority){// This is the same implementation as reconcileChildrenArray(),
7169// but using the iterator instead.
7170var iteratorFn=getIteratorFn(newChildrenIterable);!(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;{// Warn about using Maps as children
7171if(typeof newChildrenIterable.entries==='function'){var possibleMap=newChildrenIterable;if(possibleMap.entries===iteratorFn){warning$24(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$5());didWarnAboutMaps=true;}}// First, validate keys.
7172// We'll get a different iterator later for the main pass.
7173var _newChildren=iteratorFn.call(newChildrenIterable);if(_newChildren){var knownKeys=null;var _step=_newChildren.next();for(;!_step.done;_step=_newChildren.next()){var child=_step.value;knownKeys=warnOnInvalidKey(child,knownKeys);}}}var newChildren=iteratorFn.call(newChildrenIterable);!(newChildren!=null)?invariant(false,'An iterable object provided no iterator.'):void 0;var resultingFirstChild=null;var previousNewFiber=null;var oldFiber=currentFirstChild;var lastPlacedIndex=0;var newIdx=0;var nextOldFiber=null;var step=newChildren.next();for(;oldFiber!==null&&!step.done;newIdx++,step=newChildren.next()){if(oldFiber.index>newIdx){nextOldFiber=oldFiber;oldFiber=null;}else{nextOldFiber=oldFiber.sibling;}var newFiber=updateSlot(returnFiber,oldFiber,step.value,priority);if(newFiber===null){// TODO: This breaks on empty slots like null children. That's
7174// unfortunate because it triggers the slow path all the time. We need
7175// a better way to communicate whether this was a miss or null,
7176// boolean, undefined, etc.
7177if(!oldFiber){oldFiber=nextOldFiber;}break;}if(shouldTrackSideEffects){if(oldFiber&&newFiber.alternate===null){// We matched the slot, but we didn't reuse the existing fiber, so we
7178// need to delete the existing child.
7179deleteChild(returnFiber,oldFiber);}}lastPlacedIndex=placeChild(newFiber,lastPlacedIndex,newIdx);if(previousNewFiber===null){// TODO: Move out of the loop. This only happens for the first run.
7180resultingFirstChild=newFiber;}else{// TODO: Defer siblings if we're not at the right index for this slot.
7181// I.e. if we had null values before, then we want to defer this
7182// for each null value. However, we also don't want to call updateSlot
7183// with the previous one.
7184previousNewFiber.sibling=newFiber;}previousNewFiber=newFiber;oldFiber=nextOldFiber;}if(step.done){// We've reached the end of the new children. We can delete the rest.
7185deleteRemainingChildren(returnFiber,oldFiber);return resultingFirstChild;}if(oldFiber===null){// If we don't have any more existing children we can choose a fast path
7186// since the rest will all be insertions.
7187for(;!step.done;newIdx++,step=newChildren.next()){var _newFiber3=createChild(returnFiber,step.value,priority);if(_newFiber3===null){continue;}lastPlacedIndex=placeChild(_newFiber3,lastPlacedIndex,newIdx);if(previousNewFiber===null){// TODO: Move out of the loop. This only happens for the first run.
7188resultingFirstChild=_newFiber3;}else{previousNewFiber.sibling=_newFiber3;}previousNewFiber=_newFiber3;}return resultingFirstChild;}// Add all children to a key map for quick lookups.
7189var existingChildren=mapRemainingChildren(returnFiber,oldFiber);// Keep scanning and use the map to restore deleted items as moves.
7190for(;!step.done;newIdx++,step=newChildren.next()){var _newFiber4=updateFromMap(existingChildren,returnFiber,newIdx,step.value,priority);if(_newFiber4!==null){if(shouldTrackSideEffects){if(_newFiber4.alternate!==null){// The new fiber is a work in progress, but if there exists a
7191// current, that means that we reused the fiber. We need to delete
7192// it from the child list so that we don't add it to the deletion
7193// list.
7194existingChildren['delete'](_newFiber4.key===null?newIdx:_newFiber4.key);}}lastPlacedIndex=placeChild(_newFiber4,lastPlacedIndex,newIdx);if(previousNewFiber===null){resultingFirstChild=_newFiber4;}else{previousNewFiber.sibling=_newFiber4;}previousNewFiber=_newFiber4;}}if(shouldTrackSideEffects){// Any existing children that weren't consumed above were deleted. We need
7195// to add them to the deletion list.
7196existingChildren.forEach(function(child){return deleteChild(returnFiber,child);});}return resultingFirstChild;}function reconcileSingleTextNode(returnFiber,currentFirstChild,textContent,priority){// There's no need to check for keys on text nodes since we don't have a
7197// way to define them.
7198if(currentFirstChild!==null&&currentFirstChild.tag===HostText$5){// We already have an existing node so let's just update it and delete
7199// the rest.

Callers 1

reconcileChildFibersFunction · 0.85

Calls 10

warnOnInvalidKeyFunction · 0.85
updateSlotFunction · 0.85
deleteChildFunction · 0.85
placeChildFunction · 0.85
deleteRemainingChildrenFunction · 0.85
createChildFunction · 0.85
mapRemainingChildrenFunction · 0.85
updateFromMapFunction · 0.85
getIteratorFnFunction · 0.70
invariantFunction · 0.70

Tested by

no test coverage detected