SnapshotController subscribes to a State<T> container (the reactive primitive that backs a store) and triggers host updates when state changes. It has two overloads:
- Without a selector — returns the entire state object. Re-renders on any state change.
- With a selector — returns a derived slice of state. Re-renders only when the selected value changes (shallow equality).
Signature
Constructor
- Without selector
- With selector
Properties
The current state value:
- Without a selector: the full state object (
T). - With a selector: the return value of the selector applied to the current state (
R).
StoreController.value, this property never throws — the state container is provided at construction time.Methods
Switch to a different
State<T> container at runtime. Tears down the previous subscription and sets up a new one immediately.Usage
Full state subscription
Selector-based subscription
Lifecycle
hostConnected()— subscribes to theStatecontainer.hostDisconnected()— unsubscribes and clears the cached value.
SnapshotController vs StoreController
SnapshotController | StoreController | |
|---|---|---|
| Input | State<T> container | Store instance or context |
| Subscribes | Always | Only with a selector |
| Resolves store | No | Yes (from context) |
| Use case | Custom controllers, raw state | Player UI elements |
SnapshotController is lower-level and works directly with State containers — the reactive primitives that back a store. Use it when building custom controllers or working outside the player store system. For player UI elements, use StoreController or PlayerController.
SnapshotController is the reactive primitive used internally by StoreController. When you pass a selector to StoreController, it creates a SnapshotController on store.$state under the hood.