Skip to content

Instantly share code, notes, and snippets.

@asherccohen
Created July 26, 2019 11:19
Show Gist options
  • Save asherccohen/c0a360fc87e9688c21a4f080c62e04b7 to your computer and use it in GitHub Desktop.
Save asherccohen/c0a360fc87e9688c21a4f080c62e04b7 to your computer and use it in GitHub Desktop.
ErrorsSelector
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