mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-24 23:20:34 +03:00
Merge pull request #22 from declandewet/batchupdate-fallback
batchupdate fallback to setTimeout
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
// fallback to timers if rAF not present
|
||||||
|
const stopUpdate = window.cancelAnimationFrame || window.clearTimeout
|
||||||
|
const startUpdate = window.requestAnimationFrame || ((cb) => window.setTimeout(cb, 0))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs a batched update. Uses requestAnimationFrame to prevent
|
* Performs a batched update. Uses requestAnimationFrame to prevent
|
||||||
* calling a function too many times in quick succession.
|
* calling a function too many times in quick succession.
|
||||||
@@ -9,8 +13,8 @@
|
|||||||
* @return {Number} id - a new ID
|
* @return {Number} id - a new ID
|
||||||
*/
|
*/
|
||||||
export default function batchUpdate (id, callback) {
|
export default function batchUpdate (id, callback) {
|
||||||
window.cancelAnimationFrame(id)
|
stopUpdate(id)
|
||||||
return window.requestAnimationFrame(() => {
|
return startUpdate(() => {
|
||||||
id = null
|
id = null
|
||||||
callback()
|
callback()
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user