{"size": 1636, "ext": "js", "max_stars_repo_path": "src/routes/achievement-list/modules/index.js", "max_stars_repo_name": "wcl-git/react-reduxs-route-antd", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/routes/achievement-list/modules/index.js", "max_issues_repo_name": "wcl-git/react-reduxs-route-antd", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/routes/achievement-list/modules/index.js", "max_forks_repo_name": "wcl-git/react-reduxs-route-antd", "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": 21.5263157895, "max_line_length": 74, "alphanum_fraction": 0.6424205379}
import { getFormDataApi, removeFormDataApi, widthdraw } from '../servers';
export const GET_DATA = 'achievementList/Get';
export const REMOVE_DATA = 'achievementList/DEL';
export const SWITCH_TYPE = 'switch_performance_type'

//获取列表
export const getData = (params) => {
  return (dispatch, getState) => {
    return getFormDataApi(params).then((res) => {
      dispatch({
        type: GET_DATA,
        payload: res
      })
    })
  }
}

//删除后获取
export const removeData = (params) => {
  return (dispatch) => (
    removeFormDataApi(params).then((res) => {
      dispatch({
        type: REMOVE_DATA,
        payload: res
      })
    })
  )
}

//切换业绩类型
export const switchPerformanceType = (type) => {
  return (dispatch) => (
    dispatch({
      type: SWITCH_TYPE,
      payload: type
    })
  )
}

//撤销
export const withdraw = () => {
  return () => widthdraw()
}

//switch-case handler
const ACTION_HANDLERS = {
  [GET_DATA]: (state, action) => {
    state.list = action.payload.data
    state.total = action.payload.total
    return state
  },
  [REMOVE_DATA]: (state, action) => {
    state.list = action.payload.data
    state.total = action.payload.total
    return state
  },
  [SWITCH_TYPE]: (state, action) => {
    state.performanceType = action.payload
    return state
  }
}

//组件初始state
const initialState = {
  list: [],
  performanceType: 'perform_system_in',
  total: 0,
}

//纯函数reducer，唯一功能：计算state
export default function Reducer(state = initialState, action) {
  const handler = ACTION_HANDLERS[action.type]
  let nextState = Object.assign({}, state);
  return handler ? handler(nextState, action) : nextState
}
