Modifying parent state from child view controller? #1384
-
Let's say I have the following SettingsFeature module that has a userSettings struct in it:
The SettingsViewController that houses SettingsFeature allows presenting DarkModeViewController, which houses DarkModeFeature module:
Scoping/pullback would work if SettingsFeature had DarkModeFeature in its state. However, I only want to pass a subset of SettingsFeature's state to DarkModeViewController so DarkModeFeature can modify the userInterfaceStyle. Is it possible for me to modify SettingsFeature.State's userSettings within DarkModeViewController? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
@acosmicflamingo If you're looking to isowords as an example here, we'd like to warn you that we'd probably do it differently the second time around. Having settings domain live and shared in state ended up being pretty cumbersome with a lot of boilerplate. We'd like to eventually refactor settings to be more of a dependency, like |
Beta Was this translation helpful? Give feedback.
-
Thank you everyone for the help; I would not have figured it out without all the comments! In case anyone wants to know how I approached it, here is some code: UserSettingsClient logic
UserDefaults logic:
DarkModeFeature:
Goes without saying that this is all pretty much either from Isowords, the ReducerProtocol discussion, the concurrency discussion, or the discussion above. My only contribution is coming up with the action names I suppose ;) |
Beta Was this translation helpful? Give feedback.
-
To add, here's accompanying tests that demonstrate how absolutely testable this all is:
TCA leaves no stone unturned! Absolutely amazing how robust this architecture is. |
Beta Was this translation helpful? Give feedback.
@acosmicflamingo If you're looking to isowords as an example here, we'd like to warn you that we'd probably do it differently the second time around. Having settings domain live and shared in state ended up being pretty cumbersome with a lot of boilerplate. We'd like to eventually refactor settings to be more of a dependency, like
UserDefaults
, that is accessed at nodes that need it to hydrate UI that needs to reflect it.