Created
June 16, 2020 10:01
-
-
Save velotiotech/f9958986d542fbfece03896363de7719 to your computer and use it in GitHub Desktop.
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
import { | |
GET_POSTS_BY_ID_REQUEST, | |
GET_POSTS_BY_ID_SUCCESS, | |
GET_POSTS_BY_ID_FAIL, | |
GET_POSTS_BULK_REQUEST, | |
GET_POSTS_BULK_SUCCESS, | |
GET_POSTS_BULK_FAIL | |
} from "./constants"; | |
const reducer = (state, action) => { | |
switch (action.type) { | |
case GET_POSTS_BY_ID_REQUEST: | |
return { | |
...state, | |
byId: { | |
isLoading: true, | |
error: null, | |
data: null | |
} | |
} | |
case GET_POSTS_BY_ID_SUCCESS: | |
return { | |
...state, | |
byId: { | |
isLoading: false, | |
error: false, | |
data: action.payload | |
} | |
} | |
case GET_POSTS_BY_ID_FAIL: | |
return { | |
...state, | |
byId: { | |
isLoading: false, | |
error: action.payload, | |
data: false | |
} | |
} | |
case GET_POSTS_BULK_REQUEST: | |
return { | |
...state, | |
byBulk: { | |
isLoading: true, | |
error: null, | |
data: null | |
} | |
} | |
case GET_POSTS_BULK_SUCCESS: | |
return { | |
...state, | |
byBulk: { | |
isLoading: false, | |
error: false, | |
data: action.payload | |
} | |
} | |
case GET_POSTS_BULK_FAIL: | |
return { | |
...state, | |
byBulk: { | |
isLoading: false, | |
error: action.payload, | |
data: false | |
} | |
} | |
default: return state; | |
} | |
} | |
export default reducer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment