source: trip-planner-front/node_modules/rxjs/internal/operators/switchMap.js@ bdd6491

Last change on this file since bdd6491 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.5 KB
Line 
1"use strict";
2var __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);
8 }
9 return function (d, b) {
10 extendStatics(d, b);
11 function __() { this.constructor = d; }
12 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13 };
14})();
15Object.defineProperty(exports, "__esModule", { value: true });
16var map_1 = require("./map");
17var from_1 = require("../observable/from");
18var innerSubscribe_1 = require("../innerSubscribe");
19function switchMap(project, resultSelector) {
20 if (typeof resultSelector === 'function') {
21 return function (source) { return source.pipe(switchMap(function (a, i) { return from_1.from(project(a, i)).pipe(map_1.map(function (b, ii) { return resultSelector(a, b, i, ii); })); })); };
22 }
23 return function (source) { return source.lift(new SwitchMapOperator(project)); };
24}
25exports.switchMap = switchMap;
26var SwitchMapOperator = (function () {
27 function SwitchMapOperator(project) {
28 this.project = project;
29 }
30 SwitchMapOperator.prototype.call = function (subscriber, source) {
31 return source.subscribe(new SwitchMapSubscriber(subscriber, this.project));
32 };
33 return SwitchMapOperator;
34}());
35var SwitchMapSubscriber = (function (_super) {
36 __extends(SwitchMapSubscriber, _super);
37 function SwitchMapSubscriber(destination, project) {
38 var _this = _super.call(this, destination) || this;
39 _this.project = project;
40 _this.index = 0;
41 return _this;
42 }
43 SwitchMapSubscriber.prototype._next = function (value) {
44 var result;
45 var index = this.index++;
46 try {
47 result = this.project(value, index);
48 }
49 catch (error) {
50 this.destination.error(error);
51 return;
52 }
53 this._innerSub(result);
54 };
55 SwitchMapSubscriber.prototype._innerSub = function (result) {
56 var innerSubscription = this.innerSubscription;
57 if (innerSubscription) {
58 innerSubscription.unsubscribe();
59 }
60 var innerSubscriber = new innerSubscribe_1.SimpleInnerSubscriber(this);
61 var destination = this.destination;
62 destination.add(innerSubscriber);
63 this.innerSubscription = innerSubscribe_1.innerSubscribe(result, innerSubscriber);
64 if (this.innerSubscription !== innerSubscriber) {
65 destination.add(this.innerSubscription);
66 }
67 };
68 SwitchMapSubscriber.prototype._complete = function () {
69 var innerSubscription = this.innerSubscription;
70 if (!innerSubscription || innerSubscription.closed) {
71 _super.prototype._complete.call(this);
72 }
73 this.unsubscribe();
74 };
75 SwitchMapSubscriber.prototype._unsubscribe = function () {
76 this.innerSubscription = undefined;
77 };
78 SwitchMapSubscriber.prototype.notifyComplete = function () {
79 this.innerSubscription = undefined;
80 if (this.isStopped) {
81 _super.prototype._complete.call(this);
82 }
83 };
84 SwitchMapSubscriber.prototype.notifyNext = function (innerValue) {
85 this.destination.next(innerValue);
86 };
87 return SwitchMapSubscriber;
88}(innerSubscribe_1.SimpleOuterSubscriber));
89//# sourceMappingURL=switchMap.js.map
Note: See TracBrowser for help on using the repository browser.