Replies: 1 comment 1 reply
-
@sergdort We specifically push folks towards struct Parent: ReducerProtocol {
// ...
Reduce { state, action in
switch action {
case .child(.dismiss):
state.child = nil
// ...
}
}
OptionalScope(state: \.child, action: /Action.child) {
Child()
}
}
struct Child: ReducerProtocol {
// ...
func reduce(into state: inout State, action: Action) -> EffectTask<Action> {
switch action {
case .dismiss:
// 😢 Analytics event is never tracked!
return self.analytics.track(.dimissed)
// ...
}
}
}
That said, we do provide a single escape hatch out there for scoping to a specific case as a This helper technically lets you achieve more or less the same as your helper above: Scope(state: /.some, action: /Child.action) {
Child()
} However we do not recommend using such a helper outside the mutually exclusive usage I mention earlier, since it makes it easier to re-introduce the bugs our other helpers were designed to avoid. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I'm converting some of our reducers to use
ReducerProtocol
and I really loveScope
reducer for child states.I'm wondering if there is a plan to have (or there is already way of doing it) something similar for optional child states?
Because I'd prefer something similar to
Scope
rather than combination ofReduce {}.ifLet()
. In fact I've implemented it in our codebase like thisBeta Was this translation helpful? Give feedback.
All reactions