source: trip-planner-front/node_modules/rxjs/_esm2015/internal/operators/switchMap.js@ 6a3a178

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

initial commit

  • Property mode set to 100644
File size: 2.2 KB
Line 
1import { map } from './map';
2import { from } from '../observable/from';
3import { SimpleOuterSubscriber, SimpleInnerSubscriber, innerSubscribe } from '../innerSubscribe';
4export function switchMap(project, resultSelector) {
5 if (typeof resultSelector === 'function') {
6 return (source) => source.pipe(switchMap((a, i) => from(project(a, i)).pipe(map((b, ii) => resultSelector(a, b, i, ii)))));
7 }
8 return (source) => source.lift(new SwitchMapOperator(project));
9}
10class SwitchMapOperator {
11 constructor(project) {
12 this.project = project;
13 }
14 call(subscriber, source) {
15 return source.subscribe(new SwitchMapSubscriber(subscriber, this.project));
16 }
17}
18class SwitchMapSubscriber extends SimpleOuterSubscriber {
19 constructor(destination, project) {
20 super(destination);
21 this.project = project;
22 this.index = 0;
23 }
24 _next(value) {
25 let result;
26 const index = this.index++;
27 try {
28 result = this.project(value, index);
29 }
30 catch (error) {
31 this.destination.error(error);
32 return;
33 }
34 this._innerSub(result);
35 }
36 _innerSub(result) {
37 const innerSubscription = this.innerSubscription;
38 if (innerSubscription) {
39 innerSubscription.unsubscribe();
40 }
41 const innerSubscriber = new SimpleInnerSubscriber(this);
42 const destination = this.destination;
43 destination.add(innerSubscriber);
44 this.innerSubscription = innerSubscribe(result, innerSubscriber);
45 if (this.innerSubscription !== innerSubscriber) {
46 destination.add(this.innerSubscription);
47 }
48 }
49 _complete() {
50 const { innerSubscription } = this;
51 if (!innerSubscription || innerSubscription.closed) {
52 super._complete();
53 }
54 this.unsubscribe();
55 }
56 _unsubscribe() {
57 this.innerSubscription = undefined;
58 }
59 notifyComplete() {
60 this.innerSubscription = undefined;
61 if (this.isStopped) {
62 super._complete();
63 }
64 }
65 notifyNext(innerValue) {
66 this.destination.next(innerValue);
67 }
68}
69//# sourceMappingURL=switchMap.js.map
Note: See TracBrowser for help on using the repository browser.