-
Notifications
You must be signed in to change notification settings - Fork 164
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
Best practices for nested models #139
Comments
Hi again. :) This is going to be another opinionated answer, as flux really only talks about data flow, and not really the shape or access of that data. If there's no way in your API to grab the full contents of all the comments for a product, then at some point you'll end up needing to load each one individually. When you choose to perform that operation depends a lot on how you want your app to behave. I'd say in that case it likely makes sense to do it when the comment is actually shown, though I prefer this pattern for loading data than having actions that "load" things. My general recommendation, though, is to find a way to fetch the comments in aggregate (or even embed them in the product JSON response), and use a separate comment store to manage the global app state associated with them. If the comments don't do very much/you can't interact with them, you can probably get away with just keeping them as nested data in the product store, but if you want to e.g. edit, delete, and add comments, you'll probably want a comment store. |
Hello, me again.
I'm wondering which are the best practices when there are nested models, for example.
I've an action like this
the dispatched products is a list of product
Now, I've to fetch for each product the comments.
How? I think that this is really atrocious:
So how can I handle nested models with flux ?
I need to define a CommentStore ? Than I trigger the loadComment event fomr the ProductStore and waitFor it before dispatch the
LOAD_PRODUCT_SUCCESS
?The text was updated successfully, but these errors were encountered: