-
-
Save romanown/7c60ff14b92b0fb9ba4aa731b3b2df56 to your computer and use it in GitHub Desktop.
small debounce implementation without lodash
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
export const DEBOUNCE_DEFAULT_DELAY = 200; | |
export default function debounce(func, delay = DEBOUNCE_DEFAULT_DELAY) { | |
let timeout; | |
return function(...args) { | |
if (timeout) { | |
clearTimeout(timeout); | |
} | |
timeout = setTimeout(() => { | |
timeout = null; | |
func.apply(this, args); | |
}, delay); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment