Skip to content

Instantly share code, notes, and snippets.

@adrianmcli
Created January 30, 2017 01:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adrianmcli/6293f5629d86c471eec41d07f9b299ce to your computer and use it in GitHub Desktop.
Save adrianmcli/6293f5629d86c471eec41d07f9b299ce to your computer and use it in GitHub Desktop.
An RxJS example of reporting events that happened every 5 seconds.
// 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