Code coverage report for src/subject/SubjectSubscription.ts

Statements: 95.45% (21 / 22)      Branches: 77.78% (7 / 9)      Functions: 100% (3 / 3)      Lines: 94.44% (17 / 18)      Ignored: none     

All files » src/subject/ » SubjectSubscription.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35    1   1 2322   2322 2322     1 2042       2042   2042 2042   2042   2042 1402     640   640 640     1  
import {Subject} from '../Subject';
import {Observer} from '../Observer';
import {Subscription} from '../Subscription';
 
export class SubjectSubscription extends Subscription {
  isUnsubscribed: boolean = false;
 
  constructor(public subject: Subject<any>, public observer: Observer<any>) {
    super();
  }
 
  unsubscribe() {
    Iif (this.isUnsubscribed) {
      return;
    }
 
    this.isUnsubscribed = true;
 
    const subject = this.subject;
    const observers = subject.observers;
 
    this.subject = null;
 
    if (!observers || observers.length === 0 || subject.isUnsubscribed) {
      return;
    }
 
    const subscriberIndex = observers.indexOf(this.observer);
 
    Eif (subscriberIndex !== -1) {
      observers.splice(subscriberIndex, 1);
    }
  }
}