RxJS .zip and .switchLatest
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/4.1.0/rx.all.js"></script>
CSS
textarea {
font-family:"Courier New", monospace;
font-size: 12px;
width: 100%;
height: 120px;
}
JavaScript
var Observable = Rx.Observable;
Observable.of(['a', 1], ['a', 1], ['a', 0], ['a', 1])
.distinctUntilChanged(x => x[1])
.subscribe(x => console.log(x))
Observable.of({key: 'a', state: 1}, {key: 'a', state: 2}, {key: 'a', state: 0}, {key: 'a', state: 1})
.distinctUntilChanged(x => x.state)
.subscribe(x => console.log(x))
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')
}
)