mirror of
https://github.com/Polymer/polymer.git
synced 2025-02-25 18:55:30 -06:00
move src -> lib
This commit is contained in:
120
lib/utils/render-status.html
Normal file
120
lib/utils/render-status.html
Normal file
@@ -0,0 +1,120 @@
|
||||
<!--
|
||||
@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) {
|
||||
while (queue.length) {
|
||||
const q = queue.shift();
|
||||
const context = q[0];
|
||||
const callback = q[1];
|
||||
const args = q[2];
|
||||
try {
|
||||
callback.apply(context, args);
|
||||
} catch(e) {
|
||||
setTimeout(() => {
|
||||
throw e;
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function flush() {
|
||||
while (beforeRenderQueue.length || afterRenderQueue.length) {
|
||||
flushQueue(beforeRenderQueue);
|
||||
flushQueue(afterRenderQueue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Module for scheduling flushable pre-render and post-render tasks.
|
||||
*
|
||||
* @namespace
|
||||
* @memberof Polymer
|
||||
* @summary Module for scheduling flushable pre-render and post-render tasks.
|
||||
*/
|
||||
Polymer.RenderStatus = {
|
||||
|
||||
/**
|
||||
* Enqueues a callback which will be run before the next render, at
|
||||
* `requestAnimationFrame` timing.
|
||||
*
|
||||
* This method is useful for enqueuing work that requires DOM measurement,
|
||||
* since measurement may not be reliable in custom element callbacks before
|
||||
* the first render, as well as for batching measurement tasks in general.
|
||||
*
|
||||
* Tasks in this queue may be flushed by calling `Polymer.RenderStatus.flush()`.
|
||||
*
|
||||
* @memberof Polymer.RenderStatus
|
||||
* @param {*} context Context object the callback function will be bound to
|
||||
* @param {function} callback Callback function
|
||||
* @param {Array} args An array of arguments to call the callback function with
|
||||
*/
|
||||
beforeNextRender: function(context, callback, args) {
|
||||
if (!scheduled) {
|
||||
schedule();
|
||||
}
|
||||
beforeRenderQueue.push([context, callback, args]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Enqueues a callback which will be run after the next render, equivalent
|
||||
* to one task (`setTimeout`) after the next `requestAnimationFrame`.
|
||||
*
|
||||
* This method is useful for tuning the first-render performance of an
|
||||
* element or application by deferring non-critical work until after the
|
||||
* first paint. Typical non-render-critical work may include adding UI
|
||||
* event listeners and aria attributes.
|
||||
*
|
||||
* @memberof Polymer.RenderStatus
|
||||
* @param {*} context Context object the callback function will be bound to
|
||||
* @param {function} callback Callback function
|
||||
* @param {Array} args An array of arguments to call the callback function with
|
||||
*/
|
||||
afterNextRender: function(context, callback, args) {
|
||||
if (!scheduled) {
|
||||
schedule();
|
||||
}
|
||||
afterRenderQueue.push([context, callback, args]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Flushes all `beforeNextRender` tasks, followed by all `afterNextRender`
|
||||
* tasks.
|
||||
*
|
||||
* @memberof Polymer.RenderStatus
|
||||
*/
|
||||
flush: flush
|
||||
|
||||
};
|
||||
|
||||
})();
|
||||
</script>
|
||||
Reference in New Issue
Block a user