Skip to content

Instantly share code, notes, and snippets.

@arahmanali
Last active July 23, 2017 08:19
Show Gist options
  • Save arahmanali/9a09dd7a5c9bf6f828f0f1a167955449 to your computer and use it in GitHub Desktop.
Save arahmanali/9a09dd7a5c9bf6f828f0f1a167955449 to your computer and use it in GitHub Desktop.
RxJs Basic Example // source http://jsbin.com/cihibak
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="[add your bin description]">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>RxJs Basic Example</title>
</head>
<body>
<button>Click me</button>
<script src="https://unpkg.com/@reactivex/rxjs@5.4.2/dist/global/Rx.js"></script>
<script id="jsbin-javascript">
let button = document.querySelector('button');
/* Vanilla Javascript Way */
// button.addEventListener('click', (e) => {
// console.log('e');
// });
/* Reactivex Way */
Rx.Observable.fromEvent(button, 'click')
.throttleTime(2000)
.map( (event) => { return event.clientX } )
.subscribe(
(coordinate) => { console.log(coordinate); }
)
</script>
<script id="jsbin-source-javascript" type="text/javascript">
let button = document.querySelector('button');
/* Vanilla Javascript Way */
// button.addEventListener('click', (e) => {
// console.log('e');
// });
/* Reactivex Way */
Rx.Observable.fromEvent(button, 'click')
.throttleTime(2000)
.map( (event) => { return event.clientX } )
.subscribe(
(coordinate) => { console.log(coordinate); }
)</script></body>
</html>
let button = document.querySelector('button');
/* Vanilla Javascript Way */
// button.addEventListener('click', (e) => {
// console.log('e');
// });
/* Reactivex Way */
Rx.Observable.fromEvent(button, 'click')
.throttleTime(2000)
.map( (event) => { return event.clientX } )
.subscribe(
(coordinate) => { console.log(coordinate); }
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment