-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ignoreElements): add higher-order lettable version of ignoreElem…
…ents
- Loading branch information
Showing
3 changed files
with
41 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters