@hyperfrontend/state-machine/store

store

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

§class

Store

Redux-like store for managing state with dispatch and subscribe capabilities.
Constructor
§new Store()
Methods
§readonly dispatch(action: Action): void
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.

Parameters

NameTypeDescription
§action
ActionThe action to reduce, as produced by the action creators
§readonly getState(): State
Reads the current state.

Returns

State
A shallow copy of the state, so a caller can inspect it without reaching into the store
§readonly subscribe(listener: Listener): () => void
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.

Parameters

NameTypeDescription
§listener
ListenerCalled with the new state and the action after each dispatch

Returns

() => void
A 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

§type

Listener

State change listener callback type.
type Listener = (state: State, action: Action) => void