don't swallow redraws

This commit is contained in:
Leo Horie 2016-06-30 23:46:47 -04:00
parent 88b91b1073
commit 9afefe0fd7
2 changed files with 26 additions and 2 deletions

View file

@ -74,11 +74,35 @@ o.spec("throttle", function() {
}, FRAME_BUDGET) }, FRAME_BUDGET)
}) })
o("it supports forcing a synchronous redraw", function() { o("it supports forcing a synchronous redraw", function(done) {
throttled() throttled()
throttled() throttled()
throttled(true) throttled(true)
o(spy.callCount).equals(2) 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)
}) })
}) })

View file

@ -13,7 +13,7 @@ module.exports = function(callback) {
} }
else if (pending === null) { else if (pending === null) {
pending = timeout(function() { pending = timeout(function() {
pending = 0 pending = null
callback() callback()
last = new Date().getTime() last = new Date().getTime()
}, time - (now - last)) }, time - (now - last))