Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Add shared state sample #19

wants to merge 2 commits into from

Conversation

dchohfi
Copy link

@dchohfi dchohfi commented Nov 5, 2019

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 and Event for each view model, I haven't discovered a way to prevent from having a gigantic State for everything on the app with all the Events 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?


public init(context: Context<State, Event>) {
self.context = context
self.loginViewModel = LoginViewModel()
Copy link
Author

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 😞

Copy link
Author

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>
Copy link
Author

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),
Copy link
Author

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?

@dchohfi dchohfi changed the title Add sharing state sample Add shared state sample Nov 5, 2019
@dchohfi
Copy link
Author

dchohfi commented Nov 13, 2019

do you think this is a useful sample to have? I can improve it if needed.

@sergdort
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants