1 /** PURE_IMPORTS_START tslib,_OuterSubscriber,_InnerSubscriber,_util_subscribeToResult,_map,_observable_from PURE_IMPORTS_END */
2 import * as tslib_1 from "tslib";
3 import { OuterSubscriber } from '../OuterSubscriber';
4 import { InnerSubscriber } from '../InnerSubscriber';
5 import { subscribeToResult } from '../util/subscribeToResult';
6 import { map } from './map';
7 import { from } from '../observable/from';
8 export function exhaustMap(project, resultSelector) {
10 return function (source) { return source.pipe(exhaustMap(function (a, i) { return from(project(a, i)).pipe(map(function (b, ii) { return resultSelector(a, b, i, ii); })); })); };
12 return function (source) {
13 return source.lift(new ExhaustMapOperator(project));
16 var ExhaustMapOperator = /*@__PURE__*/ (function () {
17 function ExhaustMapOperator(project) {
18 this.project = project;
20 ExhaustMapOperator.prototype.call = function (subscriber, source) {
21 return source.subscribe(new ExhaustMapSubscriber(subscriber, this.project));
23 return ExhaustMapOperator;
25 var ExhaustMapSubscriber = /*@__PURE__*/ (function (_super) {
26 tslib_1.__extends(ExhaustMapSubscriber, _super);
27 function ExhaustMapSubscriber(destination, project) {
28 var _this = _super.call(this, destination) || this;
29 _this.project = project;
30 _this.hasSubscription = false;
31 _this.hasCompleted = false;
35 ExhaustMapSubscriber.prototype._next = function (value) {
36 if (!this.hasSubscription) {
40 ExhaustMapSubscriber.prototype.tryNext = function (value) {
42 var index = this.index++;
44 result = this.project(value, index);
47 this.destination.error(err);
50 this.hasSubscription = true;
51 this._innerSub(result, value, index);
53 ExhaustMapSubscriber.prototype._innerSub = function (result, value, index) {
54 var innerSubscriber = new InnerSubscriber(this, value, index);
55 var destination = this.destination;
56 destination.add(innerSubscriber);
57 var innerSubscription = subscribeToResult(this, result, undefined, undefined, innerSubscriber);
58 if (innerSubscription !== innerSubscriber) {
59 destination.add(innerSubscription);
62 ExhaustMapSubscriber.prototype._complete = function () {
63 this.hasCompleted = true;
64 if (!this.hasSubscription) {
65 this.destination.complete();
69 ExhaustMapSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
70 this.destination.next(innerValue);
72 ExhaustMapSubscriber.prototype.notifyError = function (err) {
73 this.destination.error(err);
75 ExhaustMapSubscriber.prototype.notifyComplete = function (innerSub) {
76 var destination = this.destination;
77 destination.remove(innerSub);
78 this.hasSubscription = false;
79 if (this.hasCompleted) {
80 this.destination.complete();
83 return ExhaustMapSubscriber;
85 //# sourceMappingURL=exhaustMap.js.map