Created
January 26, 2015 21:29
-
-
Save jhollingworth/2b6fac1389e6ac939af7 to your computer and use it in GitHub Desktop.
Failing actions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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