4

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

Reynier Rivero
  • 2,042
  • 2
  • 8
  • 12

2 Answers2

2

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.

satanTime
  • 12,631
  • 1
  • 25
  • 73
0

Maybe this helps: https://slides.com/jiali/deck-5/fullscreen#/36

ngrx/data extension points
Change built in behaviors
Customized EntityCollectionService
Customized EntityAction/Dispatcher
Add property to EntityCollection
Customized DataService
Customized merge strategy
Customized http url generator
Customized plural names
Customized persistentResultHandler
Use normal ngrx
Dispatch own action
Add own reducer/effects
Parth Developer
  • 1,371
  • 1
  • 13
  • 30