repod/src/utils/debounce.js

13 lines
276 B
JavaScript
Raw Normal View History

2023-07-27 23:57:37 +00:00
// https://stackoverflow.com/a/53486112
export const debounce = (fn, delay) => {
2023-07-25 23:26:46 +00:00
let timeoutID = null
return function () {
2023-07-25 23:26:46 +00:00
clearTimeout(timeoutID)
const args = arguments
const that = this
timeoutID = setTimeout(function () {
2023-07-25 23:26:46 +00:00
fn.apply(that, args)
}, delay)
}
}