Skip to content

Instantly share code, notes, and snippets.

@seanreed1111
Forked from anonymous/index.html
Created October 5, 2016 14:22
Show Gist options
  • Save seanreed1111/d4c083acb77c62a670203cfc7f426a01 to your computer and use it in GitHub Desktop.
Save seanreed1111/d4c083acb77c62a670203cfc7f426a01 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));
@seanreed1111
Copy link
Author

First use of Observables. Huzzah!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment