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

Store Dependencies #49

Closed
nickdima opened this issue Feb 26, 2015 · 2 comments
Closed

Store Dependencies #49

nickdima opened this issue Feb 26, 2015 · 2 comments

Comments

@nickdima
Copy link

I have a rather newbie question. I think it could be general to how Flux works but not specific to Flummox.

How could I handle the case when in order to call an action on a store i need a piece of data from another store? The problem arises when doing server side rendering. To be more precise: I have two nested route handlers, each one needs to get some data before rendering but the child handler data fetcher depends on whatever data is fetched by the parent handler.

@acdlite
Copy link
Owner

acdlite commented Feb 27, 2015

I assume you're using React Router? Have you checked out the async-data example? https://github.com/rackt/react-router/blob/master/examples/async-data/app.js

In that example, the static method fetchData() returns a promise for data to be added to the topmost handler as props. With Flux, I've been using a modified version of this, where you return a promise that resolves after any async actions have completed. That way you can do whatever async operations you need to do to prepare your stores. Here's a simple example: https://github.com/acdlite/flummox-isomorphic-demo/blob/master/src/shared/components/StargazerGridHandler.js#L14-L18

This pattern is pretty useful, so I wrote a helper: https://github.com/acdlite/flummox-isomorphic-demo/blob/master/src/shared/performRouteHandlerStaticMethod.js

For complex dependencies like the one you described, you just have to make sure you chain your async operations together using either then() or async-await.

Server-side data fetching is the least developed part of Flux in my opinion, which is why I'm so pumped for Relay.

@nickdima
Copy link
Author

Yeah that's the current setup I have also. React router + static route handler like in your example. The problem I had was making one route handler wait on another when you have sub-routes. Anyway I have an idea that I might try.

Yeah Relay looks awesome and makes more sense then Flux for fetching data that doesn't change much over time. I'm also excited about it but the problem will be implementing it with current "legacy" backends.

@acdlite acdlite closed this as completed Mar 6, 2015
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