# store The [`Store`](https://www.hyperfrontend.dev/docs/libraries/state-machine/store/#api-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`](https://www.hyperfrontend.dev/docs/libraries/state-machine/store/#api-Store) class without pulling in the rest of the library; it pairs with [`/state`](https://www.hyperfrontend.dev/docs/libraries/state-machine/state.md) (initial-state factory), [`/reducer`](https://www.hyperfrontend.dev/docs/libraries/state-machine/reducer.md) (the dispatch engine), and [`/selectors`](https://www.hyperfrontend.dev/docs/libraries/state-machine/selectors.md) (read-side predicates) to form the minimal store-only stack. ## API Reference ### Classes #### Store Redux-like store for managing state with dispatch and subscribe capabilities. ##### Constructor ```typescript new Store() ``` ##### dispatch ```typescript 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** | Name | Type | Description | | --- | --- | --- | | `action` | `Action` | The action to reduce, as produced by the action creators | ##### getState ```typescript 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 ##### subscribe ```typescript 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** | Name | Type | Description | | --- | --- | --- | | `listener` | `Listener` | Called 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** ```typescript const store = new Store() store.subscribe((state, action) => console.log('State:', state)) store.dispatch(start()) ``` ### Types #### Listener State change listener callback type. ```typescript type Listener = (state: State, action: Action) => void ``` --- Canonical page: https://www.hyperfrontend.dev/docs/libraries/state-machine/store/ This file: https://www.hyperfrontend.dev/docs/libraries/state-machine/store.md Documentation index: https://www.hyperfrontend.dev/llms.txt