Use data from multiple stores to compose a request to DataSource
- Dominant language
- JavaScript
- Stars
- 3.4k
- Forks
- 312
- PR merge metrics
- No merged PRs in 30d
Description
I'm trying to figure out the best way to use data from multiple Alt stores to compose a request to the backend.
Say, I have a `SheetDataStore`, `FiltersStore` and a `fetchFilteredData` method in my `DataSource` file. To get proper data from backend, i need to pass to `fetchFilteredData` both some sheet data and filters, but when you call the `fetchFilteredData` method from one of the stores, you can pass to the remote some arguments and the state of just that exact store.
So i see 2 ways of handling this case:
1) I make 2 actions: `prepareFilters` and `fetchData`. The `prepareFilters` is called from a component and gets handled by `FilterStore`, which prepares all required data and after that calls `fetchData` action, passing the prepared data as an argument. The `SheetDataStore` handles the `fetchData` action and calls the `fetchFilteredData` having all required data now.
What i don't like here is that it seems to me, Stores should not be calling actions, so that's kind of a hacky solution.
2) I import `FilterStore` to the `SheetDataStore` and use `FilterStore.getState()` inside of one of `SheetDataStore` methods to get all the data i need. That seems easy, but there might be some pitfalls of coupling the stores like that.
Are there any best practices for such a case? Maybe some of you faced similar issue and can recommend which of the paths to take from your experience? Or this all is a complete anti-pattern?
Here is a [link](http://stackoverflow.com/questions/36742565/react-alt-use-data-from-multiple-stores-to-make-a-request-to-datasource) to the copy of that question, i made at stackoverflow.
Contributor guide
Assessment
This issue has not been assessed yet.