How can I have distinctUntilChanged
work with objects like this
myObs = Observable.from([{foo: 'bar'}, {foo: 'bar'}]);
myObs.distinctUntilChanged()
.subscribe(value => {
// I only want to receive {foo: 'bar'} once
});
from converts various other objects and data types into Observables. It also converts a Promise, an array-like, or an iterable object into an Observable that emits the items in that promise, array, or iterable. A String, in this context, is treated as an array of characters.
The of Operator is a creation Operator. Creation Operators are functions that create an Observable stream from a source. The of Operator will create an Observable that emits a variable amount of values in sequence, followed by a Completion notification.
You need to pass a function inside the distinctUntilChanged
that returns a boolean to make sure that the objects are the same.
Example
myObs. distinctUntilChanged((a, b) => a.foo === b.foo)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With