{"size": 1304, "ext": "js", "max_stars_repo_path": "src/reducers/itemReducer.js", "max_stars_repo_name": "Glinkis/work-trial-softrobot", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/reducers/itemReducer.js", "max_issues_repo_name": "Glinkis/work-trial-softrobot", "max_issues_repo_issues_event_min_datetime": "2020-04-05T05:11:20.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T06:45:05.000Z", "max_forks_repo_path": "src/reducers/itemReducer.js", "max_forks_repo_name": "Glinkis/work-trial-softrobot", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 8, "max_forks_count": null, "avg_line_length": 26.612244898, "max_line_length": 71, "alphanum_fraction": 0.6518404908}
// @ts-check
/// <reference path="../types.d.ts" />
import * as itemActions from "../actions/itemActions";

/** @type {ItemReducer.<number>} */
const addUpdatingItem = (state, payload) => ({
  ...state,
  updating: [...state.updating, payload]
});

/** @type {ItemReducer.<number>} */
const removeUpdatingItem = (state, payload) => ({
  ...state,
  updating: state.updating.filter(id => id !== payload)
});

/** @type {ItemReducer.<number>} */
const addFailedItem = (state, payload) => ({
  ...state,
  failed: [...state.failed, payload]
});

/** @type {ItemReducer.<number>} */
const removeFailedItem = (state, payload) => ({
  ...state,
  failed: state.failed.filter(id => id !== payload)
});

/** @type {ItemState} */
const defaultState = {
  updating: [],
  failed: []
};

/** @type {(state: ItemState | undefined, action: any) => ItemState} */
export default function(state = defaultState, { type, payload }) {
  switch (type) {
    case itemActions.ADD_UPDATING_ITEM:
      return addUpdatingItem(state, payload);
    case itemActions.REMOVE_UPDATING_ITEM:
      return removeUpdatingItem(state, payload);
    case itemActions.ADD_FAILED_ITEM:
      return addFailedItem(state, payload);
    case itemActions.REMOVE_FAILED_ITEM:
      return removeFailedItem(state, payload);
  }
  return state;
}
