Code coverage report for cjs/operators/debounce.js

Statements: 96% (96 / 100)      Branches: 73.68% (28 / 38)      Functions: 100% (23 / 23)      Lines: 100% (78 / 78)      Ignored: none     

All files » cjs/operators/ » debounce.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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145    1   1   1   3   2   108   1   1   1   1   1   1   1   1 22     1 1 22   22     1 22     1     1 1   1 22   22 22 22 22 22     1 65 65 65 65 1   64 7   64 64       1 11 11     1 57 57 46 46       1 57 57 46 46       1     72       1     1 1   1 64   64 64 64         1 72 72 46 46 46         1 55     1 2     1 17     1     1  
'use strict';
 
exports.__esModule = true;
 
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; Iif ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { Eif (protoProps) defineProperties(Constructor.prototype, protoProps); Iif (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
 
exports['default'] = debounce;
 
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 _observablesPromiseObservable = require('../observables/PromiseObservable');
 
var _observablesPromiseObservable2 = _interopRequireDefault(_observablesPromiseObservable);
 
var _Subscriber3 = require('../Subscriber');
 
var _Subscriber4 = _interopRequireDefault(_Subscriber3);
 
var _utilTryCatch = require('../util/tryCatch');
 
var _utilTryCatch2 = _interopRequireDefault(_utilTryCatch);
 
var _utilErrorObject = require('../util/errorObject');
 
function debounce(durationSelector) {
    return this.lift(new DebounceOperator(durationSelector));
}
 
var DebounceOperator = (function () {
    function DebounceOperator(durationSelector) {
        _classCallCheck(this, DebounceOperator);
 
        this.durationSelector = durationSelector;
    }
 
    DebounceOperator.prototype.call = function call(observer) {
        return new DebounceSubscriber(observer, this.durationSelector);
    };
 
    return DebounceOperator;
})();
 
var DebounceSubscriber = (function (_Subscriber) {
    _inherits(DebounceSubscriber, _Subscriber);
 
    function DebounceSubscriber(destination, durationSelector) {
        _classCallCheck(this, DebounceSubscriber);
 
        _Subscriber.call(this, destination);
        this.durationSelector = durationSelector;
        this.debouncedSubscription = null;
        this.lastValue = null;
        this._index = 0;
    }
 
    DebounceSubscriber.prototype._next = function _next(value) {
        var destination = this.destination;
        var currentIndex = ++this._index;
        var debounce = _utilTryCatch2['default'](this.durationSelector)(value);
        if (debounce === _utilErrorObject.errorObject) {
            destination.error(_utilErrorObject.errorObject.e);
        } else {
            if (typeof debounce.subscribe !== 'function' && typeof debounce.then === 'function') {
                debounce = _observablesPromiseObservable2['default'].create(debounce);
            }
            this.lastValue = value;
            this.add(this.debouncedSubscription = debounce._subscribe(new DurationSelectorSubscriber(this, currentIndex)));
        }
    };
 
    DebounceSubscriber.prototype._complete = function _complete() {
        this.debouncedNext();
        this.destination.complete();
    };
 
    DebounceSubscriber.prototype.debouncedNext = function debouncedNext() {
        this.clearDebounce();
        if (this.lastValue != null) {
            this.destination.next(this.lastValue);
            this.lastValue = null;
        }
    };
 
    DebounceSubscriber.prototype.clearDebounce = function clearDebounce() {
        var debouncedSubscription = this.debouncedSubscription;
        if (debouncedSubscription !== null) {
            this.remove(debouncedSubscription);
            this.debouncedSubscription = null;
        }
    };
 
    _createClass(DebounceSubscriber, [{
        key: 'index',
        get: function get() {
            return this._index;
        }
    }]);
 
    return DebounceSubscriber;
})(_Subscriber4['default']);
 
var DurationSelectorSubscriber = (function (_Subscriber2) {
    _inherits(DurationSelectorSubscriber, _Subscriber2);
 
    function DurationSelectorSubscriber(parent, currentIndex) {
        _classCallCheck(this, DurationSelectorSubscriber);
 
        _Subscriber2.call(this, null);
        this.parent = parent;
        this.currentIndex = currentIndex;
    }
 
    //# sourceMappingURL=debounce.js.map
 
    DurationSelectorSubscriber.prototype.debounceNext = function debounceNext() {
        var parent = this.parent;
        if (this.currentIndex === parent.index) {
            parent.debouncedNext();
            Eif (!this.isUnsubscribed) {
                this.unsubscribe();
            }
        }
    };
 
    DurationSelectorSubscriber.prototype._next = function _next(unused) {
        this.debounceNext();
    };
 
    DurationSelectorSubscriber.prototype._error = function _error(err) {
        this.parent.error(err);
    };
 
    DurationSelectorSubscriber.prototype._complete = function _complete() {
        this.debounceNext();
    };
 
    return DurationSelectorSubscriber;
})(_Subscriber4['default']);
 
module.exports = exports['default'];
//# sourceMappingURL=debounce.js.map