It is suggested that stores must handle events triggered by actions and emit a change in view controllers.
Is it good for them to run actions, for example, in a request callback or directly in a registered store callback.
For instance:
AppDispatcher.register(function(payload) { switch(payload.action.actionType) { case Constants.PAGE_CHANGED: ActionCreator.fetchNewData(); break; case Constants.FETCH_DATA:
Is such code “correct” in the Flux architecture?
Thanks!
====== UPDATE BASED ON COMMENT:
This is not a question, “I need to do this. How do I do this?”, But “If it will be a way to do something.” And I think the answer ... is your choice.
Some useful links have been added in the comments. Thank you for that.
My understanding of things is this:
In the Flux architecture, views should be the only ones that trigger actions. Put asynchronous requests in your action creator, and the callback should start a new action.
When Flux steps are not performed, the store can also handle asynchronous requests, but make sure that the callback does not process the data directly, but instead triggers another action. See Bill Fisher's Answer for this.
In any case, as Ben Alpert said, you can create several actions for the user action (for example: REQUEST_START, REQUEST_SUCCESS, REQUEST_ERROR), which allows you to connect to the various stages of your request.
Any updates on this are welcome.