Skip to content

Class: OnCommandController<D, R>

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

Reactive controller that registers a command handler.

Remarks

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

Example

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

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

Type Parameters

Type ParameterDefault type
Dunknown
Runknown

Implements

  • ReactiveController

Constructors

Constructor

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

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

Parameters

ParameterTypeDescription
hostReactiveElementThe host element.
typeCommandTypeUnique identifier of the command to handle.
handlerCommandHandler<D, R>The command handler function.

Returns

OnCommandController<D, R>

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:70

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