Skip to content

Instantly share code, notes, and snippets.

@iansinnott
Last active September 14, 2016 20:49
Show Gist options
  • Select an option

  • Save iansinnott/60d603807ad25bab03fd4b59ab85f929 to your computer and use it in GitHub Desktop.

Select an option

Save iansinnott/60d603807ad25bab03fd4b59ab85f929 to your computer and use it in GitHub Desktop.
Debounce vs. Throttle (Rx.js v5)
// Just look the console output.
// NOTE: Requires Rx.js v5.x
var mousemoves$ = Rx.Observable.fromEvent(document.body, 'mousemove');
// Events will be fired at most once every 200ms
var throtttled = mousemoves$.throttleTime(200);
// The latest event will be fired after 200ms. This means that if you are continually
// moving your mouse around the browser, causing mousemove events, none of them will
// show up until you stop moving the mouse for at least 200ms, at which point the
// last mousemove will be allowed through.
var debounced = mousemoves$.debounceTime(200);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment