13 lines
341 B
JavaScript
13 lines
341 B
JavaScript
|
// Returns a function, that, as long as it continues to be invoked, will not
|
||
|
// be triggered. The function will be called after it stops being called for
|
||
|
// N milliseconds.
|
||
|
function debounce(fn, wait) {
|
||
|
let timeout
|
||
|
|
||
|
return (...args) => {
|
||
|
clearTimeout(timeout)
|
||
|
timeout = setTimeout(() => fn(...args), wait)
|
||
|
}
|
||
|
}
|
||
|
export default debounce
|