TCA Extensions: Typealias
Simplify TCA code with typealiases for presentation and binding actions.
1
2
public typealias PresentationActionOf<R: Reducer> = PresentationAction<R.Action>
public typealias BindingActionOf<R: Reducer> = BindingAction<R.State>
These typealiases are designed to simplify and clarify your code when working with The Composable Architecture (TCA). They help reduce verbosity and make your intent clearer, especially when dealing with presentation and binding actions.
BindingActionOf: Simplifying Binding Actions
BindingActionOf
is a typealias for BindingAction<R.State>
that simplifies the syntax for creating binding actions.
Before:
1
2
3
public enum Action: BindableAction {
case binding(BindingAction<CategoriesFeature.State>)
}
After:
1
2
3
public enum Action: BindableAction {
case binding(BindingActionOf<CategoriesFeature>)
}
PresentationActionOf: Simplifying Presentation Actions
PresentationActionOf
is a typealias for PresentationAction<R.Action>
that simplifies the syntax for creating presentation actions.
Before:
1
2
3
public enum Action {
case destination(PresentationAction<Destination.Action>)
}
After:
1
2
3
public enum Action {
case destination(PresentationActionOf<Destination>)
}
Why These Typealiases Are Helpful
When working with The Composable Architecture (TCA), you often reference a feature’s State
and Action
multiple times. TCA already provides conveniences like ReducerOf<Self>
to reduce verbosity and keep code expressive. These two additions similarly save keystrokes and clarify intent, especially when dealing with presentation or binding.
By incorporating these typealiases, your TCA code becomes more readable and maintainable, reducing boilerplate while preserving clarity. 🚀