Skip to content

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

NameTypeDefined in
type?Tsrc/wirestate-core/plugin/commands/commands.ts:43

Type Parameters

Type ParameterDefault typeDescription
RunknownResult type, optionally a Promise.
PunknownPayload type.
T extends CommandTypeCommandTypeCommand 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);