Open History to see the last commit
1import type { EventClient } from './plugin'
2import type { AllDevtoolsEvents, TanStackDevtoolsEvent } from './types'
3β
4/** Maps a type to its public members only (drops `#private`/`private`). */
5type PublicSurface<T> = { [K in keyof T]: T[K] }
6β
7/**
8 * A no-op implementation of `EventClient` with an identical public API.
9 *
10 * The package root export resolves to this class outside of development (see
11 * `index.ts`), so production bundlers can tree-shake the real client away.
12 * Authors who want devtools events in production should import the real client
13 * from `@tanstack/devtools-event-client/production` instead.
14 */
15export class EventClientNoOp<
16 TEventMap extends Record<string, any>,
17> implements PublicSurface<EventClient<TEventMap>> {
18 #pluginId: string
19β
20 constructor({
21 pluginId,
22 }: {
23 pluginId: string
24 debug?: boolean
25 reconnectEveryMs?: number
26 enabled?: boolean
27 }) {
28 this.#pluginId = pluginId
29 }
30β
31 getPluginId() {
32 return this.#pluginId
33 }
34β
35 createEventPayload<TEvent extends keyof TEventMap & string>(
36 eventSuffix: TEvent,
37 payload: TEventMap[TEvent],
38 ) {
39 return {
40 type: `${this.#pluginId}:${eventSuffix}`,
41 payload,
42 pluginId: this.#pluginId,
43 }
44 }
45β
46 emit<TEvent extends keyof TEventMap & string>(
47 _eventSuffix: TEvent,
48 _payload: TEventMap[TEvent],
49 ): void {}
50β
51 on<TEvent extends keyof TEventMap & string>(
52 _eventSuffix: TEvent,
53 _cb: (event: TanStackDevtoolsEvent<TEvent, TEventMap[TEvent]>) => void,
54 _options?: {
55 withEventTarget?: boolean
56 },
57 ) {
58 return () => {}
59 }
60β
61 onAll(_cb: (event: TanStackDevtoolsEvent<string, any>) => void) {
62 return () => {}
63 }
64β
65 onAllPluginEvents(_cb: (event: AllDevtoolsEvents<TEventMap>) => void) {
66 return () => {}
67 }
68}