(
output: OutputEventBus,
input: InputEventBus,
)
| 137 | } as const satisfies Inspector.State |
| 138 | |
| 139 | export default function createInspector( |
| 140 | output: OutputEventBus, |
| 141 | input: InputEventBus, |
| 142 | ) { |
| 143 | |
| 144 | // |
| 145 | // Inspected owner/signal |
| 146 | // |
| 147 | const [inspected, setInspected] = createStaticStore<debug.InspectedState>( |
| 148 | debug.INSPECTED_STATE_NULL |
| 149 | ) |
| 150 | const inspectedNode = s.createMemo(() => ({...inspected}), void 0, { |
| 151 | equals: (a, b) => a.ownerId === b.ownerId && a.signalId === b.signalId, |
| 152 | }) |
| 153 | const isSomeNodeInspected = s.createMemo( |
| 154 | () => inspected.ownerId !== null || inspected.signalId !== null, |
| 155 | ) |
| 156 | const isInspected = s.createSelector<debug.InspectedState, debug.NodeID>( |
| 157 | inspectedNode, |
| 158 | (id, node) => node.ownerId === id || node.signalId === id, |
| 159 | ) |
| 160 | const isInspectedTreeWalkerOwner = s.createSelector<debug.NodeID | null, debug.NodeID>( |
| 161 | () => inspected.treeWalkerOwnerId, |
| 162 | ) |
| 163 | |
| 164 | function setInspectedNode(ownerId: debug.NodeID | null, signalId: debug.NodeID | null): void { |
| 165 | s.batch(() => { |
| 166 | const prev = inspected.ownerId |
| 167 | setInspected({ownerId, signalId}) |
| 168 | if (!prev || ownerId !== prev) { |
| 169 | storeNodeMap.clear() |
| 170 | setState({...NULL_STATE}) |
| 171 | } |
| 172 | }) |
| 173 | } |
| 174 | function setInspectedOwner(id: debug.NodeID | null): void { |
| 175 | setInspectedNode(id, null) |
| 176 | } |
| 177 | function toggleInspectedOwner(id: debug.NodeID): void { |
| 178 | setInspectedNode(inspected.ownerId === id ? null : id, null) |
| 179 | } |
| 180 | function setInspectedSignal(id: debug.NodeID | null): void { |
| 181 | setInspected(prev => ({ownerId: prev.ownerId, signalId: id})) |
| 182 | } |
| 183 | |
| 184 | // sync inspected node with the debugger |
| 185 | s.createEffect(defer(inspectedNode, node => { |
| 186 | output.emit(msg('InspectNode', node)) |
| 187 | })) |
| 188 | |
| 189 | // |
| 190 | // Inspector state |
| 191 | // |
| 192 | |
| 193 | const [state, setState] = createStaticStore<Inspector.State>({...NULL_STATE}) |
| 194 | |
| 195 | const storeNodeMap = new decode.StoreNodeMap() |
| 196 |
no test coverage detected
searching dependent graphs…