import cloneObj from '../clone' ; type Actions = { type : string ; access_token ? : string ; userinfo ? : any ; unlockToken ? : string ; } ; const initialState = { userInfo : null , accessToken : '' , expires : 0 , unlockToken : '' } ; export default ( state = cloneObj ( initialState ) , action ) => { switch ( action . type ) { case 'ADD_ACCESS_TOKEN' : if ( action . access_token ) state . accessToken = action . access_token ; break ; case 'REMOVE_ACCESS_TOKEN' : state . accessToken = '' ; state . expires = 0 ; break ; case 'SET_USER' : if ( action . userinfo ) state . userInfo = action . userinfo ; break ; case 'ADD_UNLOCK_TOKEN' : if ( action . unlockToken ) state . unlockToken = action . unlockToken ; break ; case 'CLEAN' : state = { userInfo : null , accessToken : '' , expires : 0 , unlockToken : '' } ; break ; default : return state ; } return cloneObj ( state ) ; } ; export const getUserInfo = ( state ) => state . user . userInfo ; export const getAccessToken = ( state ) => state . user . accessToken ; export const getUnlockToken = ( state ) => state . user . unlockToken ;