Skip to content

Commit 0c619c8

Browse files
committed
test
1 parent 2c25bb4 commit 0c619c8

4 files changed

Lines changed: 18 additions & 38 deletions

File tree

packages/devtools-utils/src/react/panel.test.tsx

Lines changed: 0 additions & 21 deletions
This file was deleted.

packages/devtools-utils/src/react/panel.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,21 @@ export function createReactPanel<
2727
mount: (el: HTMLElement, theme: 'light' | 'dark') => void
2828
unmount: () => void
2929
},
30-
>(devtoolsPackageName: string, importName = 'default') {
30+
>(
31+
CoreClass: new () => TCoreDevtoolsClass
32+
) {
3133
function Panel(props: TComponentProps) {
3234
const devToolRef = useRef<HTMLDivElement>(null)
3335
const devtools = useRef<TCoreDevtoolsClass | null>(null)
3436
useEffect(() => {
3537
if (devtools.current) return
3638

37-
import(/* @vite-ignore */ devtoolsPackageName).then(
38-
({ [importName]: Core }) => {
39-
devtools.current = new Core()
39+
devtools.current = new CoreClass()
40+
41+
if (devToolRef.current) {
42+
devtools.current.mount(devToolRef.current, props?.theme ?? 'dark')
43+
}
4044

41-
if (devToolRef.current && devtools.current) {
42-
devtools.current.mount(devToolRef.current, props?.theme ?? 'dark')
43-
}
44-
},
45-
)
4645

4746
return () => {
4847
devtools.current?.unmount()

packages/devtools-utils/src/solid/class.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function constructCoreClass(importPath: string) {
1616
#Component: any
1717
#ThemeProvider: any
1818

19-
constructor() {}
19+
constructor() { }
2020

2121
async mount<T extends HTMLElement>(el: T, theme: 'light' | 'dark') {
2222
const { lazy } = await import('solid-js')
@@ -61,8 +61,10 @@ export function constructCoreClass(importPath: string) {
6161
constructor() {
6262
super()
6363
}
64-
async mount<T extends HTMLElement>(_el: T, _theme: 'light' | 'dark') {}
65-
unmount() {}
64+
async mount<T extends HTMLElement>(_el: T, _theme: 'light' | 'dark') { }
65+
unmount() { }
6666
}
6767
return [DevtoolsCore, NoOpDevtoolsCore] as const
6868
}
69+
70+
export type ClassType = ReturnType<typeof constructCoreClass>[0]

packages/devtools-utils/src/solid/panel.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
/** @jsxImportSource solid-js - we use Solid.js as JSX here */
22

33
import { onCleanup, onMount } from 'solid-js'
4+
import type { ClassType } from './class'
45

56
export interface DevtoolsPanelProps {
67
theme?: 'light' | 'dark'
78
}
89

910
export function createSolidPanel<
1011
TComponentProps extends DevtoolsPanelProps | undefined,
11-
>(importPath: string, importName = 'default') {
12+
>(CoreClass: ClassType) {
1213
function Panel(props: TComponentProps) {
1314
let devToolRef: HTMLDivElement | undefined
1415

15-
onMount(async () => {
16-
const devtools = await import(/* @vite-ignore */ importPath).then(
17-
(mod) => new mod[importName](),
18-
)
16+
onMount(() => {
17+
const devtools = new CoreClass()
18+
1919
if (devToolRef) {
2020
devtools.mount(devToolRef, props?.theme ?? 'dark')
2121

0 commit comments

Comments
 (0)