(owner = setup.solid.getOwner())
| 85 | * }); |
| 86 | */ |
| 87 | export 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 | } |
no test coverage detected
searching dependent graphs…