{"size": 1766, "ext": "js", "max_stars_repo_path": "src/redux/reducers/favoritesReducer.js", "max_stars_repo_name": "robSamuel/robert-samuel-applaudo", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/redux/reducers/favoritesReducer.js", "max_issues_repo_name": "robSamuel/robert-samuel-applaudo", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/redux/reducers/favoritesReducer.js", "max_forks_repo_name": "robSamuel/robert-samuel-applaudo", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.9705882353, "max_line_length": 94, "alphanum_fraction": 0.4960362401}
import { 
    ACTION_ADD_FAVORITE_CHARACTERS,
    ACTION_ADD_FAVORITE_COMICS,
    ACTION_ADD_FAVORITE_STORIES,
    ACTION_REMOVE_FAVORITE_CHARACTERS,
    ACTION_REMOVE_FAVORITE_COMICS,
    ACTION_REMOVE_FAVORITE_STORIES,
} from "../constants";

const initialState = {
    characters: [],
    comics: [],
    stories: []
};

const reducer = (state = initialState, {type, payload}) => {
    switch (type) {
        case ACTION_ADD_FAVORITE_CHARACTERS:
            return {
                ...state,
                characters: [...state.characters, payload]
            };

        case ACTION_REMOVE_FAVORITE_CHARACTERS: {
            const removed = state.characters.filter(character => character.id !== payload.id);
            
            return {
                ...state,
                characters: [...removed]
            };
        }

        case ACTION_ADD_FAVORITE_COMICS:
            return {
                ...state,
                comics: [...state.comics, payload]
            };

        case ACTION_REMOVE_FAVORITE_COMICS: {
            const removed = state.comics.filter(comic => comic.id !== payload.id);
            
            return {
                ...state,
                comics: [...removed]
            };
        }
    
        case ACTION_ADD_FAVORITE_STORIES:
            return {
                ...state,
                stories: [...state.stories, payload]
            };
            
        case ACTION_REMOVE_FAVORITE_STORIES: {
            const removed = state.stories.filter(story => story.id !== payload.id);
            
            return {
                ...state,
                stories: [...removed]
            };
        }          

        default:
            return state;
    }
};

export default reducer;