Skip to content
Source
Sign inSign up
TanStack/devtools
Open History to see the last commit

TanStackDevtools.svelte

32 lines957 Bytes

1<script lang="ts">
2 import { untrack } from 'svelte'
3 import { TanStackDevtoolsSvelteAdapter } from './devtools.svelte.js'
4 import type { TanStackDevtoolsSvelteInit } from './types'
5​
6 let { plugins, config, eventBusConfig }: TanStackDevtoolsSvelteInit = $props()
7​
8 let hostEl: HTMLDivElement
9​
10 const adapter = new TanStackDevtoolsSvelteAdapter()
11​
12 // Mount exactly once. We `untrack` the props so this effect does not re-run
13 // (and tear down + rebuild the entire devtools core) whenever a prop changes
14 // β€” prop changes are handled reactively by the `update` effect below.
15 $effect(() => {
16 adapter.mount(
17 hostEl,
18 untrack(() => ({ plugins, config, eventBusConfig })),
19 )
20​
21 return () => {
22 adapter.destroy()
23 }
24 })
25​
26 // Reactively push config/plugin changes into the existing core instance.
27 $effect(() => {
28 adapter.update({ plugins, config, eventBusConfig })
29 })
30</script>
31​
32<div bind:this={hostEl}></div>