From d542b60d6b2ddcfc0cc9b90ac2c894719bbf0945 Mon Sep 17 00:00:00 2001 From: Declan de Wet Date: Wed, 16 Nov 2016 23:37:33 +0200 Subject: [PATCH] fix regression introduced in #22 --- src/client/batchUpdate.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/client/batchUpdate.js b/src/client/batchUpdate.js index c1e2c9dd..82dc42db 100644 --- a/src/client/batchUpdate.js +++ b/src/client/batchUpdate.js @@ -1,7 +1,3 @@ -// 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. @@ -13,7 +9,14 @@ const startUpdate = window.requestAnimationFrame || ((cb) => window.setTimeout(c * @return {Number} id - a new ID */ export default function batchUpdate (id, callback) { + // fallback to timers if rAF not present + const stopUpdate = window.cancelAnimationFrame || window.clearTimeout + const startUpdate = window.requestAnimationFrame || ((cb) => window.setTimeout(cb, 0)) + + // stop any existing updates stopUpdate(id) + + // perform an update return startUpdate(() => { id = null callback()