MCPcopy Create free account
hub / github.com/TanStack/db / on

Method on

packages/db/src/event-emitter.ts:17–29  ·  view source on GitHub ↗

* Subscribe to an event * @param event - Event name to listen for * @param callback - Function to call when event is emitted * @returns Unsubscribe function

(
    event: T,
    callback: (event: TEvents[T]) => void,
  )

Source from the content-addressed store, hash-verified

15 * @returns Unsubscribe function
16 */
17 on<T extends keyof TEvents>(
18 event: T,
19 callback: (event: TEvents[T]) => void,
20 ): () => void {
21 if (!this.listeners.has(event)) {
22 this.listeners.set(event, new Set())
23 }
24 this.listeners.get(event)!.add(callback as (event: any) => void)
25
26 return () => {
27 this.listeners.get(event)?.delete(callback as (event: any) => void)
28 }
29 }
30
31 /**
32 * Subscribe to an event once (automatically unsubscribes after first emission)

Callers 15

onceMethod · 0.95
waitForMethod · 0.95
runFunction · 0.45
internalSyncFunction · 0.45
startMethod · 0.45
getAvailablePortFunction · 0.45
spawnProcessFunction · 0.45

Calls 5

hasMethod · 0.45
setMethod · 0.45
addMethod · 0.45
getMethod · 0.45
deleteMethod · 0.45

Tested by 2

getAvailablePortFunction · 0.36
spawnProcessFunction · 0.36