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
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 Parameter | Default type |
|---|---|
E extends WireEvent | WireEvent |
Implements
ReactiveController
Constructors
Constructor
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
| Parameter | Type | Description |
|---|---|---|
host | ReactiveElement | The host element. |
types | Nullable<readonly EventType[]> | Event types to listen for. If null, all events will be handled. |
handler | EventHandler<E> | The event handler function. |
Returns
OnEventController<E>
Methods
hostConnected()
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
ReactiveController.hostConnectedhostDisconnected()
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
ReactiveController.hostDisconnected