Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <script src="https://unpkg.com/@reactivex/rxjs@6.5.3/dist/global/rxjs.umd.js"></script>
  <title>JS Bin</title>
</head>
<body>
    <button id="event">event</button>
    <span id="display"></span>
    <button id="pause">pause</button>
  <div id="container"></div>
</body>
</html>
 
/* jshint esnext: true */
var { of, combineLatest, fromEvent, from } = rxjs;
var { map, mergeMap, filter, publish, startWith, bufferWhen, take } = rxjs.operators;
console.clear();
var pausableBuffer = function(pauser) {
  return (source) => source.pipe(publish(_input => 
  combineLatest(_input, pauser.pipe(startWith(true))).pipe(
    map(([inp, pa]) => pa),
    filter(pa => pa),
    publish(_switch => _input.pipe(bufferWhen(() => _switch.pipe(take(1)))))
  )),
    mergeMap(e => from(e))
  );
}
const [event$, pause$] = ['event', 'pause'].map(s => fromEvent(document.getElementById(s), 'click'));
 event$.pipe(
   pausableBuffer(pause$.pipe(map((e, i) => i % 2 === 1))),
   map((e, i) => i)
 ).subscribe((e) => console.log(e));
Output 300px

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

Dismiss x
public
Bin info
anonymouspro
0viewers