Code coverage report for cjs/operators/bufferWhen.js

Statements: 97.3% (72 / 74)      Branches: 72.73% (16 / 22)      Functions: 100% (18 / 18)      Lines: 100% (66 / 66)      Ignored: none     

All files » cjs/operators/ » bufferWhen.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126    1 1   2   2   2736   1   1   1   1   1                 1 16     1 1 16   16     1 16     1     1 1   1 16   16 16 16     1 59     1 5 5     1 6 6 6 6     1 2706 2706 19 19   2706 2706 2690   2705 2705 2705 1 1 1   2704       1     1 1   1 2704   2704 2704         1 17     1 3     1 2673     1     1  
'use strict';
 
exports.__esModule = true;
exports['default'] = bufferWhen;
 
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
 
function _inherits(subClass, superClass) { Iif (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); Eif (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
 
function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
 
var _Subscriber3 = require('../Subscriber');
 
var _Subscriber4 = _interopRequireDefault(_Subscriber3);
 
var _utilTryCatch = require('../util/tryCatch');
 
var _utilTryCatch2 = _interopRequireDefault(_utilTryCatch);
 
var _utilErrorObject = require('../util/errorObject');
 
/**
 * Opens a buffer immediately, then closes the buffer when the observable returned by calling `closingSelector` emits a value.
 * It that immediately opens a new buffer and repeats the process
 * @param {function} a function that takes no arguments and returns an Observable that signals buffer closure
 * @returns {Observable<T[]>} an observable of arrays of buffered values.
 */
 
function bufferWhen(closingSelector) {
    return this.lift(new BufferWhenOperator(closingSelector));
}
 
var BufferWhenOperator = (function () {
    function BufferWhenOperator(closingSelector) {
        _classCallCheck(this, BufferWhenOperator);
 
        this.closingSelector = closingSelector;
    }
 
    BufferWhenOperator.prototype.call = function call(subscriber) {
        return new BufferWhenSubscriber(subscriber, this.closingSelector);
    };
 
    return BufferWhenOperator;
})();
 
var BufferWhenSubscriber = (function (_Subscriber) {
    _inherits(BufferWhenSubscriber, _Subscriber);
 
    function BufferWhenSubscriber(destination, closingSelector) {
        _classCallCheck(this, BufferWhenSubscriber);
 
        _Subscriber.call(this, destination);
        this.closingSelector = closingSelector;
        this.openBuffer();
    }
 
    BufferWhenSubscriber.prototype._next = function _next(value) {
        this.buffer.push(value);
    };
 
    BufferWhenSubscriber.prototype._error = function _error(err) {
        this.buffer = null;
        this.destination.error(err);
    };
 
    BufferWhenSubscriber.prototype._complete = function _complete() {
        var buffer = this.buffer;
        this.destination.next(buffer);
        this.buffer = null;
        this.destination.complete();
    };
 
    BufferWhenSubscriber.prototype.openBuffer = function openBuffer() {
        var prevClosingNotification = this.closingNotification;
        if (prevClosingNotification) {
            this.remove(prevClosingNotification);
            prevClosingNotification.unsubscribe();
        }
        var buffer = this.buffer;
        if (buffer) {
            this.destination.next(buffer);
        }
        this.buffer = [];
        var closingNotifier = _utilTryCatch2['default'](this.closingSelector)();
        if (closingNotifier === _utilErrorObject.errorObject) {
            var err = closingNotifier.e;
            this.buffer = null;
            this.destination.error(err);
        } else {
            this.add(this.closingNotification = closingNotifier._subscribe(new BufferClosingNotifierSubscriber(this)));
        }
    };
 
    return BufferWhenSubscriber;
})(_Subscriber4['default']);
 
var BufferClosingNotifierSubscriber = (function (_Subscriber2) {
    _inherits(BufferClosingNotifierSubscriber, _Subscriber2);
 
    function BufferClosingNotifierSubscriber(parent) {
        _classCallCheck(this, BufferClosingNotifierSubscriber);
 
        _Subscriber2.call(this, null);
        this.parent = parent;
    }
 
    //# sourceMappingURL=bufferWhen.js.map
 
    BufferClosingNotifierSubscriber.prototype._next = function _next() {
        this.parent.openBuffer();
    };
 
    BufferClosingNotifierSubscriber.prototype._error = function _error(err) {
        this.parent.error(err);
    };
 
    BufferClosingNotifierSubscriber.prototype._complete = function _complete() {
        this.parent.openBuffer();
    };
 
    return BufferClosingNotifierSubscriber;
})(_Subscriber4['default']);
 
module.exports = exports['default'];
//# sourceMappingURL=bufferWhen.js.map