Skip to content

Commit f19ae87

Browse files
committed
frontend: Rename Controller to AppCtx
1 parent eef06c4 commit f19ae87

5 files changed

Lines changed: 72 additions & 75 deletions

File tree

packages/frontend/src/SidePanel.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import clsx from 'clsx'
22
import * as s from 'solid-js'
33
import * as theme from '@solid-devtools/shared/theme'
4-
import {useController} from './controller.tsx'
4+
import {useAppCtx} from './controller.tsx'
55
import * as dgraph from './dgraph.tsx'
66
import {InspectorView} from './inspector.tsx'
77
import * as ui from './ui/index.ts'
@@ -31,8 +31,8 @@ export const action_button = clsx(hover_background, hover_text, 'w-6 h-6 rounded
3131
export const action_icon = 'w-4 h-4'
3232

3333
export function createSidePanel() {
34-
35-
const ctx = useController()
34+
35+
const ctx = useAppCtx()
3636
const {inspector} = ctx
3737
const {state, openComponentLocation, setInspectedOwner} = inspector
3838

packages/frontend/src/controller.tsx

Lines changed: 54 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -53,63 +53,22 @@ export type DevtoolsOptions = Partial<DevtoolsOptionsWithDefaults>
5353

5454
export function createDevtools(props: DevtoolsOptions) {
5555

56-
let output_listeners: OutputListener[] = []
57-
const output: OutputEventBus = {
58-
listen(listener) {
59-
output_listeners.push(listener)
60-
s.onCleanup(() => {
61-
mutate_remove(output_listeners, listener)
62-
})
63-
},
64-
emit(e) {
65-
s.batch(() => {
66-
for (let fn of output_listeners) {
67-
fn(e)
68-
}
69-
})
70-
},
71-
}
72-
73-
let input_listeners: InputListener[] = []
74-
const input: InputEventBus = {
75-
listen(listener) {
76-
input_listeners.push(listener)
77-
s.onCleanup(() => {
78-
mutate_remove(input_listeners, listener)
79-
})
80-
},
81-
emit(e) {
82-
s.batch(() => {
83-
for (let fn of input_listeners) {
84-
fn(e)
85-
}
86-
})
87-
},
88-
}
89-
90-
let options: DevtoolsOptionsWithDefaults = {
91-
errorOverlayFooter: props.errorOverlayFooter ?? (() => null),
92-
headerSubtitle: props.headerSubtitle ?? (() => null),
93-
useShortcuts: props.useShortcuts ?? false,
94-
catchWindowErrors: props.catchWindowErrors ?? false,
95-
}
96-
97-
const controller = createController(output, input, options)
56+
const ctx = createAppCtx(props)
9857

9958
return {
100-
output,
101-
input,
59+
output: ctx.output,
60+
input: ctx.input,
10261
Devtools() {
10362
return (
10463
<div class={ui.devtools_root_class + ' h-inherit'}>
10564
<ui.Styles />
10665
<ui.ErrorOverlay
107-
footer={options.errorOverlayFooter()}
108-
catchWindowErrors={options.catchWindowErrors}
66+
footer={ctx.options.errorOverlayFooter()}
67+
catchWindowErrors={ctx.options.catchWindowErrors}
10968
>
110-
<ControllerCtx.Provider value={controller}>
111-
<App headerSubtitle={options.headerSubtitle()} />
112-
</ControllerCtx.Provider>
69+
<AppCtx.Provider value={ctx}>
70+
<App headerSubtitle={ctx.options.headerSubtitle()} />
71+
</AppCtx.Provider>
11372
</ui.ErrorOverlay>
11473
</div>
11574
)
@@ -157,11 +116,49 @@ function createViewCache() {
157116
return {set: setCacheGetter, get: getCache}
158117
}
159118

160-
function createController(
161-
output: OutputEventBus,
162-
input: InputEventBus,
163-
options: DevtoolsOptions,
164-
) {
119+
function createAppCtx(props: DevtoolsOptions) {
120+
121+
let output_listeners: OutputListener[] = []
122+
const output: OutputEventBus = {
123+
listen(listener) {
124+
output_listeners.push(listener)
125+
s.onCleanup(() => {
126+
mutate_remove(output_listeners, listener)
127+
})
128+
},
129+
emit(e) {
130+
s.batch(() => {
131+
for (let fn of output_listeners) {
132+
fn(e)
133+
}
134+
})
135+
},
136+
}
137+
138+
let input_listeners: InputListener[] = []
139+
const input: InputEventBus = {
140+
listen(listener) {
141+
input_listeners.push(listener)
142+
s.onCleanup(() => {
143+
mutate_remove(input_listeners, listener)
144+
})
145+
},
146+
emit(e) {
147+
s.batch(() => {
148+
for (let fn of input_listeners) {
149+
fn(e)
150+
}
151+
})
152+
},
153+
}
154+
155+
let options: DevtoolsOptionsWithDefaults = {
156+
errorOverlayFooter: props.errorOverlayFooter ?? (() => null),
157+
headerSubtitle: props.headerSubtitle ?? (() => null),
158+
useShortcuts: props.useShortcuts ?? false,
159+
catchWindowErrors: props.catchWindowErrors ?? false,
160+
}
161+
165162
//
166163
// LOCATOR
167164
//
@@ -308,8 +305,8 @@ function createController(
308305
}
309306
}
310307

311-
export type Controller = ReturnType<typeof createController>
308+
export type AppCtx = ReturnType<typeof createAppCtx>
312309

313-
const ControllerCtx = s.createContext<Controller>('ControllerCtx' as any as Controller)
310+
const AppCtx = s.createContext<AppCtx>('ControllerCtx' as any as AppCtx)
314311

315-
export const useController = () => s.useContext(ControllerCtx)
312+
export const useAppCtx = () => s.useContext(AppCtx)

packages/frontend/src/dgraph.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import * as s from 'solid-js'
33
import * as debug from '@solid-devtools/debugger/types'
44
import {createHover} from '@solid-devtools/shared/primitives'
55
import * as theme from '@solid-devtools/shared/theme'
6-
import {useController} from './controller.tsx'
6+
import {useAppCtx} from './controller.tsx'
77
import * as ui from './ui/index.ts'
88

99
export function createDependencyGraph() {
10-
const ctx = useController()
10+
const ctx = useAppCtx()
1111

1212
const [graph, setGraph] = s.createSignal<debug.DGraphUpdate>(null)
1313

@@ -220,7 +220,7 @@ function Line(props: {
220220
}
221221

222222
export function Dgraph_View(): s.JSX.Element {
223-
const ctx = useController()
223+
const ctx = useAppCtx()
224224
const {inspector, hovered} = ctx
225225
const dgraph = createDependencyGraph()
226226

packages/frontend/src/inspector.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {error, splitOnColon} from '@solid-devtools/shared/utils'
88
import * as debug from '@solid-devtools/debugger/types'
99
import * as theme from '@solid-devtools/shared/theme'
1010
import {SidePanelCtx} from './SidePanel.tsx'
11-
import {useController, type InputEventBus, type OutputEventBus} from './controller.tsx'
11+
import {useAppCtx, type InputEventBus, type OutputEventBus} from './controller.tsx'
1212
import * as ui from './ui/index.ts'
1313
import * as decode from './decode.ts'
1414

@@ -311,7 +311,7 @@ export default function createInspector(
311311
error(`ValueItem not found for id ${value_item_id}.`)
312312
break
313313
}
314-
314+
315315
if (decode.isObjectType(value_item.value)) {
316316
decode.updateCollapsedValue(value_item.value, value, storeNodeMap)
317317
}
@@ -324,7 +324,7 @@ export default function createInspector(
324324
}
325325
case 'propState': {
326326
if (!state.props) break
327-
327+
328328
for (const [key, getterState] of entries(update[DATA])) {
329329
state.props.record[key]?.setGetter(getterState)
330330
}
@@ -399,7 +399,7 @@ function ListSignals<T>(props: {when: T; title: s.JSX.Element; children: s.JSX.E
399399

400400
export function InspectorView(): s.JSX.Element {
401401

402-
const {inspector, hovered} = useController()
402+
const {inspector, hovered} = useAppCtx()
403403
const {state} = inspector
404404

405405
const {setOpenPanel} = s.useContext(SidePanelCtx)!

packages/frontend/src/structure.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {type Atom, atom, createHover} from '@solid-devtools/shared/primitives'
99
import * as theme from '@solid-devtools/shared/theme'
1010
import * as debug from '@solid-devtools/debugger/types'
1111
import {hover_background, panel_header_el_border} from './SidePanel.tsx'
12-
import {useController} from './controller.tsx'
12+
import {useAppCtx} from './controller.tsx'
1313
import * as ui from './ui/index.ts'
1414

1515

@@ -72,7 +72,7 @@ export function getNodePath(node: Structure.Node): Structure.Node[] {
7272
}
7373

7474
export function createStructure() {
75-
const ctx = useController()
75+
const ctx = useAppCtx()
7676
const cachedInitialState = ctx.viewCache.get(debug.DevtoolsMainView.Structure)
7777

7878
const [mode, setMode] = s.createSignal<debug.TreeWalkerMode>(
@@ -352,7 +352,7 @@ export function StructureView(): s.JSXElement {
352352
}
353353

354354
const LocatorButton: s.Component = () => {
355-
const {locator} = useController()
355+
const {locator} = useAppCtx()
356356
return (
357357
<ui.ToggleButton
358358
class="shrink-0 w-7 h-7"
@@ -366,7 +366,7 @@ const LocatorButton: s.Component = () => {
366366
}
367367

368368
const Search: s.Component = () => {
369-
const ctx = useController()
369+
const ctx = useAppCtx()
370370
const structure = useStructure()
371371

372372
const [value, setValue] = s.createSignal('')
@@ -496,7 +496,7 @@ const getFocusedNodeData = (
496496
}
497497

498498
const DisplayStructureTree: s.Component = () => {
499-
499+
500500
const [containerScroll, setContainerScroll] = s.createSignal({
501501
top: 0,
502502
height: 0,
@@ -526,7 +526,7 @@ const DisplayStructureTree: s.Component = () => {
526526
})
527527
}
528528

529-
const ctx = useController()
529+
const ctx = useAppCtx()
530530
const {inspector, hovered} = ctx
531531
const structure = useStructure()
532532

@@ -825,7 +825,7 @@ const DisplayStructureTree: s.Component = () => {
825825

826826

827827
export const OwnerPath: s.Component = () => {
828-
const {inspector, hovered} = useController()
828+
const {inspector, hovered} = useAppCtx()
829829
const structure = useStructure()
830830

831831
let container!: HTMLDivElement
@@ -919,7 +919,7 @@ export const OwnerNode: s.Component<{
919919
listenToUpdate(cb: VoidFunction): VoidFunction
920920
toggleCollapsed(node: Structure.Node): void
921921
}> = props => {
922-
922+
923923
const {onHoverChange, listenToUpdate, onInspectChange, toggleCollapsed} = props
924924
const {name, type, hmr} = props.owner
925925

0 commit comments

Comments
 (0)