source: trip-planner-front/node_modules/rxjs/_esm2015/internal/operators/scan.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.5 KB
Line 
1import { Subscriber } from '../Subscriber';
2export function scan(accumulator, seed) {
3 let hasSeed = false;
4 if (arguments.length >= 2) {
5 hasSeed = true;
6 }
7 return function scanOperatorFunction(source) {
8 return source.lift(new ScanOperator(accumulator, seed, hasSeed));
9 };
10}
11class ScanOperator {
12 constructor(accumulator, seed, hasSeed = false) {
13 this.accumulator = accumulator;
14 this.seed = seed;
15 this.hasSeed = hasSeed;
16 }
17 call(subscriber, source) {
18 return source.subscribe(new ScanSubscriber(subscriber, this.accumulator, this.seed, this.hasSeed));
19 }
20}
21class ScanSubscriber extends Subscriber {
22 constructor(destination, accumulator, _seed, hasSeed) {
23 super(destination);
24 this.accumulator = accumulator;
25 this._seed = _seed;
26 this.hasSeed = hasSeed;
27 this.index = 0;
28 }
29 get seed() {
30 return this._seed;
31 }
32 set seed(value) {
33 this.hasSeed = true;
34 this._seed = value;
35 }
36 _next(value) {
37 if (!this.hasSeed) {
38 this.seed = value;
39 this.destination.next(value);
40 }
41 else {
42 return this._tryNext(value);
43 }
44 }
45 _tryNext(value) {
46 const index = this.index++;
47 let result;
48 try {
49 result = this.accumulator(this.seed, value, index);
50 }
51 catch (err) {
52 this.destination.error(err);
53 }
54 this.seed = result;
55 this.destination.next(result);
56 }
57}
58//# sourceMappingURL=scan.js.map
Note: See TracBrowser for help on using the repository browser.