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
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 Event | Event |
Implements
ReactiveController
Constructors
Constructor
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
| Parameter | Type | Description |
|---|---|---|
host | ReactiveElement | The host element. |
types | Optional<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: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
ReactiveController.hostConnectedhostDisconnected()
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
ReactiveController.hostDisconnected