* @return {function(function())} requestAnimationFrame or polyfill.
()
| 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 | /** |