Skip to content

Instantly share code, notes, and snippets.

@vvscode
Created February 8, 2019 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vvscode/7925f8974782385c0ff1ec3cb51e3143 to your computer and use it in GitHub Desktop.
Save vvscode/7925f8974782385c0ff1ec3cb51e3143 to your computer and use it in GitHub Desktop.
handle-api-call-state-nicely
export function newsReducer(state: News = createDefaultNews(), action: NewsActions): News {
switch (action.type) {
case NewsActionsTypes.Load:
return onLoadableLoad(state);
case NewsActionsTypes.LoadSuccess:
return {
...onLoadableSuccess(state),
entities: action.payload.entities
};
case NewsActionsTypes.LoadError:
return onLoadableError(state, action.error);
default:
return state;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment