Last active
March 26, 2017 20:51
-
-
Save aminbenselim/fd551a45ba8385680ae88ce379d81eee 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, | |
GET_POSTS_SUCCESS, | |
GET_POSTS_FAILURE | |
} from "./../actions/actions"; | |
const INITIAL_STATE = { posts: [], error: null, loading: false, totalpages: 0 }; | |
const Posts = (state = INITIAL_STATE, action) => { | |
let error; | |
switch (action.type) { | |
case GET_POSTS: | |
return { posts: [], error: null, loading: true, totalpages: 0 }; | |
case GET_POSTS_SUCCESS: | |
return { | |
posts: action.payload, | |
error: null, | |
loading: false, | |
totalpages: action.totalpages | |
}; | |
case GET_POSTS_FAILURE: | |
error = action.payload || { message: action.payload.message }; | |
return { posts: [], error: error, loading: false, totalpages: 0 }; | |
default: | |
return state; | |
} | |
}; | |
export default Posts; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment