Skip to content

Function: onQuery()

ts
function onQuery<R, P, T>(type: T): OnQueryDecorator<R, P, T>;

Defined in: src/wirestate-lit/queries/on-query.ts:54

Decorator for Lit element methods that handle a specific query.

Type Parameters

Type ParameterDefault type
Runknown
Punknown
T extends QueryTypeQueryType

Parameters

ParameterTypeDescription
typeTQuery type to handle.

Returns

OnQueryDecorator<R, P, T>

A method decorator function.

Remarks

The handler is registered when the host connects, unregistered when it disconnects, and re-registered when the nearest container context changes. Query handlers are stack-based on the active query bus.

Example

typescript
class MyElement extends LitElement {
  @onQuery("GET_USER_NAME")
  private onGetUserName(payload: QueryPayload) {
    return "Alice";
  }
}