D
D
Dmitry Vapelnik2015-03-02 11:27:25
React
Dmitry Vapelnik, 2015-03-02 11:27:25

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

If I understand correctly, they are called (or should be called) in case of success and failure of the asynchronous task.
Do you need to attach storage methods to them to process the results, or are they needed to intercept the logging of failures?
Processing of the result and failure can be done directly in the store:
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 action methods (completed, failed).
What is the idea and subtlety of creating and using additional action methods (completed, failed)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Antropov, 2015-03-02
@dvapelnik

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 question

Ask a Question

731 491 924 answers to any question