From 926010450b824df8429a26a92f7413bc78fbea37 Mon Sep 17 00:00:00 2001 From: Declan de Wet Date: Wed, 16 Nov 2016 23:01:15 +0200 Subject: [PATCH] batchupdate fallback to setTimeout --- src/client/batchUpdate.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/client/batchUpdate.js b/src/client/batchUpdate.js index f3525b0..c1e2c9d 100644 --- a/src/client/batchUpdate.js +++ b/src/client/batchUpdate.js @@ -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 * calling a function too many times in quick succession. @@ -9,8 +13,8 @@ * @return {Number} id - a new ID */ export default function batchUpdate (id, callback) { - window.cancelAnimationFrame(id) - return window.requestAnimationFrame(() => { + stopUpdate(id) + return startUpdate(() => { id = null callback() })