Created
May 8, 2019 06:30
-
-
Save tbjgolden/d82380c0bc066d21780b4dfafd8677dc to your computer and use it in GitHub Desktop.
Lightweight JS promise debounce
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
const debounce = (func, ms = 500) => { | |
let timeout; | |
return function(...args) { | |
clearTimeout(timeout); | |
return new Promise(resolve => { | |
timeout = setTimeout(() => { | |
resolve(func.bind(this)(...args)); | |
}, ms); | |
}); | |
}; | |
}; | |
export default debounce; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment