Skip to content

Instantly share code, notes, and snippets.

@nuxodin nuxodin/dom read write.js

Last active Oct 8, 2019
Embed
What would you like to do?
/*
if (!window.requestPostAnimationFrame) {
window.requestPostAnimationFrame = function(callback){
requestAnimationFrame(function(){
setTimeout(callback)
})
}
}
*/
writeStack = [];
write = function(callback){
if (!writeStack.length) requestAnimationFrame(handleWriteStack);
writeStack.push(callback);
}
handleWriteStack = function(){
while (writeStack.length) writeStack.pop()();
}
readStack = [];
read = function(callback){
//if (!readStack.length) requestPostAnimationFrame(handleReadStack);
if (!readStack.length) setTimeout(handleReadStack);
readStack.push(callback);
}
handleReadStack = function(){
while (readStack.length) readStack.pop()();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.