Skip to content

Commit 479415b

Browse files
committed
feat: drastically improve the event buses, split into server/client, add new packages
1 parent b16e430 commit 479415b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+770
-491
lines changed

examples/react/basic/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
"test:types": "tsc"
1010
},
1111
"dependencies": {
12+
"@tanstack/devtools-event-bus-plugin": "workspace:^",
1213
"@tanstack/react-devtools": "^0.1.1",
1314
"@tanstack/react-query": "^5.83.0",
1415
"@tanstack/react-query-devtools": "^5.83.0",
1516
"@tanstack/react-router": "^1.130.2",
1617
"@tanstack/react-router-devtools": "^1.130.2",
1718
"react": "^19.1.0",
18-
"react-dom": "^19.1.0"
19+
"react-dom": "^19.1.0",
20+
"zod": "^4.0.14"
1921
},
2022
"devDependencies": {
2123
"@types/react": "^19.1.2",
@@ -35,4 +37,4 @@
3537
"last 1 safari version"
3638
]
3739
}
38-
}
40+
}

examples/react/basic/src/index.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
import ReactDOM from 'react-dom/client'
22
import Devtools from './setup'
3+
import { queryPlugin } from './plugin'
4+
setTimeout(() => {
5+
queryPlugin.emit({
6+
payload: {
7+
title: 'Test Event',
8+
description:
9+
'This is a test event from the TanStack Query Devtools plugin.',
10+
},
11+
type: 'query-devtools:test',
12+
})
13+
}, 1000)
314

