|
| 1 | +import { constructCoreClass } from '@tanstack/devtools-utils/solid' |
1 | 2 | import { lazy } from 'solid-js' |
2 | | -import { Portal, render } from 'solid-js/web' |
3 | 3 |
|
4 | | -export interface PacerDevtoolsInit {} |
5 | | - |
6 | | -export class PacerDevtoolsCore { |
7 | | - #isMounted = false |
8 | | - #dispose?: () => void |
9 | | - #Component: any |
10 | | - #ThemeProvider: any |
| 4 | +const Component = lazy(() => import('./PacerDevtools')) |
11 | 5 |
|
12 | | - constructor(_init?: PacerDevtoolsInit | undefined) {} |
13 | | - |
14 | | - mount<T extends HTMLElement>(el: T, theme: 'light' | 'dark') { |
15 | | - if (this.#isMounted) { |
16 | | - throw new Error('Devtools is already mounted') |
17 | | - } |
18 | | - const mountTo = el |
19 | | - const dispose = render(() => { |
20 | | - this.#Component = lazy(() => import('./PacerDevtools')) |
21 | | - const Devtools = this.#Component |
22 | | - this.#ThemeProvider = lazy(() => |
23 | | - import('@tanstack/devtools-ui').then((mod) => ({ |
24 | | - default: mod.ThemeContextProvider, |
25 | | - })), |
26 | | - ) |
27 | | - const ThemeProvider = this.#ThemeProvider |
| 6 | +export interface PacerDevtoolsInit {} |
28 | 7 |
|
29 | | - return ( |
30 | | - <Portal mount={mountTo}> |
31 | | - <div style={{ height: '100%' }}> |
32 | | - <ThemeProvider theme={theme}> |
33 | | - <Devtools /> |
34 | | - </ThemeProvider> |
35 | | - </div> |
36 | | - </Portal> |
37 | | - ) |
38 | | - }, mountTo) |
39 | | - this.#isMounted = true |
40 | | - this.#dispose = dispose |
41 | | - } |
| 8 | +const [PacerDevtoolsCore, PacerDevtoolsCoreNoOp] = constructCoreClass(Component) |
42 | 9 |
|
43 | | - unmount() { |
44 | | - if (!this.#isMounted) { |
45 | | - throw new Error('Devtools is not mounted') |
46 | | - } |
47 | | - this.#dispose?.() |
48 | | - this.#isMounted = false |
49 | | - } |
50 | | -} |
| 10 | +export { PacerDevtoolsCore, PacerDevtoolsCoreNoOp } |
0 commit comments