Type Alias: CommandHandler<R, P, T>
ts
type CommandHandler<R, P, T> = (payload: P) => MaybePromise<R> & {
type?: T;
};Defined in: src/wirestate-core/plugin/commands/commands.ts:40
Handles a dispatched command payload and returns the command result.
Type Declaration
| Name | Type | Defined in |
|---|---|---|
type? | T | src/wirestate-core/plugin/commands/commands.ts:43 |
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
R | unknown | Result type, optionally a Promise. |
P | unknown | Payload type. |
T extends CommandType | CommandType | Command type. |
Remarks
A handler may return a plain value or a Promise. CommandBus.execute(...) returns that result as-is. CommandBus.executeAsync(...) Promise-normalizes it.
Example
typescript
const loginHandler: CommandHandler<Session, Credentials> = (credentials) => auth.login(credentials);