Skip to content

Instantly share code, notes, and snippets.

Created October 5, 2016 14:20
Show Gist options
  • Save anonymous/fe2a4b71e3c7bfe7dd1c7c9560f117b1 to your computer and use it in GitHub Desktop.
Save anonymous/fe2a4b71e3c7bfe7dd1c7c9560f117b1 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/zoqito
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script src="https://unpkg.com/@reactivex/[email protected]/dist/global/Rx.umd.js"></script>
<button id="start">Start</button>
<button id="stop">Stop</button>
<script id="jsbin-javascript">
const Observable = Rx.Observable;
const startButton = document.querySelector('#start');
const stopButton = document.querySelector('#stop');
const start$ = Observable.fromEvent(startButton, 'click');
const stop$ = Observable.fromEvent(stopButton, 'click');
const interval$ = Observable.interval(1000);
start$
.switchMapTo(interval$)
.takeUntil(stop$)
.subscribe((x)=> console.log(x));
</script>
<script id="jsbin-source-javascript" type="text/javascript">const Observable = Rx.Observable;
const startButton = document.querySelector('#start');
const stopButton = document.querySelector('#stop');
const start$ = Observable.fromEvent(startButton, 'click');
const stop$ = Observable.fromEvent(stopButton, 'click');
const interval$ = Observable.interval(1000);
start$
.switchMapTo(interval$)
.takeUntil(stop$)
.subscribe((x)=> console.log(x));
</script></body>
</html>
const Observable = Rx.Observable;
const startButton = document.querySelector('#start');
const stopButton = document.querySelector('#stop');
const start$ = Observable.fromEvent(startButton, 'click');
const stop$ = Observable.fromEvent(stopButton, 'click');
const interval$ = Observable.interval(1000);
start$
.switchMapTo(interval$)
.takeUntil(stop$)
.subscribe((x)=> console.log(x));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment