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

Function changeRootAttachment

packages/debugger/src/main/roots.ts:54–73  ·  view source on GitHub ↗

* For switching what owner sub-roots are attached to. * It'll remove the root from its current owner and attach it to the new owner.

(root: Solid.Root, newParent: Solid.Owner | null)

Source from the content-addressed store, hash-verified

52 * It'll remove the root from its current owner and attach it to the new owner.
53 */
54function changeRootAttachment(root: Solid.Root, newParent: Solid.Owner | null): void {
55 let topRoot: Solid.Root | undefined | null
56
57 if (root.attachedTo) {
58 root.attachedTo.sdtSubRoots!.splice(root.attachedTo.sdtSubRoots!.indexOf(root), 1)
59 topRoot = getTopRoot(root.attachedTo)
60 if (topRoot) OnOwnerNeedsUpdate?.(root.attachedTo, getSdtId(topRoot, ObjectType.Owner))
61 }
62
63 if (newParent) {
64 root.attachedTo = newParent
65 if (newParent.sdtSubRoots) newParent.sdtSubRoots.push(root)
66 else newParent.sdtSubRoots = [root]
67
68 if (topRoot === undefined) topRoot = getTopRoot(newParent)
69 if (topRoot) OnOwnerNeedsUpdate?.(newParent, getSdtId(topRoot, ObjectType.Owner))
70 } else {
71 delete root.attachedTo
72 }
73}
74
75/**
76 * Helps the debugger find and reattach an reactive owner created by `createRoot` to it's detached parent.

Callers 3

cleanupRootFunction · 0.85
attachDebuggerFunction · 0.85
onParentCleanupFunction · 0.85

Calls 2

getSdtIdFunction · 0.90
getTopRootFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…