Skip to content

Instantly share code, notes, and snippets.

@maxnordlund
Last active August 22, 2016 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxnordlund/d9220154a582cd87c7f1876092d1eee8 to your computer and use it in GitHub Desktop.
Save maxnordlund/d9220154a582cd87c7f1876092d1eee8 to your computer and use it in GitHub Desktop.
A nano framework for synchronized DOM updates
(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)
})()
@maxnordlund
Copy link
Author

Compatible with something like IE5, or when then added setTimeout. That is also why I need to double check console.error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment