Created
February 8, 2019 10:36
-
-
Save vvscode/7925f8974782385c0ff1ec3cb51e3143 to your computer and use it in GitHub Desktop.
handle-api-call-state-nicely
This file contains 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 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