Files
polymer/src/utils/render-status.html

81 lines
1.9 KiB
HTML
Raw Normal View History

<!--
@license
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="boot.html">
<script>
(function() {
'use strict';
let scheduled = false;
let beforeRenderQueue = [];
let afterRenderQueue = [];
function schedule() {
scheduled = true;
// before next render
requestAnimationFrame(function() {
scheduled = false;
flushQueue(beforeRenderQueue);
// after the render
setTimeout(function() {
flushQueue(afterRenderQueue);
});
});
}
function flushQueue(queue) {
for (let i=0, q, context, callback, args; i<queue.length; i++) {
try {
q = queue[i];
context = q[0];
callback = q[1];
args = q[2];
callback.apply(context, args);
} catch(e) {
setTimeout(() => {
throw e;
})
}
}
queue.length = 0;
}
function flush() {
flushQueue(beforeRenderQueue);
flushQueue(afterRenderQueue);
if (beforeRenderQueue.length || afterRenderQueue.length) {
flush();
}
}
2017-02-15 21:13:46 -08:00
Polymer.RenderStatus = {
beforeNextRender: function(context, callback, args) {
if (!scheduled) {
schedule();
}
2017-02-21 12:08:48 -08:00
beforeRenderQueue.push([context, callback, args]);
},
afterNextRender: function(context, callback, args) {
if (!scheduled) {
schedule();
}
2017-02-21 12:08:48 -08:00
afterRenderQueue.push([context, callback, args]);
},
flush: flush
};
})();
</script>