import { createReducer, on } from '@ngrx/store'; import { initialState } from './state'; import { loginSuccess, logoutSuccess, infoUserSuccess } from './actions'; import { UserInfoUpdateType } from '@ucap/protocol-info'; export const reducer = createReducer( initialState, on(loginSuccess, (state, action) => { return { ...state, loginRes: action.res }; }), on(logoutSuccess, (state, action) => { return { ...initialState }; }), on(infoUserSuccess, (state, action) => { let loginRes = { ...state.loginRes }; switch (action.res.type) { case UserInfoUpdateType.Image: loginRes = { ...loginRes }; break; case UserInfoUpdateType.Intro: loginRes = { ...loginRes, userInfo: { ...loginRes.userInfo, intro: action.res.info } }; break; case UserInfoUpdateType.TelephoneVisible: loginRes = { ...loginRes }; break; default: break; } return { ...state, loginRes: { ...loginRes } }; }) );