This repository has been archived on 2024-07-27. You can view files and clone it, but cannot push or open issues or pull requests.
keksAccountGUI/node_modulesOLD/rxjs/_esm2015/internal/operators/bufferWhen.js
2019-08-11 20:48:02 +02:00

76 lines
No EOL
2.2 KiB
JavaScript

import { Subscription } from '../Subscription';
import { OuterSubscriber } from '../OuterSubscriber';
import { subscribeToResult } from '../util/subscribeToResult';
export function bufferWhen(closingSelector) {
return function (source) {
return source.lift(new BufferWhenOperator(closingSelector));
};
}
class BufferWhenOperator {
constructor(closingSelector) {
this.closingSelector = closingSelector;
}
call(subscriber, source) {
return source.subscribe(new BufferWhenSubscriber(subscriber, this.closingSelector));
}
}
class BufferWhenSubscriber extends OuterSubscriber {
constructor(destination, closingSelector) {
super(destination);
this.closingSelector = closingSelector;
this.subscribing = false;
this.openBuffer();
}
_next(value) {
this.buffer.push(value);
}
_complete() {
const buffer = this.buffer;
if (buffer) {
this.destination.next(buffer);
}
super._complete();
}
_unsubscribe() {
this.buffer = null;
this.subscribing = false;
}
notifyNext(outerValue, innerValue, outerIndex, innerIndex, innerSub) {
this.openBuffer();
}
notifyComplete() {
if (this.subscribing) {
this.complete();
}
else {
this.openBuffer();
}
}
openBuffer() {
let { closingSubscription } = this;
if (closingSubscription) {
this.remove(closingSubscription);
closingSubscription.unsubscribe();
}
const buffer = this.buffer;
if (this.buffer) {
this.destination.next(buffer);
}
this.buffer = [];
let closingNotifier;
try {
const { closingSelector } = this;
closingNotifier = closingSelector();
}
catch (err) {
return this.error(err);
}
closingSubscription = new Subscription();
this.closingSubscription = closingSubscription;
this.add(closingSubscription);
this.subscribing = true;
closingSubscription.add(subscribeToResult(this, closingNotifier));
this.subscribing = false;
}
}
//# sourceMappingURL=bufferWhen.js.map