My current reactjs/flux implementation is to have components call actions, and actions call the web api which then funnels back to the store.
I have a set of checkboxes where the state of the checkboxes are managed in a store, but every time I update the checkboxes, I would like to make a query to the server with the state of the store. What I am forced to do now is call an action to update checkboxes store when the checkboxes are clicked, in the checkboxes store, set a variable to "queryServer", then in the checkboxes component, check the "queryServer" and make another action to query the server.
It seems simpler if both components and stores can make action calls, that way, when I update the checkboxes store, I can initiate the action to query the server directly without setting a silly "queryServer" variable and having the component check that.
Though it does seem to make things simpler, it seems to go agains the essence of the flux architecture where all actions are initiated from the view.
My approach would be to fetch the state of the store into the view and pass it to an action from there. This would allow your store to stay as dumb as possible, simply receiving data as it comes into the application.
In more specific terms, your store would have a getData
function that returns the raw data stored. In your component the click handler for your checkboxes would include code looking something like this:
var data = MyStore.getData();
MyActions.queryServer(data);
Your action would then make the API call (since it's probably the safest place to do anything asynchronous) and pass the new data to your store via the dispatcher.