MCPcopy Index your code
hub / github.com/anomalyco/opencode / useEvent

Function useEvent

packages/tui/src/context/event.ts:9–36  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7}
8
9export function useEvent() {
10 const sdk = useSDK()
11
12 function subscribe(handler: (event: Event, metadata: EventMetadata) => void) {
13 return sdk.event.on("event", (event) => {
14 if (event.payload.type === "sync") {
15 return
16 }
17
18 handler(event.payload, { directory: event.directory, workspace: event.workspace })
19 })
20 }
21
22 function on<T extends Event["type"]>(
23 type: T,
24 handler: (event: Extract<Event, { type: T }>, metadata: EventMetadata) => void,
25 ) {
26 return subscribe((event: Event, metadata: EventMetadata) => {
27 if (event.type !== type) return
28 handler(event as Extract<Event, { type: T }>, metadata)
29 })
30 }
31
32 return {
33 subscribe,
34 on,
35 }
36}

Callers 8

ProbeFunction · 0.90
AppFunction · 0.90
DialogSessionListFunction · 0.90
PromptFunction · 0.90
SessionFunction · 0.90
sync.tsxFile · 0.90
local.tsxFile · 0.90
data.tsxFile · 0.90

Calls

no outgoing calls

Tested by 1

ProbeFunction · 0.72