userReducer.js 748 Bytes
Newer Older
zhanghaozhe committed
1
import { SET_CURRENT_USER, UPDATE_USER, START_FETCH_USER } from '@/store/userAction';
2
import { merge } from 'lodash'
3

zhanghaozhe committed
4
const notLoggedIn = 4030
5

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


export default function (state = initialState, action) {
    switch (action.type) {
        case SET_CURRENT_USER:
            return action.payload
26 27
        case UPDATE_USER:
            return merge({}, state, action.payload)
zhanghaozhe committed
28 29
        case START_FETCH_USER:
            return {...state, isFetching: true}
30 31 32
        default:
            return state
    }
33
}