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

Question about a page's state #135

Open
wemped opened this issue Jun 6, 2019 · 1 comment
Open

Question about a page's state #135

wemped opened this issue Jun 6, 2019 · 1 comment

Comments

@wemped
Copy link

wemped commented Jun 6, 2019

Maybe this is more of a question about Redux in the context of flutter -- if you have an idea of a better place to ask this question let me know! Also happy to provide more detail if part of this doesn't make sense.

I understand that Redux can be very helpful when trying to handle changes and complex logic for the global app state, but how would you use it for complex state within a single page?

For example: You have a master/detail application. Master is a list of items, w/ very little info about each item. When you click on an item, it takes you to the detail page. The detail page contains info from a few different network endpoints -- maybe even some of these endpoints depending on results from each other.

I'd love to be able to use Actions/Reducers/View Models to handle the complex logic and dependencies between each network call, loading states, etc. But the underlying data isn't really global app state. In fact, I'd like that data to be disposed if I was to navigate back to the master page. So where should this detail logic live?

One idea would be to put it in the global store something like this

class AppState {
	final List<Item> items; //shown in the master view
	final ItemDetail itemDetail; //shown in the detail view
}

And nesting the reducers and so on

But then the data isn't disposed of automatically when the view is disposed.

Another problem is that, what if a detail could have a "link" to another item, so within a detail page we could open another detail page of a different item. This implementation would override the global app state's itemDetail.

So I guess my question is, how can I harness Redux's organization of logic within a single page in the context of a navigation stack like flutter's?

@miquelbeltran
Copy link
Contributor

Hi. I use a very similar solution for a project and see nothing wrong with your proposal.

For example, in my case, I have a list of messages on the AppState which are the messages for the channel I am currently displaying. When the user opens a different channel, that list is changed by this new channel messages. This is the same idea as having an ItemDetail specified in the AppState.

However, we do have a data repository accessible through the Middleware that does the networking and caching of data, so loading the messages is a quick operation.

But at the end it is up to you to decide what to have in the AppState. Some devs like to have the UI state on it, some devs prefer to hold the whole app data model there. This is an interesting read about it: https://redux.js.org/faq/organizing-state

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