Add forcing support and improve tests

Also verify that we're using tabs, whee.
This commit is contained in:
Pat Cavit 2016-05-18 23:08:35 -07:00 committed by Pat Cavit
parent 86ce23a2bd
commit 0cf509f674
3 changed files with 104 additions and 29 deletions

View file

@ -5,22 +5,23 @@ module.exports = function($window, render) {
var cAF = $window.cancelAnimationFrame || $window.clearTimeout
var last = 0
var pending
var pending = null
return function() {
return function(force) {
var now = new Date()
// First render, OR if the time since the last render is greater
// than the frame budget
// just immediately render
if(!last || now - last > FRAME_BUDGET) {
// Immediately render if:
// Forced
// Haven't rendered yet
// Time since the last render is greater than the frame budget
if(force || !last || now - last > FRAME_BUDGET) {
last = now;
return render()
}
// Redraw already pending, abort
if(pending) {
if(pending !== null) {
return
}