Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Reflux-Action-Hooks
// this creates 'load', 'load.completed' and 'load.failed'
var Actions = Reflux.createActions({
"load": {children: ["completed","failed"]},
});
// called before the 'load' action emits an event
Actions.load.preEmit = function() {
console.log(arguments);
};
// called after preEmit
Actions.load.shouldEmit = function(isFail) {
console.log('isFail:' + isFail);
return !isFail;
}
// when 'load' is triggered, call async operation and trigger related actions
Actions.load.listen(function(isFail) {
// By default, the listener is bound to the action
// so we can access child actions using 'this'
dummyPromiseCall(isFail)
.then(this.completed)
.catch(this.failed);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment