userReducer.js 767 Bytes
Newer Older
zhanghaozhe committed
1 2 3 4 5 6 7
import {
  SET_CURRENT_USER,
  UPDATE_USER,
  START_FETCH_USER,
  END_FETCH_USER,
} from "src/store/userAction"
import { merge } from "lodash"
8

zhanghaozhe committed
9
const notLoggedIn = 4030
10

11
export const initialState = {
zhanghaozhe committed
12 13
  hasError: true,
  code: notLoggedIn,
zhanghaozhe committed
14
  msg: "",
zhanghaozhe committed
15
  data: {
zhanghaozhe committed
16 17
    username: "",
    avatar: "",
zhanghaozhe committed
18
    isVip: false,
zhanghaozhe committed
19 20 21
    token: "",
    email: "",
    uid: "",
zhanghaozhe committed
22 23
  },
  isFetching: true,
24 25 26
}

export default function (state = initialState, action) {
zhanghaozhe committed
27 28 29 30 31 32
  switch (action.type) {
    case SET_CURRENT_USER:
      return action.payload
    case UPDATE_USER:
      return merge({}, state, action.payload)
    case START_FETCH_USER:
zhanghaozhe committed
33
      return { ...state, isFetching: true }
zhanghaozhe committed
34
    case END_FETCH_USER:
zhanghaozhe committed
35
      return { ...state, isFetching: false }
zhanghaozhe committed
36 37 38
    default:
      return state
  }
39
}