1

The root state does not include data from ngrx/data, at least not when I define it. Later, it's present in the global state.

For now I have a "FilterService" that has filter functions that return an observable of some kind.

example

  containerById(id: string): Observable<Container> {
    return this.containerService.entities$.pipe(
      map(data => data.find(item => item.id === id))
    );
  }
  containersByCommunityId(id: string): Observable<Container[]> {
    return this.containerService.entities$.pipe(
      map(data => data.filter((items) => items.community_id === id)),
    );
  }

I'd like to write selectors for this. But since the store isn't "plugged" into the root state, how do I write a selector for this?

The flow is, I load the data services in the AppComponent. This FilterService holds all the filter functions and also all the service references e.g. private containerService: ContainerService. In the Component I just pass the FilterService and something like

    this.forum$ = this.store.select(selectRouteId).pipe(
      switchMap(id => this.filterService.forumById(id)),
    );
    this.container$ = this.forum$.pipe(
      switchMap(forum => this.filterService.containerById(forum && forum.container_id))
    );

However I find it would be more elegant to just reference the private store: Store<State> and this.store.select(containersById(forum && forum.container_id))

But how do I write selectors for ngrx/data states? Like I wrote, I have a global state where I plug in other states but how do I plug the various entity states of ngrx/data into the root state? Or ... write selectors for them.

  • Does this answer your question? [create a selector for a ngrx/data entity](https://stackoverflow.com/questions/58596540/create-a-selector-for-a-ngrx-data-entity) – Andrew Allen Feb 28 '20 at 14:47
  • 1
    What are the odds of you asking this the minute I come online? –  Feb 28 '20 at 14:50

0 Answers0