| name | composable-architecture |
| description | Use when building features with TCA (The Composable Architecture), structuring reducers, managing state, handling effects, navigation, or testing TCA features. Covers @Reducer, Store, Effect, TestStore, reducer composition, and TCA patterns. |
The Composable Architecture (TCA)
TCA provides architecture for building complex, testable features through composable reducers, centralized state management, and side effect handling. The core principle: predictable state evolution with clear dependencies and testable effects.
Overview
- Reducer Structure - Templates, @Reducer, State, Actions, @ViewAction, conformances
- Views - StoreOf, @Bindable, ForEach, store.scope, view actions
- Navigation - NavigationStack, StackState, path reducers, dismiss
- Shared State - @Shared, .appStorage, .withLock, FileStorageKey, InMemoryKey
- Dependencies - @DependencyClient, @Dependency, DependencyKey, streaming
- Effects - .run, .send, .merge, catch:, timers, cancellation
- Presentation - @Presents, Scope, AlertState, multiple destinations
- Testing - TestStore, TestClock, exhaustivity, dependency mocking
- Performance - Optimization, high-frequency updates, memory
Common Mistakes
Over-modularizing features — Breaking features into too many small reducers makes state management harder and adds composition overhead. Keep related state and actions together unless there's genuine reuse.
Mismanaging effect lifetimes — Forgetting to cancel effects when state changes leads to stale data, duplicate requests, or race conditions. Use
.concatenatefor sequential effects and.cancelwhen appropriate.Navigation state in wrong places — Putting navigation state in child reducers instead of parent causes unnecessary view reloads and state inconsistencies. Navigation state belongs in the feature that owns the navigation structure.
Testing without TestStore exhaustivity — Skipping TestStore assertions for "simple" effects or "obvious" state changes means you miss bugs. Use exhaustivity checking religiously; it catches regressions early.
Mixing async/await with Effects incorrectly — Converting async/await to
.runeffects without proper cancellation or error handling loses isolation guarantees. Wrap async operations carefully in.runwithyieldstatements.