Code coverage report for src/operator/isEmpty.ts

Statements: 100% (21 / 21)      Branches: 100% (0 / 0)      Functions: 100% (8 / 8)      Lines: 100% (19 / 19)      Ignored: none     

All files » src/operator/ » isEmpty.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  1                   1 7     2 1 7   1   1   1 7     1 3   3 3     1 1     1 2   1  
import {Operator} from '../Operator';
import {Subscriber} from '../Subscriber';
import {Observable} from '../Observable';
 
/**
 * If the source Observable is empty it returns an Observable that emits true, otherwise it emits false.
 *
 * <img src="./img/isEmpty.png" width="100%">
 *
 * @returns {Observable} an Observable that emits a Boolean.
 */
export function isEmpty(): Observable<boolean> {
  return this.lift(new IsEmptyOperator());
}
 
class IsEmptyOperator<T> implements Operator<boolean, boolean> {
  call (observer: Subscriber<T>): Subscriber<boolean> {
    return new IsEmptySubscriber(observer);
  }
}
 
class IsEmptySubscriber extends Subscriber<boolean> {
 
  constructor(destination: Subscriber<any>) {
    super(destination);
  }
 
  private notifyComplete(isEmpty: boolean): void {
    const destination = this.destination;
 
    destination.next(isEmpty);
    destination.complete();
  }
 
  protected _next(value: boolean) {
    this.notifyComplete(false);
  }
 
  protected _complete() {
    this.notifyComplete(true);
  }
}