You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

28 lines
797 B

  1. 'use strict';
  2. /**
  3. * Copyright (c) 2014-present, Facebook, Inc.
  4. *
  5. * This source code is licensed under the MIT license found in the
  6. * LICENSE file in the root directory of this source tree.
  7. *
  8. */
  9. var emptyFunction = require('./emptyFunction');
  10. var nativeRequestAnimationFrame = require('./nativeRequestAnimationFrame');
  11. var lastTime = 0;
  12. var requestAnimationFrame = nativeRequestAnimationFrame || function (callback) {
  13. var currTime = Date.now();
  14. var timeDelay = Math.max(0, 16 - (currTime - lastTime));
  15. lastTime = currTime + timeDelay;
  16. return global.setTimeout(function () {
  17. callback(Date.now());
  18. }, timeDelay);
  19. };
  20. // Works around a rare bug in Safari 6 where the first request is never invoked.
  21. requestAnimationFrame(emptyFunction);
  22. module.exports = requestAnimationFrame;