Skip to content

ChainGraph API Documentation / @badaitech/chaingraph-types / createTypedHandler

Function: createTypedHandler()

createTypedHandler<T>(type, handler): FlowEventHandler<T>

Defined in: packages/chaingraph-types/src/flow/eventHandlers.ts:133

Helper function to create a strongly-typed event handler for a specific event type

Type Parameters

T

T extends FlowEventType

Parameters

type

T

Flow event type

handler

FlowEventHandler<T>

Handler function for the event

Returns

FlowEventHandler<T>

Typed event handler

Example

typescript
const handleNodeAdded = createTypedHandler(
  FlowEventType.NodeAdded,
  (data) => console.log('Node added:', data.node.id)
)

// Type-safe usage in handler map
const handlers: FlowEventHandlerMap = {
  [FlowEventType.NodeAdded]: handleNodeAdded
}

Licensed under BUSL-1.1