1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112 | 1
2
1
1
1
1
1
1
1
14
14
14
14
1
1
1
14
14
14
1
14
1
1
1
1
1
14
14
14
14
14
14
14
14
3
1
1
98
98
98
98
83
83
83
1
82
82
15
1
82
4
78
78
1
14
14
3
1
60
1
74
74
74
74
15
74
9
1
1
| var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) Eif (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var tryCatch_1 = require('../util/tryCatch');
var errorObject_1 = require('../util/errorObject');
var OuterSubscriber_1 = require('../OuterSubscriber');
var subscribeToResult_1 = require('../util/subscribeToResult');
/**
* Returns an Observable where for each item in the source Observable, the supplied function is applied to each item,
* resulting in a new value to then be applied again with the function.
* @param {function} project the function for projecting the next emitted item of the Observable.
* @param {number} [concurrent] the max number of observables that can be created concurrently. defaults to infinity.
* @param {Scheduler} [scheduler] The Scheduler to use for managing the expansions.
* @returns {Observable} an Observable containing the expansions of the source Observable.
*/
function expand(project, concurrent, scheduler) {
if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
Eif (scheduler === void 0) { scheduler = undefined; }
concurrent = (concurrent || 0) < 1 ? Number.POSITIVE_INFINITY : concurrent;
return this.lift(new ExpandOperator(project, concurrent, scheduler));
}
exports.expand = expand;
var ExpandOperator = (function () {
function ExpandOperator(project, concurrent, scheduler) {
this.project = project;
this.concurrent = concurrent;
this.scheduler = scheduler;
}
ExpandOperator.prototype.call = function (subscriber) {
return new ExpandSubscriber(subscriber, this.project, this.concurrent, this.scheduler);
};
return ExpandOperator;
})();
exports.ExpandOperator = ExpandOperator;
var ExpandSubscriber = (function (_super) {
__extends(ExpandSubscriber, _super);
function ExpandSubscriber(destination, project, concurrent, scheduler) {
_super.call(this, destination);
this.project = project;
this.concurrent = concurrent;
this.scheduler = scheduler;
this.index = 0;
this.active = 0;
this.hasCompleted = false;
if (concurrent < Number.POSITIVE_INFINITY) {
this.buffer = [];
}
}
ExpandSubscriber.dispatch = function (_a) {
var subscriber = _a.subscriber, result = _a.result, value = _a.value, index = _a.index;
subscriber.subscribeToProjection(result, value, index);
};
ExpandSubscriber.prototype._next = function (value) {
var destination = this.destination;
Iif (destination.isUnsubscribed) {
this._complete();
return;
}
var index = this.index++;
if (this.active < this.concurrent) {
destination.next(value);
var result = tryCatch_1.tryCatch(this.project)(value, index);
if (result === errorObject_1.errorObject) {
destination.error(errorObject_1.errorObject.e);
}
else Eif (!this.scheduler) {
this.subscribeToProjection(result, value, index);
}
else {
var state = { subscriber: this, result: result, value: value, index: index };
this.add(this.scheduler.schedule(ExpandSubscriber.dispatch, 0, state));
}
}
else {
this.buffer.push(value);
}
};
ExpandSubscriber.prototype.subscribeToProjection = function (result, value, index) {
if (result._isScalar) {
this._next(result.value);
}
else {
this.active++;
this.add(subscribeToResult_1.subscribeToResult(this, result, value, index));
}
};
ExpandSubscriber.prototype._complete = function () {
this.hasCompleted = true;
if (this.hasCompleted && this.active === 0) {
this.destination.complete();
}
};
ExpandSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex) {
this._next(innerValue);
};
ExpandSubscriber.prototype.notifyComplete = function (innerSub) {
var buffer = this.buffer;
this.remove(innerSub);
this.active--;
if (buffer && buffer.length > 0) {
this._next(buffer.shift());
}
if (this.hasCompleted && this.active === 0) {
this.destination.complete();
}
};
return ExpandSubscriber;
})(OuterSubscriber_1.OuterSubscriber);
exports.ExpandSubscriber = ExpandSubscriber;
//# sourceMappingURL=expand.js.map |