Reflux: why we need methods of action.completed and action.failed?

Deal with Flux architecture example RefluxJS.
In Manet the library describes two methods for asynchronous actions:
someAction.completed
someAction.failed

If I understand correctly, they are called (or should be called) in case of success and failure of an asynchronous task.
They need to hang the methods of storage to handle the results or they are needed to intercept logging failures?
Treatment outcome and failure can be done directly in the storage:
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
}
});

And this is without additional method steps (completed, failed).
What is the idea and the subtlety of the creation and use of an additional method to the action (completed, failed)?
September 19th 19 at 00:20
1 answer
September 19th 19 at 00:22
Solution
The main idea is to separate acquisition logic from processing logic, that is to listen to events of success and failure in other stores, for example store the boot loader, which will control the display of the download progress bar, and another to e.g. generate notifications to the user of the incident. It's three separate places that respond to the same event.
if I understand correctly, it will look something like this:
var someAsyncAction = Reflux.createAction({
 children: ['completed', 'failed']
});

var someStore = Reflux.createStore({
 data: [],
 init: function () {
 this.listenTo(someAsyncAction, this.onAsyncAction);
 this.listenTo(someAsyncAction.completed this.onAsyncCompleted);
},
 onAsyncAction: function (url) {
$.ajax({
 url: url,
 type: 'get',
 success: function (data) {
someAsyncAction.completed(data);
},
 error: function (jqXHR, textStatus, errorThrown) {
someAsyncAction.failed(errorThrown);
}
})
},
 onAsyncCompleted: function (data) {
 //to do something with the data and store is
this.trigger({
 data: this.data
});
console.log('someStore.onAsyncCompleted');
}
});

var progressStore = Reflux.createStore({
 init: function () {
 this.listenTo(someAsyncAction.completed this.onAsyncComplete);
 this.listenTo(someAsyncAction.failed, this.onAsyncFailed);
},
 onAsyncComplete: function (data) {
console.log('progressStore.onAsyncCompleted');
},
 onAsyncFailed: function (error) {
console.log('progressStore.onAsyncFailed');
}
});

someAsyncAction('/');
someAsyncAction('/sadasd');
- arlene_Lebsa commented on September 19th 19 at 00:25
: Yes, as it turns out - Susana.Ullrich commented on September 19th 19 at 00:28
: Thank you ) You helped me - arlene_Lebsa commented on September 19th 19 at 00:31

Find more questions by tags FluxReact