One addition I think would really be helpful would be the option to specify compare function for the select for using with distinctUntilChanged. Which means the function will be
What is the use-case? Normally you want the Observable returned by select to only emit when it has a new Object reference. It's the same in Akita or NgRx. That behaviour encourages also updating state in an immutable manner.
Sorry for necroposting, but let's say, we have two different properties in our state. Both are known to be complex, not trivial. To give a better idea, here's an example:
and you want to know when only the value of the city property will change. You wouldn't be able to achieve that, because distinctUntilChanged uses a strict comparsion by default, so the state subject will emit the same value of the city property every time the user changes. Sometimes this can lead to unwanted behaviour, such as requesting data.
One addition I think would really be helpful would be the option to specify compare function for the select for using with distinctUntilChanged. Which means the function will be
What is the use-case? Normally you want the Observable returned by
select
to only emit when it has a new Object reference. It's the same in Akita or NgRx. That behaviour encourages also updating state in an immutable manner.Sorry for necroposting, but let's say, we have two different properties in our state. Both are known to be complex, not trivial. To give a better idea, here's an example:
and you want to know when only the value of the
city
property will change. You wouldn't be able to achieve that, becausedistinctUntilChanged
uses a strict comparsion by default, so the state subject will emit the same value of thecity
property every time theuser
changes. Sometimes this can lead to unwanted behaviour, such as requesting data.If you are interested in city changes, then you can write a selector specific for the city:
city$ = this.select(state => state.city);
The
distinctUntilChanges
operator inside theselect
method will make sure that there is only an emission if the city object changes.However, this selector would emit when city or user change:
userAndCityState$ = this.select(state => state);