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

Function createDependencyGraph

packages/debugger/src/dependency/index.ts:14–85  ·  view source on GitHub ↗
(props: {
    enabled:        s.Accessor<boolean>
    inspectedState: s.Accessor<InspectedState>
    onNodeUpdate:   (nodeId: NodeID) => void
    emit:           OutputEmit
})

Source from the content-addressed store, hash-verified

12export type DGraphUpdate = SerializedDGraph.Graph | null
13
14export function createDependencyGraph(props: {
15 enabled: s.Accessor<boolean>
16 inspectedState: s.Accessor<InspectedState>
17 onNodeUpdate: (nodeId: NodeID) => void
18 emit: OutputEmit
19}) {
20
21 let clearListeners: VoidFunction | null = null
22
23 const onNodeUpdate: OnNodeUpdate = id => {
24 // separate the callback from the computation
25 queueMicrotask(() => {
26 if (!props.enabled()) return
27 props.onNodeUpdate(id)
28 triggerInspect()
29 })
30 }
31
32 const inspectedNode = s.createMemo(() => {
33 const state = props.inspectedState()
34 let node_raw: Solid.Owner | Solid.Signal | null = null
35
36 if (state.signalId) {
37 node_raw = getObjectById(state.signalId, ObjectType.Signal)
38 } else if (state.ownerId) {
39 node_raw = getObjectById(state.ownerId, ObjectType.Owner)
40 }
41
42 if (node_raw != null) {
43 return getNode(node_raw)
44 }
45
46 return null
47 })
48
49 function inspectDGraph() {
50 // listeners need to be cleared each time, because each update will cause the graph to be mapped again
51 clearListeners?.()
52
53 let node = inspectedNode()
54
55 if (!props.enabled() ||
56 !node ||
57 node.kind === NodeType.Root ||
58 node.kind === NodeType.Component ||
59 node.kind === NodeType.Context
60 ) {
61 clearListeners = null
62 props.emit(msg('DgraphUpdate', null))
63 return
64 }
65
66 const dgraph = collectDependencyGraph(node.data as any, {
67 onNodeUpdate,
68 })
69 clearListeners = dgraph.clearListeners
70 props.emit(msg('DgraphUpdate', dgraph.graph))
71 }

Callers 1

createDebuggerFunction · 0.90

Calls 2

getObjectByIdFunction · 0.90
getNodeFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…