Function: OnCommand()
ts
function OnCommand(type: CommandType): OnCommandDecorator;Defined in: src/wirestate-core/plugin/commands/on-command.ts:92
Marks an injectable service method as a provision-scoped command handler.
Parameters
| Parameter | Type | Description |
|---|---|---|
type | CommandType | Command token. |
Returns
Method decorator.
Remarks
The handler is registered when the owning container is provisioned and unregistered when that provision cycle ends. Register CommandsPlugin on the container, or on an ancestor container, to enable command handlers.
One command call goes to one handler: the newest registered handler for the command token. The method receives the command payload and may return either a plain value or a Promise.
Example
typescript
import { Injectable, OnCommand } from "@wirestate/core";
@Injectable()
class UserService {
@OnCommand("USER_LOGIN")
public onUserLogin(credentials: Credentials): Promise<Session> {
return auth.login(credentials);
}
}