Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

repeat.js 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 Subscriber_1 = require("../Subscriber");
  17. var empty_1 = require("../observable/empty");
  18. function repeat(count) {
  19. if (count === void 0) { count = -1; }
  20. return function (source) {
  21. if (count === 0) {
  22. return empty_1.empty();
  23. }
  24. else if (count < 0) {
  25. return source.lift(new RepeatOperator(-1, source));
  26. }
  27. else {
  28. return source.lift(new RepeatOperator(count - 1, source));
  29. }
  30. };
  31. }
  32. exports.repeat = repeat;
  33. var RepeatOperator = (function () {
  34. function RepeatOperator(count, source) {
  35. this.count = count;
  36. this.source = source;
  37. }
  38. RepeatOperator.prototype.call = function (subscriber, source) {
  39. return source.subscribe(new RepeatSubscriber(subscriber, this.count, this.source));
  40. };
  41. return RepeatOperator;
  42. }());
  43. var RepeatSubscriber = (function (_super) {
  44. __extends(RepeatSubscriber, _super);
  45. function RepeatSubscriber(destination, count, source) {
  46. var _this = _super.call(this, destination) || this;
  47. _this.count = count;
  48. _this.source = source;
  49. return _this;
  50. }
  51. RepeatSubscriber.prototype.complete = function () {
  52. if (!this.isStopped) {
  53. var _a = this, source = _a.source, count = _a.count;
  54. if (count === 0) {
  55. return _super.prototype.complete.call(this);
  56. }
  57. else if (count > -1) {
  58. this.count = count - 1;
  59. }
  60. source.subscribe(this._unsubscribeAndRecycle());
  61. }
  62. };
  63. return RepeatSubscriber;
  64. }(Subscriber_1.Subscriber));
  65. //# sourceMappingURL=repeat.js.map