Answer the question
In order to leave comments, you need to log in
Reflux: what are the action.completed and action.failed methods for?
Understanding Flux architecture using RefluxJS as an example .
The library mana describes two methods for asynchronous actions:
someAction.completed
someAction.failed
var asyncAction = Reflux.createAction({});
var someStore = Reflux.createStore({
data: [],
init: function () {
this.listenTo(asyncAction, this.onAsyncAction);
},
onAsyncAction: function () {
myAsyncWorker()
.success(this.storeNewData)
.error(this.asyncErrorHandler)
.complete(function () {
this.trigger({
data: this.data
});
});
},
storeNewData: function (data) {
//todo something with data and store it
},
asyncErrorHandler: function (error) {
//todo something with error
}
});
Answer the question
In order to leave comments, you need to log in
The main idea is to separate the receiving logic from the processing logic, that is, you can listen to success and failure events in other stores, for example, a store for the loader, which will control the display of the loading indicator, and another for, for example, generating user notifications about what happened. These are three independent places that react to the same events.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question