MCPcopy Create free account
hub / github.com/RobPruzan/react-scratch / findParentViewNode

Function findParentViewNode

src/react/core.ts:484–512  ·  view source on GitHub ↗
(id: string)

Source from the content-addressed store, hash-verified

482};
483
484const findParentViewNode = (id: string): ReactViewTreeNode => {
485 const aux = (viewNode: ReactViewTreeNode): ReactViewTreeNode | undefined => {
486 if (viewNode.kind === "empty-slot") {
487 return;
488 }
489 for (const node of viewNode.childNodes) {
490 if (node.id === id) {
491 return viewNode;
492 }
493
494 const res = aux(node);
495
496 if (res) {
497 return res;
498 }
499 }
500 };
501
502 if (currentTreeRef.viewTree?.root?.id === id) {
503 return currentTreeRef.viewTree.root;
504 }
505
506 const result = aux(currentTreeRef.viewTree?.root!);
507
508 if (!result) {
509 throw new Error("detached node or wrong id:" + id + "\n\n");
510 }
511 return result;
512};
513
514const findParentRenderNode = (renderNode: ReactRenderTreeNode) => {
515 if (!currentTreeRef.renderTree) {

Callers 1

triggerReRenderFunction · 0.85

Calls 1

auxFunction · 0.70

Tested by

no test coverage detected