On this page of NgRx selectors, there are few ways the select function can be called.
- this.store.select(selectValues)
- this.store.pipe(select(selectValues))
- this.store.pipe(map(state => selectValues(state)))
What are the differences between the above three?
First of all,
this.store.select(), andthis.store.pipe(select())are essentially the same.Based on this file, we can see that
StoreextendsObservable. Moreover, whenstore.select()is called, we can see that a differentselectfunction is called. This function is defined as a custom RxJS operator, which is a function whose return type is another function which accepts an Observable(i.e. the source Observable) as its sole argument and also returns an Observable.This means that whichever approach you choose, the same result is achieved and both methods will return an Observable that you can work with.
The difference with the third approach,
.map(state => selectValues(state)), when strictly compared to the previous two, is that this one won't add adistinctUntilChanged()operator at the end.