Last active
August 22, 2016 21:03
-
-
Save maxnordlund/d9220154a582cd87c7f1876092d1eee8 to your computer and use it in GitHub Desktop.
A nano framework for synchronized DOM updates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var consoleError, | |
renderLoop, | |
queue = [], | |
rAF = window.requestAnimationFrame || function(fn) { | |
setTimeout(fn, 0) | |
} | |
if (typeof console === "object" && | |
typeof console.error === "function") { | |
consoleError = function(error) { | |
console.error(error) | |
} | |
} else { | |
consoleError = function() {} | |
} | |
window.enqueue = function(fn) { | |
queue[queue.length] = fn | |
} | |
renderLoop = function() { | |
var error, i | |
rAF(renderLoop) | |
for (i = 0; i < queue.length; ++i) try { | |
queue[i]() | |
} catch(error) { | |
consoleError(error) | |
} | |
queue = [] | |
} | |
rAF(renderLoop) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compatible with something like IE5, or when then added
setTimeout
. That is also why I need to double checkconsole.error
.