{"size": 939, "ext": "js", "max_stars_repo_path": "src/modules/pokelist/reducer.js", "max_stars_repo_name": "afbeals/CBRA", "max_stars_repo_stars_event_min_datetime": "2019-12-22T01:25:22.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-22T01:25:22.000Z", "max_issues_repo_path": "src/modules/pokelist/reducer.js", "max_issues_repo_name": "afbeals/CBRA", "max_issues_repo_issues_event_min_datetime": "2021-05-10T22:01:05.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-10T22:10:02.000Z", "max_forks_repo_path": "src/modules/pokelist/reducer.js", "max_forks_repo_name": "afbeals/CBRA", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 17.7169811321, "max_line_length": 74, "alphanum_fraction": 0.5559105431}
// Local
import actionTypes from './actionTypes';
import pokelistUtility from './utility';

// constants
const {
  FETCH_LIST_SUCCESS,
  FETCH_MON_SUCCESS,
  SELECT_POKEMON,
  RESET,
} = actionTypes;
const { buildInitialStore } = pokelistUtility;

const initialStore = buildInitialStore();

export default function reducer(state = initialStore, { type, payload }) {
  switch (type) {
    case FETCH_LIST_SUCCESS: {
      return {
        ...state,
        pokemon: payload,
      };
    }

    case FETCH_MON_SUCCESS: {
      return {
        ...state,
        pokemon: {
          ...state.pokemon,
          [payload.urlId]: {
            ...state.pokemon[payload.urlId],
            ...payload,
          },
        },
      };
    }

    case SELECT_POKEMON: {
      return {
        ...state,
        selectedPokemon: payload,
      };
    }

    case RESET: {
      return initialStore;
    }

    default:
      return state;
  }
}
