Skip to content

lit-ui-router-effect / RefController

Class: RefController<Refs, T>

Defined in: ref-controller.ts:100

A ReactiveController that composes Effect's SubscriptionRef with the Lit lifecycle: it selects over one or more refs and calls host.requestUpdate() when the selected value changes.

The subscription is a single fiber — Stream.runForEach over the refs' changes — forked in hostConnected and interrupted in hostDisconnected, so it lives exactly as long as the host is in the document. changes replays the current value, and the controller also seeds .value synchronously on connect, so a reconnected host (a sticky routed component) renders current state, never stale state.

Refs given directly are read once more at construction, so .value is live before the host ever connects — a host rendered on the server sees the same value a browser would. Refs resolved on connect carry options.initialValue until then.

The selected value is exposed as .value for use in render().

Extended by

Type Parameters

Type Parameter
Refs extends SubscriptionRefs
T

Implements

Constructors

Constructor

ts
new RefController<Refs, T>(
   host, 
   refs, 
   selector, 
   options?
): RefController<Refs, T>;

Defined in: ref-controller.ts:111

Parameters

ParameterType
hostReactiveControllerHost
refsRefSource<Refs>
selector(...values) => T
optionsRefControllerOptions<T>

Returns

RefController<Refs, T>

Properties

PropertyTypeDescriptionDefined in
valueTThe selected value, for use in render().ref-controller.ts:105

Methods

hostConnected()

ts
hostConnected(): void;

Defined in: ref-controller.ts:127

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: ref-controller.ts:140

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