Created
January 30, 2017 01:01
-
-
Save adrianmcli/6293f5629d86c471eec41d07f9b299ce to your computer and use it in GitHub Desktop.
An RxJS example of reporting events that happened every 5 seconds.
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
// throw these two lines into the markup: | |
// <button id="btn">Click</button> | |
// <script src="https://unpkg.com/@reactivex/rxjs/dist/global/Rx.js"></script> | |
const button = document.querySelector('#btn'); | |
const click$ = Rx.Observable.fromEvent(button, 'click'); | |
click$ | |
.map(() => Date.now()) | |
.bufferTime(5000) | |
.filter(e => e.length > 0) | |
.subscribe(console.log) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment