all files / src/util/ raf.js

63.64% Statements 7/11
25% Branches 4/16
40% Functions 2/5
63.64% Lines 7/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35                                                       
import { inBrowser } from './env'
 
const DEFAULT_INTERVAL = 100 / 60
 
function noop() {
}
 
export const requestAnimationFrame = (() => {
  Iif (!inBrowser) {
    /* istanbul ignore if */
    return noop
  }
  return window.requestAnimationFrame ||
    window.webkitRequestAnimationFrame ||
    window.mozRequestAnimationFrame ||
    window.oRequestAnimationFrame ||
    // if all else fails, use setTimeout
    function (callback) {
      return window.setTimeout(callback, (callback.interval || DEFAULT_INTERVAL) / 2) // make interval as precise as possible.
    }
})()
 
export const cancelAnimationFrame = (() => {
  Iif (!inBrowser) {
    /* istanbul ignore if */
    return noop
  }
  return window.cancelAnimationFrame ||
    window.webkitCancelAnimationFrame ||
    window.mozCancelAnimationFrame ||
    window.oCancelAnimationFrame ||
    function (id) {
      window.clearTimeout(id)
    }
})()