source: trip-planner-front/node_modules/rxjs/_esm2015/internal/operators/find.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.7 KB
Line 
1import { Subscriber } from '../Subscriber';
2export function find(predicate, thisArg) {
3 if (typeof predicate !== 'function') {
4 throw new TypeError('predicate is not a function');
5 }
6 return (source) => source.lift(new FindValueOperator(predicate, source, false, thisArg));
7}
8export class FindValueOperator {
9 constructor(predicate, source, yieldIndex, thisArg) {
10 this.predicate = predicate;
11 this.source = source;
12 this.yieldIndex = yieldIndex;
13 this.thisArg = thisArg;
14 }
15 call(observer, source) {
16 return source.subscribe(new FindValueSubscriber(observer, this.predicate, this.source, this.yieldIndex, this.thisArg));
17 }
18}
19export class FindValueSubscriber extends Subscriber {
20 constructor(destination, predicate, source, yieldIndex, thisArg) {
21 super(destination);
22 this.predicate = predicate;
23 this.source = source;
24 this.yieldIndex = yieldIndex;
25 this.thisArg = thisArg;
26 this.index = 0;
27 }
28 notifyComplete(value) {
29 const destination = this.destination;
30 destination.next(value);
31 destination.complete();
32 this.unsubscribe();
33 }
34 _next(value) {
35 const { predicate, thisArg } = this;
36 const index = this.index++;
37 try {
38 const result = predicate.call(thisArg || this, value, index, this.source);
39 if (result) {
40 this.notifyComplete(this.yieldIndex ? index : value);
41 }
42 }
43 catch (err) {
44 this.destination.error(err);
45 }
46 }
47 _complete() {
48 this.notifyComplete(this.yieldIndex ? -1 : undefined);
49 }
50}
51//# sourceMappingURL=find.js.map
Note: See TracBrowser for help on using the repository browser.