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

Function createInspector

packages/debugger/src/inspector/index.ts:22–227  ·  view source on GitHub ↗
(props: {
    inspectedState:     s.Accessor<InspectedState>
    enabled:            s.Accessor<boolean>
    resetInspectedNode: VoidFunction
    emit:               OutputEmit
})

Source from the content-addressed store, hash-verified

20 * Plugin module
21 */
22export function createInspector(props: {
23 inspectedState: s.Accessor<InspectedState>
24 enabled: s.Accessor<boolean>
25 resetInspectedNode: VoidFunction
26 emit: OutputEmit
27}) {
28
29 let lastDetails: Mapped.OwnerDetails | undefined
30 let inspectedOwner: Solid.Owner | null
31 let valueMap: inspector.Value_Node_Map = new Map()
32 const propsMap: inspector.Observed_Props_Map = new WeakMap()
33 /** compare props object with the previous one to see whats changed */
34 let checkProxyProps: (() => InspectorUpdateMap['propKeys'] | null) | null
35
36 /*
37 For the extension for inspecting values through `inspect()`
38 */
39 function getValue(id: ValueItemID): unknown {
40 let node = valueMap.get(id)
41 return node ? inspector.value_data_get_value(node.data) : undefined
42 }
43 window[GLOBAL_GET_VALUE] = getValue
44
45 // Batch and dedupe inspector updates
46 // these will include updates to signals, stores, props, and node value
47 const {pushPropState, pushValueUpdate, pushInspectToggle, triggerPropsCheck, clearUpdates} =
48 (() => {
49 const valueUpdates = new Map<ValueItemID, boolean | null>()
50 let storeUpdates: [storeProperty: store.StoreNodeProperty, data: store.StoreUpdateData][] = []
51 let checkProps = false
52 let propStates: InspectorUpdateMap['propState'] = {}
53
54 const flush = scheduleIdle(() => {
55 const batchedUpdates: InspectorUpdate[] = []
56
57 // Value Nodes (signals, props, and owner value)
58 for (const [id, toggleChange] of valueUpdates) {
59 const node = valueMap.get(id)
60 if (!node) continue
61 // TODO shouldn't the previous stores be unsubscribed here? after update, they might no longer be here
62 const selected = inspector.value_node_is_selected(node)
63 const encoded = encodeValue(
64 inspector.value_data_get_value(node.data),
65 selected,
66 setup.eli,
67 selected &&
68 (storeNode => inspector.value_node_add_store_observer(node, store.observeStoreNode(storeNode))),
69 )
70 batchedUpdates.push([
71 toggleChange === null ? 'value' : 'inspectToggle',
72 [id, encoded],
73 ])
74 }
75 valueUpdates.clear()
76
77 // Stores
78 for (const [storeProperty, data] of storeUpdates)
79 batchedUpdates.push([

Callers 1

createDebuggerFunction · 0.90

Calls 7

encodeValueFunction · 0.90
msgFunction · 0.90
addSolidUpdateListenerFunction · 0.90
inspectOwnerIdFunction · 0.85
triggerPropsCheckFunction · 0.85
getMethod · 0.80
clearMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…