Last active
November 14, 2017 23:31
-
-
Save slugbyte/3a5619108725a917d439ca73f9d86354 to your computer and use it in GitHub Desktop.
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
// great for perioticly limiting events | |
throttle = (fn, ms) => { | |
let ready = true; | |
return (...args) => { | |
if(ready){ | |
ready = false | |
setTimeout(() => ready = true, ms) | |
return fn(...args) | |
} | |
} | |
} | |
// great for delaying until the last event | |
debounce = (fn, ms) => { | |
let timeout; | |
return (...args) => { | |
if(timeout) clearTimeout(timeout) | |
timeout = setTimeout(() => { | |
timeout = null | |
fn(...args) | |
}, ms) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment