Спасибо! Я получил решение, если мы хотим использовать два объекта одновременно, нам нужно использовать два состояния. Было нормально, что у меня была перезапись, потому что я использовал только одно состояние. Это мой код:
import { Actions, ActionTypes } from './actions';
import { initialStateProfile, StateProfile, initialStateProfilePage, StateProfilePage } from './state';
export function featureReducerProfile (state: StateProfile = initialStateProfile, action: Actions) {
switch (action.type) {
case ActionTypes.UPDATE_PROFILE_SUCCESS:
case ActionTypes.GET_PROFILE_SUCCESS: {
return {
...state,
profile: action.payload,
isLoading: false,
error: null
};
}
case ActionTypes.GET_PROFILE_START:
case ActionTypes.UPDATE_PROFILE_START: {
return {
...state,
isLoading: true,
error: null
};
}
case ActionTypes.GET_PROFILE_FAIL:
case ActionTypes.UPDATE_PROFILE_FAIL: {
return {
...state,
isLoading: false,
error: action.payload
};
}
default: {
return state;
}
}
}
export function featureReducerProfilePage (state: StateProfilePage = initialStateProfilePage, action: Actions) {
switch (action.type) {
case ActionTypes.GET_PROFILE_BY_PSEUDO_SUCCESS: {
return {
...state,
profile: action.payload,
isLoading: false,
error: null
};
}
case ActionTypes.GET_PROFILE_BY_PSEUDO_START: {
return {
...state,
isLoading: true,
error: null
};
}
case ActionTypes.GET_PROFILE_BY_PSEUDO_FAIL: {
return {
...state,
isLoading: false,
error: action.payload
};
}
default: {
return state;
}
}
}
Не забудьте изменить свой NgModule:
@NgModule({
declarations: [],
imports: [
CommonModule,
StoreModule.forFeature('profileFeature', featureReducerProfile),
StoreModule.forFeature('profilePageFeature', featureReducerProfilePage),
EffectsModule.forFeature([ProfileFeatureEffects])
],
providers: [
ProfileFeatureEffects
]
})