This week, our RxJs operator of choice is distinctUntilChanged
, another of these few operators with a name that is explicit enough.
distinctUntilChanged
ignores unchanged values that get emitted several times:
This operator is beneficial when using RxJs to filter out data based on filters selected by the end user in the UI. For instance, it’s a way to ensure that we only trigger a data update (such as an HTTP request) when the filters have changed.
A notable feature is that you can pass a custom comparison function as a parameter to determine how to compare those values. Otherwise, the operator uses ===
as a default comparison, which is acceptable for basic types but not for comparing objects unless you want to compare references.