Skip to content

Function: onCommand()

ts
function onCommand<R, P, T>(type: T): OnCommandDecorator<R, P, T>;

Defined in: src/wirestate-lit/commands/on-command.ts:53

Decorator for Lit element methods that handle a specific command.

Type Parameters

Type ParameterDefault type
Runknown
Punknown
T extends CommandTypeCommandType

Parameters

ParameterTypeDescription
typeTCommand type to handle.

Returns

OnCommandDecorator<R, P, T>

A method decorator function.

Remarks

The handler is registered when the host connects, unregistered when it disconnects, and re-registered when the nearest container context changes. Command handlers are stack-based on the active command bus.

Example

typescript
class MyElement extends LitElement {
  @onCommand("SAVE")
  private onSave(payload: SomeData): void {
    // handle command
  }
}