animationFrames.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.animationFrames = void 0;
  4. var Observable_1 = require("../../Observable");
  5. var performanceTimestampProvider_1 = require("../../scheduler/performanceTimestampProvider");
  6. var animationFrameProvider_1 = require("../../scheduler/animationFrameProvider");
  7. function animationFrames(timestampProvider) {
  8. return timestampProvider ? animationFramesFactory(timestampProvider) : DEFAULT_ANIMATION_FRAMES;
  9. }
  10. exports.animationFrames = animationFrames;
  11. function animationFramesFactory(timestampProvider) {
  12. return new Observable_1.Observable(function (subscriber) {
  13. var provider = timestampProvider || performanceTimestampProvider_1.performanceTimestampProvider;
  14. var start = provider.now();
  15. var id = 0;
  16. var run = function () {
  17. if (!subscriber.closed) {
  18. id = animationFrameProvider_1.animationFrameProvider.requestAnimationFrame(function (timestamp) {
  19. id = 0;
  20. var now = provider.now();
  21. subscriber.next({
  22. timestamp: timestampProvider ? now : timestamp,
  23. elapsed: now - start,
  24. });
  25. run();
  26. });
  27. }
  28. };
  29. run();
  30. return function () {
  31. if (id) {
  32. animationFrameProvider_1.animationFrameProvider.cancelAnimationFrame(id);
  33. }
  34. };
  35. });
  36. }
  37. var DEFAULT_ANIMATION_FRAMES = animationFramesFactory();
  38. //# sourceMappingURL=animationFrames.js.map