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. * * * * @return {Observable} an Observable that emits a Boolean. * @method isEmpty * @owner Observable */ export function isEmpty(this: Observable): Observable { return this.lift(new IsEmptyOperator()); } class IsEmptyOperator implements Operator { call (observer: Subscriber, source: any): any { return source.subscribe(new IsEmptySubscriber(observer)); } } /** * We need this JSDoc comment for affecting ESDoc. * @ignore * @extends {Ignored} */ class IsEmptySubscriber extends Subscriber { constructor(destination: Subscriber) { 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); } }