RxJS distinctUntilChanged - object comparison
<p>I have a stream of objects and I need to compare if the current object is not the same as the previous and in this case emit a new value. I found distinctUntilChanged operator should do exactly what I want, but for some reason, it never emits value except the first one. If I remove distinctUntilChanged values are emitted normally.</p>
<p>My code:</p>
<pre class="lang-ts prettyprint-override"><code>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 =&gt; {console.log('value on way to distinct', x); return x;})
            .distinctUntilChanged(x =&gt; JSON.stringify(x))
            .subscribe(settings =&gt; {
                console.log('typeChangeStream', settings);
                this._user.setNotificationSettings(settings);
            });
    }

    toggleType() {
        this.typeChangeStream.next({
            &quot;sound&quot;: true,
            &quot;vibrate&quot;: false,
            &quot;badge&quot;: false,
            &quot;types&quot;: {
                &quot;newDeals&quot;: true,
                &quot;nearDeals&quot;: true,
                &quot;tematicDeals&quot;: false,
                &quot;infoWarnings&quot;: false,
                &quot;expireDeals&quot;: true
            }
        });
    }

    emitDifferent() {
        this.typeChangeStream.next({
            &quot;sound&quot;: false,
            &quot;vibrate&quot;: false,
            &quot;badge&quot;: false,
            &quot;types&quot;: {
                &quot;newDeals&quot;: false,
                &quot;nearDeals&quot;: false,
                &quot;tematicDeals&quot;: false,
                &quot;infoWarnings&quot;: false,
                &quot;expireDeals&quot;: false
            }
        });
    }
}
</code></pre>