Created
March 17, 2022 21:07
-
-
Save giventofly/182137bd1d99fee9549b0ff15ef4e69c to your computer and use it in GitHub Desktop.
debounce javascript
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
//search decks | |
document.getElementById("decktosearch").addEventListener("keyup", debounceSearchDeck); | |
const debounce = (callback, wait) => { | |
let timeoutId = null; | |
return (...args) => { | |
window.clearTimeout(timeoutId); | |
timeoutId = window.setTimeout(() => { | |
callback.apply(null, args); | |
}, wait); | |
}; | |
} | |
const debounceSearchDeck = debounce((e) =>{ | |
searchDeck(e.target.value); | |
}, 500); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment