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);
9 return function (d, b) {
11 function __() { this.constructor = d; }
12 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15 Object.defineProperty(exports, "__esModule", { value: true });
16 var innerSubscribe_1 = require("../innerSubscribe");
17 function mergeScan(accumulator, seed, concurrent) {
18 if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
19 return function (source) { return source.lift(new MergeScanOperator(accumulator, seed, concurrent)); };
21 exports.mergeScan = mergeScan;
22 var MergeScanOperator = (function () {
23 function MergeScanOperator(accumulator, seed, concurrent) {
24 this.accumulator = accumulator;
26 this.concurrent = concurrent;
28 MergeScanOperator.prototype.call = function (subscriber, source) {
29 return source.subscribe(new MergeScanSubscriber(subscriber, this.accumulator, this.seed, this.concurrent));
31 return MergeScanOperator;
33 exports.MergeScanOperator = MergeScanOperator;
34 var MergeScanSubscriber = (function (_super) {
35 __extends(MergeScanSubscriber, _super);
36 function MergeScanSubscriber(destination, accumulator, acc, concurrent) {
37 var _this = _super.call(this, destination) || this;
38 _this.accumulator = accumulator;
40 _this.concurrent = concurrent;
41 _this.hasValue = false;
42 _this.hasCompleted = false;
48 MergeScanSubscriber.prototype._next = function (value) {
49 if (this.active < this.concurrent) {
50 var index = this.index++;
51 var destination = this.destination;
54 var accumulator = this.accumulator;
55 ish = accumulator(this.acc, value, index);
58 return destination.error(e);
64 this.buffer.push(value);
67 MergeScanSubscriber.prototype._innerSub = function (ish) {
68 var innerSubscriber = new innerSubscribe_1.SimpleInnerSubscriber(this);
69 var destination = this.destination;
70 destination.add(innerSubscriber);
71 var innerSubscription = innerSubscribe_1.innerSubscribe(ish, innerSubscriber);
72 if (innerSubscription !== innerSubscriber) {
73 destination.add(innerSubscription);
76 MergeScanSubscriber.prototype._complete = function () {
77 this.hasCompleted = true;
78 if (this.active === 0 && this.buffer.length === 0) {
79 if (this.hasValue === false) {
80 this.destination.next(this.acc);
82 this.destination.complete();
86 MergeScanSubscriber.prototype.notifyNext = function (innerValue) {
87 var destination = this.destination;
88 this.acc = innerValue;
90 destination.next(innerValue);
92 MergeScanSubscriber.prototype.notifyComplete = function () {
93 var buffer = this.buffer;
95 if (buffer.length > 0) {
96 this._next(buffer.shift());
98 else if (this.active === 0 && this.hasCompleted) {
99 if (this.hasValue === false) {
100 this.destination.next(this.acc);
102 this.destination.complete();
105 return MergeScanSubscriber;
106 }(innerSubscribe_1.SimpleOuterSubscriber));
107 exports.MergeScanSubscriber = MergeScanSubscriber;
108 //# sourceMappingURL=mergeScan.js.map