Skip to content

Function: onCommand()

ts
function onCommand<D, R>(type: CommandType): OnCommandDecorator<D, R>;

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

Decorator for Lit element methods that handle a specific command.

Type Parameters

Type ParameterDefault type
Dunknown
Runknown

Parameters

ParameterTypeDescription
typeCommandTypeUnique identifier of the command to handle.

Returns

OnCommandDecorator<D, R>

A method decorator function.

Remarks

The handler is registered when the host connects and unregistered when it disconnects.

Example

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