PlayerController is a reactive controller that consumes the player store from the nearest provider element in the DOM tree. It is returned (pre-typed) from createPlayer.
- Without a selector — returns the store instance directly. Does not subscribe to state changes. Use this for dispatching actions.
- With a selector — returns the selected value and subscribes to changes, triggering a host update on shallow-equal change.
.value. Returns undefined until the host is connected to a provider.
Signature
Constructor
- Without selector
- With selector
Properties
The current selected state, or
undefined if the host is not yet connected to a provider.- Without a selector: the store instance itself.
- With a selector: the return value of the selector applied to the current state.
The
displayName of the selector function, if set. Useful for debugging.Usage
Accessing actions (without selector)
Without a selector,PlayerController returns the store directly and does not subscribe to updates. Use this pattern to invoke actions imperatively.
Subscribing to state (with selector)
With a selector,PlayerController subscribes to the player store and triggers a host update whenever the selected value changes.
Lifecycle
PlayerController hooks into the host’s reactive controller lifecycle:
hostConnected()— resolves the store from context and, if a selector was provided, creates an internalStoreControllerto subscribe to state changes.hostDisconnected()— tears down the internal store controller;.valuereturnsundefined.
PlayerController uses a ContextConsumer internally, so it automatically reconnects if the host is moved in the DOM and reattaches to a new provider.