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 subscribeToResult_1 = require("../util/subscribeToResult");
17 var OuterSubscriber_1 = require("../OuterSubscriber");
18 var InnerSubscriber_1 = require("../InnerSubscriber");
19 function mergeScan(accumulator, seed, concurrent) {
20 if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
21 return function (source) { return source.lift(new MergeScanOperator(accumulator, seed, concurrent)); };
23 exports.mergeScan = mergeScan;
24 var MergeScanOperator = (function () {
25 function MergeScanOperator(accumulator, seed, concurrent) {
26 this.accumulator = accumulator;
28 this.concurrent = concurrent;
30 MergeScanOperator.prototype.call = function (subscriber, source) {
31 return source.subscribe(new MergeScanSubscriber(subscriber, this.accumulator, this.seed, this.concurrent));
33 return MergeScanOperator;
35 exports.MergeScanOperator = MergeScanOperator;
36 var MergeScanSubscriber = (function (_super) {
37 __extends(MergeScanSubscriber, _super);
38 function MergeScanSubscriber(destination, accumulator, acc, concurrent) {
39 var _this = _super.call(this, destination) || this;
40 _this.accumulator = accumulator;
42 _this.concurrent = concurrent;
43 _this.hasValue = false;
44 _this.hasCompleted = false;
50 MergeScanSubscriber.prototype._next = function (value) {
51 if (this.active < this.concurrent) {
52 var index = this.index++;
53 var destination = this.destination;
56 var accumulator = this.accumulator;
57 ish = accumulator(this.acc, value, index);
60 return destination.error(e);
63 this._innerSub(ish, value, index);
66 this.buffer.push(value);
69 MergeScanSubscriber.prototype._innerSub = function (ish, value, index) {
70 var innerSubscriber = new InnerSubscriber_1.InnerSubscriber(this, value, index);
71 var destination = this.destination;
72 destination.add(innerSubscriber);
73 var innerSubscription = subscribeToResult_1.subscribeToResult(this, ish, undefined, undefined, innerSubscriber);
74 if (innerSubscription !== innerSubscriber) {
75 destination.add(innerSubscription);
78 MergeScanSubscriber.prototype._complete = function () {
79 this.hasCompleted = true;
80 if (this.active === 0 && this.buffer.length === 0) {
81 if (this.hasValue === false) {
82 this.destination.next(this.acc);
84 this.destination.complete();
88 MergeScanSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
89 var destination = this.destination;
90 this.acc = innerValue;
92 destination.next(innerValue);
94 MergeScanSubscriber.prototype.notifyComplete = function (innerSub) {
95 var buffer = this.buffer;
96 var destination = this.destination;
97 destination.remove(innerSub);
99 if (buffer.length > 0) {
100 this._next(buffer.shift());
102 else if (this.active === 0 && this.hasCompleted) {
103 if (this.hasValue === false) {
104 this.destination.next(this.acc);
106 this.destination.complete();
109 return MergeScanSubscriber;
110 }(OuterSubscriber_1.OuterSubscriber));
111 exports.MergeScanSubscriber = MergeScanSubscriber;
112 //# sourceMappingURL=mergeScan.js.map