Search code examples
javascriptreactjseventemitterfluxrefluxjs

Listen to Reflux actions outside of stores


I'm trying to figure out how to fit ajax calls into the flux/reflux way of doing things. From the scraps of info I've found online it seems correct to separate the API logic from the stores.

Starting there, I've created a client API that makes requests to the server. Now I want these functions them listen to my actions, then make a request, and upon success to trigger other actions that subsequently update the stores with the new data from the server.

How can go about having something similar to the reflux createStore method for my API? Or, is there some other clean way for my server calls to listen to actions?


Solution

  • The store is the glue between your actions and the API. Just like answered in https://stackoverflow.com/a/27487312/274483

    The difference in your case is that you don't perform the ajax request directly in the store, but go through your API-class, populate the store with the data returned from your API and trigger an update of the store.