Skip to content

Commit

Permalink
feat(ignoreElements): add higher-order lettable version of ignoreElem…
Browse files Browse the repository at this point in the history
…ents
  • Loading branch information
benlesh committed Jun 16, 2017
1 parent 21fba63 commit 68286d4
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 21 deletions.
23 changes: 2 additions & 21 deletions src/operator/ignoreElements.ts
@@ -1,7 +1,5 @@
import { Observable } from '../Observable';
import { Operator } from '../Operator';
import { Subscriber } from '../Subscriber';
import { noop } from '../util/noop';
import { ignoreElements as higherOrder } from '../operators';

/**
* Ignores all items emitted by the source Observable and only passes calls of `complete` or `error`.
Expand All @@ -14,22 +12,5 @@ import { noop } from '../util/noop';
* @owner Observable
*/
export function ignoreElements<T>(this: Observable<T>): Observable<T> {
return this.lift(new IgnoreElementsOperator());
return higherOrder()(this);
};

class IgnoreElementsOperator<T, R> implements Operator<T, R> {
call(subscriber: Subscriber<R>, source: any): any {
return source.subscribe(new IgnoreElementsSubscriber(subscriber));
}
}

/**
* We need this JSDoc comment for affecting ESDoc.
* @ignore
* @extends {Ignored}
*/
class IgnoreElementsSubscriber<T> extends Subscriber<T> {
protected _next(unused: T): void {
noop();
}
}
38 changes: 38 additions & 0 deletions src/operators/ignoreElements.ts
@@ -0,0 +1,38 @@
import { Observable } from '../Observable';
import { Operator } from '../Operator';
import { Subscriber } from '../Subscriber';
import { noop } from '../util/noop';
import { MonoTypeOperatorFunction } from '../interfaces';

/**
* Ignores all items emitted by the source Observable and only passes calls of `complete` or `error`.
*
* <img src="./img/ignoreElements.png" width="100%">
*
* @return {Observable} An empty Observable that only calls `complete`
* or `error`, based on which one is called by the source Observable.
* @method ignoreElements
* @owner Observable
*/
export function ignoreElements<T>(): MonoTypeOperatorFunction<T> {
return function ignoreElementsOperatorFunction(source: Observable<T>) {
return source.lift(new IgnoreElementsOperator());
};
}

class IgnoreElementsOperator<T, R> implements Operator<T, R> {
call(subscriber: Subscriber<R>, source: any): any {
return source.subscribe(new IgnoreElementsSubscriber(subscriber));
}
}

/**
* We need this JSDoc comment for affecting ESDoc.
* @ignore
* @extends {Ignored}
*/
class IgnoreElementsSubscriber<T> extends Subscriber<T> {
protected _next(unused: T): void {
noop();
}
}
1 change: 1 addition & 0 deletions src/operators/index.ts
Expand Up @@ -2,6 +2,7 @@ export { catchError } from './catchError';
export { concatMap } from './concatMap';
export { defaultIfEmpty } from './defaultIfEmpty';
export { filter } from './filter';
export { ignoreElements } from './ignoreElements';
export { map } from './map';
export { max } from './max';
export { mergeMap } from './mergeMap';
Expand Down

0 comments on commit 68286d4

Please sign in to comment.