src/utils.js
function debounce(fn, time) {
  let timeoutId

  function cancel() {
    if (timeoutId) {
      clearTimeout(timeoutId)
    }
  }

  function wrapper(...args) {
    cancel()
    timeoutId = setTimeout(() => {
      timeoutId = null
      fn(...args)
    }, time)
  }

  wrapper.cancel = cancel

  return wrapper
}
function debounce(fn, time) {
  let timeoutId

  function cancel() {
    if (timeoutId) {
      clearTimeout(timeoutId)
    }
  }

  function wrapper(...args) {
    cancel()
    timeoutId = setTimeout(() => {
      timeoutId = null
      fn(...args)
    }, time)
  }

  wrapper.cancel = cancel

  return wrapper
}
function debounce ( fn , time ) { let timeoutId function cancel ( ) { if ( timeoutId ) { clearTimeout ( timeoutId ) } } function wrapper ( ... args ) { cancel ( ) timeoutId = setTimeout ( ( ) => { timeoutId = null fn ( ... args ) } , time ) } wrapper . cancel = cancel return wrapper }
Simple debounce implementation. Will call the given
function once after the time given has passed since
it was last called.
@param {Function} fn the function to call after the time
@param {Number} time the time to wait
@return {Function} the debounced function
Simple debounce implementation . Will call the given function once after the time given has passed since it was last called .