mapTo
RxJS 5 mapTo
by superj80820
HTML
<script src="https://npmcdn.com/@reactivex/[email protected]/dist/global/Rx.umd.js"></script>
<div id="output">1</div>
<button id="plus" type="button">+1</button>
<button id="minus" type="button">-1</button>
JavaScript
Rx.Observable.fromEvent(document.getElementById('plus'), 'click')
.mapTo(1)
.merge(
Rx.Observable.fromEvent(document.getElementById('minus'), 'click')
.mapTo(-1)
)
.scan((total, now) => total + now)
.subscribe(value => {
document.getElementById('output').innerText = value;
})