Incorporating a function as my selector, it allows me to choose between selecting either a specific section of my personalized store or the entire entity.
select<K>(mapFn: (state: T) => K): Observable<K> {
return this.internalState$.asObservable().pipe(
map((state: T) => mapFn(state)),
distinctUntilChanged()
);
}
For implementation, I utilize it in the following manner:
this.title$ = this.store.select((s) => s.title)
While this method serves its purpose adequately, there have been instances where I require two segments from my state. In such cases, I tackle the issue by composing it like so:
this.store.select((s) => s).pipe(map((m) => ({ date: m.date, zone: m.zone })))
, choosing the whole store and then extracting the relevant properties in subsequent operations, or utilizing combineLatest with the chosen states.
Could there be a way to devise a selector that picks out the needed properties from the store? I've previously employed Pick<T>
, although how it can be applied within this context remains uncertain.