如何使用@ngrx/data 自定义我的减速器? [英] How can I customize my reducers using @ngrx/data?
问题描述
我正在学习使用@ngrx/data,确实,使用该库,我改进了很多代码,但在对其进行个性化时遇到了问题.我已经看到如何向集合添加字段
I am learning to use @ngrx/data, it is true that with that library I advance a lot of code, but I am having problems when it comes to personalizing it. I already saw how to add fields to collections
export const entityMetadata: EntityMetadataMap = {用户:{附加集合状态:{测试:空}}};
并在此处设置模块:
export class UsersModule {
constructor(private eds: EntityDefinitionService) {
eds.registerMetadataMap(entityMetadata);
}
}
一切都很好,但是...,我如何添加自己的减速器,在文档中我看的不是很清楚
All good up there, but ..., How can I add my own reducers, in the documentation I don't see it very clearly
推荐答案
只需按照他们的文档如何添加自定义减速器:https://ngrx.io/guide/data/entity-reducer#customizing-entity-reducer-behavior
simply follow their docs how to add custom reducers: https://ngrx.io/guide/data/entity-reducer#customizing-entity-reducer-behavior
您可以为实体类型创建自定义缩减器,并直接使用 EntityCollectionReducerRegistry.registerReducer()
注册它.
You can create a custom reducer for an entity type and register it directly with EntityCollectionReducerRegistry.registerReducer()
.
您可以通过调用EntityCollectionReducerRegistry.registerReducers(reducerMap)
同时注册多个自定义reducer,其中reducerMap是reducer的散列,以entity-type-name为键.
You can register several custom reducers at the same time by calling EntityCollectionReducerRegistry.registerReducers(reducerMap)
where the reducerMap is a hash of reducers, keyed by entity-type-name.
这篇关于如何使用@ngrx/data 自定义我的减速器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!