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 OuterSubscriber_1 = require("../OuterSubscriber");
17 var subscribeToResult_1 = require("../util/subscribeToResult");
18 function withLatestFrom() {
20 for (var _i = 0; _i < arguments.length; _i++) {
21 args[_i] = arguments[_i];
23 return function (source) {
25 if (typeof args[args.length - 1] === 'function') {
28 var observables = args;
29 return source.lift(new WithLatestFromOperator(observables, project));
32 exports.withLatestFrom = withLatestFrom;
33 var WithLatestFromOperator = (function () {
34 function WithLatestFromOperator(observables, project) {
35 this.observables = observables;
36 this.project = project;
38 WithLatestFromOperator.prototype.call = function (subscriber, source) {
39 return source.subscribe(new WithLatestFromSubscriber(subscriber, this.observables, this.project));
41 return WithLatestFromOperator;
43 var WithLatestFromSubscriber = (function (_super) {
44 __extends(WithLatestFromSubscriber, _super);
45 function WithLatestFromSubscriber(destination, observables, project) {
46 var _this = _super.call(this, destination) || this;
47 _this.observables = observables;
48 _this.project = project;
50 var len = observables.length;
51 _this.values = new Array(len);
52 for (var i = 0; i < len; i++) {
53 _this.toRespond.push(i);
55 for (var i = 0; i < len; i++) {
56 var observable = observables[i];
57 _this.add(subscribeToResult_1.subscribeToResult(_this, observable, observable, i));
61 WithLatestFromSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
62 this.values[outerIndex] = innerValue;
63 var toRespond = this.toRespond;
64 if (toRespond.length > 0) {
65 var found = toRespond.indexOf(outerIndex);
67 toRespond.splice(found, 1);
71 WithLatestFromSubscriber.prototype.notifyComplete = function () {
73 WithLatestFromSubscriber.prototype._next = function (value) {
74 if (this.toRespond.length === 0) {
75 var args = [value].concat(this.values);
77 this._tryProject(args);
80 this.destination.next(args);
84 WithLatestFromSubscriber.prototype._tryProject = function (args) {
87 result = this.project.apply(this, args);
90 this.destination.error(err);
93 this.destination.next(result);
95 return WithLatestFromSubscriber;
96 }(OuterSubscriber_1.OuterSubscriber));
97 //# sourceMappingURL=withLatestFrom.js.map