How can I customize my reducers using @ngrx/data?

不想你离开。 提交于 2021-02-19 05:19:32

问题


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 = { User: { additionalCollectionState: { testing: null } } };

and set the module here:

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


回答1:


simply follow their docs how to add custom reducers: https://ngrx.io/guide/data/entity-reducer#customizing-entity-reducer-behavior

You can create a custom reducer for an entity type and register it directly with EntityCollectionReducerRegistry.registerReducer().

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.



来源:https://stackoverflow.com/questions/61296660/how-can-i-customize-my-reducers-using-ngrx-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!