wandres.dev
Composable Architecture cheatsheet
⌘ REFERENCIA · 32 elementos

Cheatsheet de Composable Architecture

TCA en un sitio: State, Action, Reducer, Effect y Store; composición, dependencias, navegación y testing.

🍎 Las piezas 6

La macro que genera el andamiaje@Reducer struct Feature
El estado observado por SwiftUI@ObservableState struct State
Todo lo que puede ocurrirenum Action
La lógica compuestavar body: some ReducerOf<Self>
El reducer propioReduce { state, action in … }
El motor que une estado y reducerStoreOf<Feature>

⚡ Efectos 6

Sin efecto.none
Trabajo asíncrono.run { send in await … }
Enviar otra acción.send(.accion)
Combinar efectos.merge / .concatenate
Cancelar por identificador.cancellable(id:) / .cancel(id:)
Cancelar la ejecución anteriorcancelInFlight: true

💉 Dependencias 5

Reloj inyectado@Dependency(\.continuousClock) var clock
Identificadores controlados@Dependency(\.uuid) var uuid
Definir la tuyaDependencyKey { liveValue }
Macro del cliente de closures@DependencyClient
Sobrescribir en un ámbitowithDependencies { } operation:

🧩 Composición 5

Embeber un reducer hijoScope(state:action:) { Hija() }
Colección de features.forEach(\.items, action: \.items)
Feature opcional.ifLet(\.destino, action: \.destino)
Colección con identidadIdentifiedArrayOf<T>
Contrato del hijo hacia el padrecase delegate(Delegate)

🧭 Navegación y UI 5

Estado presentado@Presents var destino: Destino.State?
Conectar un sheet.sheet($store.scope(...))
Pila de navegaciónStackState / StackAction
Bindings en la vista@Bindable var store
Formularios sin una acción por campoBindingReducer()

🧪 Testing y estado 5

Store de test exhaustivoTestStore(initialState:) { Feature() }
Afirmar la mutaciónawait store.send(.accion) { $0.x = 1 }
Afirmar el efecto recibidoawait store.receive(\.respuesta)
Testing no exhaustivostore.exhaustivity = .off
Estado compartido y persistido@Shared(.appStorage("k"))