首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >分层存储组织

分层存储组织
EN

Stack Overflow用户
提问于 2019-10-06 06:32:12
回答 1查看 171关注 0票数 2

我有一个问题,那就是如何在Angular中构建分层存储。我想在应用程序的特定部分工作的多个减速器。

下面是一个描述:这是一个HR应用程序。我有人才(员工)模块,其数据分为五个部分:专业知识、教育程度、backgroundCheck、位置和工资、工作保留。

每个部分都包含相当复杂的逻辑,以满足业务期望。我们正在为市场更新一些案例,我们需要在多个部件上的组件之间共享数据。

所以从根模块开始,我已经为人才模块定义了根状态

我试着像下面这篇文章中描述的那样使用combineReducers:Angular 6 / NGRX Combine Reducers

所以从根模块开始,我已经为人才模块定义了根状态

代码语言:javascript
复制
export interface ITalentState {
    profile: IProfileState;
}

这里是天赋状态的缩减程序

代码语言:javascript
复制
export function talentReducer(state = talentInitialState, action: TalentActions): ITalentState {
    switch(action.type) {
        case TalentActionTypes.SetProfile:
            return {
                ...state,
                profile: action.profileData 
            }
        default: return state;
    }
}

ProfileState的定义如下

代码语言:javascript
复制
export interface IProfileState {
    expertiseState: IExpertiseState;
}

以下是专业知识部分:

代码语言:javascript
复制
export interface IExpertiseState {
    expertiseQuestions: ExpertiseQuestions;
    error: string;
}

专业知识部分

代码语言:javascript
复制
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,也不更新存储中的值。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-10 00:25:42

我想通了。基本上,要使用这种存储,我们需要为每个特性组合一个reducer (取决于粒度),然后将其公开为一个公共reducer,以下是解决方案:

代码语言:javascript
复制
export interface TalentState {
expertise: fromExpertise.ExpertiseState
}

export const reducers: ActionReducerMap<TalentState>  = {
expertise: fromExpertise.expertiseReducer
}

export const getTalentState = createFeatureSelector<TalentState>('talent')
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58252837

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档