Last active
September 14, 2016 20:49
-
-
Save iansinnott/60d603807ad25bab03fd4b59ab85f929 to your computer and use it in GitHub Desktop.
Debounce vs. Throttle (Rx.js v5)
This file contains hidden or 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
| // 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