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

Function generateViewTreeHelper

src/react/core.ts:959–1266  ·  view source on GitHub ↗
({
  renderNode,
  startingFromRenderNodeId,
  parentViewNode,
  isEntrypoint = false,
}: {
  renderNode: ReactRenderTreeNode;

  parentViewNode: ReactViewTreeNode | null;
  startingFromRenderNodeId: string;
  isEntrypoint?: boolean;
})

Source from the content-addressed store, hash-verified

957};
958
959const generateViewTreeHelper = ({
960 renderNode,
961 startingFromRenderNodeId,
962 parentViewNode,
963 isEntrypoint = false,
964}: {
965 renderNode: ReactRenderTreeNode;
966
967 parentViewNode: ReactViewTreeNode | null;
968 startingFromRenderNodeId: string;
969 isEntrypoint?: boolean;
970}): ReactViewTreeNode => {
971 if (!currentTreeRef.renderTree) {
972 throw new Error("Cannot render component outside of react tree");
973 }
974 // if the node itself represents nothing, don't traverse
975 if (renderNode.kind === "empty-slot") {
976 const newId = crypto.randomUUID();
977 // renderNode.computedViewTreeNodeId = newId;
978 return {
979 kind: "empty-slot",
980 id: newId,
981 parent: parentViewNode,
982 };
983 }
984
985 // console.log(
986 // "bytes of render tree",
987 // calculateJsonBytes(JSON.stringify(currentTreeRef.renderTree))
988 // );
989 // if the component directly outputs an empty slot, nothing to generate so don't traverse
990 if (renderNode.internalMetadata.kind === "empty-slot") {
991 const newId = crypto.randomUUID();
992 renderNode.computedViewTreeNodeId = newId;
993 const node: ReactViewTreeNodeRealElement = {
994 id: newId,
995 metadata: renderNode.internalMetadata,
996 childNodes: [],
997 indexPath: renderNode.indexPath,
998 kind: "real-element",
999 parent: parentViewNode,
1000 };
1001 node.childNodes.push({
1002 kind: "empty-slot",
1003 id: crypto.randomUUID(),
1004 parent: node,
1005 });
1006 return node;
1007 }
1008
1009 const newNode: ReactViewTreeNodeRealElement = {
1010 id: crypto.randomUUID(),
1011 metadata: renderNode.internalMetadata,
1012 childNodes: [],
1013 indexPath: renderNode.indexPath,
1014 kind: "real-element",
1015 parent: parentViewNode,
1016

Callers 2

generateViewTreeFunction · 0.85
reRenderChildFunction · 0.85

Calls 8

findRenderNodeOrThrowFunction · 0.85
reRenderChildFunction · 0.85
findViewNodeOrThrowFunction · 0.85
isChildOfFunction · 0.85
getComponentNameFunction · 0.85
compareIndexPathsFunction · 0.85

Tested by

no test coverage detected