Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81158 views
1
/**
2
* Copyright 2014, Facebook, Inc.
3
* All rights reserved.
4
*
5
* This source code is licensed under the BSD-style license found in the
6
* LICENSE file in the root directory of this source tree. An additional grant
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
* @providesModule requestAnimationFrame
10
*/
11
12
var emptyFunction = require('emptyFunction');
13
var nativeRequestAnimationFrame = require('nativeRequestAnimationFrame');
14
15
var lastTime = 0;
16
17
var requestAnimationFrame =
18
nativeRequestAnimationFrame ||
19
function(callback) {
20
var currTime = Date.now();
21
var timeDelay = Math.max(0, 16 - (currTime - lastTime));
22
lastTime = currTime + timeDelay;
23
return global.setTimeout(function() {
24
callback(Date.now());
25
}, timeDelay);
26
};
27
28
// Works around a rare bug in Safari 6 where the first request is never invoked.
29
requestAnimationFrame(emptyFunction);
30
31
module.exports = requestAnimationFrame;
32
33