diff --git a/src/operator/isEmpty.ts b/src/operator/isEmpty.ts index b086d45183..68235bce8a 100644 --- a/src/operator/isEmpty.ts +++ b/src/operator/isEmpty.ts @@ -1,6 +1,6 @@ -import { Operator } from '../Operator'; -import { Subscriber } from '../Subscriber'; + import { Observable } from '../Observable'; +import { isEmpty as higherOrder } from '../operators'; /** * If the source Observable is empty it returns an Observable that emits true, otherwise it emits false. @@ -12,37 +12,5 @@ import { Observable } from '../Observable'; * @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); - } + return higherOrder()(this); } diff --git a/src/operators/index.ts b/src/operators/index.ts index 84dfabf597..38ddb2bb8f 100644 --- a/src/operators/index.ts +++ b/src/operators/index.ts @@ -31,6 +31,7 @@ export { findIndex } from './findIndex'; export { first } from './first'; export { groupBy } from './groupBy'; export { ignoreElements } from './ignoreElements'; +export { isEmpty } from './isEmpty'; export { map } from './map'; export { materialize } from './materialize'; export { max } from './max'; diff --git a/src/operators/isEmpty.ts b/src/operators/isEmpty.ts new file mode 100644 index 0000000000..f6b64d2849 --- /dev/null +++ b/src/operators/isEmpty.ts @@ -0,0 +1,40 @@ +import { Operator } from '../Operator'; +import { Subscriber } from '../Subscriber'; +import { Observable } from '../Observable'; +import { OperatorFunction } from '../interfaces'; + +export function isEmpty(): OperatorFunction { + return (source: Observable) => source.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); + } +}