Code coverage report for lib\streams\BaseStream.js

Statements: 94.21% (114 / 121)      Branches: 71.43% (10 / 14)      Functions: 97.56% (40 / 41)      Lines: 94.21% (114 / 121)      Ignored: none     

All files » lib\streams\ » BaseStream.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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219  1   1 45 44 44   1     1 1 1       1 100 100 31   100 69 69   31 31       1     1 3 3 3 3 23   3 3 3     1 4 4 4               4     1 1 1           1 28 28     1 5 5       1 14 14 14     1 2 2       1 9 9     1 2 2     1 3 3     1 2 2       1 1     1 1     1 1     1 1       1 1     1 1     1 1     1 6     1 1     1 1     1 1     1 1     1 1       1 1     1 1     1 1     1 1     1 1     1 1     1 1     1 1     1 1     1 1     1 1     1 1     1 1     1
'use strict';
var kefir = require('kefir');
 
var BaseStream = function BaseStream() {
    if (this instanceof BaseStream) {
        this.init();
        return this;
    }
    return new BaseStream();
};
 
BaseStream.prototype.emitter = null;
BaseStream.prototype.origin = null;
BaseStream.prototype.preInit = function() {
 
};
 
BaseStream.prototype.init = function(emitter, isNew) {
    var self = this;
    if (isNew) {
        self = new self.constructor();
    }
    if (emitter === undefined) {
        self.emitter = kefir.emitter();
        return self;
    }
    self.emitter = emitter;
    return self;
};
 
 
BaseStream.prototype.pipeListener = null;
 
 
BaseStream.prototype.from = function from(stream) {
    var self = this;
    self.broke();
    self.origin = stream;
    self.pipeListener = function requestEmitter(request) {
        self.emitter.emit(request);
    }
    stream.onValue(self.pipeListener);
    stream.onEnd(self.broke);
    return this;
};
 
BaseStream.prototype.broke = function broke(stream) {
    var self = this;
    stream = stream || self.origin;
    Iif (stream) {
        if (typeof self.pipeListener === 'function') {
            stream.offValue(self.pipeListener);
            self.pipeListener = null;
        }
        stream.offEnd(self.broke);
        stream.origin = null;         
    }
    return this;
};
 
BaseStream.prototype.to = function to(stream) {
    Eif (stream.from) {
        return stream.from(this);
    }
    this.onValue(stream);
    return this;
};
 
BaseStream.prototype.emit = function emit(val) {
    this.emitter.emit(val);
    return this;
};
 
BaseStream.prototype.end = function end() {
    this.emitter.end();
    return this;
};
 
 
BaseStream.prototype.onValue = function onValue(listener) {
    var self = this;
    self.emitter.onValue(listener);
    return this;
};
 
BaseStream.prototype.offValue = function offValue(listener) {
    this.emitter.offValue(listener);
    return this;
};
 
 
BaseStream.prototype.onEnd = function onEnd(listener) {
    this.emitter.onEnd(listener);
    return this;
};
 
BaseStream.prototype.offEnd = function offEnd(listener) {
    this.emitter.offEnd(listener);
    return this;
};
 
BaseStream.prototype.onAny = function onAny(listener) {
    this.emitter.onAny(listener);
    return this;
};
 
BaseStream.prototype.offAny = function offAny(listener) {
    this.emitter.offAny(listener);
    return this;
};
 
//Kefir observable
BaseStream.prototype.map = function map(fn) {
    return this.init(this.emitter.map(fn), true);
};
 
BaseStream.prototype.mapTo = function mapTo(value) {
    return this.init(this.emitter.mapTo(value), true);
};
 
BaseStream.prototype.pluck = function pluck(property) {
    return this.init(this.emitter.pluck(property), true);
};
 
BaseStream.prototype.invoke = function invoke(method) {
    return this.init(this.emitter.invoke(method), true);
};
 
 
BaseStream.prototype.not = function not() {
    return this.init(this.emitter.not(), true);
};
 
BaseStream.prototype.timestamp = function timestamp() {
    return this.init(this.emitter.timestamp(), true);
};
 
BaseStream.prototype.tap = function tap(fn) {
    return this.init(this.emitter.tap(fn), true);
};
 
BaseStream.prototype.filter = function filter(fn) {
    return this.init(this.emitter.filter(fn), true);
};
 
BaseStream.prototype.take = function take(n) {
    return this.init(this.emitter.take(n), true);
};
 
BaseStream.prototype.takeWhile = function takeWhile(predicate) {
    return this.init(this.emitter.takeWhile(predicate), true);
};
 
BaseStream.prototype.skip = function skip(n) {
    return this.init(this.emitter.skip(n), true);
};
 
BaseStream.prototype.skipWhile = function skipWhile(predicate) {
    return this.init(this.emitter.skipWhile(predicate), true);
};
 
BaseStream.prototype.skipDuplicates = function skipDuplicates(comparator) {
    return this.init(this.emitter.skipDuplicates(comparator), true);
};
 
 
BaseStream.prototype.diff = function diff(fn, seed) {
    return this.init(this.emitter.diff(fn, seed), true);
};
 
BaseStream.prototype.scan = function scan(fn, seed) {
    return this.init(this.emitter.scan(fn, seed), true);
};
 
BaseStream.prototype.reduce = function reduce(fn, seed) {
    return this.init(this.emitter.reduce(fn, seed), true);
};
 
BaseStream.prototype.mapEnd = function mapEnd(fn) {
    return this.init(this.emitter.mapEnd(fn), true);
};
 
BaseStream.prototype.skipEnd = function skipEnd() {
    return this.init(this.emitter.skipEnd(), true);
};
 
BaseStream.prototype.slidingWindow = function slidingWindow(max, min) {
    return this.init(this.emitter.slidingWindow(max, min), true);
};
 
BaseStream.prototype.bufferWhile = function bufferWhile(predicate, options) {
    return this.init(this.emitter.bufferWhile(predicate, options), true);
};
 
BaseStream.prototype.delay = function delay(wait) {
    return this.init(this.emitter.delay(wait), true);
};
 
BaseStream.prototype.throttle = function throttle(wait, options) {
    return this.init(this.emitter.throttle(wait, options), true);
};
 
BaseStream.prototype.debounce = function debounce(wait, options) {
    return this.init(this.emitter.debounce(wait, options), true);
};
 
BaseStream.prototype.flatten = function flatten(transformer) {
    return this.init(this.emitter.flatten(transformer), true);
};
 
BaseStream.prototype.transduce = function transduce(transducer) {
    return this.init(this.emitter.transduce(transducer), true);
};
 
BaseStream.prototype.withHandler = function withHandler(handler) {
    return this.init(this.emitter.withHandler(handler), true);
};
 
module.exports = BaseStream;