15+
queryPlugin.on('query-devtools:test', (event) => {
16+
console.log('Received test event:', event)
17+
})
418
function App() {
519
return (
620
<div>

examples/react/basic/src/plugin.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { z } from 'zod'
2+
import { TanstackDevtoolsEventSubscription } from '@tanstack/devtools-event-bus-plugin'
3+
4+
const eventMap = {
5+
'query-devtools:test': z.object({
6+
title: z.string(),
7+
description: z.string(),
8+
}),
9+
'query-devtools:init': z.object({
10+
title: z.string(),
11+
description: z.string(),
12+
}),
13+
'query-devtools:query': z.object({
14+
title: z.string(),
15+
description: z.string(),
16+
}),
17+
}
18+
19+
class QueryDevtoolsPlugin extends TanstackDevtoolsEventSubscription<
20+
typeof eventMap
21+
> {
22+
constructor() {
23+
super({
24+
pluginId: 'query-devtools',
25+
})
26+
}
27+
}
28+
29+
export const queryPlugin = new QueryDevtoolsPlugin()

examples/react/start/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
"@prisma/extension-accelerate": "^2.0.2",
1818
"@prisma/studio-core": "^0.5.1",
1919
"@tailwindcss/vite": "^4.0.6",
20+
"@tanstack/devtools-event-bus": "workspace:^",
21+
"@tanstack/devtools-event-bus-plugin": "workspace:^",
2022
"@tanstack/react-devtools": "^0.1.1",
2123
"@tanstack/react-query": "^5.83.0",
2224
"@tanstack/react-query-devtools": "^5.83.0",

examples/react/start/src/client-setup.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

examples/react/start/src/components/client-plugin.tsx

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,21 @@
1+
import { queryPlugin } from '@/plugin'
12
import { useEffect, useState } from 'react'
2-
import { devtoolsClient } from '@/client-setup'
3-
3+
queryPlugin.on('query-devtools:test', (event) => {
4+
console.log('Received message in here:', event)
5+
})
46
export default function ClientPlugin() {
5-
const [events, setEvents] = useState<
7+
const [events] = useState<
68
Array<{ type: string; payload: { title: string; description: string } }>
79
>([])
8-
useEffect(() => {
9-
devtoolsClient.onAll((event) => {
10-
console.log('Received message:', event)
11-
setEvents((prev) => [...prev, event])
12-
})
13-
devtoolsClient.emit({
14-
type: 'init',
15-
payload: {
16-
title: 'Client Plugin Initialized',
17-
description: 'Listening for events',
18-
},
19-
})
20-
}, [])
10+
2111
return (
2212
<div>
2313
<h1>Client Plugin Initialized</h1>
2414
<p>Devtools Client is connected.</p>
2515
<button
2616
onClick={() =>
27-
devtoolsClient.emit({
28-
type: 'click-event',
17+
queryPlugin.emit({
18+
type: 'query-devtools:test',
2919
payload: {
3020
title: 'Button Clicked',
3121
description:

examples/react/start/src/components/devtools.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default function DevtoolsExample() {
1212
<>
1313
<QueryClientProvider client={queryClient}>
1414
<TanstackDevtools
15+
hasDevtoolsServer={true}
1516
plugins={[
1617
{
1718
name: 'Tanstack Query',

examples/react/start/src/plugin.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { z } from 'zod'
2+
import { TanstackDevtoolsEventSubscription } from '@tanstack/devtools-event-bus-plugin'
3+
4+
const eventMap = {
5+
'query-devtools:test': z.object({
6+
title: z.string(),
7+
description: z.string(),
8+
}),
9+
'query-devtools:init': z.object({
10+
title: z.string(),
11+
description: z.string(),
12+
}),
13+
'query-devtools:query': z.object({
14+
title: z.string(),
15+
description: z.string(),
16+
}),
17+
}
18+
19+
class QueryDevtoolsPlugin extends TanstackDevtoolsEventSubscription<
20+
typeof eventMap
21+
> {
22+
constructor() {
23+
super({
24+
pluginId: 'query-devtools',
25+
})
26+
}
27+
}
28+
29+
export const queryPlugin = new QueryDevtoolsPlugin()
Lines changed: 3 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,7 @@
1-
import {
2-
DevtoolsServer,
3-
DevtoolsPlugin,
4-
type EventMap,
5-
} from '@tanstack/devtools/server'
6-
import { z } from 'zod'
7-
const devtoolsServer = new DevtoolsServer()
1+
import { TanstackDevtoolsServerEventBus } from '@tanstack/devtools-event-bus/server'
82

9-
devtoolsServer.start()
10-
11-
devtoolsServer.on('click-event', (payload) => {
12-
console.log('Click event received:', payload)
13-
})
14-
15-
devtoolsServer.onAll((e) => {
16-
console.log('All events:', e)
17-
})
18-
19-
setInterval(() => {
20-
console.log('Emitting server event...')
21-
devtoolsServer.emit({
22-
type: 'server-event',
23-
payload: {
24-
title: 'Server Event',
25-
description: 'This is a custom event emitted by the server.',
26-
},
27-
})
28-
}, 5000)
3+
const devtoolsServer = new TanstackDevtoolsServerEventBus()
294

30-
const eventMap = {
31-
'query-devtools:test': z.object({
32-
title: z.string(),
33-
description: z.string(),
34-
}),
35-
'query-devtools:init': z.object({
36-
title: z.string(),
37-
description: z.string(),
38-
}),
39-
'query-devtools:b': z.object({
40-
title: z.string(),
41-
description: z.string(),
42-
}),
43-
} satisfies EventMap<'query-devtools'>
44-
45-
class QueryDevtoolsPlugin extends DevtoolsPlugin<typeof eventMap> {
46-
constructor() {
47-
super({
48-
pluginId: 'query-devtools',
49-
})
50-
}
51-
}
52-
53-
const plugin = new QueryDevtoolsPlugin()
54-
/* plugin.emit({
55-
type: `query-devtools:init`,
56-
payload: {
57-
// Add your payload data here
58-
},
59-
}) */
60-
61-
plugin.onAll((e) => {
62-
if (e.type === 'query-devtools:test') {
63-
console.log('Received query-devtools:test event:', e.payload)
64-
}
65-
})
66-
plugin.on('query-devtools:test', (e) => {
67-
e.payload
68-
})
5+
devtoolsServer.start()
696

707
export { devtoolsServer }

examples/react/start/vite.config.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,7 @@ const config = defineConfig({
1111
viteTsConfigPaths({
1212
projects: ['./tsconfig.json'],
1313
}),
14-
{
15-
name: 'custom-devtools',
1614

17-
configureServer() {
18-
devtoolsServer.on('init', (payload) => {
19-
console.log('Devtools server initialized:', payload)
20-
})
21-
},
22-
},
2315
tailwindcss(),
2416
tanstackStart({
2517
customViteReactPlugin: true,

0 commit comments

Comments
 (0)