-
Hey everyone, I have a pretty big reducer and it seems that if I chain a lot of I was able to circumvent the issue by chaining reducers to an My original Reducer was:
Reduce(_reduce(into:action:))
.ifLet(
\.onboardingState,
action: /Action.onboarding,
then: Onboarding.init
)
.ifLet(
\.quoteOfTheDayState,
action: /Action.quoteOfTheDay,
then: QuoteOfTheDay.init
)
.ifLet(
\.nutritionState,
action: /Action.nutrition,
then: Nutrition.init
)
.ifLet(
\.mentalHealthState,
action: /Action.mentalHealth,
then: MentalHealth.init
)
.ifLet(
\.surveyState,
action: /Action.survey,
then: Survey.init
)
.ifLet(
\.communityNavState,
action: /Action.communityNav,
then: CommunityNav.init
)
} The "fixed" reducer is this: Reduce(_reduce(into:action:))
.ifLet(
\.onboardingState,
action: /Action.onboarding,
then: Onboarding.init
)
.ifLet(
\.quoteOfTheDayState,
action: /Action.quoteOfTheDay,
then: QuoteOfTheDay.init
)
.ifLet(
\.nutritionState,
action: /Action.nutrition,
then: Nutrition.init
)
.ifLet(
\.mentalHealthState,
action: /Action.mentalHealth,
then: MentalHealth.init
)
EmptyReducer()
.ifLet(
\.surveyState,
action: /Action.survey,
then: Survey.init
)
.ifLet(
\.communityNavState,
action: /Action.communityNav,
then: CommunityNav.init
)
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
Hi @gkaimakas, I'm not aware of any real limitation, but also it does not seem optimal to hold 6 optionals in state. That consists of 2^6 = 64 different states of being It seems more likely that only one of those values can be non- |
Beta Was this translation helpful? Give feedback.
-
If multiple of these need to be non-nil at the same time, it is possible to still use enum state, as @mbrandonw suggested, but contain them in a StackState as if you are using them in a SwiftUI NavigationStack (even if you aren't). |
Beta Was this translation helpful? Give feedback.
Hi @gkaimakas, I'm not aware of any real limitation, but also it does not seem optimal to hold 6 optionals in state. That consists of 2^6 = 64 different states of being
nil
or non-nil
. Are all of those states valid?It seems more likely that only one of those values can be non-
nil
at a time, in which case an enum is better suited. You may be interested in our article on Tree-based navigation.