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

Function precacheChildNodes

bundle.js:5629–5632  ·  view source on GitHub ↗

* Populate `_hostNode` on each child of `inst`, assuming that the children * match up with the DOM (element) children of `node`. * * We cache entire levels at once to avoid an n^2 problem where we access the * children of a node sequentially and have to walk from the start to our target * node

(inst,node)

Source from the content-addressed store, hash-verified

5627 * `prepareToManageChildren` before we change `_renderedChildren`, at which
5628 * time the container's child nodes are always cached (until it unmounts).
5629 */function precacheChildNodes(inst,node){if(inst._flags&Flags.hasCachedChildNodes){return;}var children=inst._renderedChildren;var childNode=node.firstChild;outer:for(var name in children){if(!children.hasOwnProperty(name)){continue;}var childInst=children[name];var childID=getRenderedHostOrTextFromComponent(childInst)._domID;if(childID===0){// We're currently unmounting this child in ReactMultiChild; skip it.
5630continue;}// We assume the child nodes are in the same order as the child instances.
5631for(;childNode!==null;childNode=childNode.nextSibling){if(shouldPrecacheNode(childNode,childID)){precacheNode(childInst,childNode);continue outer;}}// We reached the end of the DOM children without finding an ID match.
5632invariant(false,'Unable to find element with ID %s.',childID);}inst._flags|=Flags.hasCachedChildNodes;}/**
5633 * Given a DOM node, return the closest ReactDOMComponent or
5634 * ReactDOMTextComponent instance ancestor.
5635 */function getClosestInstanceFromNode(node){if(node[internalInstanceKey]){return node[internalInstanceKey];}// Walk up the tree until we find an ancestor whose instance we have cached.

Callers 2

getNodeFromInstanceFunction · 0.85

Calls 4

shouldPrecacheNodeFunction · 0.85
precacheNodeFunction · 0.85
invariantFunction · 0.70

Tested by

no test coverage detected