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

Single model over multiple pages #5

Closed
Ayush789 opened this issue May 22, 2019 · 4 comments
Closed

Single model over multiple pages #5

Ayush789 opened this issue May 22, 2019 · 4 comments

Comments

@Ayush789
Copy link

How to use the same model in multiple pages

I am making a cryptocurrency app and following your provider guide 010 using get it
For the main page, I made a HomeModel class with a list of Coin instances and used it in dashboard page by using BaseView<HomeModel>.
Now, for adding another item to list in HomeModel I move on to another page add_coin where also I use BaseView<HomeModel>.
But here if I register it using locator.registerLazySingleton(()=>HomeModel()); it gives error HomeModel was used after being disposed.
And if I register it using factory it does not change the value in initial page

You can see the code here:
https://github.com/Ayush789/crypto_provider

@FilledStacks
Copy link
Owner

Don't use the same model for two views, you're not using the architecture correctly then. Each view has it's own model. Use a service to share your information.

Create an information service that's a singleton and keep your list of coins in there. In the AddCoin page call your function addCoin on your information service from the model. In your HomeModel get the coins from the information service. The service manages all your shared information the models should just use services to produce state.

@Ayush789
Copy link
Author

Thank you.
Is there a general base info service that I can rely on. I am trying to use this system as a base for my upcoming projects.

@Ayush789
Copy link
Author

Made an AllCoins repository class with all the global required things and put it under core > shared.
Registered it with the locator and used it in whatever page it was needed by calling through the locator.
It's working correctly.

Is that the correct approach?

@FilledStacks
Copy link
Owner

No there's no base info service. A service is just a plain class that performs logic. There's nothing to share between the services.

Yes, That's the approach you'd want to use. Models talk to service/repo and that's it. Any data shown is requested from the service/repo and displayed in the UI.

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

No branches or pull requests

2 participants