Skip to content

lit-ui-router-signals / SignalController

Class: SignalController<T> ​

Defined in: signal-controller.ts:42

A ReactiveController that composes TC39 Signals with the Lit lifecycle: while the host is connected it watches a selector through a Signal.Computed and calls host.requestUpdate() when the selected value changes.

A selector-based alternative to @lit-labs/signals' SignalWatcher mixin: no base class, explicit dependencies, and an equals comparer for value-based change detection. Changes are delivered in a microtask, since a watcher may not read signals while one is being set.

The selector runs immediately on every (re)connect, so hosts that re-enter the DOM (e.g. sticky routed components) synchronize with current values. The selected value is exposed as .value for use in render().

Type Parameters ​

Type Parameter
T

Implements ​

Constructors ​

Constructor ​

ts
new SignalController<T>(
   host, 
   expression, 
   options?
): SignalController<T>;

Defined in: signal-controller.ts:48

Parameters ​

ParameterType
hostReactiveControllerHost
expression() => T
options?SignalControllerOptions<T>

Returns ​

SignalController<T>

Properties ​

PropertyTypeDescriptionDefined in
valueTthe selected value as of the last read; read it in render()signal-controller.ts:44

Methods ​

hostConnected() ​

ts
hostConnected(): void;

Defined in: signal-controller.ts:58

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