import {
  CHANGE_FORM,
  SET_AUTH,
  SENDING_REQUEST,
  REQUEST_ERROR,
  CLEAR_ERROR
} from '../actions/constants'
import auth from '../auth'

let initialState = {
  formState: {
    username: '',
    password: ''
  },
  error: '',
  currentlySending: false,
  loggedIn: auth.loggedIn()
}

function reducer (state = initialState, action) {
  switch (action.type) {
    case CHANGE_FORM:
      return {...state, formState: action.newFormState}
    case SET_AUTH:
      return {...state, loggedIn: action.newAuthState}
    case SENDING_REQUEST:
      return {...state, currentlySending: action.sending}
    case REQUEST_ERROR:
      return {...state, error: action.error}
    case CLEAR_ERROR:
      return {...state, error: ''}
    default:
      return state
  }
}

export default reducer

@@ -1,12 +1,90 @@
+/*%0A * The reducer takes care of state changes in our app through actions%0A */%0A%0A
 import %7B%0A  C
@@ -215,16 +215,49 @@
 /auth'%0A%0A
+// The initial application state%0A
 let init
@@ -395,16 +395,64 @@
 In()%0A%7D%0A%0A
+// Takes care of changing the application state%0A
 function

Document reducer