Skip to content

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

Function: OnPortUpdate()

OnPortUpdate<TNode, TPort>(handler): PropertyDecorator

Defined in: packages/chaingraph-types/src/decorator/port-update.decorator.ts:131

Decorator for defining port update handlers

This decorator allows you to specify a handler function that will be called whenever the decorated port is updated. The handler receives the node instance, the updated port, and the port update event.

Example usage:

typescript
class MyNode extends BaseNode {
  @Passthrough()
  @PortObject({
    title: 'Output Schema',
    schema: { properties: {} },
    isSchemaMutable: true,
  })
  @OnPortUpdate(async (node: INode, port: IPort) => {
    const targetPort = node.getOutputs().find(p => p.getConfig().key === 'result')
    if (targetPort instanceof ObjectPort) {
      node.copyObjectSchemaTo(node, port, targetPort)
    }
  })
  outputSchema: Record<string, any> = {}
}

Type Parameters

TNode

TNode extends INode = INode

TPort

TPort extends IPort<IPortConfig> = IPort<IPortConfig>

Parameters

handler

PortUpdateHandler<TNode, TPort>

The handler function to call when the port is updated

Returns

PropertyDecorator

Licensed under BUSL-1.1