Last change
on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Line | |
---|
1 | import { Subscriber } from '../Subscriber';
|
---|
2 | import { empty } from '../observable/empty';
|
---|
3 | export function repeat(count = -1) {
|
---|
4 | return (source) => {
|
---|
5 | if (count === 0) {
|
---|
6 | return empty();
|
---|
7 | }
|
---|
8 | else if (count < 0) {
|
---|
9 | return source.lift(new RepeatOperator(-1, source));
|
---|
10 | }
|
---|
11 | else {
|
---|
12 | return source.lift(new RepeatOperator(count - 1, source));
|
---|
13 | }
|
---|
14 | };
|
---|
15 | }
|
---|
16 | class RepeatOperator {
|
---|
17 | constructor(count, source) {
|
---|
18 | this.count = count;
|
---|
19 | this.source = source;
|
---|
20 | }
|
---|
21 | call(subscriber, source) {
|
---|
22 | return source.subscribe(new RepeatSubscriber(subscriber, this.count, this.source));
|
---|
23 | }
|
---|
24 | }
|
---|
25 | class RepeatSubscriber extends Subscriber {
|
---|
26 | constructor(destination, count, source) {
|
---|
27 | super(destination);
|
---|
28 | this.count = count;
|
---|
29 | this.source = source;
|
---|
30 | }
|
---|
31 | complete() {
|
---|
32 | if (!this.isStopped) {
|
---|
33 | const { source, count } = this;
|
---|
34 | if (count === 0) {
|
---|
35 | return super.complete();
|
---|
36 | }
|
---|
37 | else if (count > -1) {
|
---|
38 | this.count = count - 1;
|
---|
39 | }
|
---|
40 | source.subscribe(this._unsubscribeAndRecycle());
|
---|
41 | }
|
---|
42 | }
|
---|
43 | }
|
---|
44 | //# sourceMappingURL=repeat.js.map |
---|
Note:
See
TracBrowser
for help on using the repository browser.