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

67 lines
1.5 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; i<queue.length; i++) {
try {
queue[i]();
} catch(e) {
setTimeout(() => {
throw e;
})
}
}
queue.length = 0;
}
2017-02-15 21:13:46 -08:00
Polymer.RenderStatus = {
beforeNextRender: function(cb) {
if (!scheduled) {
schedule();
}
beforeRenderQueue.push(cb);
},
afterNextRender: function(cb) {
if (!scheduled) {
schedule();
}
afterRenderQueue.push(cb);
}
};
})();
</script>