UNPKG

rambdax

Version:

Extended version of Rambda - a lightweight, faster alternative to Ramda

21 lines (19 loc) 403 B
export function debounce( func, ms, immediate = false ){ let timeout return function (...input){ const later = function (){ timeout = null if (!immediate){ return func.apply(null, input) } } const callNow = immediate && !timeout clearTimeout(timeout) timeout = setTimeout(later, ms) if (callNow){ return func.apply(null, input) } } }