{ const next = () => { throt…">ThrottlingAndAntiShaking - Saber2pr's Blog
Saber2pr's Blog

ThrottlingAndAntiShaking

Throttling

const throttle = (callback, delta = 500, id = "default") => {
  const next = () => {
    throttle[id] = Date.now() + delta
  }
  throttle[id] || next()
  if (Date.now() > throttle[id]) {
    next()
    callback()
  }
}

Anti-shaking

const debounce = (callback, delta = 300, id = "default") => {
  clearTimeout(debounce[id])
  debounce[id] = setTimeout(callback, delta)
}