@hyperfrontend/state-machine/reducer

reducer

The root reducer that dispatches actions to per-process state handlers and returns the next state.

rootReducer(state, action) is the pure function the Store runs on every dispatch. It owns no state itself; it routes actions to the per-process handlers that compute the next process state, then folds the results back into the workspace-level state. The reducer is intentionally thin — most of the real logic lives in the action handlers and the selectors that downstream code uses to read state out.

API Reference

ƒ Functions

§function

rootReducer(state: State, action: Action): State

Root reducer that handles state transitions based on action types.

Parameters

NameTypeDescription
§state
State
Current state or undefined for initial state
(default: ...)
§action
Action
Action to process

Returns

State
Updated state after applying the action

Example

Processing an action

const state = rootReducer(undefined, start())
// => { inProgress: true, success: false, fail: false, halt: false }