Skip to content

Instantly share code, notes, and snippets.

@unel
Last active November 20, 2017 14:04
Show Gist options
  • Save unel/278739942a298d240d8522596dd231fb to your computer and use it in GitHub Desktop.
Save unel/278739942a298d240d8522596dd231fb to your computer and use it in GitHub Desktop.
export default function asyncReducer(state = isLoading, { type, payload }) {
switch (type) {
case AJAX_CALL_BEGIN:
if (payload === 'comments') {
return { ...state, comments: 1 };
}
return { ...state, product: 1 };
case AJAX_CALL_SUCCESS:
if (payload === 'comments') {
return { ...state, comments: 0 };
}
return { ...state, product: 0 };
case AJAX_CALL_ERROR:
if (payload.target === 'comments') {
return { ...state, comments: 0, error: payload.eror };
}
return { ...state, product: 0, error: payload.error };
default:
return state;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment