Fluxapp uses namespaced actions, and handles both async and sync responses using bluebirds Promise API.

Action Lifecycle

When an action is invoked if successful it invokes the handler, emits a before event, the actual event response and finally the after event.

In the event an event fails, throws or promise is rejected, the lifecycle changes to before and failed.

Given this examlple action

fluxapp.registerActions('user', {
  login: function() {
    return {
      id: 1
    };
  },
  
  logout: function() {
    throw new Error('No logging out allowed');
  }
});
React.createClass({
  mixins: [fluxapp.mixins.component],
  
  flux: {
    actions: {
      onUserLogoutFailed: 'user.logout:failed'
    }        
  },
  
  handleLogin: function() {
    var userAction = this.getActions('user');
    
    userActions.login();
  },
  
  handleLogout: function() {
    var userAction = this.getActions('user');
    
    userActions.logout();
  }
});

userActions.login Lifecycle

📘

Stores receive second parameter

When stores bind to the action they also provide a secondary parameter that contains the converted action type that allows them to process multiple similar actions.

Action Type (string)Action Type (converted)Listener parameters
user.login:beforeUSER_LOGIN_BEFORE
user.loginUSER_LOGIN1. Action resolved result
user.login:afterUSER_LOGIN_AFTER

userActions.logout Lifecycle

Action Type (string)Action Type (converted)Listener parameters
user.logout:beforeUSER_LOGOUT_BEFORE
user.logout:failedUSER_LOGOUT_FAILED1. Reason for the failure

📘

On to Action Types