From 9afefe0fd75110f81b1c07ff33766774ae548adb Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Thu, 30 Jun 2016 23:46:47 -0400 Subject: [PATCH] don't swallow redraws --- api/tests/test-throttle.js | 26 +++++++++++++++++++++++++- api/throttle.js | 2 +- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/api/tests/test-throttle.js b/api/tests/test-throttle.js index 1077802f..0663f98e 100644 --- a/api/tests/test-throttle.js +++ b/api/tests/test-throttle.js @@ -74,11 +74,35 @@ o.spec("throttle", function() { }, FRAME_BUDGET) }) - o("it supports forcing a synchronous redraw", function() { + o("it supports forcing a synchronous redraw", function(done) { throttled() throttled() throttled(true) o(spy.callCount).equals(2) + + setTimeout(function() { + o(spy.callCount).equals(3) + + done() + }, FRAME_BUDGET) + }) + + o("it doesn't swallow redraws", function(done, timeout) { + timeout(60) + + throttled() + + setTimeout(function() { + throttled() + setTimeout(function() { + throttled() + setTimeout(function() { + o(spy.callCount).equals(3) + + done() + }, FRAME_BUDGET) + }, 0) + }, 0) }) }) diff --git a/api/throttle.js b/api/throttle.js index edc2e4bc..cd4f4470 100644 --- a/api/throttle.js +++ b/api/throttle.js @@ -13,7 +13,7 @@ module.exports = function(callback) { } else if (pending === null) { pending = timeout(function() { - pending = 0 + pending = null callback() last = new Date().getTime() }, time - (now - last))