Last active
April 21, 2018 10:59
-
-
Save dewey92/03e399df15f58d15354153bbd5693ed1 to your computer and use it in GitHub Desktop.
User with Post reducer
This file contains hidden or 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 default (state = initialState, action) => { | |
| switch (action.type) { | |
| case 'GET_USER_REQUEST': | |
| return { | |
| ...state, | |
| user: { | |
| ...state.user, | |
| asyncState: AsyncState.loading | |
| } | |
| } | |
| case 'GET_USER_SUCCESS': | |
| return { | |
| ...state, | |
| user: { | |
| ...state.user, | |
| data: action.payload.result, | |
| asyncState: AsyncState.loaded | |
| } | |
| } | |
| case 'GET_USER_FAILED': | |
| return { | |
| ...state, | |
| user: { | |
| ...state.user, | |
| asyncState: AsyncState.error, | |
| error: action.payload.error | |
| } | |
| } | |
| /** KOPAS DARI ATAS **/ | |
| case 'GET_POST_REQUEST': | |
| return { | |
| ...state, | |
| post: { | |
| ...state.post, | |
| asyncState: AsyncState.loading | |
| } | |
| } | |
| case 'GET_POST_SUCCESS': | |
| return { | |
| ...state, | |
| post: { | |
| ...state.post, | |
| data: action.payload.result, | |
| asyncState: AsyncState.loaded | |
| } | |
| } | |
| case 'GET_POST_FAILED': | |
| return { | |
| ...state, | |
| post: { | |
| ...state.post, | |
| asyncState: AsyncState.error, | |
| error: action.payload.error | |
| } | |
| } | |
| default: | |
| return state | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment