Code coverage report for src/subject/SubjectSubscription.ts

Statements: 100% (25 / 25)      Branches: 81.82% (9 / 11)      Functions: 100% (3 / 3)      Lines: 100% (21 / 21)      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 36 37 38  1   1   1 1974   1974 1974     1 1799 5     1794   1794 1794   1794   1794 1299     495 495   495   495 495     1
import {Subject} from '../Subject';
import {Subscription} from '../Subscription';
import {Observer} from '../Observer';
import {Subscriber} from '../Subscriber';
 
export class SubjectSubscription<T> extends Subscription<T> {
  isUnsubscribed: boolean = false;
 
  constructor(public subject: Subject<T>, public observer: Observer<any>) {
    super();
  }
 
  unsubscribe() {
    if (this.isUnsubscribed) {
      return;
    }
 
    this.isUnsubscribed = true;
 
    const subject = this.subject;
    const observers = subject.observers;
 
    this.subject = void 0;
 
    if (!observers || observers.length === 0 || subject.isUnsubscribed) {
      return;
    }
 
    Eif (this.observer instanceof Subscriber) {
      (<Subscriber<T>> this.observer).unsubscribe();
    }
    const subscriberIndex = observers.indexOf(this.observer);
 
    Eif (subscriberIndex !== -1) {
      observers.splice(subscriberIndex, 1);
    }
  }
}