Code coverage report for src/operator/skipWhile.ts

Statements: 100% (31 / 31)      Branches: 100% (6 / 6)      Functions: 100% (7 / 7)      Lines: 100% (29 / 29)      Ignored: none     

All files » src/operator/ » skipWhile.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    1 1 1 1   1 15     1     1 15     1 15   1   1 15 15   1 15 15     1 60 60 34 34 34 1   33     60 35     1  
import {Observable} from '../Observable';
import {Operator} from '../Operator';
import {Subscriber} from '../Subscriber';
import {tryCatch} from '../util/tryCatch';
import {errorObject} from '../util/errorObject';
import {bindCallback} from '../util/bindCallback';
 
export function skipWhile<T>(predicate: (x: T, index: number) => boolean, thisArg?: any): Observable<T> {
  return this.lift(new SkipWhileOperator(predicate, thisArg));
}
 
class SkipWhileOperator<T, R> implements Operator<T, R> {
  private predicate: (x: T, index: number) => boolean;
 
  constructor(predicate: (x: T, index: number) => boolean, thisArg?: any) {
    this.predicate = <(x: T, index: number) => boolean>bindCallback(predicate, thisArg, 2);
  }
 
  call(subscriber: Subscriber<T>): Subscriber<T> {
    return new SkipWhileSubscriber(subscriber, this.predicate);
  }
}
 
class SkipWhileSubscriber<T> extends Subscriber<T> {
  private skipping: boolean = true;
  private index: number = 0;
 
  constructor(destination: Subscriber<T>,
              private predicate: (x: T, index: number) => boolean) {
    super(destination);
  }
 
  _next(value: T): void {
    const destination = this.destination;
    if (this.skipping === true) {
      const index = this.index++;
      const result = tryCatch(this.predicate)(value, index);
      if (result === errorObject) {
        destination.error(result.e);
      } else {
        this.skipping = Boolean(result);
      }
    }
    if (this.skipping === false) {
      destination.next(value);
    }
  }
}