Last active
January 24, 2018 17:15
-
-
Save abezhinaru/37bfceb6aa2f564b12519e32b679ee08 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
const debounce = (func, waitTime) => { | |
let startTime; | |
let timeoutId; | |
let isWorking = () => { | |
return timeoutId && startTime + waitTime > Date.now(); | |
} | |
return () => { | |
if (isWorking()) { | |
clearInterval(timeoutId); | |
} | |
startTime = Date.now(); | |
timeoutId = setTimeout(() => { | |
func.apply(this, arguments); | |
}, waitTime); | |
} | |
} | |
export { | |
Debounce | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The arguments you are sending the callback are not available in setTimeout(). This should solve this:
😸