Skip to content

Class: OnEventController<E>

Defined in: src/wirestate-lit/events/on-event-controller.ts:32

Reactive controller that subscribes to container events.

Remarks

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

Example

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

class AuditLog extends LitElement {
  private readonly events = new OnEventController(this, ["USER_LOGIN"], (event) => {
    console.log(event.payload);
  });
}

Type Parameters

Type ParameterDefault type
E extends EventEvent

Implements

  • ReactiveController

Constructors

Constructor

ts
new OnEventController<E>(
   host: ReactiveElement, 
   types: Optional<readonly EventType[]>, 
handler: EventHandler<E>): OnEventController<E>;

Defined in: src/wirestate-lit/events/on-event-controller.ts:44

Parameters

ParameterTypeDescription
hostReactiveElementThe host element.
typesOptional<readonly EventType[]>Event types to listen for. If null, all events will be handled.
handlerEventHandler<E>The event handler function.

Returns

OnEventController<E>

Methods

hostConnected()

ts
hostConnected(): void;

Defined in: src/wirestate-lit/events/on-event-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/events/on-event-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