Skip to content

Instantly share code, notes, and snippets.

@rockydd
Created May 23, 2019 00:43
Show Gist options
  • Save rockydd/2bcc3b3a5966c4eeb19784a12952576a to your computer and use it in GitHub Desktop.
Save rockydd/2bcc3b3a5966c4eeb19784a12952576a to your computer and use it in GitHub Desktop.
import { fromEvent, interval } from 'rxjs';
import { tap, throttle } from 'rxjs/operators';
const clicks = fromEvent(document, 'click');
//const result = clicks.pipe(throttle(ev => interval(1000)));
const result = interval(2000).pipe(tap(x => console.log('v:', x)), throttle( i => clicks, {leading: true, trailing: true}));
result.subscribe(x => console.log(x));
// trailing true, so emit the latest value when mouse clicked.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment