Reactive-Extensions / RxJS

The Reactive Extensions for JavaScript
http://reactivex.io
Other
19.49k stars 2.1k forks source link

Operator is failing if not proceeded by .distinctUntilChanged #1511

Open mrpmorris opened 6 years ago

mrpmorris commented 6 years ago

I'm hoping someone can explain something to me. In this file -> https://github.com/mrpmorris/rxjs-garbage-collect/blob/master/src/rxjs-garbage-collect/src/selectors/StateSelector.ts

...there is a chunk of code that looks like this

    this.observable$ = parent.asObservable()
      .map(x => getProperty(x, this.path))
      .distinctUntilChanged()
      .monitorSubscriberCount(args => this.subscriberCountChanged(args));

My monitorSubscriberCount operator merely calls back the specified method whenever a subscription is added/removed. What I find weird about this though is that I have had to add .distinctUntilChanged in order to make it work. Without it, it seems the .map operator is not remapping the source data into the target.

To see this problem in action clone https://github.com/mrpmorris/rxjs-garbage-collect and then type "ng test" in a command prompt. Note how everything works fine, but then removing the .distinctUntilChanged line in /src/rxjs-garbage-collect/src/selectors/StateSelector.ts breaks everything.