Last active
July 23, 2017 08:19
-
-
Save arahmanali/9a09dd7a5c9bf6f828f0f1a167955449 to your computer and use it in GitHub Desktop.
RxJs Basic Example // source http://jsbin.com/cihibak
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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