[6a3a178] | 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) {
|
---|
| 7 | if (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); })); })); };
|
---|
| 9 | }
|
---|
| 10 | return function (source) {
|
---|
| 11 | return source.lift(new ExhaustMapOperator(project));
|
---|
| 12 | };
|
---|
| 13 | }
|
---|
| 14 | var ExhaustMapOperator = /*@__PURE__*/ (function () {
|
---|
| 15 | function ExhaustMapOperator(project) {
|
---|
| 16 | this.project = project;
|
---|
| 17 | }
|
---|
| 18 | ExhaustMapOperator.prototype.call = function (subscriber, source) {
|
---|
| 19 | return source.subscribe(new ExhaustMapSubscriber(subscriber, this.project));
|
---|
| 20 | };
|
---|
| 21 | return ExhaustMapOperator;
|
---|
| 22 | }());
|
---|
| 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;
|
---|
| 30 | _this.index = 0;
|
---|
| 31 | return _this;
|
---|
| 32 | }
|
---|
| 33 | ExhaustMapSubscriber.prototype._next = function (value) {
|
---|
| 34 | if (!this.hasSubscription) {
|
---|
| 35 | this.tryNext(value);
|
---|
| 36 | }
|
---|
| 37 | };
|
---|
| 38 | ExhaustMapSubscriber.prototype.tryNext = function (value) {
|
---|
| 39 | var result;
|
---|
| 40 | var index = this.index++;
|
---|
| 41 | try {
|
---|
| 42 | result = this.project(value, index);
|
---|
| 43 | }
|
---|
| 44 | catch (err) {
|
---|
| 45 | this.destination.error(err);
|
---|
| 46 | return;
|
---|
| 47 | }
|
---|
| 48 | this.hasSubscription = true;
|
---|
| 49 | this._innerSub(result);
|
---|
| 50 | };
|
---|
| 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);
|
---|
| 58 | }
|
---|
| 59 | };
|
---|
| 60 | ExhaustMapSubscriber.prototype._complete = function () {
|
---|
| 61 | this.hasCompleted = true;
|
---|
| 62 | if (!this.hasSubscription) {
|
---|
| 63 | this.destination.complete();
|
---|
| 64 | }
|
---|
| 65 | this.unsubscribe();
|
---|
| 66 | };
|
---|
| 67 | ExhaustMapSubscriber.prototype.notifyNext = function (innerValue) {
|
---|
| 68 | this.destination.next(innerValue);
|
---|
| 69 | };
|
---|
| 70 | ExhaustMapSubscriber.prototype.notifyError = function (err) {
|
---|
| 71 | this.destination.error(err);
|
---|
| 72 | };
|
---|
| 73 | ExhaustMapSubscriber.prototype.notifyComplete = function () {
|
---|
| 74 | this.hasSubscription = false;
|
---|
| 75 | if (this.hasCompleted) {
|
---|
| 76 | this.destination.complete();
|
---|
| 77 | }
|
---|
| 78 | };
|
---|
| 79 | return ExhaustMapSubscriber;
|
---|
| 80 | }(SimpleOuterSubscriber));
|
---|
| 81 | //# sourceMappingURL=exhaustMap.js.map
|
---|