source: trip-planner-front/node_modules/rxjs/_esm2015/internal/operators/bufferWhen.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: 2.2 KB
Line 
1import { Subscription } from '../Subscription';
2import { SimpleOuterSubscriber, innerSubscribe, SimpleInnerSubscriber } from '../innerSubscribe';
3export function bufferWhen(closingSelector) {
4 return function (source) {
5 return source.lift(new BufferWhenOperator(closingSelector));
6 };
7}
8class BufferWhenOperator {
9 constructor(closingSelector) {
10 this.closingSelector = closingSelector;
11 }
12 call(subscriber, source) {
13 return source.subscribe(new BufferWhenSubscriber(subscriber, this.closingSelector));
14 }
15}
16class BufferWhenSubscriber extends SimpleOuterSubscriber {
17 constructor(destination, closingSelector) {
18 super(destination);
19 this.closingSelector = closingSelector;
20 this.subscribing = false;
21 this.openBuffer();
22 }
23 _next(value) {
24 this.buffer.push(value);
25 }
26 _complete() {
27 const buffer = this.buffer;
28 if (buffer) {
29 this.destination.next(buffer);
30 }
31 super._complete();
32 }
33 _unsubscribe() {
34 this.buffer = undefined;
35 this.subscribing = false;
36 }
37 notifyNext() {
38 this.openBuffer();
39 }
40 notifyComplete() {
41 if (this.subscribing) {
42 this.complete();
43 }
44 else {
45 this.openBuffer();
46 }
47 }
48 openBuffer() {
49 let { closingSubscription } = this;
50 if (closingSubscription) {
51 this.remove(closingSubscription);
52 closingSubscription.unsubscribe();
53 }
54 const buffer = this.buffer;
55 if (this.buffer) {
56 this.destination.next(buffer);
57 }
58 this.buffer = [];
59 let closingNotifier;
60 try {
61 const { closingSelector } = this;
62 closingNotifier = closingSelector();
63 }
64 catch (err) {
65 return this.error(err);
66 }
67 closingSubscription = new Subscription();
68 this.closingSubscription = closingSubscription;
69 this.add(closingSubscription);
70 this.subscribing = true;
71 closingSubscription.add(innerSubscribe(closingNotifier, new SimpleInnerSubscriber(this)));
72 this.subscribing = false;
73 }
74}
75//# sourceMappingURL=bufferWhen.js.map
Note: See TracBrowser for help on using the repository browser.