StoreController is a reactive controller for accessing store state and actions in custom elements. It accepts a store instance or a context and resolves the store automatically.
- Without a selector — returns the store instance directly. Does not subscribe to changes. Use this to access store actions.
- With a selector — returns the selected value and subscribes to changes. Triggers a host update when the selected value changes (shallow equality).
Signature
Constructor
- Without selector
- With selector
The host element (
ReactiveControllerHost & HTMLElement) that owns this controller. Typically this inside a custom element class.A store instance or a context object. When a context is provided, the store is resolved from the nearest provider in the DOM tree.
Properties
The current value:
- Without a selector: the store instance.
- With a selector: the return value of the selector applied to the current state.
Usage
Accessing actions (without selector)
Without a selector,StoreController returns the store and does not subscribe to updates. Use this to dispatch actions imperatively.
Subscribing to state (with selector)
With a selector,StoreController subscribes to the store and triggers a host update whenever the selected value changes.
StoreController vs PlayerController vs SnapshotController
StoreController | PlayerController | SnapshotController | |
|---|---|---|---|
| Input | Any store or context | Player store context | State<T> container |
| Typed to | Generic store | Player features | Raw state |
| Resolves store | Yes (from context) | Yes (from player context) | No |
| Use case | General-purpose store access | Player UI elements | Low-level state subscription |
PlayerController is a typed wrapper around StoreController scoped to the player store. For player UI, prefer PlayerController. Use StoreController when working with a custom store outside the player system.
When you pass a selector, StoreController internally creates a SnapshotController on store.$state. Without a selector, no subscription is created.
StoreController.value throws if the store is not available. Without a selector, guard access with a conditional or call .value only inside event handlers where the element is guaranteed to be connected.