import { combineReducers } from 'redux' ; import StorageUtils , { LoginUser } from '../utils/StorageUtils' ; import { SET_HEAD_TITLE , RECEIVE_USER , SHOW_ERROR_MSG , RESET_USER } from './action-types' ; const initHeadTitle = '首页' ; function headTitle ( state = initHeadTitle , action ) { switch ( action . type ) { case SET_HEAD_TITLE : return action . payload ; default : return state ; } } const initUser = StorageUtils . getUser ( ) ; function user ( state = initUser , action ) { switch ( action . type ) { case RECEIVE_USER : return action . payload ; case SHOW_ERROR_MSG : const errorMsg = action . payload . errorMsg ; return { ... state , errorMsg } ; case RESET_USER : StorageUtils . removeUser ( ) ; return { } ; default : return state ; } } const rootReducer = combineReducers ( { headTitle , user , } ) ; export default rootReducer ;