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 InnerSubscriber_1 = require("../InnerSubscriber");
18 var subscribeToResult_1 = require("../util/subscribeToResult");
19 var map_1 = require("./map");
20 var from_1 = require("../observable/from");
21 function exhaustMap(project, resultSelector) {
23 return function (source) { return source.pipe(exhaustMap(function (a, i) { return from_1.from(project(a, i)).pipe(map_1.map(function (b, ii) { return resultSelector(a, b, i, ii); })); })); };
25 return function (source) {
26 return source.lift(new ExhaustMapOperator(project));
29 exports.exhaustMap = exhaustMap;
30 var ExhaustMapOperator = (function () {
31 function ExhaustMapOperator(project) {
32 this.project = project;
34 ExhaustMapOperator.prototype.call = function (subscriber, source) {
35 return source.subscribe(new ExhaustMapSubscriber(subscriber, this.project));
37 return ExhaustMapOperator;
39 var ExhaustMapSubscriber = (function (_super) {
40 __extends(ExhaustMapSubscriber, _super);
41 function ExhaustMapSubscriber(destination, project) {
42 var _this = _super.call(this, destination) || this;
43 _this.project = project;
44 _this.hasSubscription = false;
45 _this.hasCompleted = false;
49 ExhaustMapSubscriber.prototype._next = function (value) {
50 if (!this.hasSubscription) {
54 ExhaustMapSubscriber.prototype.tryNext = function (value) {
56 var index = this.index++;
58 result = this.project(value, index);
61 this.destination.error(err);
64 this.hasSubscription = true;
65 this._innerSub(result, value, index);
67 ExhaustMapSubscriber.prototype._innerSub = function (result, value, index) {
68 var innerSubscriber = new InnerSubscriber_1.InnerSubscriber(this, value, index);
69 var destination = this.destination;
70 destination.add(innerSubscriber);
71 var innerSubscription = subscribeToResult_1.subscribeToResult(this, result, undefined, undefined, innerSubscriber);
72 if (innerSubscription !== innerSubscriber) {
73 destination.add(innerSubscription);
76 ExhaustMapSubscriber.prototype._complete = function () {
77 this.hasCompleted = true;
78 if (!this.hasSubscription) {
79 this.destination.complete();
83 ExhaustMapSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
84 this.destination.next(innerValue);
86 ExhaustMapSubscriber.prototype.notifyError = function (err) {
87 this.destination.error(err);
89 ExhaustMapSubscriber.prototype.notifyComplete = function (innerSub) {
90 var destination = this.destination;
91 destination.remove(innerSub);
92 this.hasSubscription = false;
93 if (this.hasCompleted) {
94 this.destination.complete();
97 return ExhaustMapSubscriber;
98 }(OuterSubscriber_1.OuterSubscriber));
99 //# sourceMappingURL=exhaustMap.js.map