withLatestFrom.js
2.95 KB
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
/** PURE_IMPORTS_START tslib,_OuterSubscriber,_util_subscribeToResult PURE_IMPORTS_END */
import * as tslib_1 from "tslib";
import { OuterSubscriber } from '../OuterSubscriber';
import { subscribeToResult } from '../util/subscribeToResult';
export function withLatestFrom() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return function (source) {
var project;
if (typeof args[args.length - 1] === 'function') {
project = args.pop();
}
var observables = args;
return source.lift(new WithLatestFromOperator(observables, project));
};
}
var WithLatestFromOperator = /*@__PURE__*/ (function () {
function WithLatestFromOperator(observables, project) {
this.observables = observables;
this.project = project;
}
WithLatestFromOperator.prototype.call = function (subscriber, source) {
return source.subscribe(new WithLatestFromSubscriber(subscriber, this.observables, this.project));
};
return WithLatestFromOperator;
}());
var WithLatestFromSubscriber = /*@__PURE__*/ (function (_super) {
tslib_1.__extends(WithLatestFromSubscriber, _super);
function WithLatestFromSubscriber(destination, observables, project) {
var _this = _super.call(this, destination) || this;
_this.observables = observables;
_this.project = project;
_this.toRespond = [];
var len = observables.length;
_this.values = new Array(len);
for (var i = 0; i < len; i++) {
_this.toRespond.push(i);
}
for (var i = 0; i < len; i++) {
var observable = observables[i];
_this.add(subscribeToResult(_this, observable, undefined, i));
}
return _this;
}
WithLatestFromSubscriber.prototype.notifyNext = function (_outerValue, innerValue, outerIndex) {
this.values[outerIndex] = innerValue;
var toRespond = this.toRespond;
if (toRespond.length > 0) {
var found = toRespond.indexOf(outerIndex);
if (found !== -1) {
toRespond.splice(found, 1);
}
}
};
WithLatestFromSubscriber.prototype.notifyComplete = function () {
};
WithLatestFromSubscriber.prototype._next = function (value) {
if (this.toRespond.length === 0) {
var args = [value].concat(this.values);
if (this.project) {
this._tryProject(args);
}
else {
this.destination.next(args);
}
}
};
WithLatestFromSubscriber.prototype._tryProject = function (args) {
var result;
try {
result = this.project.apply(this, args);
}
catch (err) {
this.destination.error(err);
return;
}
this.destination.next(result);
};
return WithLatestFromSubscriber;
}(OuterSubscriber));
//# sourceMappingURL=withLatestFrom.js.map