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

Function createStructure

packages/debugger/src/structure/index.ts:45–166  ·  view source on GitHub ↗
(props: {
    onStructureUpdate: (updates: StructureUpdates) => void
    onNodeUpdate:      (nodeId: NodeID) => void
    enabled:           () => boolean
    component_registry: walker.ComponentRegistry<TEl>,
})

Source from the content-addressed store, hash-verified

43}
44
45export function createStructure<TEl extends object>(props: {
46 onStructureUpdate: (updates: StructureUpdates) => void
47 onNodeUpdate: (nodeId: NodeID) => void
48 enabled: () => boolean
49 component_registry: walker.ComponentRegistry<TEl>,
50}) {
51
52 let treeWalkerMode: TreeWalkerMode = DEFAULT_WALKER_MODE
53
54 const updateQueue = new Set<Solid.Owner>()
55 /** root ids correcponding to owners in the update queue */
56 const ownerRoots = new Map<Solid.Owner, NodeID>()
57 const removedRoots = new Set<NodeID>()
58 let shouldUpdateAllRoots = true
59
60 const onComputationUpdate: walker.ComputationUpdateHandler = (
61 root_id, owner, changed_structure,
62 ) => {
63 // separate the callback from the computation
64 queueMicrotask(() => {
65 if (!props.enabled()) return
66 if (changed_structure) {
67 let owner_to_update = getClosestIncludedOwner(owner, treeWalkerMode) ?? owner
68 updateOwner(owner_to_update, root_id)
69 }
70 let id = getSdtId(owner, ObjectType.Owner)
71 props.onNodeUpdate(id)
72 })
73 }
74
75 function forceFlushRootUpdateQueue(): void {
76
77 if (props.enabled()) {
78
79 let partial = !shouldUpdateAllRoots
80 shouldUpdateAllRoots = false
81
82 let updated: StructureUpdates['updated'] = {}
83
84 let owners: Iterable<Solid.Owner>
85 let getRootId: (owner: Solid.Owner) => NodeID
86
87 if (partial) {
88 owners = updateQueue
89 getRootId = owner => ownerRoots.get(owner)!
90 } else {
91 owners = roots.getCurrentRoots()
92 getRootId = owner => getSdtId(owner, ObjectType.Owner)
93 }
94
95 for (let owner of owners) {
96 let root_id = getRootId(owner)
97 let tree = walker.walkSolidTree(owner, {
98 rootId: root_id,
99 mode: treeWalkerMode,
100 onUpdate: onComputationUpdate,
101 eli: props.component_registry.eli,
102 registry: props.component_registry,

Callers 1

createDebuggerFunction · 0.90

Calls 3

getClosestIncludedOwnerFunction · 0.85
updateOwnerFunction · 0.85
setTreeWalkerModeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…