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

windowCount.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 Subject_1 = require("../Subject");
  18. function windowCount(windowSize, startWindowEvery) {
  19. if (startWindowEvery === void 0) { startWindowEvery = 0; }
  20. return function windowCountOperatorFunction(source) {
  21. return source.lift(new WindowCountOperator(windowSize, startWindowEvery));
  22. };
  23. }
  24. exports.windowCount = windowCount;
  25. var WindowCountOperator = (function () {
  26. function WindowCountOperator(windowSize, startWindowEvery) {
  27. this.windowSize = windowSize;
  28. this.startWindowEvery = startWindowEvery;
  29. }
  30. WindowCountOperator.prototype.call = function (subscriber, source) {
  31. return source.subscribe(new WindowCountSubscriber(subscriber, this.windowSize, this.startWindowEvery));
  32. };
  33. return WindowCountOperator;
  34. }());
  35. var WindowCountSubscriber = (function (_super) {
  36. __extends(WindowCountSubscriber, _super);
  37. function WindowCountSubscriber(destination, windowSize, startWindowEvery) {
  38. var _this = _super.call(this, destination) || this;
  39. _this.destination = destination;
  40. _this.windowSize = windowSize;
  41. _this.startWindowEvery = startWindowEvery;
  42. _this.windows = [new Subject_1.Subject()];
  43. _this.count = 0;
  44. destination.next(_this.windows[0]);
  45. return _this;
  46. }
  47. WindowCountSubscriber.prototype._next = function (value) {
  48. var startWindowEvery = (this.startWindowEvery > 0) ? this.startWindowEvery : this.windowSize;
  49. var destination = this.destination;
  50. var windowSize = this.windowSize;
  51. var windows = this.windows;
  52. var len = windows.length;
  53. for (var i = 0; i < len && !this.closed; i++) {
  54. windows[i].next(value);
  55. }
  56. var c = this.count - windowSize + 1;
  57. if (c >= 0 && c % startWindowEvery === 0 && !this.closed) {
  58. windows.shift().complete();
  59. }
  60. if (++this.count % startWindowEvery === 0 && !this.closed) {
  61. var window_1 = new Subject_1.Subject();
  62. windows.push(window_1);
  63. destination.next(window_1);
  64. }
  65. };
  66. WindowCountSubscriber.prototype._error = function (err) {
  67. var windows = this.windows;
  68. if (windows) {
  69. while (windows.length > 0 && !this.closed) {
  70. windows.shift().error(err);
  71. }
  72. }
  73. this.destination.error(err);
  74. };
  75. WindowCountSubscriber.prototype._complete = function () {
  76. var windows = this.windows;
  77. if (windows) {
  78. while (windows.length > 0 && !this.closed) {
  79. windows.shift().complete();
  80. }
  81. }
  82. this.destination.complete();
  83. };
  84. WindowCountSubscriber.prototype._unsubscribe = function () {
  85. this.count = 0;
  86. this.windows = null;
  87. };
  88. return WindowCountSubscriber;
  89. }(Subscriber_1.Subscriber));
  90. //# sourceMappingURL=windowCount.js.map