Skip to content

Class: OnCommandController<R, P, T> ​

Defined in: src/wirestate-lit/commands/on-command-controller.ts:29

Reactive controller that registers a command handler.

Remarks ​

Registers on host connect. Unregisters on disconnect. Re-registers when the nearest container context changes.

Example ​

typescript
import { LitElement } from "lit";
import { OnCommandController } from "@wirestate/lit";

class SaveButton extends LitElement {
  private readonly saveCommand = new OnCommandController(this, "SAVE", (payload: FormData) => {
    console.log("save", payload);
  });
}

Type Parameters ​

Type ParameterDefault type
Runknown
Punknown
T extends CommandTypeCommandType

Implements ​

  • ReactiveController

Constructors ​

Constructor ​

ts
new OnCommandController<R, P, T>(
   host: ReactiveElement, 
   type: T, 
handler: CommandHandler<R, P, T>): OnCommandController<R, P, T>;

Defined in: src/wirestate-lit/commands/on-command-controller.ts:45

Parameters ​

ParameterTypeDescription
hostReactiveElementThe host element.
typeTCommand type to handle.
handlerCommandHandler<R, P, T>The command handler function.

Returns ​

OnCommandController<R, P, T>

Methods ​

hostConnected() ​

ts
hostConnected(): void;

Defined in: src/wirestate-lit/commands/on-command-controller.ts:65

Called when the host is connected to the component tree. For custom element hosts, this corresponds to the connectedCallback() lifecycle, which is only called when the component is connected to the document.

Returns ​

void

Implementation of ​

ts
ReactiveController.hostConnected

hostDisconnected() ​

ts
hostDisconnected(): void;

Defined in: src/wirestate-lit/commands/on-command-controller.ts:69

Called when the host is disconnected from the component tree. For custom element hosts, this corresponds to the disconnectedCallback() lifecycle, which is called the host or an ancestor component is disconnected from the document.

Returns ​

void

Implementation of ​

ts
ReactiveController.hostDisconnected