Skip to content

Function: OnCommand()

ts
function OnCommand(type: CommandType): MethodDecorator;

Defined in: src/wirestate-core/commands/on-command.ts:34

Marks a service method as a command handler.

Parameters

ParameterTypeDescription
typeCommandTypeCommand token.

Returns

MethodDecorator

Method decorator.

Remarks

The handler registers when the service activates and unregisters when the service deactivates. One command call goes to one handler: the newest registered handler for that token.

Example

typescript
import { Injectable, OnCommand } from "@wirestate/core";

@Injectable()
class UserService {
  @OnCommand("USER_LOGIN")
  private onUserLogin(credentials: Credentials): Promise<Session> {
    return auth.login(credentials);
  }
}