Created
July 26, 2019 11:19
-
-
Save asherccohen/c0a360fc87e9688c21a4f080c62e04b7 to your computer and use it in GitHub Desktop.
ErrorsSelector
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 const errorByActionSelector = (state = {}, action = '') => { | |
if (state.errors[action] && state.errors[action].message) { | |
return { [action]: state.errors[action] }; | |
} | |
return undefined; | |
}; | |
export const errorsSelector = (state = {}, actions = []) => { | |
const errors = actions.reduce((accumulator, action) => { | |
if (errorByActionSelector(state, action)) { | |
return { | |
…accumulator, | |
…errorByActionSelector(state, action), | |
}; | |
} | |
return accumulator; | |
}, {}); | |
if (Object.keys(errors).length) { | |
return errors; | |
} | |
return undefined; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment