AnimationFrameAction.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. }
  9. return function (d, b) {
  10. extendStatics(d, b);
  11. function __() { this.constructor = d; }
  12. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13. };
  14. })();
  15. Object.defineProperty(exports, "__esModule", { value: true });
  16. var AsyncAction_1 = require("./AsyncAction");
  17. var AnimationFrameAction = (function (_super) {
  18. __extends(AnimationFrameAction, _super);
  19. function AnimationFrameAction(scheduler, work) {
  20. var _this = _super.call(this, scheduler, work) || this;
  21. _this.scheduler = scheduler;
  22. _this.work = work;
  23. return _this;
  24. }
  25. AnimationFrameAction.prototype.requestAsyncId = function (scheduler, id, delay) {
  26. if (delay === void 0) { delay = 0; }
  27. if (delay !== null && delay > 0) {
  28. return _super.prototype.requestAsyncId.call(this, scheduler, id, delay);
  29. }
  30. scheduler.actions.push(this);
  31. return scheduler.scheduled || (scheduler.scheduled = requestAnimationFrame(function () { return scheduler.flush(null); }));
  32. };
  33. AnimationFrameAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
  34. if (delay === void 0) { delay = 0; }
  35. if ((delay !== null && delay > 0) || (delay === null && this.delay > 0)) {
  36. return _super.prototype.recycleAsyncId.call(this, scheduler, id, delay);
  37. }
  38. if (scheduler.actions.length === 0) {
  39. cancelAnimationFrame(id);
  40. scheduler.scheduled = undefined;
  41. }
  42. return undefined;
  43. };
  44. return AnimationFrameAction;
  45. }(AsyncAction_1.AsyncAction));
  46. exports.AnimationFrameAction = AnimationFrameAction;
  47. //# sourceMappingURL=AnimationFrameAction.js.map