quasar
Version:
Build high-performance VueJS user interfaces (SPA, PWA, SSR, Mobile and Desktop) in record time
25 lines (20 loc) • 445 B
JavaScript
export default function frameDebounce(fn) {
let wait = false,
frame,
callArgs
function debounced(/* ...args */) {
callArgs = arguments
if (wait === true) return
wait = true
frame = window.requestAnimationFrame(() => {
fn.apply(this, callArgs)
callArgs = void 0
wait = false
})
}
debounced.cancel = () => {
window.cancelAnimationFrame(frame)
wait = false
}
return debounced
}