@hyperfrontend/state-machine/storestore
The Store runtime: state container, dispatch entry point, and subscription registry.
The store owns the current state, applies actions through the root reducer, and notifies subscribers on every transition. Importing from this entry point gives consumers direct access to the Store class without pulling in the rest of the library; it pairs with /state (initial-state factory), /reducer (the dispatch engine), and /selectors (read-side predicates) to form the minimal store-only stack.
API Reference§
◇ Classes
Redux-like store for managing state with dispatch and subscribe capabilities.
Constructor
§
new Store( )Methods
Reduces an action into the state and notifies every subscriber.
Listeners run synchronously before this returns, each receiving a fresh copy of the new state together with the action that produced it, so none of them can mutate what the store holds. An action no handler recognises leaves the state as it was but still notifies the listeners.
Listeners run synchronously before this returns, each receiving a fresh copy of the new state together with the action that produced it, so none of them can mutate what the store holds. An action no handler recognises leaves the state as it was but still notifies the listeners.
Registers a listener for every dispatch that follows.
The registry is a set, so a listener added twice is held once. It is not called with the current state on registration; the first call comes with the next dispatch.
The registry is a set, so a listener added twice is held once. It is not called with the current state on registration; the first call comes with the next dispatch.
Returns
( ) => voidA function that removes the listener; calling it more than once is harmless
Example
Using the store
const store = new Store()
store.subscribe((state, action) => console.log('State:', state))
store.dispatch(start())◆ Types
State change listener callback type.