source: trip-planner-front/node_modules/rxjs/_esm2015/internal/operators/take.js@ 6a3a178

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.1 KB
Line 
1import { Subscriber } from '../Subscriber';
2import { ArgumentOutOfRangeError } from '../util/ArgumentOutOfRangeError';
3import { empty } from '../observable/empty';
4export function take(count) {
5 return (source) => {
6 if (count === 0) {
7 return empty();
8 }
9 else {
10 return source.lift(new TakeOperator(count));
11 }
12 };
13}
14class TakeOperator {
15 constructor(total) {
16 this.total = total;
17 if (this.total < 0) {
18 throw new ArgumentOutOfRangeError;
19 }
20 }
21 call(subscriber, source) {
22 return source.subscribe(new TakeSubscriber(subscriber, this.total));
23 }
24}
25class TakeSubscriber extends Subscriber {
26 constructor(destination, total) {
27 super(destination);
28 this.total = total;
29 this.count = 0;
30 }
31 _next(value) {
32 const total = this.total;
33 const count = ++this.count;
34 if (count <= total) {
35 this.destination.next(value);
36 if (count === total) {
37 this.destination.complete();
38 this.unsubscribe();
39 }
40 }
41 }
42}
43//# sourceMappingURL=take.js.map
Note: See TracBrowser for help on using the repository browser.