我有一个问题,那就是如何在Angular中构建分层存储。我想在应用程序的特定部分工作的多个减速器。
下面是一个描述:这是一个HR应用程序。我有人才(员工)模块,其数据分为五个部分:专业知识、教育程度、backgroundCheck、位置和工资、工作保留。
每个部分都包含相当复杂的逻辑,以满足业务期望。我们正在为市场更新一些案例,我们需要在多个部件上的组件之间共享数据。
所以从根模块开始,我已经为人才模块定义了根状态
我试着像下面这篇文章中描述的那样使用combineReducers:Angular 6 / NGRX Combine Reducers
所以从根模块开始,我已经为人才模块定义了根状态
export interface ITalentState {
profile: IProfileState;
}这里是天赋状态的缩减程序
export function talentReducer(state = talentInitialState, action: TalentActions): ITalentState {
switch(action.type) {
case TalentActionTypes.SetProfile:
return {
...state,
profile: action.profileData
}
default: return state;
}
}ProfileState的定义如下
export interface IProfileState {
expertiseState: IExpertiseState;
}以下是专业知识部分:
export interface IExpertiseState {
expertiseQuestions: ExpertiseQuestions;
error: string;
}专业知识部分
function expertiseReducer(state, action)
switch(action.type) {
case ExpertiseActionsTypes.LoadFailed:
return {
...state,
expertiseQuestions: new ExpertiseQuestions(),
error: action.message
}
case ExpertiseActionsTypes.LoadSuccess:
return {
...state,
expertiseQuestions: action.questions,
error: ''
}
default: return state;
}
}我希望有一种方法可以实现存储粒化,并拆分reducer,使它们更易于管理,但我在调试器中看到的唯一一件事是,调用了专业技术存储方法,但从不调用reducer,也不更新存储中的值。
发布于 2019-10-10 00:25:42
我想通了。基本上,要使用这种存储,我们需要为每个特性组合一个reducer (取决于粒度),然后将其公开为一个公共reducer,以下是解决方案:
export interface TalentState {
expertise: fromExpertise.ExpertiseState
}
export const reducers: ActionReducerMap<TalentState> = {
expertise: fromExpertise.expertiseReducer
}
export const getTalentState = createFeatureSelector<TalentState>('talent')https://stackoverflow.com/questions/58252837
复制相似问题