var NOOP = require('../utils/NOOP'); var RequestAnimationFrame = function (){ this.isRunning = false ; this.callback = NOOP; this.tick = 0; this.isSetTimeOut = false ; this.timeOutID = null ; var _this = this; var step = function (timestamp){ _this.tick = timestamp; _this.callback(timestamp); _this.timeOutID = window.requestAnimationFrame(step); } ; var stepTimeout = function (){ var d = Date.now(); _this.tick = d; _this.callback(d); _this.timeOutID = _AN_Call_settimeout('setTimeout', window, stepTimeout, _this.timeToCall); } ; this.step = step; this.stepTimeout = stepTimeout; } ; RequestAnimationFrame.prototype.constructor = RequestAnimationFrame; RequestAnimationFrame.prototype = { start: function (callback, forceSetTimeOut){ this.callback = callback; this.isSetTimeOut = forceSetTimeOut; this.isRunning = true ; var _this = this; this.timeOutID = (forceSetTimeOut)? _AN_Call_settimeout('setTimeout', window, _this.stepTimeout, 0): window.requestAnimationFrame(_this.step); } , stop: function (){ this.isRunning = false ; if (this.isSetTimeOut) { clearTimeout(this.timeOutID); } else { window.cancelAnimationFrame(this.timeOutID); } } , destroy: function (){ this.stop(); this.callback = NOOP; } } ; module.exports = RequestAnimationFrame;