Created
June 29, 2018 18:30
-
-
Save fang0rnz/437c738f89033bb7b44c718984d1dcfd to your computer and use it in GitHub Desktop.
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
export function debounce(func, wait, immediate) { | |
let timeout; | |
return function() { | |
const later = () => { | |
timeout = null; | |
if (!immediate) func.apply(this, arguments); | |
}; | |
const callNow = immediate && !timeout; | |
clearTimeout(timeout); | |
timeout = setTimeout(later, wait); | |
if (callNow) func.apply(this, arguments); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment