Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / rxjs / src / internal / SubjectSubscription.ts
1 import { Subject } from './Subject';
2 import { Observer } from './types';
3 import { Subscription } from './Subscription';
4
5 /**
6  * We need this JSDoc comment for affecting ESDoc.
7  * @ignore
8  * @extends {Ignored}
9  */
10 export class SubjectSubscription<T> extends Subscription {
11   closed: boolean = false;
12
13   constructor(public subject: Subject<T>, public subscriber: Observer<T>) {
14     super();
15   }
16
17   unsubscribe() {
18     if (this.closed) {
19       return;
20     }
21
22     this.closed = true;
23
24     const subject = this.subject;
25     const observers = subject.observers;
26
27     this.subject = null;
28
29     if (!observers || observers.length === 0 || subject.isStopped || subject.closed) {
30       return;
31     }
32
33     const subscriberIndex = observers.indexOf(this.subscriber);
34
35     if (subscriberIndex !== -1) {
36       observers.splice(subscriberIndex, 1);
37     }
38   }
39 }