budibase/packages/client/src/utils/domDebounce.js

15 lines
321 B
JavaScript
Raw Normal View History

export const domDebounce = (callback, extractParams = x => x) => {
let active = false
let lastParams
return (...params) => {
lastParams = extractParams(...params)
if (!active) {
active = true
requestAnimationFrame(() => {
callback(lastParams)
active = false
})
}
}
}