source: trip-planner-front/node_modules/rxjs/internal/operators/mergeScan.js@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 4.1 KB
Line 
1"use strict";
2var __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})();
15Object.defineProperty(exports, "__esModule", { value: true });
16var innerSubscribe_1 = require("../innerSubscribe");
17function 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)); };
20}
21exports.mergeScan = mergeScan;
22var MergeScanOperator = (function () {
23 function MergeScanOperator(accumulator, seed, concurrent) {
24 this.accumulator = accumulator;
25 this.seed = seed;
26 this.concurrent = concurrent;
27 }
28 MergeScanOperator.prototype.call = function (subscriber, source) {
29 return source.subscribe(new MergeScanSubscriber(subscriber, this.accumulator, this.seed, this.concurrent));
30 };
31 return MergeScanOperator;
32}());
33exports.MergeScanOperator = MergeScanOperator;
34var 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;
39 _this.acc = acc;
40 _this.concurrent = concurrent;
41 _this.hasValue = false;
42 _this.hasCompleted = false;
43 _this.buffer = [];
44 _this.active = 0;
45 _this.index = 0;
46 return _this;
47 }
48 MergeScanSubscriber.prototype._next = function (value) {
49 if (this.active < this.concurrent) {
50 var index = this.index++;
51 var destination = this.destination;
52 var ish = void 0;
53 try {
54 var accumulator = this.accumulator;
55 ish = accumulator(this.acc, value, index);
56 }
57 catch (e) {
58 return destination.error(e);
59 }
60 this.active++;
61 this._innerSub(ish);
62 }
63 else {
64 this.buffer.push(value);
65 }
66 };
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);
74 }
75 };
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);
81 }
82 this.destination.complete();
83 }
84 this.unsubscribe();
85 };
86 MergeScanSubscriber.prototype.notifyNext = function (innerValue) {
87 var destination = this.destination;
88 this.acc = innerValue;
89 this.hasValue = true;
90 destination.next(innerValue);
91 };
92 MergeScanSubscriber.prototype.notifyComplete = function () {
93 var buffer = this.buffer;
94 this.active--;
95 if (buffer.length > 0) {
96 this._next(buffer.shift());
97 }
98 else if (this.active === 0 && this.hasCompleted) {
99 if (this.hasValue === false) {
100 this.destination.next(this.acc);
101 }
102 this.destination.complete();
103 }
104 };
105 return MergeScanSubscriber;
106}(innerSubscribe_1.SimpleOuterSubscriber));
107exports.MergeScanSubscriber = MergeScanSubscriber;
108//# sourceMappingURL=mergeScan.js.map
Note: See TracBrowser for help on using the repository browser.