The SubcollectionService
is an extended version of the CollectionService
. It's designed to answer common subcollection specific behaviors.
Important: SubcollectionService
relies on the RouterService
from Angular Router Store.
@Injectable({ providedIn: 'root' })
@CollectionConfig({ path: 'movies/:movieId/stakeholders' })
export class StakeholderService extends SubcollectionService<StakeholderState> {
constructor(store: StakeholderStore) {
super(store);
}
}
and in main.ts
, activate reset.
SubcollectionService
provides you an elegant way to describe your deeply nested subcollection with params.
@CollectionConfig({ path: 'movies/:movieId/stakeholders' })
The SubcollectionService
uses the Routes params as source of parameters for the path to automate sync. It'll reset the store if one of the params have changed. Like that your store doesn't merge several subcollections data.
To analyse this path in your code, akita-ng-fire
gives access to two helpers methods :
It will retrieve the params names from your path :
function getPathParams(path: string): string[]
Example :
getPathParams('movies/:movieId/stakeholders') // 'movieId'
It will generate the path by replacing parameters with the one provided as second argument :
function pathWithParams(path: string, params: HashMap<string>): string
Example :
pathWithParams('movies/:movieId/stakeholders', {movieId: 123}) //'movies/123/stakeholders'