flush without recursion

This commit is contained in:
Steven Orvell 2017-02-27 10:20:48 -08:00
parent f20cc83f7f
commit ae34824c94

View File

@ -32,12 +32,12 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
}
function flushQueue(queue) {
for (let i=0, q, context, callback, args; i<queue.length; i++) {
while (queue.length) {
const q = queue.shift();
const context = q[0];
const callback = q[1];
const args = q[2];
try {
q = queue[i];
context = q[0];
callback = q[1];
args = q[2];
callback.apply(context, args);
} catch(e) {
setTimeout(() => {
@ -45,14 +45,12 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
})
}
}
queue.length = 0;
}
function flush() {
flushQueue(beforeRenderQueue);
flushQueue(afterRenderQueue);
if (beforeRenderQueue.length || afterRenderQueue.length) {
flush();
while (beforeRenderQueue.length || afterRenderQueue.length) {
flushQueue(beforeRenderQueue);
flushQueue(afterRenderQueue);
}
}