0

I'm learning React and flux.

Say there's a route like

// Route
/continent/:continentId/countries
// Example
/continent/europe/countries

There are two stores, a ContinentsStore and a CountriesStore

What's the best design pattern, in Flux, so that when the route is loaded, the ContinentsStore asynchronously fetches a list of all the continents, sets the current one to Europe, and then CountriesStore looks for the current continent in ContinentsStore, then proceeds to download a list of all the countries in that Continent.

Specifically, where are the action creators, and what might the actions types be?

Thanks.

Qiming
  • 1,664
  • 1
  • 14
  • 18

1 Answers1

1

There is an aggregation store concept in reflux.js. So one store can listen to another one and provides additional logic that depends on data changes in an observable store. This approach is useful for data aggregation and chaining operations.

shadeglare
  • 7,006
  • 7
  • 47
  • 59
  • This is interesting, do you have any resources that you like that you can link me towards? Also, in this paradigm, can one store asynchronously wait for another one? I'm familiar with the regular dispatcher.waitFor([storeTokens...]) – Qiming May 07 '15 at 21:43
  • Conceptually it's quite simple. You could aggregate stores like: var Store1 = Reflux.createStore({}); var Store2 = Reflux.createStore({}); Reflux.all(Store1, Store2).listen(function() { console.log(arguments); }); Store1.trigger("store1"); Store2.trigger("store2"); – shadeglare May 09 '15 at 13:14