From 711ba0e7aa98b2adf8f2331adc7dc7dd34a1a955 Mon Sep 17 00:00:00 2001 From: Ward Bell Date: Wed, 26 Feb 2020 01:39:55 -0800 Subject: [PATCH] fix(data): correct AppEntityServices example in ngrx data doc page (#2413) closes #2280 --- .../content/guide/data/entity-services.md | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/projects/ngrx.io/content/guide/data/entity-services.md b/projects/ngrx.io/content/guide/data/entity-services.md index 39886c2420..13dc6b7353 100644 --- a/projects/ngrx.io/content/guide/data/entity-services.md +++ b/projects/ngrx.io/content/guide/data/entity-services.md @@ -135,12 +135,7 @@ The following `AppEntityServices` demonstrates. import { Injectable } from '@angular/core'; -import { Store } from '@ngrx/store'; -import { - EntityCache, - EntityCollectionServiceFactory, - EntityServicesBase -} from '@ngrx/data'; +import { EntityServicesBase, EntityServicesElements } from '@ngrx/data'; import { SideKick } from '../../model'; import { HeroService, VillainService } from '../../services'; @@ -148,19 +143,16 @@ import { HeroService, VillainService } from '../../services'; @Injectable() export class AppEntityServices extends EntityServicesBase { constructor( - public readonly store: Store<EntityCache>, - public readonly entityCollectionServiceFactory: EntityCollectionServiceFactory, + elements: EntityServicesElements, // Inject custom services, register them with the EntityServices, and expose in API. - public readonly heroesService: HeroesService, - public readonly villainsService: VillainsService + readonly heroesService: HeroesService, + readonly villainsService: VillainsService ) { - super(store, entityCollectionServiceFactory); + super(elements); this.registerEntityCollectionServices([heroesService, villainsService]); } - // ... Additional convenience members - /** get the (default) SideKicks service */ get sideKicksService() { return this.getEntityCollectionService<SideKick>('SideKick'); @@ -168,10 +160,13 @@ export class AppEntityServices extends EntityServicesBase { } -`AppEntityServices` injects the two custom collection services, `HeroesService` and `VillainsService`, -which it also exposes directly as convenience properties. +`AppEntityService` first injects the `EntityServicesElements` helper which it passes straight through to the base class constructor. +The "elements" enclose the ingredients that the base class needs to make and manage the entities you described in metadata. + +Then it injects your two custom collection services, `HeroesService` and `VillainsService`, +and exposes them directly to consumers as convenience properties for accessing those services. -There is no custom collections service for the `SideKick`. +In this example, we don't need a custom collection service for the `SideKick` entity. The default service will do. Nonetheless, we add a `sideKicksService` property that gets or creates a default service for `SideKick`.