# Code coverage report for RxJS/dist/cjs/observables/TimerObservable.js

## Statements: 93.65% (59 / 63) Branches: 76.92% (30 / 39) Functions: 100% (8 / 8) Lines: 100% (53 / 53) Ignored: none

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

    1

    3

    35

    1

    1

    1

    1

    1

    1

    1

    1
    1

    1
    35

    35

    35
    35
    35
    35
    35
    2
    33
    25

    35
    9

    35

    1
    35

    35

    1
    39
    39
    39

    39
    39
    39
    31
    31
    8
    2

    6
    1

    5
    5

    1
    35
    35
    35
    35
    35

    1

    1
    1'use strict';

    exports.__esModule = true;

    function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

    function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }

    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; }

    var _utilIsNumeric = require('../util/isNumeric');

    var _utilIsNumeric2 = _interopRequireDefault(_utilIsNumeric);

    var _Observable2 = require('../Observable');

    var _Observable3 = _interopRequireDefault(_Observable2);

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

    var _schedulersNextTick2 = _interopRequireDefault(_schedulersNextTick);

    var TimerObservable = (function (_Observable) {
        _inherits(TimerObservable, _Observable);

        function TimerObservable(dueTime, period, scheduler) {
            Iif (dueTime === undefined) dueTime = 0;

            _classCallCheck(this, TimerObservable);

            _Observable.call(this);
            this.dueTime = dueTime;
            this.period = period;
            this.scheduler = scheduler;
            if (_utilIsNumeric2['default'](period)) {
                this._period = Number(period) < 1 && 1 || Number(period);
            } else if (period && typeof period.schedule === 'function') {
                scheduler = period;
            }
            if (!scheduler || typeof scheduler.schedule !== 'function') {
                scheduler = _schedulersNextTick2['default'];
            }
            this.scheduler = scheduler;
        }

        TimerObservable.create = function create(dueTime, period, scheduler) {
            Iif (dueTime === undefined) dueTime = 0;

            return new TimerObservable(dueTime, period, scheduler);
        };

        TimerObservable.dispatch = function dispatch(state) {
            var index = state.index;
            var period = state.period;
            var subscriber = state.subscriber;

            var action = this;
            subscriber.next(index);
            if (typeof period === 'undefined') {
                subscriber.complete();
                return;
            } else if (subscriber.isUnsubscribed) {
                return;
            }
            if (typeof action.delay === 'undefined') {
                action.add(action.scheduler.schedule(TimerObservable.dispatch, period, {
                    index: index + 1, period: period, subscriber: subscriber
                }));
            } else {
                state.index = index + 1;
                action.schedule(state, period);
            }
        };

        TimerObservable.prototype._subscribe = function _subscribe(subscriber) {
            var index = 0;
            var period = this._period;
            var dueTime = this.dueTime;
            var scheduler = this.scheduler;
            subscriber.add(scheduler.schedule(TimerObservable.dispatch, dueTime, { index: index, period: period, subscriber: subscriber }));
        };

        return TimerObservable;
    })(_Observable3['default']);

    exports['default'] = TimerObservable;
    module.exports = exports['default'];