52 lines
2.0 KiB
JavaScript
52 lines
2.0 KiB
JavaScript
"use strict";
|
|
var __extends = (this && this.__extends) || function (d, b) {
|
|
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
var OuterSubscriber_1 = require('../OuterSubscriber');
|
|
var subscribeToResult_1 = require('../util/subscribeToResult');
|
|
/**
|
|
* Buffers the incoming observable values until the passed `closingNotifier`
|
|
* emits a value, at which point it emits the buffer on the returned observable
|
|
* and starts a new buffer internally, awaiting the next time `closingNotifier`
|
|
* emits.
|
|
*
|
|
* <img src="./img/buffer.png" width="100%">
|
|
*
|
|
* @param {Observable<any>} closingNotifier an Observable that signals the
|
|
* buffer to be emitted} from the returned observable.
|
|
* @returns {Observable<T[]>} an Observable of buffers, which are arrays of
|
|
* values.
|
|
*/
|
|
function buffer(closingNotifier) {
|
|
return this.lift(new BufferOperator(closingNotifier));
|
|
}
|
|
exports.buffer = buffer;
|
|
var BufferOperator = (function () {
|
|
function BufferOperator(closingNotifier) {
|
|
this.closingNotifier = closingNotifier;
|
|
}
|
|
BufferOperator.prototype.call = function (subscriber) {
|
|
return new BufferSubscriber(subscriber, this.closingNotifier);
|
|
};
|
|
return BufferOperator;
|
|
}());
|
|
var BufferSubscriber = (function (_super) {
|
|
__extends(BufferSubscriber, _super);
|
|
function BufferSubscriber(destination, closingNotifier) {
|
|
_super.call(this, destination);
|
|
this.buffer = [];
|
|
this.add(subscribeToResult_1.subscribeToResult(this, closingNotifier));
|
|
}
|
|
BufferSubscriber.prototype._next = function (value) {
|
|
this.buffer.push(value);
|
|
};
|
|
BufferSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
|
|
var buffer = this.buffer;
|
|
this.buffer = [];
|
|
this.destination.next(buffer);
|
|
};
|
|
return BufferSubscriber;
|
|
}(OuterSubscriber_1.OuterSubscriber));
|
|
//# sourceMappingURL=buffer.js.map
|