UNPKG

@tanstack/devtools-utils

Version:

TanStack Devtools utilities for creating your own devtools.

59 lines (58 loc) • 1.83 kB
//#region src/solid/class.ts /** * Constructs the core class for the Devtools. * This utility is used to construct a lazy loaded Solid component for the Devtools. * It returns a tuple containing the main DevtoolsCore class and a NoOpDevtoolsCore class. * The NoOpDevtoolsCore class is a no-op implementation that can be used for production if you want to explicitly exclude * the Devtools from your application. * @param importFn A function that returns a dynamic import of the Solid component * @returns Tuple containing the DevtoolsCore class and a NoOpDevtoolsCore class */ function constructCoreClass(importFn) { class DevtoolsCore { #isMounted = false; #isMounting = false; #abortMount = false; #dispose; constructor() {} async mount(el, props) { if (this.#isMounted || this.#isMounting) throw new Error("Devtools is already mounted"); this.#isMounting = true; this.#abortMount = false; try { const { __mountComponent } = await import("./class-mount-impl.js"); if (this.#abortMount) { this.#isMounting = false; return; } this.#dispose = __mountComponent(el, props, importFn); this.#isMounted = true; this.#isMounting = false; } catch (err) { this.#isMounting = false; console.error("[TanStack Devtools] Failed to load:", err); } } unmount() { if (!this.#isMounted && !this.#isMounting) throw new Error("Devtools is not mounted"); if (this.#isMounting) { this.#abortMount = true; this.#isMounting = false; return; } this.#dispose?.(); this.#isMounted = false; } } class NoOpDevtoolsCore extends DevtoolsCore { constructor() { super(); } async mount(_el, _props) {} unmount() {} } return [DevtoolsCore, NoOpDevtoolsCore]; } //#endregion export { constructCoreClass }; //# sourceMappingURL=class.js.map