Function: OnQuery()
ts
function OnQuery(type: QueryType): OnQueryDecorator;Defined in: src/wirestate-core/plugin/queries/on-query.ts:93
Marks an injectable service method as a provision-scoped query handler.
Parameters
| Parameter | Type | Description |
|---|---|---|
type | QueryType | Query token. |
Returns
Method decorator.
Remarks
The handler is registered when the owning container is provisioned and unregistered when that provision cycle ends. Register QueriesPlugin on the container, or on an ancestor container, to enable query handlers.
Queries answer read-oriented requests. One query call goes to one handler: the newest registered handler for the query token.
Example
typescript
import { Injectable, OnQuery } from "@wirestate/core";
@Injectable()
class UserProfileService {
private readonly avatars = new Map<string, string>();
@OnQuery("GET_USER_AVATAR")
public onGetUserAvatar(userId: string): string {
return this.avatars.get(userId) ?? "";
}
}