Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rx.Observable.prototype.distinctUntilChanged のおかしな挙動
describe 'distinctUntilChanged', ->
it 'comparer', ->
isEqual = require 'lodash.isequal'
subjectX = new Rx.Subject()
subjectX
.distinctUntilChanged null, isEqual
.toArray()
.subscribe (a) ->
# currentKey was updated by `o.value = 2`
assert a.length is 1
[o1] = a
assert.deepEqual o1, value: 2 # oh...
o = {}
o.value = 1
subjectX.onNext o
o.value = 2
subjectX.onNext o
subjectX.onCompleted()
it 'key selector', ->
hash = require 'object-hash'
subjectX = new Rx.Subject()
subjectX
.distinctUntilChanged hash
.toArray()
.subscribe (a) ->
assert a.length is 2
[o1, o2] = a
assert.deepEqual o1, value: 2 # oh...
assert.deepEqual o2, value: 2
o = {}
o.value = 1
subjectX.onNext o
o.value = 2
subjectX.onNext o
subjectX.onCompleted()
@bouzuya
Copy link
Author

bouzuya commented Nov 9, 2015

原因としては currentKey として保持している直前の値はその参照を書き換えられると、比較が正しく動かないため。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment