Skip to content

Latest commit

 

History

History
50 lines (36 loc) · 1.74 KB

api.md

File metadata and controls

50 lines (36 loc) · 1.74 KB

Subcollection Service - Getting Started

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.

Path

SubcollectionService provides you an elegant way to describe your deeply nested subcollection with params.

@CollectionConfig({ path: 'movies/:movieId/stakeholders' })

SubcollectionService

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.

Utils

To analyse this path in your code, akita-ng-fire gives access to two helpers methods :

getPathParams

It will retrieve the params names from your path :

function getPathParams(path: string): string[]

Example : getPathParams('movies/:movieId/stakeholders') // 'movieId'

pathWithParams

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'