Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/2.5.3/rx.all.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <button id="dec">-</button>
  <span id="out"></span>
  <button id="inc">+</button>
  <button id="res">RESET</button>
</body>
</html>
 
const {when, fromEvent} = Rx.Observable;
const decObs = fromEvent(document.getElementById('dec'), 'click');
const incObs = fromEvent(document.getElementById('inc'), 'click');
const resetObs = fromEvent(document.getElementById('res'), 'click');
when(
  decObs.thenDo(x => prev => prev - 1),
  incObs.thenDo(x => prev => prev + 1),
  resetObs.thenDo(x => prev => 0)
).startWith(0).scan((prev, f) => f(prev)).subscribe(v => document.getElementById('out').innerHTML = v);
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
dstoyanovpro
0viewers