function profileReducer(
  state = { isLoaded: false, isEmpty: true },
  action
) {
  switch (action.type) {
    case SET_PROFILE:
      if (!action.profile) {
        return {
          ...state,
          isEmpty: true,
          isLoaded: true
        }
      }
      return {
        ...action.profile,
        isEmpty: false,
        isLoaded: true
      }
    case PROFILE_UPDATE_SUCCESS:
      return Object.assign({}, state, action.payload)
    case LOGIN:
      // Support keeping data when logging out
      if (action.preserve && action.preserve.profile) {
        return preserveValuesFromState(state, action.preserve.profile, {
          isLoaded: true,
          isEmpty: true
        })
      }
      return {
        isEmpty: true,
        isLoaded: false
      }
    case LOGOUT:
    case AUTH_EMPTY_CHANGE:
      // Support keeping data when logging out
      if (action.preserve && action.preserve.profile) {
        return preserveValuesFromState(state, action.preserve.profile, {
          isLoaded: true,
          isEmpty: true
        })
      }
      return { isLoaded: true, isEmpty: true }
    default:
      return state
  }
}
Reducer for profile state. Changed by `SET_PROFILE`, `LOGOUT`, and
`LOGIN_ERROR` actions.
@param  {object} [state={isLoaded: false}] - Current profile redux state
@param  {object} action - Object containing the action that was dispatched
@param  {string} action.type - Type of action that was dispatched
@returns {object} Profile state after reduction