Skip to content

Instantly share code, notes, and snippets.

@jhollingworth
Created January 26, 2015 21:29
Show Gist options
  • Save jhollingworth/2b6fac1389e6ac939af7 to your computer and use it in GitHub Desktop.
Save jhollingworth/2b6fac1389e6ac939af7 to your computer and use it in GitHub Desktop.
Failing actions
var UsersStore = Marty.createStore({
handlers: {
addUser: [UserConstants.ADD_USER, UserConstants.CREATE_USER]
},
addUser: function (user) {
this.state[user.id] = user;
this.hasChanged();
return function actionFailed(error) {
this.state.errors[user.id] = error;
delete this.state[user.id];
this.hasChanged();
}
}
});
var UserActionCreators = Marty.createActionCreators({
createUser: UserConstants.CREATE_USER(function (user) {
var action = this.dispatch(user);
//actionFailed will be called if
//you throw Error();
//or call action.rollback();
//or this promise is rejected
return UserAPI.createUser(user);
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment