Created
October 1, 2018 14:22
-
-
Save talyssonoc/61535ffa31a959c6a0b92b16b1c6e5e8 to your computer and use it in GitHub Desktop.
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
export default ({ validateUser, userRepository }) => async (userData, { onSuccess, onError, onValidationError }) => { | |
if(!validateUser(userData)) { | |
return onValidationError(new Error('Invalid user')); | |
} | |
try { | |
const user = await userRepository.add(userData); | |
onSuccess(user); | |
} catch(error) { | |
onError(error); | |
} | |
}; |
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
const createUserAction = (userData) => (dispatch, getState, container) => { | |
container.createUser(userData, { | |
// notice that we don't add conditionals to emit any of these actions | |
onSuccess: (user) => dispatch(createUserSuccessAction(user)), | |
onError: (error) => dispatch(createUserErrorAction(error)), | |
onValidationError: (error) => dispatch(createUserValidationErrorAction(error)) | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment