PrismStore
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
Creating a Store
There are three ways to create a store:Closure-based
Pass a closure that mutates state and returns an effect:Closure Init
Typed Reducer
Pass a type conforming toPrismReducer:
Typed Reducer Init
With Middleware
Attach middleware for cross-cutting concerns like logging:Store with Middleware
Sending Actions
Dispatch actions synchronously withsend(_:) or asynchronously with dispatch(action:):
Dispatching Actions
Observing State in SwiftUI
PrismStore is @Observable, so SwiftUI views re-render automatically when state changes:
SwiftUI View
Scoping
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
Cancelling Effects
Cancel all in-flight asynchronous effects:Cancel Effects
Full Example
A realistic todo list feature with async persistence:Todo Feature
Next Steps
Reducers
Pure business logic functions that transform state.
Middleware
Cross-cutting concerns like logging, analytics, persistence.
Router
Type-safe navigation driven by state.
UI Components
Build views with PrismUI components that bind to stores.