Reducers Action Handling Response Pattern #2495
Replies: 2 comments 4 replies
-
I have seen people propose nesting enums, I might have seen in one of the example apps enum Action {
case view(View)
case _internal(Internal)
enum View {
case userTappedLogin
case userTappedLogout
case userTappedButton
case showPromoAlert
}
enum Internal {
case userTappedLoginResponse
case userTappedLogoutResponse
case userTappedButtonResponse
}
} so in your view you will only invoke viewStore.send(.view(.userTappedLogin)) |
Beta Was this translation helpful? Give feedback.
-
Just noting that this doesn't bother me in practice, and almost[1] every time I've added such layers it seems unnecessary. I only separate "delegate" actions to clarify the parent integration points. Everything else is internal. A parent observing those internal (non-delegate) actions is both a super power and a code smell that a new delegate action may be appropriate. If the above example were sufficiently complex, I'd say that login, logout and promo might be separate features, for example: enum Action {
case login(LoginFeature.Action)
case logout(LogoutFeature.Action)
caes promo(PromoFeature.Action)
case userTappedButton
}
enum LoginFeature.Action { // LoginFeature is a Reducer
case delegate(Delegate)
case loginButtonTapped
case loginResponse(TaskResult<LoginResponse>)
enum Delegate {
case didLoginSuccessfully
}
} [1] Sometimes a single domain can get really complex, I find most often when integrating with UIKit. In those cases I've carved up the actions with |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I've been running into this pain point with TCA for a while now and I'm curious to get people's thoughts. The problem is with reducer actions. Take the code from the README:
There are five actions here but really, there are four actions and a response. That right there is the problem; that this mechanism of responding to actions inside a reducer by doing something like
is an anti-pattern because it's
When apps get really large, you end up with actions that look like this:
I may be alone in this, I just don't love that what should be an implementation detail, is exposed right alongside all the ways my application can be mutated.
Beta Was this translation helpful? Give feedback.
All reactions