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 switchMap(project, resultSelector) {
7 if (typeof resultSelector === 'function') {
8 return function (source) { return source.pipe(switchMap(function (a, i) { return from(project(a, i)).pipe(map(function (b, ii) { return resultSelector(a, b, i, ii); })); })); };
10 return function (source) { return source.lift(new SwitchMapOperator(project)); };
12 var SwitchMapOperator = /*@__PURE__*/ (function () {
13 function SwitchMapOperator(project) {
14 this.project = project;
16 SwitchMapOperator.prototype.call = function (subscriber, source) {
17 return source.subscribe(new SwitchMapSubscriber(subscriber, this.project));
19 return SwitchMapOperator;
21 var SwitchMapSubscriber = /*@__PURE__*/ (function (_super) {
22 tslib_1.__extends(SwitchMapSubscriber, _super);
23 function SwitchMapSubscriber(destination, project) {
24 var _this = _super.call(this, destination) || this;
25 _this.project = project;
29 SwitchMapSubscriber.prototype._next = function (value) {
31 var index = this.index++;
33 result = this.project(value, index);
36 this.destination.error(error);
39 this._innerSub(result);
41 SwitchMapSubscriber.prototype._innerSub = function (result) {
42 var innerSubscription = this.innerSubscription;
43 if (innerSubscription) {
44 innerSubscription.unsubscribe();
46 var innerSubscriber = new SimpleInnerSubscriber(this);
47 var destination = this.destination;
48 destination.add(innerSubscriber);
49 this.innerSubscription = innerSubscribe(result, innerSubscriber);
50 if (this.innerSubscription !== innerSubscriber) {
51 destination.add(this.innerSubscription);
54 SwitchMapSubscriber.prototype._complete = function () {
55 var innerSubscription = this.innerSubscription;
56 if (!innerSubscription || innerSubscription.closed) {
57 _super.prototype._complete.call(this);
61 SwitchMapSubscriber.prototype._unsubscribe = function () {
62 this.innerSubscription = undefined;
64 SwitchMapSubscriber.prototype.notifyComplete = function () {
65 this.innerSubscription = undefined;
67 _super.prototype._complete.call(this);
70 SwitchMapSubscriber.prototype.notifyNext = function (innerValue) {
71 this.destination.next(innerValue);
73 return SwitchMapSubscriber;
74 }(SimpleOuterSubscriber));
75 //# sourceMappingURL=switchMap.js.map