MCPcopy Create free account
hub / github.com/ampproject/amphtml / getRaf_

Method getRaf_

src/service/vsync-impl.js:429–444  ·  view source on GitHub ↗

* @return {function(function())} requestAnimationFrame or polyfill.

()

Source from the content-addressed store, hash-verified

427 * @return {function(function())} requestAnimationFrame or polyfill.
428 */
429 getRaf_() {
430 const raf =
431 this.win.requestAnimationFrame || this.win.webkitRequestAnimationFrame;
432 if (raf) {
433 return raf.bind(this.win);
434 }
435 let lastTime = 0;
436 return (fn) => {
437 const now = Date.now();
438 // By default we take 16ms between frames, but if the last frame is say
439 // 10ms ago, we only want to wait 6ms.
440 const timeToCall = Math.max(0, FRAME_TIME - (now - lastTime));
441 lastTime = now + timeToCall;
442 this.win.setTimeout(fn, timeToCall);
443 };
444 }
445}
446
447/**

Callers 1

constructorMethod · 0.95

Calls 1

nowMethod · 0.80

Tested by

no test coverage detected