Handle complex logic cases may create huge code inside Reducer. Ideas in how to handle that? #1421
Replies: 1 comment 5 replies
-
Hey @joelCHonor! Extracting cases as functions is indeed a good idea, but I have trouble understanding this. Are you defining functions of func onValueChange(value: Value, state: inout State) -> Effect<Action, Never> { … } If you call functions like that from your reducer, they will update the state transparently: case let valueDidChange(value):
return onValueChange(value, state: &state) If you have many actions, it is also maybe a sign that you can decompose your domain into smaller sub-domains (with their own smaller reducers). |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
I have a very complex SwiftUI screen (It has a lot of different states and interactions in how to present the controls).
Each state change handling in the reducer will have complex logic. As the reducer became huge, I just moved code to separated functions to handle each state. The only downside is as I need to change properties for the State, each function I created will prepare and update models and returning that into the Reducer to update the State.
Is there a better way to handle this case of cases where the screen is so complex, that each state handling has lot of code?
Beta Was this translation helpful? Give feedback.
All reactions