Skip to content

lit-ui-router-mobx / ReactionController

Class: ReactionController<T>

Defined in: reaction-controller.ts:39

A ReactiveController that composes MobX with the Lit lifecycle: it runs a MobX reaction over an explicit selector while the host is connected and calls host.requestUpdate() when the selected value changes.

This is a selector-based alternative to render auto-tracking mixins such as MobxLitElement:

  • No base class required — works on any LitElement (or other host).
  • Dependencies are explicit: the selector names exactly which observables drive the host, and equals: comparer.structural gives precise, value-based change detection.
  • Lifecycle is automatic: the reaction is created in hostConnected and disposed in hostDisconnected — no manual disposer bookkeeping.
  • The reaction fires immediately on (re)connect, so hosts that re-enter the DOM (e.g. sticky routed components) synchronize with the current store state instead of rendering stale values.

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

Type Parameters

Type Parameter
T

Implements

Constructors

Constructor

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

Defined in: reaction-controller.ts:44

Parameters

ParameterType
hostReactiveControllerHost
expression() => T
optionsReactionControllerOptions<T>

Returns

ReactionController<T>

Properties

PropertyTypeDefined in
valueTreaction-controller.ts:40

Methods

hostConnected()

ts
hostConnected(): void;

Defined in: reaction-controller.ts:52

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: reaction-controller.ts:64

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;