Skip to content

Commit f5b38d9

Browse files
committed
Add setDebuggerOptions to debugger/setup
1 parent a72919e commit f5b38d9

File tree

2 files changed

+48
-34
lines changed

2 files changed

+48
-34
lines changed

packages/debugger/src/main/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as s from 'solid-js'
22
import {createStaticStore} from '@solid-primitives/static-store'
33
import {defer} from '@solid-primitives/utils'
4-
import {log_message, msg, mutate_remove, type Timeout} from '@solid-devtools/shared/utils'
4+
import {assert, log_message, msg, mutate_remove, type Timeout} from '@solid-devtools/shared/utils'
55
import {createDependencyGraph} from '../dependency/index.ts'
66
import {createInspector} from '../inspector/index.ts'
77
import {createLocator} from '../locator/index.ts'
@@ -20,15 +20,16 @@ import {
2020
type OutputListener,
2121
type OutputMessage,
2222
type DebuggerOptions,
23-
dom_element_interface,
24-
type ElementInterface,
2523
} from './types.ts'
2624

2725
function createDebugger<TEl extends object>(
2826
options?: DebuggerOptions<TEl>,
2927
) {
28+
assert(globalThis.SolidDevtools$$, 'solid-devtools is not setup')
3029

31-
let eli = options?.eli ?? dom_element_interface as any as ElementInterface<TEl>
30+
if (options != null) {
31+
globalThis.SolidDevtools$$.options = options
32+
}
3233

3334
initRoots()
3435

@@ -146,7 +147,7 @@ function createDebugger<TEl extends object>(
146147
}
147148
}
148149

149-
let component_registry = walker.makeComponentRegistry(eli)
150+
let component_registry = walker.makeComponentRegistry(setup.options.eli)
150151

151152
//
152153
// Structure:

packages/debugger/src/setup.ts

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,32 @@ It also starts listening to Solid DEV events and stores them to be sent to the d
88

99
import * as s from 'solid-js'
1010
import * as store from 'solid-js/store'
11-
import {error} from '@solid-devtools/shared/utils'
12-
import type {LocatorOptions} from './locator/locator.ts'
13-
import type {Solid} from './main/types.ts'
11+
import * as debug from '@solid-devtools/debugger/types'
12+
import {assert, error} from '@solid-devtools/shared/utils'
1413

15-
16-
let PassedLocatorOptions: LocatorOptions | null = null
1714
/** @deprecated use `setLocatorOptions` */
18-
export function useLocator(options: LocatorOptions) {
19-
PassedLocatorOptions = options
15+
export function useLocator(options: debug.LocatorOptions) {
16+
setLocatorOptions(options)
2017
}
21-
export function setLocatorOptions(options: LocatorOptions) {
22-
PassedLocatorOptions = options
18+
export function setLocatorOptions(options: debug.LocatorOptions) {
19+
assert(globalThis.SolidDevtools$$, 'solid-devtools is not setup')
20+
globalThis.SolidDevtools$$.locator_options = options
2321
}
2422

25-
let ClientVersion: string | null = null
26-
let SolidVersion: string | null = null
27-
let ExpectedSolidVersion: string | null = null
23+
export function setDebuggerOptions(options: debug.DebuggerOptions<any>) {
24+
assert(globalThis.SolidDevtools$$, 'solid-devtools is not setup')
25+
globalThis.SolidDevtools$$.debugger_options = options
26+
}
2827

2928
export function setClientVersion(version: string) {
30-
ClientVersion = version
29+
assert(globalThis.SolidDevtools$$, 'solid-devtools is not setup')
30+
globalThis.SolidDevtools$$.versions.client = version
3131
}
3232

3333
export function setSolidVersion(version: string, expected: string) {
34-
SolidVersion = version
35-
ExpectedSolidVersion = expected
34+
assert(globalThis.SolidDevtools$$, 'solid-devtools is not setup')
35+
globalThis.SolidDevtools$$.versions.solid = version
36+
globalThis.SolidDevtools$$.versions.expected_solid = expected
3637
}
3738

3839
export type SetupApi = {
@@ -50,17 +51,22 @@ export type SetupApi = {
5051
$RAW: typeof store.$RAW
5152
}
5253
// custom
53-
get_created_owners(): Solid.Owner[]
54-
get_locator_options(): LocatorOptions | null
54+
debugger_options: debug.DebuggerOptions<any>
55+
locator_options: debug.LocatorOptions | null
56+
get_created_owners: () => debug.Solid.Owner[]
57+
get_locator_options: () => debug.LocatorOptions | null
5558
versions: {
56-
get_client(): string | null
57-
get_solid(): string | null
58-
get_expected_solid(): string | null
59+
client: string | null
60+
solid: string | null
61+
expected_solid: string | null
62+
get_client: () => string | null
63+
get_solid: () => string | null
64+
get_expected_solid: () => string | null
5965
}
6066
unowned: {
61-
signals: WeakRef<Solid.Signal>[]
62-
onSignalAdded: ((ref: WeakRef<Solid.Signal>, idx: number) => void) | null
63-
onSignalRemoved: ((ref: WeakRef<Solid.Signal>, idx: number) => void) | null
67+
signals: WeakRef<debug.Solid.Signal>[]
68+
onSignalAdded: ((ref: WeakRef<debug.Solid.Signal>, idx: number) => void) | null
69+
onSignalRemoved: ((ref: WeakRef<debug.Solid.Signal>, idx: number) => void) | null
6470
}
6571
}
6672

@@ -77,7 +83,7 @@ if (!s.DEV || !store.DEV) {
7783
error('SolidJS in not in development mode!')
7884
} else {
7985

80-
let created_owners: Solid.Owner[] | null = []
86+
let created_owners: debug.Solid.Owner[] | null = []
8187

8288
let setup: SetupApi = {
8389
solid: {
@@ -100,13 +106,20 @@ if (!s.DEV || !store.DEV) {
100106
created_owners = null
101107
return events
102108
},
109+
debugger_options: {
110+
eli: debug.dom_element_interface,
111+
},
112+
locator_options: null,
103113
get_locator_options() {
104-
return PassedLocatorOptions
114+
return this.locator_options
105115
},
106116
versions: {
107-
get_client() {return ClientVersion},
108-
get_solid() {return SolidVersion},
109-
get_expected_solid() {return ExpectedSolidVersion},
117+
client: null,
118+
solid: null,
119+
expected_solid: null,
120+
get_client() {return this.client},
121+
get_solid() {return this.solid},
122+
get_expected_solid() {return this.expected_solid},
110123
},
111124
unowned: {
112125
signals: [],
@@ -120,7 +133,7 @@ if (!s.DEV || !store.DEV) {
120133
created_owners?.push(owner)
121134
}
122135

123-
let signals_registry = new FinalizationRegistry<WeakRef<Solid.Signal>>(ref => {
136+
let signals_registry = new FinalizationRegistry<WeakRef<debug.Solid.Signal>>(ref => {
124137
let idx = setup.unowned.signals.indexOf(ref)
125138
setup.unowned.signals.splice(idx, 1)
126139
setup.unowned.onSignalRemoved?.(ref, idx)

0 commit comments

Comments
 (0)