Reactive-Extensions / RxJS

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

distinctUntilChanged broken or API change? #1188

Closed 0x80 closed 8 years ago

0x80 commented 8 years ago

This example from the docs

/* With key selector */
Observable.of({value: 42}, {value: 42}, {value: 24}, {value: 24})
  .distinctUntilChanged(x => x.value)
  .subscribe(
    function (x) {
      console.log('Next: ', x)
    },
    function (err) {
      console.log('Error: ' + err)
    },
    function () {
      console.log('Completed')
    }
  )

output v4 (as expected):

Next:  { value: 42 }
Next:  { value: 24 }
Completed

output v5:

Next:  { value: 42 }
Completed
david-driscoll commented 8 years ago

the parameters are different between rxjs5 and rxjs4 it looks like.

in rxjs4: distinctUntilChanged = function (keyFn, comparer) in rxjs5: distinctUntilChanged<T, K>(compare?: (x: K, y: K) => boolean, keySelector?: (x: T) => K)

If this is something you think should be changed, feel free to raise issue over at https://github.com/ReactiveX/rxjs

0x80 commented 8 years ago

Oops I meant to post this in the v5 repo.

I have a hard time understanding the new API from just the type signature, and the links in the v5 docs are dead. How would you write the above call to distinctUntilChanged with v5 arguments?

david-driscoll commented 8 years ago

the comparer and the key selector are just swapped.

.distinctUntilChanged(x => x.value) -> .distinctUntilChanged(null, x => x.value)

0x80 commented 8 years ago

Aaah :smiley: thanks!

Could you maybe point me to where this is documented?

david-driscoll commented 8 years ago

The docs are a work in progress, but as they get fleshed out they get updated @ http://reactivex.io/rxjs/

0x80 commented 8 years ago

Ok, I think I better stick to v4 then for now :+1:

spankyed commented 6 years ago

This is poorly documented.