Skip to content

Commit 458b217

Browse files
committed
Remove viewChange event bus
1 parent 6d5f5e3 commit 458b217

3 files changed

Lines changed: 26 additions & 36 deletions

File tree

packages/debugger/src/dependency/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {type EmitterEmit, type Listen} from '@solid-primitives/event-bus'
1+
import {type EmitterEmit} from '@solid-primitives/event-bus'
22
import {throttle} from '@solid-primitives/scheduled'
33
import {defer} from '@solid-primitives/utils'
44
import {type Accessor, createEffect, createMemo} from 'solid-js'
@@ -17,7 +17,6 @@ export function createDependencyGraph(props: {
1717
emit: EmitterEmit<Debugger.OutputChannels>
1818
enabled: Accessor<boolean>
1919
inspectedState: Accessor<Debugger.InspectedState>
20-
listenToViewChange: Listen<DevtoolsMainView>
2120
onNodeUpdate: (nodeId: NodeID) => void
2221
}) {
2322
let clearListeners: VoidFunction | null = null
@@ -76,7 +75,9 @@ export function createDependencyGraph(props: {
7675
}),
7776
)
7877

79-
props.listenToViewChange(() => {
80-
inspectDGraph()
81-
})
78+
return {
79+
onViewChange(_: DevtoolsMainView) {
80+
inspectDGraph()
81+
}
82+
}
8283
}

packages/debugger/src/main/index.ts

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {createEventBus, createGlobalEmitter, type GlobalEmitter} from '@solid-primitives/event-bus'
1+
import {createGlobalEmitter, type GlobalEmitter} from '@solid-primitives/event-bus'
22
import {createStaticStore} from '@solid-primitives/static-store'
33
import {defer} from '@solid-primitives/utils'
44
import * as s from 'solid-js'
@@ -69,33 +69,25 @@ const [modules, toggleModules] = createStaticStore({
6969
})
7070

7171
// The debugger can be enabled by devtools or by the locator
72-
const debuggerEnabled = s.createMemo(() => modules.debugger || modules.locatorKeyPressSignal())
73-
const dgraphEnabled = s.createMemo(() => modules.dgraph && debuggerEnabled())
72+
const debuggerEnabled = s.createMemo(
73+
() => modules.debugger || modules.locatorKeyPressSignal()
74+
)
75+
const dgraphEnabled = s.createMemo(
76+
() => modules.dgraph && debuggerEnabled()
77+
)
7478
// locator is enabled if debugger is enabled, and user pressed the key to activate it, or the plugin activated it
7579
const locatorEnabled = s.createMemo(
7680
() => (modules.locatorKeyPressSignal() || modules.locator) && debuggerEnabled(),
7781
)
7882

79-
s.createEffect(
80-
defer(debuggerEnabled, enabled => {
81-
hub.output.emit('DebuggerEnabled', enabled)
82-
}),
83-
)
83+
s.createEffect(defer(debuggerEnabled, enabled => {
84+
hub.output.emit('DebuggerEnabled', enabled)
85+
}))
8486

8587
//
8688
// Current Open VIEW (currently not used)
8789
//
88-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
8990
let currentView: DevtoolsMainView = DEFAULT_MAIN_VIEW
90-
const viewChange = createEventBus<DevtoolsMainView>()
91-
92-
function setView(view: DevtoolsMainView) {
93-
s.batch(() => {
94-
// setStructureEnabled(view === DevtoolsMainView.Structure)
95-
// setDgraphEnabled(view === DevtoolsMainView.Dgraph)
96-
viewChange.emit((currentView = view))
97-
})
98-
}
9991

10092
//
10193
// Enabled Modules
@@ -194,7 +186,6 @@ const structure = createStructure({
194186
},
195187
onNodeUpdate: pushNodeUpdate,
196188
enabled: debuggerEnabled,
197-
listenToViewChange: viewChange.listen,
198189
})
199190

200191
//
@@ -210,10 +201,9 @@ const inspector = createInspector({
210201
//
211202
// Dependency Graph
212203
//
213-
createDependencyGraph({
204+
const dgraph = createDependencyGraph({
214205
emit: hub.output.emit,
215206
enabled: dgraphEnabled,
216-
listenToViewChange: viewChange.listen,
217207
onNodeUpdate: pushNodeUpdate,
218208
inspectedState,
219209
})
@@ -272,7 +262,9 @@ hub.input.listen(e => {
272262
structure.setTreeWalkerMode(e.details)
273263
break
274264
case 'ViewChange':
275-
setView(e.details)
265+
currentView = e.details
266+
structure.onViewChange(currentView)
267+
dgraph.onViewChange(currentView)
276268
break
277269
case 'ToggleModule':
278270
toggleModule(e.details)

packages/debugger/src/structure/index.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {type Listen} from '@solid-primitives/event-bus'
21
import {throttle} from '@solid-primitives/scheduled'
32
import * as registry from '../main/component-registry.ts'
43
import {DEFAULT_WALKER_MODE, DevtoolsMainView, NodeType, TreeWalkerMode} from '../main/constants.ts'
@@ -49,7 +48,6 @@ export function createStructure(props: {
4948
onStructureUpdate: (updates: StructureUpdates) => void
5049
onNodeUpdate: (nodeId: NodeID) => void
5150
enabled: () => boolean
52-
listenToViewChange: Listen<DevtoolsMainView>
5351
}) {
5452
let treeWalkerMode: TreeWalkerMode = DEFAULT_WALKER_MODE
5553

@@ -125,13 +123,6 @@ export function createStructure(props: {
125123
flushRootUpdateQueue()
126124
})
127125

128-
props.listenToViewChange(view => {
129-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
130-
if (view === DevtoolsMainView.Structure) {
131-
updateAllRoots()
132-
}
133-
})
134-
135126
function updateAllRoots(): void {
136127
shouldUpdateAllRoots = true
137128
flushRootUpdateQueue()
@@ -156,5 +147,11 @@ export function createStructure(props: {
156147
getClosestIncludedOwner(owner: Solid.Owner) {
157148
return getClosestIncludedOwner(owner, treeWalkerMode)
158149
},
150+
onViewChange(view: DevtoolsMainView) {
151+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
152+
if (view === DevtoolsMainView.Structure) {
153+
updateAllRoots()
154+
}
155+
},
159156
}
160157
}

0 commit comments

Comments
 (0)