1 /** PURE_IMPORTS_START tslib,_map,_observable_from,_innerSubscribe PURE_IMPORTS_END */
2 import * as tslib_1 from "tslib";
3 import { map } from './map';
4 import { from } from '../observable/from';
5 import { SimpleOuterSubscriber, SimpleInnerSubscriber, innerSubscribe } from '../innerSubscribe';
6 export function exhaustMap(project, resultSelector) {
8 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); })); })); };
10 return function (source) {
11 return source.lift(new ExhaustMapOperator(project));
14 var ExhaustMapOperator = /*@__PURE__*/ (function () {
15 function ExhaustMapOperator(project) {
16 this.project = project;
18 ExhaustMapOperator.prototype.call = function (subscriber, source) {
19 return source.subscribe(new ExhaustMapSubscriber(subscriber, this.project));
21 return ExhaustMapOperator;
23 var ExhaustMapSubscriber = /*@__PURE__*/ (function (_super) {
24 tslib_1.__extends(ExhaustMapSubscriber, _super);
25 function ExhaustMapSubscriber(destination, project) {
26 var _this = _super.call(this, destination) || this;
27 _this.project = project;
28 _this.hasSubscription = false;
29 _this.hasCompleted = false;
33 ExhaustMapSubscriber.prototype._next = function (value) {
34 if (!this.hasSubscription) {
38 ExhaustMapSubscriber.prototype.tryNext = function (value) {
40 var index = this.index++;
42 result = this.project(value, index);
45 this.destination.error(err);
48 this.hasSubscription = true;
49 this._innerSub(result);
51 ExhaustMapSubscriber.prototype._innerSub = function (result) {
52 var innerSubscriber = new SimpleInnerSubscriber(this);
53 var destination = this.destination;
54 destination.add(innerSubscriber);
55 var innerSubscription = innerSubscribe(result, innerSubscriber);
56 if (innerSubscription !== innerSubscriber) {
57 destination.add(innerSubscription);
60 ExhaustMapSubscriber.prototype._complete = function () {
61 this.hasCompleted = true;
62 if (!this.hasSubscription) {
63 this.destination.complete();
67 ExhaustMapSubscriber.prototype.notifyNext = function (innerValue) {
68 this.destination.next(innerValue);
70 ExhaustMapSubscriber.prototype.notifyError = function (err) {
71 this.destination.error(err);
73 ExhaustMapSubscriber.prototype.notifyComplete = function () {
74 this.hasSubscription = false;
75 if (this.hasCompleted) {
76 this.destination.complete();
79 return ExhaustMapSubscriber;
80 }(SimpleOuterSubscriber));
81 //# sourceMappingURL=exhaustMap.js.map