1 /** PURE_IMPORTS_START tslib,_OuterSubscriber,_util_subscribeToResult PURE_IMPORTS_END */
2 import * as tslib_1 from "tslib";
3 import { OuterSubscriber } from '../OuterSubscriber';
4 import { subscribeToResult } from '../util/subscribeToResult';
5 export function withLatestFrom() {
7 for (var _i = 0; _i < arguments.length; _i++) {
8 args[_i] = arguments[_i];
10 return function (source) {
12 if (typeof args[args.length - 1] === 'function') {
15 var observables = args;
16 return source.lift(new WithLatestFromOperator(observables, project));
19 var WithLatestFromOperator = /*@__PURE__*/ (function () {
20 function WithLatestFromOperator(observables, project) {
21 this.observables = observables;
22 this.project = project;
24 WithLatestFromOperator.prototype.call = function (subscriber, source) {
25 return source.subscribe(new WithLatestFromSubscriber(subscriber, this.observables, this.project));
27 return WithLatestFromOperator;
29 var WithLatestFromSubscriber = /*@__PURE__*/ (function (_super) {
30 tslib_1.__extends(WithLatestFromSubscriber, _super);
31 function WithLatestFromSubscriber(destination, observables, project) {
32 var _this = _super.call(this, destination) || this;
33 _this.observables = observables;
34 _this.project = project;
36 var len = observables.length;
37 _this.values = new Array(len);
38 for (var i = 0; i < len; i++) {
39 _this.toRespond.push(i);
41 for (var i = 0; i < len; i++) {
42 var observable = observables[i];
43 _this.add(subscribeToResult(_this, observable, observable, i));
47 WithLatestFromSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
48 this.values[outerIndex] = innerValue;
49 var toRespond = this.toRespond;
50 if (toRespond.length > 0) {
51 var found = toRespond.indexOf(outerIndex);
53 toRespond.splice(found, 1);
57 WithLatestFromSubscriber.prototype.notifyComplete = function () {
59 WithLatestFromSubscriber.prototype._next = function (value) {
60 if (this.toRespond.length === 0) {
61 var args = [value].concat(this.values);
63 this._tryProject(args);
66 this.destination.next(args);
70 WithLatestFromSubscriber.prototype._tryProject = function (args) {
73 result = this.project.apply(this, args);
76 this.destination.error(err);
79 this.destination.next(result);
81 return WithLatestFromSubscriber;
83 //# sourceMappingURL=withLatestFrom.js.map