Skip to main content

Advanced Features

PrismArchitecture ships with several advanced tools for debugging, persistence, and testing.

State Persistence

Persist state across app launches using PrismPersistenceStrategy. Three built-in strategies are provided:

Disk Persistence

Saves state as JSON files to the Documents directory:
Disk Persistence
You can specify a custom directory:

UserDefaults Persistence

Stores state in UserDefaults for lightweight data:
UserDefaults Persistence

Keychain Persistence

Stores sensitive state in the system Keychain:
Keychain Persistence

Custom Strategy

Implement PrismPersistenceStrategy for any backend:
Custom Persistence

Time-Travel Debugger

PrismTimeTravelDebugger records state snapshots at every action, letting you navigate through your app’s history:
Time Travel Setup

Inspecting Snapshots

Each snapshot captures the state, action description, timestamp, and position:
Snapshot Inspection
Set maxSnapshots to limit memory usage. Old snapshots are evicted when the limit is exceeded.

Undo / Redo

PrismUndoRedoStack provides a classic undo/redo mechanism:
Undo / Redo
The redo stack is automatically cleared when a new state is pushed, matching standard undo/redo behavior.

Derived Store

PrismDerivedStore provides a read-only view into a parent store that only notifies when the derived value actually changes:
Derived Store
PrismDerivedStore uses Equatable on the local state to avoid unnecessary SwiftUI re-renders.

Testing with PrismTestStore

PrismTestStore wraps PrismStore with testing utilities for deterministic assertions:
PrismTestStore

Testing Async Effects

Use waitForEffects() to wait for in-flight effects to complete before asserting:
Testing Effects

Testing with Middleware

Testing Middleware

Summary