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


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


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