kopia lustrzana https://github.com/nolanlawson/pinafore
19 wiersze
389 B
JavaScript
19 wiersze
389 B
JavaScript
// ensure callback is only executed once per raf
|
|
export const throttleRaf = () => {
|
|
let rafCallback
|
|
let rafQueued
|
|
|
|
return function throttledRaf (callback) {
|
|
rafCallback = callback
|
|
if (!rafQueued) {
|
|
rafQueued = true
|
|
requestAnimationFrame(() => {
|
|
const cb = rafCallback
|
|
rafCallback = null
|
|
rafQueued = false
|
|
cb()
|
|
})
|
|
}
|
|
}
|
|
}
|