MCPcopy Create free account
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 * time, and without this every unrelated store write would look like a change
31 * and re-run each plugin's `render`.
32 */
33 const activePlugins = createMemo(() => flattenTabs(store.state.layout), {
34 equals: (a, b) => a.length === b.length && a.every((id, i) => id === b[i]),
35 })
36 const layout = createMemo(() => store.state.layout)
37
38 const setLayout = (next: LayoutNode | null) => {
39 setStore((previous) => ({
40 ...previous,
41 state: { ...previous.state, layout: next },
42 }))
43 }
44
45 const toggleActivePlugins = (pluginId: string) => {
46 const current = store.state.layout
47 const isActive = flattenTabs(current).includes(pluginId)
48
49 if (isActive) {
50 // `destroy` is deliberately not called here. It hangs off the pane's own
51 // teardown in `PluginWorkspace`, so it fires exactly once however the pane
52 // was closed — this toggle, a tab's close button, or a whole group going
53 // away — and it fires before the mount node is detached.
54 setLayout(closeTab(current, pluginId))
55 return
56 }
57
58 if (flattenTabs(current).length >= MAX_ACTIVE_PLUGINS) return
59
60 // Opening from the strip adds a pane alongside the others at an equal share,
61 // which is the side-by-side behaviour the strip has always had. Dragging
62 // decides placement for itself.
63 setLayout(appendPane(current, pluginId))
64 }
65
66 return { plugins, toggleActivePlugins, activePlugins, layout, setLayout }
67}
68
69export const createDevtoolsState = () => {
70 const { store, setStore } = createDevtoolsContext()
71 const state = createMemo(() => store.state)
72 const setState = (newState: Partial<DevtoolsStore['state']>) => {
73 setStore((previous) => ({
74 ...previous,
75 state: {
76 ...previous.state,
77 ...newState,

Callers 2

PluginMarketplaceFunction · 0.90
PluginsTabFunction · 0.90

Calls 2

createDevtoolsContextFunction · 0.85
createDrawContextFunction · 0.85

Tested by

no test coverage detected