File tree Expand file tree Collapse file tree
packages/event-bus-plugin Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,17 +2,14 @@ import ReactDOM from 'react-dom/client'
22import Devtools from './setup'
33import { queryPlugin } from './plugin'
44setTimeout ( ( ) => {
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' ,
5+ queryPlugin . emit ( 'test' , {
6+ title : 'Test Event' ,
7+ description :
8+ 'This is a test event from the TanStack Query Devtools plugin.' ,
129 } )
1310} , 1000 )
1411
15- queryPlugin . on ( 'query-devtools: test' , ( event ) => {
12+ queryPlugin . on ( 'test' , ( event ) => {
1613 console . log ( 'Received test event:' , event )
1714} )
1815function App ( ) {
Original file line number Diff line number Diff line change 1- import { z } from 'zod'
21import { TanstackDevtoolsEventSubscription } from '@tanstack/devtools-event-bus-plugin'
32
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- } ) ,
3+ interface EventMap {
4+ 'query-devtools:test' : {
5+ title : string
6+ description : string
7+ }
8+ 'query-devtools:init' : {
9+ title : string
10+ description : string
11+ }
12+ 'query-devtools:query' : {
13+ title : string
14+ description : string
15+ }
1716}
18-
19- class QueryDevtoolsPlugin extends TanstackDevtoolsEventSubscription <
20- typeof eventMap
21- > {
17+ class QueryDevtoolsPlugin extends TanstackDevtoolsEventSubscription < EventMap > {
2218 constructor ( ) {
2319 super ( {
2420 pluginId : 'query-devtools' ,
Original file line number Diff line number Diff line change @@ -6,9 +6,9 @@ export default function ClientPlugin() {
66 Array < { type : string ; payload : { title : string ; description : string } } >
77 > ( [ ] )
88 useEffect ( ( ) => {
9- const cleanup = queryPlugin . on ( 'query-devtools: test' , ( event ) => {
9+ const cleanup = queryPlugin . on ( 'test' , ( event ) => {
1010 console . log ( 'Received message in here:' , event )
11- setEvents ( ( prev ) => [ ...prev , event ] )
11+ setEvents ( ( prev ) => [ ...prev , event as any ] )
1212 } )
1313
1414 return cleanup
@@ -21,13 +21,10 @@ export default function ClientPlugin() {
2121 className = "bg-blue-500 text-white px-4 py-2 rounded"
2222 onClick = { ( ) => {
2323 console . log ( 'Button clicked, emitting event' )
24- queryPlugin . emit ( {
25- type : 'query-devtools:test' ,
26- payload : {
27- title : 'Button Clicked' ,
28- description :
29- 'This is a custom event triggered by the client plugin.' ,
30- } ,
24+ queryPlugin . emit ( 'test' , {
25+ title : 'Button Clicked' ,
26+ description :
27+ 'This is a custom event triggered by the client plugin.' ,
3128 } )
3229 } }
3330 >
Original file line number Diff line number Diff line change 1- import { z } from 'zod'
21import { TanstackDevtoolsEventSubscription } from '@tanstack/devtools-event-bus-plugin'
32
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- } ) ,
3+ interface EventMap {
4+ 'query-devtools:test' : {
5+ title : string
6+ description : string
7+ }
8+ 'query-devtools:init' : {
9+ title : string
10+ description : string
11+ }
12+ 'query-devtools:query' : {
13+ title : string
14+ description : string
15+ }
1716}
1817
19- class QueryDevtoolsPlugin extends TanstackDevtoolsEventSubscription <
20- typeof eventMap
21- > {
18+ class QueryDevtoolsPlugin extends TanstackDevtoolsEventSubscription < EventMap > {
2219 constructor ( ) {
2320 super ( {
2421 pluginId : 'query-devtools' ,
Original file line number Diff line number Diff line change @@ -6,16 +6,13 @@ This package is still under active development and might have breaking changes i
66
77``` tsx
88import { TanstackDevtoolsEventSubscription } from ' @tanstack/devtools-event-bus-plugin'
9- interface EventMap {
9+
10+ interface EventMap {
1011 ' query-devtools:a' : { foo: string }
1112 ' query-devtools:b' : { foo: number }
12- }
13-
14-
13+ }
1514
16- class QueryDevtoolsPlugin extends TanstackDevtoolsEventSubscription <
17- EventMap
18- > {
15+ class QueryDevtoolsPlugin extends TanstackDevtoolsEventSubscription <EventMap > {
1916 constructor () {
2017 super ({
2118 pluginId: ' query-devtools' ,
Original file line number Diff line number Diff line change 5151 "test:types" : " tsc" ,
5252 "test:build" : " publint --strict" ,
5353 "build" : " vite build"
54- },
55- "devDependencies" : {}
56- }
54+ }
55+ }
Original file line number Diff line number Diff line change 11export { TanstackDevtoolsEventSubscription } from './plugin'
2- export type { EventMap } from './plugin'
Original file line number Diff line number Diff line change @@ -22,8 +22,8 @@ export class TanstackDevtoolsEventSubscription<
2222> {
2323 #pluginId: TPluginId
2424 #eventTarget: ( ) => EventTarget
25- #debug: boolean
2625
26+ #debug: boolean
2727 constructor ( {
2828 pluginId,
2929 debug = false ,
@@ -72,18 +72,31 @@ export class TanstackDevtoolsEventSubscription<
7272 )
7373 }
7474
75- emit < TSuffix extends string > (
75+ emit <
76+ TSuffix extends Extract <
77+ keyof TEventMap ,
78+ `${TPluginId & string } :${string } `
79+ > extends `${TPluginId & string } :${infer S } `
80+ ? S
81+ : never ,
82+ > (
7683 eventSuffix : TSuffix ,
7784 payload : TEventMap [ `${TPluginId & string } :${TSuffix } `] ,
7885 ) {
7986 this . emitEventToBus ( {
8087 type : `${ this . #pluginId} :${ eventSuffix } ` ,
8188 payload,
82- pluginId : this . #pluginId,
8389 } )
8490 }
8591
86- on < TSuffix extends string > (
92+ on <
93+ TSuffix extends Extract <
94+ keyof TEventMap ,
95+ `${TPluginId & string } :${string } `
96+ > extends `${TPluginId & string } :${infer S } `
97+ ? S
98+ : never ,
99+ > (
87100 eventSuffix : TSuffix ,
88101 cb : (
89102 event : TanStackDevtoolsEvent <
You can’t perform that action at this time.
0 commit comments