'Adding a partial entity with a default @ngrx/data entity collection service
I've got an issue with @ngrx/data which I'm not sure would be considered a bug or working as intended. The issue centers around adding a new entity to the store with a partial type.
With this package you can create an entity collection service a couple different ways:
- Inject EntityServices and use it to grab one of the default entity collection services from its registry like so...
constructor(entityServices: EntityServices) {
this.defautHeroesService = entityServices.getEntityCollectionService('Hero');
this.heroes$ = this.defautHeroesService.entities$;
}
- Or, create a custom entity collection service by extending EntityCollectionServiceBase then inject that service like so...
constructor(public customHeroesService: HeroesService) {
this.heroes$ = this.customHeroesService.entities$;
}
I've noticed the add method of default vs custom entity collection services behaves differently. The custom service will let you supply a partial type which is very handy if any of your database fields are nullable. However, with the add method of the default service TypeScript will complain if you try supplying a partial. I would like to avoid creating a custom service for every single entity type as the only reason I went down this @ngrx/data path in the first place was the promise of "Zero Ngrx Boilerplate" for entity data, or at lease minimal boilerplate.
Am I doing something wrong? Is there a legitimate reason for this? Is there some other way to grab a default service?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
