I have a stream of objects, and I need to compare if the current object is not the same as the previous one, in which case it emits a new value. I found that the differUntilChanged statement should do exactly what I want, but for some reason it never emits a value other than the first one. If I delete the differUntilChanged value, it returns fine.
My code is:
export class SettingsPage { static get parameters() { return [[NavController], [UserProvider]]; } constructor(nav, user) { this.nav = nav; this._user = user; this.typeChangeStream = new Subject(); this.notifications = {}; } ngOnInit() { this.typeChangeStream .map(x => {console.log('value on way to distinct', x); return x;}) .distinctUntilChanged(x => JSON.stringify(x)) .subscribe(settings => { console.log('typeChangeStream', settings); this._user.setNotificationSettings(settings); }); } toggleType() { this.typeChangeStream.next({ "sound": true, "vibrate": false, "badge": false, "types": { "newDeals": true, "nearDeals": true, "tematicDeals": false, "infoWarnings": false, "expireDeals": true } }); } emitDifferent() { this.typeChangeStream.next({ "sound": false, "vibrate": false, "badge": false, "types": { "newDeals": false, "nearDeals": false, "tematicDeals": false, "infoWarnings": false, "expireDeals": false } }); } }
angular reactive-programming rxjs
Daniel SuchΓ½
source share