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

Function getClosestInstanceFromNode

bundle.js:5635–5639  ·  view source on GitHub ↗

* Given a DOM node, return the closest ReactDOMComponent or * ReactDOMTextComponent instance ancestor.

(node)

Source from the content-addressed store, hash-verified

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.
5636var parents=[];while(!node[internalInstanceKey]){parents.push(node);if(node.parentNode){node=node.parentNode;}else{// Top of the tree. This node must not be part of a React tree (or is
5637// unmounted, potentially).
5638return null;}}var closest;var inst=node[internalInstanceKey];if(inst.tag===HostComponent||inst.tag===HostText){// In Fiber, this will always be the deepest root.
5639return inst;}for(;node&&(inst=node[internalInstanceKey]);node=parents.pop()){closest=inst;if(parents.length){precacheChildNodes(inst,node);}}return closest;}/**
5640 * Given a DOM node, return the ReactDOMComponent or ReactDOMTextComponent
5641 * instance, or null if the node was not rendered by this React.
5642 */function getInstanceFromNode(node){var inst=node[internalInstanceKey];if(inst){if(inst.tag===HostComponent||inst.tag===HostText){return inst;}else if(inst._hostNode===node){return inst;}else{return null;}}inst=getClosestInstanceFromNode(node);if(inst!=null&&inst._hostNode===node){return inst;}else{return null;}}/**

Callers 1

getInstanceFromNodeFunction · 0.85

Calls 1

precacheChildNodesFunction · 0.85

Tested by

no test coverage detected