Bug 1235286 - Part 1: Add an argument to waitForAnimationFrames to run a task in each requestAnimationFrame callback. r=birtles

--HG--
extra : transplant_source : %AF%A0%20%B8%D7%3A%7F%C2_y%0A%82%88w%5E%95%8D%17%EA%EF
This commit is contained in:
Hiroyuki Ikezoe 2016-01-08 09:49:04 +09:00
parent 5f6447339c
commit cf03d3bfaf

View File

@ -41,13 +41,19 @@ function waitForFrame() {
/**
* Returns a Promise that is resolved after the given number of consecutive
* animation frames have occured (using requestAnimationFrame callbacks).
*
* @param frameCount The number of animation frames.
* @param onFrame An optional function to be processed in each animation frame.
*/
function waitForAnimationFrames(frameCount) {
function waitForAnimationFrames(frameCount, onFrame) {
return new Promise(function(resolve, reject) {
function handleFrame() {
if (--frameCount <= 0) {
resolve();
} else {
if (onFrame && typeof onFrame === 'function') {
onFrame();
}
window.requestAnimationFrame(handleFrame); // wait another frame
}
}