2023-02-25 17:33:20 +01:00
|
|
|
export const domDebounce = (callback, extractParams = x => x) => {
|
2021-06-10 10:05:08 +02:00
|
|
|
let active = false
|
2023-02-25 17:33:20 +01:00
|
|
|
let lastParams
|
|
|
|
return (...params) => {
|
|
|
|
lastParams = extractParams(...params)
|
2021-06-10 10:05:08 +02:00
|
|
|
if (!active) {
|
2023-02-25 17:33:20 +01:00
|
|
|
active = true
|
|
|
|
requestAnimationFrame(() => {
|
|
|
|
callback(lastParams)
|
2021-06-10 10:05:08 +02:00
|
|
|
active = false
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|