Skip to content

Type Alias: QueryHandler<R, P, T>

ts
type QueryHandler<R, P, T> = (payload: P) => MaybePromise<R> & {
  type?: T;
};

Defined in: src/wirestate-core/plugin/queries/queries.ts:40

Answers a dispatched query payload and returns the query result.

Type Declaration

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

Type Parameters

Type ParameterDefault typeDescription
RunknownResult type, optionally a Promise.
PunknownPayload type.
T extends QueryTypeQueryTypeQuery type.

Remarks

A handler may return a plain value or a Promise. QueryBus.query(...) returns that result as-is. QueryBus.queryAsync(...) Promise-normalizes it.

Example

typescript
const currentUserHandler: QueryHandler<User> = () => userRepository.current();