MCPcopy Index your code
hub / github.com/TanStack/devtools / createPlugins

Function createPlugins

packages/devtools/src/context/use-devtools-context.ts:32–74  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

30}
31
32export const createPlugins = () => {
33 const { store, setStore } = createDevtoolsContext()
34 const { setForceExpand } = createDrawContext()
35
36 const plugins = createMemo(() => store.plugins)
37 const activePlugins = createMemo(() => store.state.activePlugins)
38
39 createEffect(() => {
40 if (activePlugins().length === 0) {
41 setForceExpand(true)
42 } else {
43 setForceExpand(false)
44 }
45 })
46
47 const toggleActivePlugins = (pluginId: string) => {
48 setStore((prev) => {
49 const isActive = prev.state.activePlugins.includes(pluginId)
50
51 const currentPlugin = store.plugins?.find(
52 (plugin) => plugin.id === pluginId,
53 )
54
55 if (currentPlugin?.destroy && isActive) {
56 currentPlugin.destroy(pluginId)
57 }
58
59 const updatedPlugins = isActive
60 ? prev.state.activePlugins.filter((id) => id !== pluginId)
61 : [...prev.state.activePlugins, pluginId]
62 if (updatedPlugins.length > MAX_ACTIVE_PLUGINS) return prev
63 return {
64 ...prev,
65 state: {
66 ...prev.state,
67 activePlugins: updatedPlugins,
68 },
69 }
70 })
71 }
72
73 return { plugins, toggleActivePlugins, activePlugins }
74}
75
76export const createDevtoolsState = () => {
77 const { store, setStore } = createDevtoolsContext()

Callers 2

PluginMarketplaceFunction · 0.90
PluginsTabFunction · 0.90

Calls 2

createDevtoolsContextFunction · 0.85
createDrawContextFunction · 0.85

Tested by

no test coverage detected