MCPcopy Create free account
hub / github.com/thetarnav/solid-devtools / attachDebugger

Function attachDebugger

packages/debugger/src/main/roots.ts:87–145  ·  view source on GitHub ↗
(owner = setup.solid.getOwner())

Source from the content-addressed store, hash-verified

85 * });
86 */
87export function attachDebugger(owner = setup.solid.getOwner()): void {
88
89 if (!owner)
90 return warn('reatachOwner helper should be called synchronously in a reactive owner.')
91
92 // find all the roots in the owner tree (walking up the tree)
93 const roots: Solid.Root[] = []
94 let isFirstTopLevel = true
95 while (owner) {
96 if (isSolidRoot(owner)) {
97 // disposed
98 if (owner.isDisposed) return
99 // already attached
100 if (RootMap.has(getSdtId(owner, ObjectType.Owner))) {
101 isFirstTopLevel = false
102 break
103 }
104 roots.push(owner)
105 }
106 owner = owner.owner
107 }
108
109 // attach roots in reverse order (from top to bottom)
110 for (let i = roots.length - 1; i >= 0; i--) {
111 const root = roots[i]!
112 root.sdtType = NodeType.Root
113
114 onOwnerCleanup(root, () => cleanupRoot(root), true)
115
116 const isTopLevel = isFirstTopLevel && i === 0
117
118 // root (top-level)
119 if (isTopLevel) {
120 createTopRoot(root)
121 return
122 }
123 // sub-root (nested)
124 let parent = findClosestAliveParent(root)
125 if (!parent.owner) return warn('Parent owner is missing.')
126 changeRootAttachment(root, parent.owner)
127
128 const onParentCleanup = () => {
129 const newParent = findClosestAliveParent(root)
130 changeRootAttachment(root, newParent.owner)
131 // still a sub-root
132 if (newParent.owner) {
133 parent = newParent
134 onOwnerCleanup(parent.root, onParentCleanup)
135 }
136 // becomes a root
137 else {
138 removeOwnCleanup()
139 createTopRoot(root)
140 }
141 }
142 const removeParentCleanup = onOwnerCleanup(parent.root, onParentCleanup)
143 const removeOwnCleanup = onOwnerCleanup(root, removeParentCleanup)
144 }

Callers 3

createDebuggerFunction · 0.90
handleCreatedOwnerFunction · 0.90
walker.test.tsxFile · 0.90

Calls 8

warnFunction · 0.90
isSolidRootFunction · 0.90
getSdtIdFunction · 0.90
onOwnerCleanupFunction · 0.90
cleanupRootFunction · 0.85
createTopRootFunction · 0.85
findClosestAliveParentFunction · 0.85
changeRootAttachmentFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…