<commit_before>import _ from 'lodash';
import {FETCH_POSTS, FETCH_POST} from '../actions';

export default function (state = {}, action) {
    switch (action.type) {
        case FETCH_POSTS:
            return _.mapKeys(action.payload.data, 'id');
        case FETCH_POST:
            // const post = action.payload.data;
            // const newState = {...state};
            // newState[post.id] = post;
            // return newState;
            //Include all the posts we have fetched already
            //[] is not an array here, key interpolation -> make a new key on object
            return {...state, [action.payload.data.id]: action.payload.data};
        default:
            return state;
    }
}<commit_msg>Tweaking post deletion<commit_after>import _ from 'lodash';
import {FETCH_POSTS, FETCH_POST, DELETE_POST} from '../actions';

export default function (state = {}, action) {
    switch (action.type) {
        case FETCH_POSTS:
            return _.mapKeys(action.payload.data, 'id');
        case FETCH_POST:
            // const post = action.payload.data;
            // const newState = {...state};
            // newState[post.id] = post;
            // return newState;
            //Include all the posts we have fetched already
            //[] is not an array here, key interpolation -> make a new key on object
            return {...state, [action.payload.data.id]: action.payload.data};
        case DELETE_POST:
            //_.omit does not modify the existing state object
            return _.omit(state, action.payload);
            //if we had an array
            //return _.reject(state, post => post === action.payload);
        default:
            return state;
    }
}
{'fraction_non_alphanumeric': 0.12011661807580175, 'fraction_numerical': 0.0, 'mean_word_length': 1.8791946308724832, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5154589', 'n_tokens_mistral': 476, 'n_tokens_neox': 465, 'n_words': 146}