Code coverage report for src/operator/takeUntil.ts

Statements: 100% (35 / 35)      Branches: 100% (0 / 0)      Functions: 100% (12 / 12)      Lines: 100% (30 / 30)      Ignored: none     

All files » src/operator/ » takeUntil.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    1 1   1 16     1 16     1 16   1   1 16   1 16 16 16 16     1 3 3   1   1 16 16     1 5     1 2     1 2   1  
import {Operator} from '../Operator';
import {Observable} from '../Observable';
import {Subscriber} from '../Subscriber';
import {noop} from '../util/noop';
 
export function takeUntil<T>(notifier: Observable<any>) {
  return this.lift(new TakeUntilOperator(notifier));
}
 
class TakeUntilOperator<T, R> implements Operator<T, R> {
  constructor(private notifier: Observable<any>) {
  }
 
  call(subscriber: Subscriber<T>): Subscriber<T> {
    return new TakeUntilSubscriber(subscriber, this.notifier);
  }
}
 
class TakeUntilSubscriber<T> extends Subscriber<T> {
  private notificationSubscriber: TakeUntilInnerSubscriber<any> = null;
 
  constructor(destination: Subscriber<T>,
              private notifier: Observable<any>) {
    super(destination);
    this.notificationSubscriber = new TakeUntilInnerSubscriber(destination);
    this.add(notifier.subscribe(this.notificationSubscriber));
  }
 
  _complete(): void {
    this.destination.complete();
    this.notificationSubscriber.unsubscribe();
  }
}
 
class TakeUntilInnerSubscriber<T> extends Subscriber<T> {
  constructor(protected destination: Subscriber<T>) {
    super(null);
  }
 
  _next(unused: T): void {
    this.destination.complete();
  }
 
  _error(err: any): void {
    this.destination.error(err);
  }
 
  _complete(): void {
    noop();
  }
}