{"size": 906, "ext": "js", "max_stars_repo_path": "src/reducers/formReducer.js", "max_stars_repo_name": "yingzhao-1/Sia-EventUI", "max_stars_repo_stars_event_min_datetime": "2018-01-01T07:06:32.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-01T14:54:31.000Z", "max_issues_repo_path": "src/reducers/formReducer.js", "max_issues_repo_name": "yingzhao-1/Sia-EventUI", "max_issues_repo_issues_event_min_datetime": "2017-11-13T23:40:55.000Z", "max_issues_repo_issues_event_max_datetime": "2018-04-23T19:58:52.000Z", "max_forks_repo_path": "src/reducers/formReducer.js", "max_forks_repo_name": "yingzhao-1/Sia-EventUI", "max_forks_repo_forks_event_min_datetime": "2017-11-13T17:16:53.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-10T10:28:48.000Z"}
{"max_stars_count": 4, "max_issues_count": 87, "max_forks_count": 9, "avg_line_length": 24.4864864865, "max_line_length": 74, "alphanum_fraction": 0.6876379691}
import * as formActions from 'actions/formActions'

const defaultForms = {}

const updateInput = (state, form, field, value = null) => {
  var newState = {...state}
  const oldForm = state[form]
  var newForm = {...oldForm}

  newForm[field] = value
  newState[form] = newForm
  return newState
}

const clearInput = (state, form, field) => updateInput(state, form, field)

const clearForm = (state, form) => {
  var newState = {...state}
  newState[form] = null
  return newState
}

export const reducer = (state = defaultForms, action) => {
  switch (action.type) {
    case formActions.UPDATE_INPUT:
      return updateInput(state, action.form, action.field, action.value)
    case formActions.CLEAR_INPUT:
      return clearInput(state, action.form, action.field)
    case formActions.CLEAR_FORM:
      return clearForm(state, action.form)
    default:
      return state
  }
}

export default reducer
