Code coverage report for cjs/observables/ScalarObservable.js

Statements: 81.32% (74 / 91)      Branches: 75% (39 / 52)      Functions: 80% (12 / 15)      Lines: 81.93% (68 / 83)      Ignored: none     

All files » cjs/observables/ » ScalarObservable.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    1   4   72   1   1   1   1   1   1   1   1   1   1   1 1   1 72   72 72 72 72         1       1                                 1 17 17 17         17 16 16         1     1 1 1 3 3 1   2     1 4 4 2 2 1   1     1 2 1   1 1     1     1     1 4 1   3 3 1   2       1 2 1   1   1 2 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 _Observable2 = require('../Observable');
 
var _Observable3 = _interopRequireDefault(_Observable2);
 
var _utilTryCatch = require('../util/tryCatch');
 
var _utilTryCatch2 = _interopRequireDefault(_utilTryCatch);
 
var _utilErrorObject = require('../util/errorObject');
 
var _ErrorObservable = require('./ErrorObservable');
 
var _ErrorObservable2 = _interopRequireDefault(_ErrorObservable);
 
var _EmptyObservable = require('./EmptyObservable');
 
var _EmptyObservable2 = _interopRequireDefault(_EmptyObservable);
 
var ScalarObservable = (function (_Observable) {
    _inherits(ScalarObservable, _Observable);
 
    function ScalarObservable(value, scheduler) {
        _classCallCheck(this, ScalarObservable);
 
        _Observable.call(this);
        this.value = value;
        this.scheduler = scheduler;
        this._isScalar = true;
    }
 
    // TypeScript is weird about class prototype member functions and instance properties touching on it's plate.
 
    ScalarObservable.create = function create(value, scheduler) {
        return new ScalarObservable(value, scheduler);
    };
 
    ScalarObservable.dispatch = function dispatch(state) {
        var done = state.done;
        var value = state.value;
        var subscriber = state.subscriber;
 
        if (done) {
            subscriber.complete();
            return;
        }
        subscriber.next(value);
        if (subscriber.isUnsubscribed) {
            return;
        }
        state.done = true;
        this.schedule(state);
    };
 
    ScalarObservable.prototype._subscribe = function _subscribe(subscriber) {
        var value = this.value;
        var scheduler = this.scheduler;
        Iif (scheduler) {
            subscriber.add(scheduler.schedule(ScalarObservable.dispatch, 0, {
                done: false, value: value, subscriber: subscriber
            }));
        } else {
            subscriber.next(value);
            Eif (!subscriber.isUnsubscribed) {
                subscriber.complete();
            }
        }
    };
 
    return ScalarObservable;
})(_Observable3['default']);
 
exports['default'] = ScalarObservable;
var proto = ScalarObservable.prototype;
proto.map = function (project, thisArg) {
    var result = _utilTryCatch2['default'](project).call(thisArg || this, this.value, 0);
    if (result === _utilErrorObject.errorObject) {
        return new _ErrorObservable2['default'](_utilErrorObject.errorObject.e);
    } else {
        return new ScalarObservable(project.call(thisArg || this, this.value, 0));
    }
};
proto.filter = function (select, thisArg) {
    var result = _utilTryCatch2['default'](select).call(thisArg || this, this.value, 0);
    if (result === _utilErrorObject.errorObject) {
        return new _ErrorObservable2['default'](_utilErrorObject.errorObject.e);
    } else if (result) {
        return this;
    } else {
        return new _EmptyObservable2['default']();
    }
};
proto.reduce = function (project, acc) {
    if (typeof acc === 'undefined') {
        return this;
    }
    var result = _utilTryCatch2['default'](project)(acc, this.value);
    Iif (result === _utilErrorObject.errorObject) {
        return new _ErrorObservable2['default'](_utilErrorObject.errorObject.e);
    } else {
        return new ScalarObservable(result);
    }
};
proto.scan = function (project, acc) {
    return this.reduce(project, acc);
};
proto.count = function (predicate, thisArg) {
    if (!predicate) {
        return new ScalarObservable(1);
    } else {
        var result = _utilTryCatch2['default'](predicate).call(thisArg || this, this.value, 0, this);
        if (result === _utilErrorObject.errorObject) {
            return new _ErrorObservable2['default'](_utilErrorObject.errorObject.e);
        } else {
            return new ScalarObservable(result ? 1 : 0);
        }
    }
};
proto.skip = function (count) {
    if (count > 0) {
        return new _EmptyObservable2['default']();
    }
    return this;
};
proto.take = function (count) {
    if (count > 0) {
        return this;
    }
    return new _EmptyObservable2['default']();
};
//# sourceMappingURL=ScalarObservable.js.map
module.exports = exports['default'];
//# sourceMappingURL=ScalarObservable.js.map