Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bufferCount.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. function bufferCount(bufferSize, startBufferEvery) {
  18. if (startBufferEvery === void 0) { startBufferEvery = null; }
  19. return function bufferCountOperatorFunction(source) {
  20. return source.lift(new BufferCountOperator(bufferSize, startBufferEvery));
  21. };
  22. }
  23. exports.bufferCount = bufferCount;
  24. var BufferCountOperator = (function () {
  25. function BufferCountOperator(bufferSize, startBufferEvery) {
  26. this.bufferSize = bufferSize;
  27. this.startBufferEvery = startBufferEvery;
  28. if (!startBufferEvery || bufferSize === startBufferEvery) {
  29. this.subscriberClass = BufferCountSubscriber;
  30. }
  31. else {
  32. this.subscriberClass = BufferSkipCountSubscriber;
  33. }
  34. }
  35. BufferCountOperator.prototype.call = function (subscriber, source) {
  36. return source.subscribe(new this.subscriberClass(subscriber, this.bufferSize, this.startBufferEvery));
  37. };
  38. return BufferCountOperator;
  39. }());
  40. var BufferCountSubscriber = (function (_super) {
  41. __extends(BufferCountSubscriber, _super);
  42. function BufferCountSubscriber(destination, bufferSize) {
  43. var _this = _super.call(this, destination) || this;
  44. _this.bufferSize = bufferSize;
  45. _this.buffer = [];
  46. return _this;
  47. }
  48. BufferCountSubscriber.prototype._next = function (value) {
  49. var buffer = this.buffer;
  50. buffer.push(value);
  51. if (buffer.length == this.bufferSize) {
  52. this.destination.next(buffer);
  53. this.buffer = [];
  54. }
  55. };
  56. BufferCountSubscriber.prototype._complete = function () {
  57. var buffer = this.buffer;
  58. if (buffer.length > 0) {
  59. this.destination.next(buffer);
  60. }
  61. _super.prototype._complete.call(this);
  62. };
  63. return BufferCountSubscriber;
  64. }(Subscriber_1.Subscriber));
  65. var BufferSkipCountSubscriber = (function (_super) {
  66. __extends(BufferSkipCountSubscriber, _super);
  67. function BufferSkipCountSubscriber(destination, bufferSize, startBufferEvery) {
  68. var _this = _super.call(this, destination) || this;
  69. _this.bufferSize = bufferSize;
  70. _this.startBufferEvery = startBufferEvery;
  71. _this.buffers = [];
  72. _this.count = 0;
  73. return _this;
  74. }
  75. BufferSkipCountSubscriber.prototype._next = function (value) {
  76. var _a = this, bufferSize = _a.bufferSize, startBufferEvery = _a.startBufferEvery, buffers = _a.buffers, count = _a.count;
  77. this.count++;
  78. if (count % startBufferEvery === 0) {
  79. buffers.push([]);
  80. }
  81. for (var i = buffers.length; i--;) {
  82. var buffer = buffers[i];
  83. buffer.push(value);
  84. if (buffer.length === bufferSize) {
  85. buffers.splice(i, 1);
  86. this.destination.next(buffer);
  87. }
  88. }
  89. };
  90. BufferSkipCountSubscriber.prototype._complete = function () {
  91. var _a = this, buffers = _a.buffers, destination = _a.destination;
  92. while (buffers.length > 0) {
  93. var buffer = buffers.shift();
  94. if (buffer.length > 0) {
  95. destination.next(buffer);
  96. }
  97. }
  98. _super.prototype._complete.call(this);
  99. };
  100. return BufferSkipCountSubscriber;
  101. }(Subscriber_1.Subscriber));
  102. //# sourceMappingURL=bufferCount.js.map