Skip to content

Instantly share code, notes, and snippets.

@mvbattan
Last active December 11, 2017 17:49
Show Gist options
  • Save mvbattan/3ef1dedf1fd256b24e8ccb4cb30c4b7c to your computer and use it in GitHub Desktop.
Save mvbattan/3ef1dedf1fd256b24e8ccb4cb30c4b7c to your computer and use it in GitHub Desktop.
Effects
export function onLoading(selector = (action, state) => true) {
return (state, action) => ({ ...state, [`${action.target}Loading`]: selector(action, state) });
}
export function onSuccess(selector = (action, state) => action.payload) {
return (state, action) => ({
...state,
[`${action.target}Loading`]: false,
[action.target]: selector(action, state),
[`${action.target}Error`]: null
});
}
export function onFailure(selector = (action, state) => action.payload) {
return (state, action) => ({
...state,
[`${action.target}Loading`]: false,
[`${action.target}Error`]: selector(action, state)
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment