Code coverage report for src/operator/skipUntil.ts

Statements: 98% (49 / 50)      Branches: 87.5% (7 / 8)      Functions: 100% (15 / 15)      Lines: 97.78% (44 / 45)      Ignored: none     

All files » src/operator/ » skipUntil.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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78  1     1 18     1 18     1 18   1   1 18   1 18 18 18 18     1 50 2       1 3     1 9 5   9     1 16 3 13 13 13         1   1 18 18   18 18     1 4     1 3 3     1 8   1  
import {Operator} from '../Operator';
import {Subscriber} from '../Subscriber';
import {Observable} from '../Observable';
 
export function skipUntil<T>(notifier: Observable<any>): Observable<T> {
  return this.lift(new SkipUntilOperator(notifier));
}
 
class SkipUntilOperator<T, R> implements Operator<T, R> {
  constructor(private notifier: Observable<any>) {
  }
 
  call(subscriber: Subscriber<T>): Subscriber<T> {
    return new SkipUntilSubscriber(subscriber, this.notifier);
  }
}
 
class SkipUntilSubscriber<T> extends Subscriber<T> {
  private notificationSubscriber: NotificationSubscriber<any> = null;
 
  constructor(destination: Subscriber<T>,
              private notifier: Observable<any>) {
    super(destination);
    this.notificationSubscriber = new NotificationSubscriber(this);
    this.add(this.notifier.subscribe(this.notificationSubscriber));
  }
 
  _next(value: T) {
    if (this.notificationSubscriber.hasValue) {
      this.destination.next(value);
    }
  }
 
  _error(err: any) {
    this.destination.error(err);
  }
 
  _complete() {
    if (this.notificationSubscriber.hasCompleted) {
      this.destination.complete();
    }
    this.notificationSubscriber.unsubscribe();
  }
 
  unsubscribe() {
    if (this._isUnsubscribed) {
      return;
    } else Eif (this._subscription) {
      this._subscription.unsubscribe();
      this._isUnsubscribed = true;
    } else {
      super.unsubscribe();
    }
  }
}
 
class NotificationSubscriber<T> extends Subscriber<T> {
  hasValue: boolean = false;
  hasCompleted: boolean = false;
 
  constructor(private parent: SkipUntilSubscriber<any>) {
    super(null);
  }
 
  _next(unused: T) {
    this.hasValue = true;
  }
 
  _error(err) {
    this.parent.error(err);
    this.hasValue = true;
  }
 
  _complete() {
    this.hasCompleted = true;
  }
}