animationFrameProvider.js 1.1 KB

123456789101112131415161718192021222324252627
  1. import { Subscription } from '../Subscription';
  2. export const animationFrameProvider = {
  3. schedule(callback) {
  4. let request = requestAnimationFrame;
  5. let cancel = cancelAnimationFrame;
  6. const { delegate } = animationFrameProvider;
  7. if (delegate) {
  8. request = delegate.requestAnimationFrame;
  9. cancel = delegate.cancelAnimationFrame;
  10. }
  11. const handle = request((timestamp) => {
  12. cancel = undefined;
  13. callback(timestamp);
  14. });
  15. return new Subscription(() => cancel === null || cancel === void 0 ? void 0 : cancel(handle));
  16. },
  17. requestAnimationFrame(...args) {
  18. const { delegate } = animationFrameProvider;
  19. return ((delegate === null || delegate === void 0 ? void 0 : delegate.requestAnimationFrame) || requestAnimationFrame)(...args);
  20. },
  21. cancelAnimationFrame(...args) {
  22. const { delegate } = animationFrameProvider;
  23. return ((delegate === null || delegate === void 0 ? void 0 : delegate.cancelAnimationFrame) || cancelAnimationFrame)(...args);
  24. },
  25. delegate: undefined,
  26. };
  27. //# sourceMappingURL=animationFrameProvider.js.map