-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add shared state sample #19
base: master
Are you sure you want to change the base?
Conversation
|
||
public init(context: Context<State, Event>) { | ||
self.context = context | ||
self.loginViewModel = LoginViewModel() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not happy about this 😞
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I don't really know who is responsible for instantiating view models, as it might need to receive some dependencies and would be nice to be able to mock them when testing.
public typealias State = UserAccountViewModel.State | ||
public typealias Event = UserAccountViewModel.Event | ||
|
||
private let context: Context<State, Event> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes a lot of sense that the Context
don't expose the ViewModel
directly, making it harder to try to work without sending an action to it.
self.loginViewModel = LoginViewModel() | ||
self.registrationViewModel = RegistrationViewModel() | ||
|
||
self.cancellable = Publishers.Merge(self.loginViewModel.state.filter { $0.dismissed }.map(\.loggedAccount), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be done before instantiating UserAccountView
? Connecting the view models before even the view is created?
do you think this is a useful sample to have? I can improve it if needed. |
Hey @dchohfi sorry noticed this PR just now :( In the latest release I've added Single store example inspired by Pointfree videos. https://www.pointfree.co |
I'm trying to figure out what is the best approach to share state between multiple Systems.
Also, I'm not that familiar with the Redux paradigm, so I might be missing something and would love to talk around it.
As we have generics constraints around
State
andEvent
for each view model, I haven't discovered a way to prevent from having a giganticState
for everything on the app with all theEvents
in one place, having a single reducer for multiple view models.Could we try to debate on what is the best alternative for handling this use case and add as a sample to the project?