{"size": 682, "ext": "js", "max_stars_repo_path": "redux-counter/src/store/reducers/result.js", "max_stars_repo_name": "kburudi/React-001-Tutorial", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "redux-counter/src/store/reducers/result.js", "max_issues_repo_name": "kburudi/React-001-Tutorial", "max_issues_repo_issues_event_min_datetime": "2020-09-05T02:08:44.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T15:19:50.000Z", "max_forks_repo_path": "redux-counter/src/store/reducers/result.js", "max_forks_repo_name": "kburudi/React-001-Tutorial", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 27, "max_forks_count": null, "avg_line_length": 27.28, "max_line_length": 106, "alphanum_fraction": 0.6627565982}
import {STORE_RESULT, DEL_RESULT} from '../actions/types';
import { updateObject } from '../utility';

const initialState = {
    result: []
}

const delResult = (state, action) => {
  const updatedArray = state.result.filter(result => result.id !== action.resElId)
  return updateObject(state, {result: updatedArray});
};

const resultReducer = (state = initialState, action) => {
    switch (action.type) {
      case STORE_RESULT:
        return updateObject(state, {result: state.result.concat({value: action.result, id: new Date()})});
      case DEL_RESULT:
        return delResult(state, action);
      default:
        return state;
    }
};

export default resultReducer;
