Created
March 30, 2019 19:40
-
-
Save jonasraoni/4919f9e1698e77a5b675eb9375e46c8d to your computer and use it in GitHub Desktop.
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
//+ Jonas Raoni Soares Silva | |
//@ http://raoni.org | |
export default function debounce (action, delay) { | |
let handle; | |
return function (...args) { | |
if (handle) { | |
clearTimeout(handle); | |
handle = null; | |
} | |
handle = setTimeout(() => action.call(this, ...args), delay); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment