Last change
on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Line | |
---|
1 | import { Operator } from '../Operator';
|
---|
2 | import { Subscriber } from '../Subscriber';
|
---|
3 | import { Observable } from '../Observable';
|
---|
4 | import { MonoTypeOperatorFunction, TeardownLogic } from '../types';
|
---|
5 |
|
---|
6 | /**
|
---|
7 | * Returns an Observable that skips the first `count` items emitted by the source Observable.
|
---|
8 | *
|
---|
9 | * ![](skip.png)
|
---|
10 | *
|
---|
11 | * @param {Number} count - The number of times, items emitted by source Observable should be skipped.
|
---|
12 | * @return {Observable} An Observable that skips values emitted by the source Observable.
|
---|
13 | *
|
---|
14 | * @method skip
|
---|
15 | * @owner Observable
|
---|
16 | */
|
---|
17 | export function skip<T>(count: number): MonoTypeOperatorFunction<T> {
|
---|
18 | return (source: Observable<T>) => source.lift(new SkipOperator(count));
|
---|
19 | }
|
---|
20 |
|
---|
21 | class SkipOperator<T> implements Operator<T, T> {
|
---|
22 | constructor(private total: number) {
|
---|
23 | }
|
---|
24 |
|
---|
25 | call(subscriber: Subscriber<T>, source: any): TeardownLogic {
|
---|
26 | return source.subscribe(new SkipSubscriber(subscriber, this.total));
|
---|
27 | }
|
---|
28 | }
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * We need this JSDoc comment for affecting ESDoc.
|
---|
32 | * @ignore
|
---|
33 | * @extends {Ignored}
|
---|
34 | */
|
---|
35 | class SkipSubscriber<T> extends Subscriber<T> {
|
---|
36 | count: number = 0;
|
---|
37 |
|
---|
38 | constructor(destination: Subscriber<T>, private total: number) {
|
---|
39 | super(destination);
|
---|
40 | }
|
---|
41 |
|
---|
42 | protected _next(x: T) {
|
---|
43 | if (++this.count > this.total) {
|
---|
44 | this.destination.next(x);
|
---|
45 | }
|
---|
46 | }
|
---|
47 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.