angular - Ngrx:如何将 simpe store 模式与实体状态结合起来?
问题描述
最近很抱歉,如果它与某人的问题重复。但是我找不到我的问题的解决方案。
我遇到了一个问题,我想让我的商店状态有点复杂,ngrx/entity提供但我不知道如何正确地做到这一点。
以下是我现在拥有的减速器模型:
export interface State extends EntityState<BagParametres> {
SimpleBag: BagParametres;
}
export const adapter: EntityAdapter<BagParametres> = createEntityAdapter<BagParametres>({
selectId: (params: BagParametres) => params.id
});
export const initialState: State = adapter.getInitialState({
SimpleBag: defaultParams,
RareBags: {
ids: [],
entities: []
}
});
所以我期望什么商店:
{
SimpleBag: {
//params
},
RareBags: {
ids: [2, 3, 4 //, ...etc],
entities: [
{ id: 2 //, etc params },
{ id: 3 //, etc params },
{ id: 4 //, etc params }
// ... and so on
]
}
}
我要买什么商店:
{
SimpleBag: {
id: 1
// etc params
},,
RareBags: {
ids: [],
entities: []
},
ids: [2, 3, 4 //, ...etc],
entities: [
{ id: 2 //, etc params },
{ id: 3 //, etc params },
{ id: 4 //, etc params }
// ... and so on
]
}
如何在其中放置 id 和实体RareBags
?
解决方案
您正在混淆状态。你想要的是 2 个不同的实体存储。
export interface State {
simpleBag: BagParametres;
rareBag: RareBagState
}
export interface RareBagState extends EntityState<BagParametres> {}
export const rareAdapter: EntityAdapter<BagParametres> = createEntityAdapter<BagParametres>({
selectId: (params: BagParametres) => params.id
});
export const initialState: State = {
simpleBag: defaultParams,
rareBag: rareAdapter.getInitialState({})
};
推荐阅读
- php - 输入类型=文件不能接受大尺寸图片
- javascript - 我想更改条形图单个条的颜色
- neo4j - 在 neo4j-admin 导入后创建唯一约束时遇到无限重启
- python - 测试发布请求时的Django消息中间件问题
- php - Wordpress Ajax 调用成功(200)但没有响应消息
- android - 当 isResumed() 返回 true 时,片段 getContext() 是否可以返回 null
- java - 如何在不克隆本地存储库的情况下获取提交列表
- excel - 表中相同项目的总和
- sql-server - SSIS 包升级 2008 到 2017
- java - 使用并行流和原子变量期间发生的竞争条件