8d1894ffa046455cad01a119d4563d5d698d5991
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / rxjs / _esm2015 / internal / operators / switchMap.js
1 import { OuterSubscriber } from '../OuterSubscriber';
2 import { InnerSubscriber } from '../InnerSubscriber';
3 import { subscribeToResult } from '../util/subscribeToResult';
4 import { map } from './map';
5 import { from } from '../observable/from';
6 export function switchMap(project, resultSelector) {
7     if (typeof resultSelector === 'function') {
8         return (source) => source.pipe(switchMap((a, i) => from(project(a, i)).pipe(map((b, ii) => resultSelector(a, b, i, ii)))));
9     }
10     return (source) => source.lift(new SwitchMapOperator(project));
11 }
12 class SwitchMapOperator {
13     constructor(project) {
14         this.project = project;
15     }
16     call(subscriber, source) {
17         return source.subscribe(new SwitchMapSubscriber(subscriber, this.project));
18     }
19 }
20 class SwitchMapSubscriber extends OuterSubscriber {
21     constructor(destination, project) {
22         super(destination);
23         this.project = project;
24         this.index = 0;
25     }
26     _next(value) {
27         let result;
28         const index = this.index++;
29         try {
30             result = this.project(value, index);
31         }
32         catch (error) {
33             this.destination.error(error);
34             return;
35         }
36         this._innerSub(result, value, index);
37     }
38     _innerSub(result, value, index) {
39         const innerSubscription = this.innerSubscription;
40         if (innerSubscription) {
41             innerSubscription.unsubscribe();
42         }
43         const innerSubscriber = new InnerSubscriber(this, value, index);
44         const destination = this.destination;
45         destination.add(innerSubscriber);
46         this.innerSubscription = subscribeToResult(this, result, undefined, undefined, innerSubscriber);
47         if (this.innerSubscription !== innerSubscriber) {
48             destination.add(this.innerSubscription);
49         }
50     }
51     _complete() {
52         const { innerSubscription } = this;
53         if (!innerSubscription || innerSubscription.closed) {
54             super._complete();
55         }
56         this.unsubscribe();
57     }
58     _unsubscribe() {
59         this.innerSubscription = null;
60     }
61     notifyComplete(innerSub) {
62         const destination = this.destination;
63         destination.remove(innerSub);
64         this.innerSubscription = null;
65         if (this.isStopped) {
66             super._complete();
67         }
68     }
69     notifyNext(outerValue, innerValue, outerIndex, innerIndex, innerSub) {
70         this.destination.next(innerValue);
71     }
72 }
73 //# sourceMappingURL=switchMap.js.map