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

Why is the counter state saved in the store, but not the weather forecasts? #94

Closed
MrYossu opened this issue Aug 27, 2020 · 4 comments
Closed

Comments

@MrYossu
Copy link

MrYossu commented Aug 27, 2020

Still following the Blazor web tutorials (done the second one now), and I've noticed that when you click away from the counter page and then click back, the counter state is preserved, so if I click the button to increase the counter a few times, go to another page and come back, the number is the same as it was before, not reset to zero.

However, if I do the same with the fetch data page, the weather forecasts are reloaded. I noticed this as I was looking at what the IsLoading property was doing, and added a delay when loading the weather data. This allowed me to see the "Loading..." message, but also clarified that the data was reloaded every time I went back to the page.

How do I make it so that the weather data is also saved in the store and not reloaded? Thanks

@mrpmorris
Copy link
Owner

There is a reducer that sets forecasts to null, change it to state.Forecasts if you want to keep the forecasts from the previous state.

@MrYossu
Copy link
Author

MrYossu commented Aug 30, 2020

@mrpmorris Hello again and thanks for the reply.

Unfortunately, that didn't work. When I clicked to another page and clicked back, it reloaded the forecasts.

Any idea? Thanks

@mrpmorris
Copy link
Owner

That's because the page dispatches an action to go and fetch the data. You'd have to change the page to only ask if it needs it.

@MrYossu
Copy link
Author

MrYossu commented Aug 31, 2020

@mrpmorris Thanks, obvious when you point it out!

I think I was assuming there was something in the flux pipeline that would take care of this, as opposed to having logic in the razor view (which this pattern seems to minimise).

Thanks again

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