# Code coverage report for RxJS/dist/cjs/operators/debounceTime.js

## Statements: 96.61% (57 / 59) Branches: 70.83% (17 / 24) Functions: 100% (14 / 14) Lines: 100% (51 / 51) Ignored: none

All files » RxJS/dist/cjs/operators/ » debounceTime.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

    1
    1

    2

    1

    24

    1

    1

    1

    1

    1
    12

    12

    1
    1
    12

    12
    12

    1
    12

    1

    1
    1

    1
    12

    12
    12
    12
    12
    12

    1
    30
    30
    30

    1
    5
    5

    1
    13
    13
    10
    10

    1
    43
    43
    28
    28
    28

    1

    1
    8

    1'use strict';

    exports.__esModule = true;
    exports['default'] = debounceTime;

    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 _Subscriber2 = require('../Subscriber');

    var _Subscriber3 = _interopRequireDefault(_Subscriber2);

    var _schedulersNextTick = require('../schedulers/nextTick');

    var _schedulersNextTick2 = _interopRequireDefault(_schedulersNextTick);

    function debounceTime(dueTime) {
        var scheduler = arguments.length <= 1 || arguments[1] === undefined ? _schedulersNextTick2['default'] : arguments[1];

        return this.lift(new DebounceTimeOperator(dueTime, scheduler));
    }

    var DebounceTimeOperator = (function () {
        function DebounceTimeOperator(dueTime, scheduler) {
            _classCallCheck(this, DebounceTimeOperator);

            this.dueTime = dueTime;
            this.scheduler = scheduler;
        }

        DebounceTimeOperator.prototype.call = function call(subscriber) {
            return new DebounceTimeSubscriber(subscriber, this.dueTime, this.scheduler);
        };

        return DebounceTimeOperator;
    })();

    var DebounceTimeSubscriber = (function (_Subscriber) {
        _inherits(DebounceTimeSubscriber, _Subscriber);

        function DebounceTimeSubscriber(destination, dueTime, scheduler) {
            _classCallCheck(this, DebounceTimeSubscriber);

            _Subscriber.call(this, destination);
            this.dueTime = dueTime;
            this.scheduler = scheduler;
            this.debouncedSubscription = null;
            this.lastValue = null;
        }

        DebounceTimeSubscriber.prototype._next = function _next(value) {
            this.clearDebounce();
            this.lastValue = value;
            this.add(this.debouncedSubscription = this.scheduler.schedule(dispatchNext, this.dueTime, this));
        };

        DebounceTimeSubscriber.prototype._complete = function _complete() {
            this.debouncedNext();
            this.destination.complete();
        };

        DebounceTimeSubscriber.prototype.debouncedNext = function debouncedNext() {
            this.clearDebounce();
            if (this.lastValue != null) {
                this.destination.next(this.lastValue);
                this.lastValue = null;
            }
        };

        DebounceTimeSubscriber.prototype.clearDebounce = function clearDebounce() {
            var debouncedSubscription = this.debouncedSubscription;
            if (debouncedSubscription !== null) {
                this.remove(debouncedSubscription);
                debouncedSubscription.unsubscribe();
                this.debouncedSubscription = null;
            }
        };

        return DebounceTimeSubscriber;
    })(_Subscriber3['default']);

    function dispatchNext(subscriber) {
        subscriber.debouncedNext();
    }
    module.exports = exports['default'];