/
eapostnova
/
2026-1--study--mathmod
Обзор
Документация
Войти
/
eapostnova
/
2026-1--study--mathmod
Код
Запросы
0
Задачи
Пакеты
0
Релизы
6
Аналитика
Безопасность
develop
node_modules/rxjs/_esm2015/internal/operators/bufferWhen.js
75 строк
2 KB
Елизавета Постнова
feat(lab): lab04
24 мар 2026, 02:59
Верифицирован
24 мар 2026, 02:59
7783508
Код
Авторство
О чём код?
import { Subscription } from '../Subscription'; import { SimpleOuterSubscriber, innerSubscribe, SimpleInnerSubscriber } from '../innerSubscribe'; 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 SimpleOuterSubscriber { 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 = undefined; this.subscribing = false; } notifyNext() { 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(innerSubscribe(closingNotifier, new SimpleInnerSubscriber(this))); this.subscribing = false; } } //# sourceMappingURL=bufferWhen.js.map