MCPcopy Create free account
hub / github.com/TanStack/devtools / constructCoreClass

Function constructCoreClass

packages/devtools-utils/src/solid/class.ts:13–81  ·  view source on GitHub ↗
(
  importFn: () => Promise<{
    default: (props: TanStackDevtoolsPluginProps) => JSX.Element
  }>,
)

Source from the content-addressed store, hash-verified

11 * @returns Tuple containing the DevtoolsCore class and a NoOpDevtoolsCore class
12 */
13export function constructCoreClass(
14 importFn: () => Promise<{
15 default: (props: TanStackDevtoolsPluginProps) => JSX.Element
16 }>,
17) {
18 class DevtoolsCore {
19 #isMounted = false
20 #isMounting = false
21 #abortMount = false
22 #dispose?: () => void
23
24 constructor() {}
25
26 async mount<T extends HTMLElement>(
27 el: T,
28 props: TanStackDevtoolsPluginProps,
29 ) {
30 if (this.#isMounted || this.#isMounting) {
31 throw new Error('Devtools is already mounted')
32 }
33 this.#isMounting = true
34 this.#abortMount = false
35
36 try {
37 const { __mountComponent } = await import('./class-mount-impl')
38 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- can be set by unmount() during await
39 if (this.#abortMount) {
40 this.#isMounting = false
41 return
42 }
43
44 this.#dispose = __mountComponent(el, props, importFn)
45 this.#isMounted = true
46 this.#isMounting = false
47 } catch (err) {
48 this.#isMounting = false
49 console.error('[TanStack Devtools] Failed to load:', err)
50 }
51 }
52
53 unmount() {
54 if (!this.#isMounted && !this.#isMounting) {
55 throw new Error('Devtools is not mounted')
56 }
57
58 if (this.#isMounting) {
59 this.#abortMount = true
60 this.#isMounting = false
61 return
62 }
63
64 this.#dispose?.()
65 this.#isMounted = false
66 }
67 }
68
69 class NoOpDevtoolsCore extends DevtoolsCore {
70 constructor() {

Callers 2

core.tsxFile · 0.90
class.test.tsxFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected