Skip to content

Class: OnEventController<E> ​

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

Reactive controller that subscribes to container events.

Remarks ​

Subscribes on host connect. Unsubscribes on disconnect. Re-subscribes when the nearest container context 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 WireEventWireEvent

Implements ​

  • ReactiveController

Constructors ​

Constructor ​

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

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

Parameters ​

ParameterTypeDescription
hostReactiveElementThe host element.
typesNullable<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:61

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

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