Replies: 1 comment
-
Hey @jtflaten! Both approaches are mostly equivalent, and if there are performance differences, they will probably not be noticeable. extension Domain.State {
mutating func handleSharedThing(parameter: Int) {
if parameter.isMultiple(of: 3) {
self.value = 0
}
}
}
…
func reduce(into state: inout State, action: Action) -> EffectTask<Action> {
switch action {
case .doSomething(let amount):
state.handleSharedThing(parameter: amount)
return .none
}
} It really depends if the shared work is more |
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.
-
I'd like to share logic for updating the state in a reducer and as far as I can tell both of these compile and work:
A function inside the the reducer itself:
Compared to a method outside this reducer that we pass the
State
into as an inout param:I'm wondering if there is any known pros/cons that would help me choose one or the other? Alternatively is there a reason I should avoid doing both of these and find another way to share the logic?
Beta Was this translation helpful? Give feedback.
All reactions