source: trip-planner-front/node_modules/rxjs/_esm2015/internal/operators/takeWhile.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.3 KB
Line 
1import { Subscriber } from '../Subscriber';
2export function takeWhile(predicate, inclusive = false) {
3 return (source) => source.lift(new TakeWhileOperator(predicate, inclusive));
4}
5class TakeWhileOperator {
6 constructor(predicate, inclusive) {
7 this.predicate = predicate;
8 this.inclusive = inclusive;
9 }
10 call(subscriber, source) {
11 return source.subscribe(new TakeWhileSubscriber(subscriber, this.predicate, this.inclusive));
12 }
13}
14class TakeWhileSubscriber extends Subscriber {
15 constructor(destination, predicate, inclusive) {
16 super(destination);
17 this.predicate = predicate;
18 this.inclusive = inclusive;
19 this.index = 0;
20 }
21 _next(value) {
22 const destination = this.destination;
23 let result;
24 try {
25 result = this.predicate(value, this.index++);
26 }
27 catch (err) {
28 destination.error(err);
29 return;
30 }
31 this.nextOrComplete(value, result);
32 }
33 nextOrComplete(value, predicateResult) {
34 const destination = this.destination;
35 if (Boolean(predicateResult)) {
36 destination.next(value);
37 }
38 else {
39 if (this.inclusive) {
40 destination.next(value);
41 }
42 destination.complete();
43 }
44 }
45}
46//# sourceMappingURL=takeWhile.js.map
Note: See TracBrowser for help on using the repository browser.