File size: 582 Bytes
f5071ca |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import {
RECEIVE_ALL_POSTS,
RECEIVE_POST,
REMOVE_POST,
} from '../actions/post_actions';
import merge from 'lodash/merge';
const PostsReducer = (oldState = {}, action) => {
Object.freeze(oldState);
switch (action.type) {
case RECEIVE_ALL_POSTS:
return action.posts;
case RECEIVE_POST:
return Object.assign({}, oldState,{[action.post.id]: action.post});
case REMOVE_POST:
let newState = merge({}, oldState);
delete newState[action.postId];
return newState;
default:
return oldState;
}
};
export default PostsReducer;
|