PrismStore is the central piece of PrismArchitecture. It owns your application state, processes actions through a reducer, executes asynchronous effects, and supports scoping to derive child stores for sub-features.
Minimal Counter
import PrismArchitecturestruct CounterState: Sendable, Equatable { var count = 0}enum CounterAction: Sendable { case increment case decrement}let store = PrismStore( initialState: CounterState(), reduce: { state, action in switch action { case .increment: state.count += 1 case .decrement: state.count -= 1 } return .none })store.send(.increment)// store.state.count == 1
Derive child stores that focus on a subset of state and actions. The child stays synchronized with the parent — actions sent to the child are transformed and forwarded upstream.
Scoping a Store
struct AppState: Sendable, Equatable { var counter = CounterState() var settings = SettingsState()}enum AppAction: Sendable { case counter(CounterAction) case settings(SettingsAction)}let counterStore = store.scope( state: \.counter, action: AppAction.counter)// Or with just a state key path (same action type)let simpleScope = store.scope(state: \.counter)
Scoped stores are lightweight. They don’t duplicate state — they project a view of the parent’s state and forward actions back. Use them freely to isolate sub-features.