debounce.js 361 B

123456789101112131415161718
  1. export const _debounce = (func, waitFor) => {
  2. let timeout = null
  3. const debounceFunction = (...args) => {
  4. if (timeout) {
  5. clearTimeout(timeout)
  6. timeout = null
  7. }
  8. timeout = setTimeout(() => {
  9. return func(...args)
  10. }, waitFor)
  11. }
  12. return debounceFunction
  13. }
  14. export const debounce = _debounce((func, args) => func(args), 400)