xstream
Version:
An extremely intuitive, small, and fast functional reactive stream library for JavaScript
92 lines • 2.71 kB
JavaScript
;
var core_1 = require('../core');
var FCIL = (function () {
function FCIL(out, op) {
this.out = out;
this.op = op;
}
FCIL.prototype._n = function (t) {
this.out._n(t);
};
FCIL.prototype._e = function (err) {
this.out._e(err);
};
FCIL.prototype._c = function () {
this.op.less();
};
return FCIL;
}());
var FlattenConcOperator = (function () {
function FlattenConcOperator(ins) {
this.ins = ins;
this.type = 'flattenConcurrently';
this.active = 1; // number of outers and inners that have not yet ended
this.out = null;
}
FlattenConcOperator.prototype._start = function (out) {
this.out = out;
this.ins._add(this);
};
FlattenConcOperator.prototype._stop = function () {
this.ins._remove(this);
this.active = 1;
this.out = null;
};
FlattenConcOperator.prototype.less = function () {
if (--this.active === 0) {
var u = this.out;
if (!u)
return;
u._c();
}
};
FlattenConcOperator.prototype._n = function (s) {
var u = this.out;
if (!u)
return;
this.active++;
s._add(new FCIL(u, this));
};
FlattenConcOperator.prototype._e = function (err) {
var u = this.out;
if (!u)
return;
u._e(err);
};
FlattenConcOperator.prototype._c = function () {
this.less();
};
return FlattenConcOperator;
}());
exports.FlattenConcOperator = FlattenConcOperator;
/**
* Flattens a "stream of streams", handling multiple concurrent nested streams
* simultaneously.
*
* If the input stream is a stream that emits streams, then this operator will
* return an output stream which is a flat stream: emits regular events. The
* flattening happens concurrently. It works like this: when the input stream
* emits a nested stream, *flattenConcurrently* will start imitating that
* nested one. When the next nested stream is emitted on the input stream,
* *flattenConcurrently* will also imitate that new one, but will continue to
* imitate the previous nested streams as well.
*
* Marble diagram:
*
* ```text
* --+--------+---------------
* \ \
* \ ----1----2---3--
* --a--b----c----d--------
* flattenConcurrently
* -----a--b----c-1--d-2---3--
* ```
*
* @return {Stream}
*/
function flattenConcurrently(ins) {
return new core_1.Stream(new FlattenConcOperator(ins));
}
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = flattenConcurrently;
//# sourceMappingURL=flattenConcurrently.js.map