DistinctMutableLiveData
An implementation of MutableLiveData that only emits updates when the value actually changed, i.e. when newValue != oldValue
. This differs from regular MutableLiveData because if you set its value to an equal same value, it still emits an update, causing observers to get a callback.
This is more suitable than the distinctUntilChanged transformation for the cases where the values are not necessarily going to be observed: distinctUntilChanged only changes value when observers are registered.
NB: This should only be used in situations where it's guaranteed to not lead to side-effects. The most common situation where this should not be used is for instances of T
that are both mutable and have a custom Object.equals implementation. This could lead to situations where a set value is ignored but mutated afterwards, meaning the value shouldn't have been ignored after all. As a guideline, only use DistinctMutableLiveData for types that could also be used as a key in a Map.