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.
What is the use-case? Normally you want the Observable returned by
selectto 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
cityproperty will change. You wouldn't be able to achieve that, becausedistinctUntilChangeduses a strict comparsion by default, so the state subject will emit the same value of thecityproperty every time theuserchanges. 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
distinctUntilChangesoperator inside theselectmethod 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);