@cycle/xstream-adapter
Advanced tools
Comparing version 3.0.2 to 3.0.3
1369
dist/xstream.js
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.xstream = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
"use strict"; | ||
var xstream_1 = require('xstream'); | ||
function logToConsoleError(err) { | ||
var target = err.stack || err; | ||
if (console && console.error) { | ||
console.error(target); | ||
} | ||
else if (console && console.log) { | ||
console.log(target); | ||
} | ||
} | ||
var XStreamAdapter = { | ||
@@ -22,7 +13,3 @@ adapt: function (originStream, originStreamSubscribe) { | ||
start: function (out) { | ||
var observer = { | ||
next: function (value) { return out.shamefullySendNext(value); }, | ||
error: function (err) { return out.shamefullySendError(err); }, | ||
complete: function () { return out.shamefullySendComplete(); }, | ||
}; | ||
var observer = out; | ||
dispose = originStreamSubscribe(originStream, observer); | ||
@@ -37,20 +24,7 @@ }, | ||
}, | ||
dispose: function (sinks, sinkProxies, sources) { | ||
Object.keys(sources).forEach(function (k) { | ||
if (typeof sources[k].dispose === 'function') { | ||
sources[k].dispose(); | ||
} | ||
}); | ||
Object.keys(sinkProxies).forEach(function (k) { | ||
sinkProxies[k].observer.complete(); | ||
}); | ||
}, | ||
makeHoldSubject: function () { | ||
var stream = xstream_1.default.createWithMemory(); | ||
makeSubject: function () { | ||
var stream = xstream_1.default.create(); | ||
var observer = { | ||
next: function (x) { stream.shamefullySendNext(x); }, | ||
error: function (err) { | ||
logToConsoleError(err); | ||
stream.shamefullySendError(err); | ||
}, | ||
error: function (err) { stream.shamefullySendError(err); }, | ||
complete: function () { stream.shamefullySendComplete(); } | ||
@@ -60,5 +34,8 @@ }; | ||
}, | ||
remember: function (stream) { | ||
return stream.remember(); | ||
}, | ||
isValidStream: function (stream) { | ||
return (typeof stream.addListener === 'function' && | ||
typeof stream.imitate === 'function'); | ||
typeof stream.shamefullySendNext === 'function'); | ||
}, | ||
@@ -80,5 +57,13 @@ streamSubscribe: function (stream, observer) { | ||
}; | ||
var empty = {}; | ||
var NO = {}; | ||
function noop() { } | ||
var emptyListener = { | ||
function copy(a) { | ||
var l = a.length; | ||
var b = Array(l); | ||
for (var i = 0; i < l; ++i) { | ||
b[i] = a[i]; | ||
} | ||
return b; | ||
} | ||
exports.NO_IL = { | ||
_n: noop, | ||
@@ -99,13 +84,2 @@ _e: noop, | ||
} | ||
function invoke(f, args) { | ||
switch (args.length) { | ||
case 0: return f(); | ||
case 1: return f(args[0]); | ||
case 2: return f(args[0], args[1]); | ||
case 3: return f(args[0], args[1], args[2]); | ||
case 4: return f(args[0], args[1], args[2], args[3]); | ||
case 5: return f(args[0], args[1], args[2], args[3], args[4]); | ||
default: return f.apply(void 0, args); | ||
} | ||
} | ||
function compose2(f1, f2) { | ||
@@ -116,32 +90,81 @@ return function composedFn(arg) { | ||
} | ||
function and(f1, f2) { | ||
return function andFn(t) { | ||
return f1(t) && f2(t); | ||
}; | ||
} | ||
var MergeProducer = (function () { | ||
function MergeProducer(insArr) { | ||
this.type = 'merge'; | ||
this.insArr = insArr; | ||
this.out = NO; | ||
this.ac = 0; | ||
} | ||
MergeProducer.prototype._start = function (out) { | ||
this.out = out; | ||
var s = this.insArr; | ||
var L = s.length; | ||
this.ac = L; | ||
for (var i = 0; i < L; i++) { | ||
s[i]._add(this); | ||
} | ||
}; | ||
MergeProducer.prototype._stop = function () { | ||
var s = this.insArr; | ||
var L = s.length; | ||
for (var i = 0; i < L; i++) { | ||
s[i]._remove(this); | ||
} | ||
this.out = NO; | ||
}; | ||
MergeProducer.prototype._n = function (t) { | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
u._n(t); | ||
}; | ||
MergeProducer.prototype._e = function (err) { | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
u._e(err); | ||
}; | ||
MergeProducer.prototype._c = function () { | ||
if (--this.ac <= 0) { | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
u._c(); | ||
} | ||
}; | ||
return MergeProducer; | ||
}()); | ||
exports.MergeProducer = MergeProducer; | ||
var CombineListener = (function () { | ||
function CombineListener(i, prod) { | ||
function CombineListener(i, out, p) { | ||
this.i = i; | ||
this.prod = prod; | ||
prod.proxies.push(this); | ||
this.out = out; | ||
this.p = p; | ||
p.ils.push(this); | ||
} | ||
CombineListener.prototype._n = function (t) { | ||
var prod = this.prod; | ||
var vals = prod.vals; | ||
prod.hasVal[this.i] = true; | ||
vals[this.i] = t; | ||
if (!prod.ready) { | ||
prod.up(); | ||
var p = this.p, out = this.out; | ||
if (!out) | ||
return; | ||
if (p.up(t, this.i)) { | ||
out._n(p.vals); | ||
} | ||
if (prod.ready) { | ||
try { | ||
prod.out._n(invoke(prod.project, vals)); | ||
} | ||
catch (e) { | ||
prod.out._e(e); | ||
} | ||
} | ||
}; | ||
CombineListener.prototype._e = function (err) { | ||
this.prod.out._e(err); | ||
var out = this.out; | ||
if (!out) | ||
return; | ||
out._e(err); | ||
}; | ||
CombineListener.prototype._c = function () { | ||
var prod = this.prod; | ||
if (--prod.ac === 0) { | ||
prod.out._c(); | ||
var p = this.p; | ||
if (!p.out) | ||
return; | ||
if (--p.Nc === 0) { | ||
p.out._c(); | ||
} | ||
@@ -151,44 +174,50 @@ }; | ||
}()); | ||
exports.CombineListener = CombineListener; | ||
var CombineProducer = (function () { | ||
function CombineProducer(project, streams) { | ||
this.project = project; | ||
this.streams = streams; | ||
this.out = emptyListener; | ||
this.proxies = []; | ||
this.ready = false; | ||
this.vals = new Array(streams.length); | ||
this.hasVal = new Array(streams.length); | ||
this.ac = streams.length; | ||
function CombineProducer(insArr) { | ||
this.type = 'combine'; | ||
this.insArr = insArr; | ||
this.out = NO; | ||
this.ils = []; | ||
this.Nc = this.Nn = 0; | ||
this.vals = []; | ||
} | ||
CombineProducer.prototype.up = function () { | ||
for (var i = this.hasVal.length - 1; i >= 0; i--) { | ||
if (!this.hasVal[i]) { | ||
return; | ||
} | ||
} | ||
this.ready = true; | ||
CombineProducer.prototype.up = function (t, i) { | ||
var v = this.vals[i]; | ||
var Nn = !this.Nn ? 0 : v === NO ? --this.Nn : this.Nn; | ||
this.vals[i] = t; | ||
return Nn === 0; | ||
}; | ||
CombineProducer.prototype._start = function (out) { | ||
this.out = out; | ||
var streams = this.streams; | ||
for (var i = streams.length - 1; i >= 0; i--) { | ||
streams[i]._add(new CombineListener(i, this)); | ||
var s = this.insArr; | ||
var n = this.Nc = this.Nn = s.length; | ||
var vals = this.vals = new Array(n); | ||
if (n === 0) { | ||
out._n([]); | ||
out._c(); | ||
} | ||
else { | ||
for (var i = 0; i < n; i++) { | ||
vals[i] = NO; | ||
s[i]._add(new CombineListener(i, out, this)); | ||
} | ||
} | ||
}; | ||
CombineProducer.prototype._stop = function () { | ||
var streams = this.streams; | ||
for (var i = streams.length - 1; i >= 0; i--) { | ||
streams[i]._remove(this.proxies[i]); | ||
var s = this.insArr; | ||
var n = s.length; | ||
for (var i = 0; i < n; i++) { | ||
s[i]._remove(this.ils[i]); | ||
} | ||
this.out = null; | ||
this.ac = streams.length; | ||
this.proxies = []; | ||
this.ready = false; | ||
this.vals = new Array(streams.length); | ||
this.hasVal = new Array(streams.length); | ||
this.out = NO; | ||
this.ils = []; | ||
this.vals = []; | ||
}; | ||
return CombineProducer; | ||
}()); | ||
exports.CombineProducer = CombineProducer; | ||
var FromArrayProducer = (function () { | ||
function FromArrayProducer(a) { | ||
this.type = 'fromArray'; | ||
this.a = a; | ||
@@ -207,6 +236,8 @@ } | ||
}()); | ||
exports.FromArrayProducer = FromArrayProducer; | ||
var FromPromiseProducer = (function () { | ||
function FromPromiseProducer(p) { | ||
this.type = 'fromPromise'; | ||
this.on = false; | ||
this.p = p; | ||
this.on = false; | ||
} | ||
@@ -232,38 +263,6 @@ FromPromiseProducer.prototype._start = function (out) { | ||
}()); | ||
var MergeProducer = (function () { | ||
function MergeProducer(streams) { | ||
this.streams = streams; | ||
this.out = emptyListener; | ||
this.ac = streams.length; | ||
} | ||
MergeProducer.prototype._start = function (out) { | ||
this.out = out; | ||
var streams = this.streams; | ||
for (var i = streams.length - 1; i >= 0; i--) { | ||
streams[i]._add(this); | ||
} | ||
}; | ||
MergeProducer.prototype._stop = function () { | ||
var streams = this.streams; | ||
for (var i = streams.length - 1; i >= 0; i--) { | ||
streams[i]._remove(this); | ||
} | ||
this.out = null; | ||
this.ac = streams.length; | ||
}; | ||
MergeProducer.prototype._n = function (t) { | ||
this.out._n(t); | ||
}; | ||
MergeProducer.prototype._e = function (err) { | ||
this.out._e(err); | ||
}; | ||
MergeProducer.prototype._c = function () { | ||
if (--this.ac === 0) { | ||
this.out._c(); | ||
} | ||
}; | ||
return MergeProducer; | ||
}()); | ||
exports.FromPromiseProducer = FromPromiseProducer; | ||
var PeriodicProducer = (function () { | ||
function PeriodicProducer(period) { | ||
this.type = 'periodic'; | ||
this.period = period; | ||
@@ -286,8 +285,16 @@ this.intervalID = -1; | ||
}()); | ||
exports.PeriodicProducer = PeriodicProducer; | ||
var DebugOperator = (function () { | ||
function DebugOperator(spy, ins) { | ||
if (spy === void 0) { spy = null; } | ||
this.spy = spy; | ||
function DebugOperator(arg, ins) { | ||
this.type = 'debug'; | ||
this.ins = ins; | ||
this.out = null; | ||
this.out = NO; | ||
this.s = noop; | ||
this.l = ''; | ||
if (typeof arg === 'string') { | ||
this.l = arg; | ||
} | ||
else if (typeof arg === 'function') { | ||
this.s = arg; | ||
} | ||
} | ||
@@ -300,31 +307,46 @@ DebugOperator.prototype._start = function (out) { | ||
this.ins._remove(this); | ||
this.out = null; | ||
this.out = NO; | ||
}; | ||
DebugOperator.prototype._n = function (t) { | ||
if (this.spy) { | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
var s = this.s, l = this.l; | ||
if (s !== noop) { | ||
try { | ||
this.spy(t); | ||
s(t); | ||
} | ||
catch (e) { | ||
this.out._e(e); | ||
u._e(e); | ||
} | ||
} | ||
else if (l) { | ||
console.log(l + ':', t); | ||
} | ||
else { | ||
console.log(t); | ||
} | ||
this.out._n(t); | ||
u._n(t); | ||
}; | ||
DebugOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
u._e(err); | ||
}; | ||
DebugOperator.prototype._c = function () { | ||
this.out._c(); | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
u._c(); | ||
}; | ||
return DebugOperator; | ||
}()); | ||
exports.DebugOperator = DebugOperator; | ||
var DropOperator = (function () { | ||
function DropOperator(max, ins) { | ||
this.type = 'drop'; | ||
this.ins = ins; | ||
this.out = NO; | ||
this.max = max; | ||
this.ins = ins; | ||
this.out = null; | ||
this.dropped = 0; | ||
@@ -334,2 +356,3 @@ } | ||
this.out = out; | ||
this.dropped = 0; | ||
this.ins._add(this); | ||
@@ -339,44 +362,53 @@ }; | ||
this.ins._remove(this); | ||
this.out = null; | ||
this.dropped = 0; | ||
this.out = NO; | ||
}; | ||
DropOperator.prototype._n = function (t) { | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
if (this.dropped++ >= this.max) | ||
this.out._n(t); | ||
u._n(t); | ||
}; | ||
DropOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
u._e(err); | ||
}; | ||
DropOperator.prototype._c = function () { | ||
this.out._c(); | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
u._c(); | ||
}; | ||
return DropOperator; | ||
}()); | ||
var OtherListener = (function () { | ||
function OtherListener(out, op) { | ||
exports.DropOperator = DropOperator; | ||
var OtherIL = (function () { | ||
function OtherIL(out, op) { | ||
this.out = out; | ||
this.op = op; | ||
} | ||
OtherListener.prototype._n = function (t) { | ||
OtherIL.prototype._n = function (t) { | ||
this.op.end(); | ||
}; | ||
OtherListener.prototype._e = function (err) { | ||
OtherIL.prototype._e = function (err) { | ||
this.out._e(err); | ||
}; | ||
OtherListener.prototype._c = function () { | ||
OtherIL.prototype._c = function () { | ||
this.op.end(); | ||
}; | ||
return OtherListener; | ||
return OtherIL; | ||
}()); | ||
var EndWhenOperator = (function () { | ||
function EndWhenOperator(o, // o = other | ||
ins) { | ||
function EndWhenOperator(o, ins) { | ||
this.type = 'endWhen'; | ||
this.ins = ins; | ||
this.out = NO; | ||
this.o = o; | ||
this.ins = ins; | ||
this.out = null; | ||
this.oli = emptyListener; // oli = other listener | ||
this.oil = exports.NO_IL; | ||
} | ||
EndWhenOperator.prototype._start = function (out) { | ||
this.out = out; | ||
this.o._add(this.oli = new OtherListener(out, this)); | ||
this.o._add(this.oil = new OtherIL(out, this)); | ||
this.ins._add(this); | ||
@@ -386,14 +418,23 @@ }; | ||
this.ins._remove(this); | ||
this.o._remove(this.oli); | ||
this.out = null; | ||
this.oli = null; | ||
this.o._remove(this.oil); | ||
this.out = NO; | ||
this.oil = exports.NO_IL; | ||
}; | ||
EndWhenOperator.prototype.end = function () { | ||
this.out._c(); | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
u._c(); | ||
}; | ||
EndWhenOperator.prototype._n = function (t) { | ||
this.out._n(t); | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
u._n(t); | ||
}; | ||
EndWhenOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
u._e(err); | ||
}; | ||
@@ -405,7 +446,9 @@ EndWhenOperator.prototype._c = function () { | ||
}()); | ||
exports.EndWhenOperator = EndWhenOperator; | ||
var FilterOperator = (function () { | ||
function FilterOperator(passes, ins) { | ||
this.type = 'filter'; | ||
this.ins = ins; | ||
this.out = NO; | ||
this.passes = passes; | ||
this.ins = ins; | ||
this.out = null; | ||
} | ||
@@ -418,97 +461,62 @@ FilterOperator.prototype._start = function (out) { | ||
this.ins._remove(this); | ||
this.out = null; | ||
this.out = NO; | ||
}; | ||
FilterOperator.prototype._n = function (t) { | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
try { | ||
if (this.passes(t)) | ||
this.out._n(t); | ||
u._n(t); | ||
} | ||
catch (e) { | ||
this.out._e(e); | ||
u._e(e); | ||
} | ||
}; | ||
FilterOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
u._e(err); | ||
}; | ||
FilterOperator.prototype._c = function () { | ||
this.out._c(); | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
u._c(); | ||
}; | ||
return FilterOperator; | ||
}()); | ||
var FCInner = (function () { | ||
function FCInner(out, op) { | ||
exports.FilterOperator = FilterOperator; | ||
var FlattenListener = (function () { | ||
function FlattenListener(out, op) { | ||
this.out = out; | ||
this.op = op; | ||
} | ||
FCInner.prototype._n = function (t) { | ||
FlattenListener.prototype._n = function (t) { | ||
this.out._n(t); | ||
}; | ||
FCInner.prototype._e = function (err) { | ||
FlattenListener.prototype._e = function (err) { | ||
this.out._e(err); | ||
}; | ||
FCInner.prototype._c = function () { | ||
FlattenListener.prototype._c = function () { | ||
this.op.inner = NO; | ||
this.op.less(); | ||
}; | ||
return FCInner; | ||
return FlattenListener; | ||
}()); | ||
var FlattenConcOperator = (function () { | ||
function FlattenConcOperator(ins) { | ||
this.ins = ins; | ||
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) { | ||
this.out._c(); | ||
} | ||
}; | ||
FlattenConcOperator.prototype._n = function (s) { | ||
this.active++; | ||
s._add(new FCInner(this.out, this)); | ||
}; | ||
FlattenConcOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
}; | ||
FlattenConcOperator.prototype._c = function () { | ||
this.less(); | ||
}; | ||
return FlattenConcOperator; | ||
}()); | ||
exports.FlattenConcOperator = FlattenConcOperator; | ||
var FInner = (function () { | ||
function FInner(out, op) { | ||
this.out = out; | ||
this.op = op; | ||
} | ||
FInner.prototype._n = function (t) { | ||
this.out._n(t); | ||
}; | ||
FInner.prototype._e = function (err) { | ||
this.out._e(err); | ||
}; | ||
FInner.prototype._c = function () { | ||
this.op.curr = null; | ||
this.op.less(); | ||
}; | ||
return FInner; | ||
}()); | ||
var FlattenOperator = (function () { | ||
function FlattenOperator(ins) { | ||
this.type = 'flatten'; | ||
this.ins = ins; | ||
this.curr = null; // Current inner Stream | ||
this.inner = null; // Current inner InternalListener | ||
this.out = NO; | ||
this.open = true; | ||
this.out = null; | ||
this.inner = NO; | ||
this.il = exports.NO_IL; | ||
} | ||
FlattenOperator.prototype._start = function (out) { | ||
this.out = out; | ||
this.open = true; | ||
this.inner = NO; | ||
this.il = exports.NO_IL; | ||
this.ins._add(this); | ||
@@ -518,24 +526,32 @@ }; | ||
this.ins._remove(this); | ||
this.curr = null; | ||
this.inner = null; | ||
if (this.inner !== NO) | ||
this.inner._remove(this.il); | ||
this.out = NO; | ||
this.open = true; | ||
this.out = null; | ||
this.inner = NO; | ||
this.il = exports.NO_IL; | ||
}; | ||
FlattenOperator.prototype.cut = function () { | ||
var _a = this, curr = _a.curr, inner = _a.inner; | ||
if (curr && inner) { | ||
curr._remove(inner); | ||
} | ||
}; | ||
FlattenOperator.prototype.less = function () { | ||
if (!this.open && !this.curr) { | ||
this.out._c(); | ||
} | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
if (!this.open && this.inner === NO) | ||
u._c(); | ||
}; | ||
FlattenOperator.prototype._n = function (s) { | ||
this.cut(); | ||
(this.curr = s)._add(this.inner = new FInner(this.out, this)); | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
var _a = this, inner = _a.inner, il = _a.il; | ||
if (s === inner && s._prod !== NO) | ||
s._stopNow(); | ||
if (inner !== NO && il !== exports.NO_IL) | ||
inner._remove(il); | ||
(this.inner = s)._add(this.il = new FlattenListener(u, this)); | ||
}; | ||
FlattenOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
u._e(err); | ||
}; | ||
@@ -551,10 +567,11 @@ FlattenOperator.prototype._c = function () { | ||
function FoldOperator(f, seed, ins) { | ||
this.type = 'fold'; | ||
this.ins = ins; | ||
this.out = NO; | ||
this.f = f; | ||
this.seed = seed; | ||
this.ins = ins; | ||
this.out = null; | ||
this.acc = seed; | ||
this.acc = this.seed = seed; | ||
} | ||
FoldOperator.prototype._start = function (out) { | ||
this.out = out; | ||
this.acc = this.seed; | ||
out._n(this.acc); | ||
@@ -565,30 +582,42 @@ this.ins._add(this); | ||
this.ins._remove(this); | ||
this.out = null; | ||
this.out = NO; | ||
this.acc = this.seed; | ||
}; | ||
FoldOperator.prototype._n = function (t) { | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
try { | ||
this.out._n(this.acc = this.f(this.acc, t)); | ||
u._n(this.acc = this.f(this.acc, t)); | ||
} | ||
catch (e) { | ||
this.out._e(e); | ||
u._e(e); | ||
} | ||
}; | ||
FoldOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
u._e(err); | ||
}; | ||
FoldOperator.prototype._c = function () { | ||
this.out._c(); | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
u._c(); | ||
}; | ||
return FoldOperator; | ||
}()); | ||
exports.FoldOperator = FoldOperator; | ||
var LastOperator = (function () { | ||
function LastOperator(ins) { | ||
this.type = 'last'; | ||
this.ins = ins; | ||
this.out = null; | ||
this.out = NO; | ||
this.has = false; | ||
this.val = empty; | ||
this.val = NO; | ||
} | ||
LastOperator.prototype._start = function (out) { | ||
this.out = out; | ||
this.has = false; | ||
this.ins._add(this); | ||
@@ -598,5 +627,4 @@ }; | ||
this.ins._remove(this); | ||
this.out = null; | ||
this.has = false; | ||
this.val = empty; | ||
this.out = NO; | ||
this.val = NO; | ||
}; | ||
@@ -608,12 +636,17 @@ LastOperator.prototype._n = function (t) { | ||
LastOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
u._e(err); | ||
}; | ||
LastOperator.prototype._c = function () { | ||
var out = this.out; | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
if (this.has) { | ||
out._n(this.val); | ||
out._c(); | ||
u._n(this.val); | ||
u._c(); | ||
} | ||
else { | ||
out._e('TODO show proper error'); | ||
u._e('TODO show proper error'); | ||
} | ||
@@ -623,82 +656,35 @@ }; | ||
}()); | ||
var MFCInner = (function () { | ||
function MFCInner(out, op) { | ||
exports.LastOperator = LastOperator; | ||
var MapFlattenInner = (function () { | ||
function MapFlattenInner(out, op) { | ||
this.out = out; | ||
this.op = op; | ||
} | ||
MFCInner.prototype._n = function (t) { | ||
this.out._n(t); | ||
MapFlattenInner.prototype._n = function (r) { | ||
this.out._n(r); | ||
}; | ||
MFCInner.prototype._e = function (err) { | ||
MapFlattenInner.prototype._e = function (err) { | ||
this.out._e(err); | ||
}; | ||
MFCInner.prototype._c = function () { | ||
MapFlattenInner.prototype._c = function () { | ||
this.op.inner = NO; | ||
this.op.less(); | ||
}; | ||
return MFCInner; | ||
return MapFlattenInner; | ||
}()); | ||
var MapFlattenConcOperator = (function () { | ||
function MapFlattenConcOperator(mapOp) { | ||
this.mapOp = mapOp; | ||
this.active = 1; // number of outers and inners that have not yet ended | ||
this.out = null; | ||
} | ||
MapFlattenConcOperator.prototype._start = function (out) { | ||
this.out = out; | ||
this.mapOp.ins._add(this); | ||
}; | ||
MapFlattenConcOperator.prototype._stop = function () { | ||
this.mapOp.ins._remove(this); | ||
this.active = 1; | ||
this.out = null; | ||
}; | ||
MapFlattenConcOperator.prototype.less = function () { | ||
if (--this.active === 0) { | ||
this.out._c(); | ||
} | ||
}; | ||
MapFlattenConcOperator.prototype._n = function (v) { | ||
this.active++; | ||
try { | ||
this.mapOp.project(v)._add(new MFCInner(this.out, this)); | ||
} | ||
catch (e) { | ||
this.out._e(e); | ||
} | ||
}; | ||
MapFlattenConcOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
}; | ||
MapFlattenConcOperator.prototype._c = function () { | ||
this.less(); | ||
}; | ||
return MapFlattenConcOperator; | ||
}()); | ||
var MFInner = (function () { | ||
function MFInner(out, op) { | ||
this.out = out; | ||
this.op = op; | ||
} | ||
MFInner.prototype._n = function (t) { | ||
this.out._n(t); | ||
}; | ||
MFInner.prototype._e = function (err) { | ||
this.out._e(err); | ||
}; | ||
MFInner.prototype._c = function () { | ||
this.op.curr = null; | ||
this.op.less(); | ||
}; | ||
return MFInner; | ||
}()); | ||
var MapFlattenOperator = (function () { | ||
function MapFlattenOperator(mapOp) { | ||
this.type = mapOp.type + "+flatten"; | ||
this.ins = mapOp.ins; | ||
this.out = NO; | ||
this.mapOp = mapOp; | ||
this.curr = null; // Current inner Stream | ||
this.inner = null; // Current inner InternalListener | ||
this.inner = NO; | ||
this.il = exports.NO_IL; | ||
this.open = true; | ||
this.out = null; | ||
} | ||
MapFlattenOperator.prototype._start = function (out) { | ||
this.out = out; | ||
this.inner = NO; | ||
this.il = exports.NO_IL; | ||
this.open = true; | ||
this.mapOp.ins._add(this); | ||
@@ -708,29 +694,40 @@ }; | ||
this.mapOp.ins._remove(this); | ||
this.curr = null; | ||
this.inner = null; | ||
this.open = true; | ||
this.out = null; | ||
if (this.inner !== NO) | ||
this.inner._remove(this.il); | ||
this.out = NO; | ||
this.inner = NO; | ||
this.il = exports.NO_IL; | ||
}; | ||
MapFlattenOperator.prototype.cut = function () { | ||
var _a = this, curr = _a.curr, inner = _a.inner; | ||
if (curr && inner) { | ||
curr._remove(inner); | ||
} | ||
}; | ||
MapFlattenOperator.prototype.less = function () { | ||
if (!this.open && !this.curr) { | ||
this.out._c(); | ||
if (!this.open && this.inner === NO) { | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
u._c(); | ||
} | ||
}; | ||
MapFlattenOperator.prototype._n = function (v) { | ||
this.cut(); | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
var _a = this, inner = _a.inner, il = _a.il; | ||
var s; | ||
try { | ||
(this.curr = this.mapOp.project(v))._add(this.inner = new MFInner(this.out, this)); | ||
s = this.mapOp.project(v); | ||
} | ||
catch (e) { | ||
this.out._e(e); | ||
u._e(e); | ||
return; | ||
} | ||
if (s === inner && s._prod !== NO) | ||
s._stopNow(); | ||
if (inner !== NO && il !== exports.NO_IL) | ||
inner._remove(il); | ||
(this.inner = s)._add(this.il = new MapFlattenInner(u, this)); | ||
}; | ||
MapFlattenOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
u._e(err); | ||
}; | ||
@@ -743,7 +740,9 @@ MapFlattenOperator.prototype._c = function () { | ||
}()); | ||
exports.MapFlattenOperator = MapFlattenOperator; | ||
var MapOperator = (function () { | ||
function MapOperator(project, ins) { | ||
this.type = 'map'; | ||
this.ins = ins; | ||
this.out = NO; | ||
this.project = project; | ||
this.ins = ins; | ||
this.out = null; | ||
} | ||
@@ -756,20 +755,30 @@ MapOperator.prototype._start = function (out) { | ||
this.ins._remove(this); | ||
this.out = null; | ||
this.out = NO; | ||
}; | ||
MapOperator.prototype._n = function (t) { | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
try { | ||
this.out._n(this.project(t)); | ||
u._n(this.project(t)); | ||
} | ||
catch (e) { | ||
this.out._e(e); | ||
u._e(e); | ||
} | ||
}; | ||
MapOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
u._e(err); | ||
}; | ||
MapOperator.prototype._c = function () { | ||
this.out._c(); | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
u._c(); | ||
}; | ||
return MapOperator; | ||
}()); | ||
exports.MapOperator = MapOperator; | ||
var FilterMapOperator = (function (_super) { | ||
@@ -779,2 +788,3 @@ __extends(FilterMapOperator, _super); | ||
_super.call(this, project, ins); | ||
this.type = 'filter+map'; | ||
this.passes = passes; | ||
@@ -790,32 +800,26 @@ } | ||
}(MapOperator)); | ||
var MapToOperator = (function () { | ||
function MapToOperator(val, ins) { | ||
this.val = val; | ||
exports.FilterMapOperator = FilterMapOperator; | ||
var RememberOperator = (function () { | ||
function RememberOperator(ins) { | ||
this.type = 'remember'; | ||
this.ins = ins; | ||
this.out = null; | ||
this.out = NO; | ||
} | ||
MapToOperator.prototype._start = function (out) { | ||
RememberOperator.prototype._start = function (out) { | ||
this.out = out; | ||
this.ins._add(this); | ||
this.ins._add(out); | ||
}; | ||
MapToOperator.prototype._stop = function () { | ||
this.ins._remove(this); | ||
this.out = null; | ||
RememberOperator.prototype._stop = function () { | ||
this.ins._remove(this.out); | ||
this.out = NO; | ||
}; | ||
MapToOperator.prototype._n = function (t) { | ||
this.out._n(this.val); | ||
}; | ||
MapToOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
}; | ||
MapToOperator.prototype._c = function () { | ||
this.out._c(); | ||
}; | ||
return MapToOperator; | ||
return RememberOperator; | ||
}()); | ||
exports.RememberOperator = RememberOperator; | ||
var ReplaceErrorOperator = (function () { | ||
function ReplaceErrorOperator(fn, ins) { | ||
this.type = 'replaceError'; | ||
this.ins = ins; | ||
this.out = NO; | ||
this.fn = fn; | ||
this.ins = ins; | ||
this.out = empty; | ||
} | ||
@@ -828,8 +832,14 @@ ReplaceErrorOperator.prototype._start = function (out) { | ||
this.ins._remove(this); | ||
this.out = null; | ||
this.out = NO; | ||
}; | ||
ReplaceErrorOperator.prototype._n = function (t) { | ||
this.out._n(t); | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
u._n(t); | ||
}; | ||
ReplaceErrorOperator.prototype._e = function (err) { | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
try { | ||
@@ -840,19 +850,24 @@ this.ins._remove(this); | ||
catch (e) { | ||
this.out._e(e); | ||
u._e(e); | ||
} | ||
}; | ||
ReplaceErrorOperator.prototype._c = function () { | ||
this.out._c(); | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
u._c(); | ||
}; | ||
return ReplaceErrorOperator; | ||
}()); | ||
exports.ReplaceErrorOperator = ReplaceErrorOperator; | ||
var StartWithOperator = (function () { | ||
function StartWithOperator(ins, value) { | ||
function StartWithOperator(ins, val) { | ||
this.type = 'startWith'; | ||
this.ins = ins; | ||
this.value = value; | ||
this.out = emptyListener; | ||
this.out = NO; | ||
this.val = val; | ||
} | ||
StartWithOperator.prototype._start = function (out) { | ||
this.out = out; | ||
this.out._n(this.value); | ||
this.out._n(this.val); | ||
this.ins._add(out); | ||
@@ -862,11 +877,13 @@ }; | ||
this.ins._remove(this.out); | ||
this.out = null; | ||
this.out = NO; | ||
}; | ||
return StartWithOperator; | ||
}()); | ||
exports.StartWithOperator = StartWithOperator; | ||
var TakeOperator = (function () { | ||
function TakeOperator(max, ins) { | ||
this.type = 'take'; | ||
this.ins = ins; | ||
this.out = NO; | ||
this.max = max; | ||
this.ins = ins; | ||
this.out = null; | ||
this.taken = 0; | ||
@@ -876,2 +893,3 @@ } | ||
this.out = out; | ||
this.taken = 0; | ||
this.ins._add(this); | ||
@@ -881,89 +899,62 @@ }; | ||
this.ins._remove(this); | ||
this.out = null; | ||
this.taken = 0; | ||
this.out = NO; | ||
}; | ||
TakeOperator.prototype._n = function (t) { | ||
var out = this.out; | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
if (this.taken++ < this.max - 1) { | ||
out._n(t); | ||
u._n(t); | ||
} | ||
else { | ||
out._n(t); | ||
out._c(); | ||
this._stop(); | ||
u._n(t); | ||
u._c(); | ||
} | ||
}; | ||
TakeOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
u._e(err); | ||
}; | ||
TakeOperator.prototype._c = function () { | ||
this.out._c(); | ||
var u = this.out; | ||
if (u === NO) | ||
return; | ||
u._c(); | ||
}; | ||
return TakeOperator; | ||
}()); | ||
exports.TakeOperator = TakeOperator; | ||
var Stream = (function () { | ||
function Stream(producer) { | ||
this._stopID = empty; | ||
/** | ||
* Combines multiple streams with the input stream to return a stream whose | ||
* events are calculated from the latest events of each of its input streams. | ||
* | ||
* *combine* remembers the most recent event from each of the input streams. | ||
* When any of the input streams emits an event, that event together with all | ||
* the other saved events are combined in the `project` function which should | ||
* return a value. That value will be emitted on the output stream. It's | ||
* essentially a way of mixing the events from multiple streams according to a | ||
* formula. | ||
* | ||
* Marble diagram: | ||
* | ||
* ```text | ||
* --1----2-----3--------4--- | ||
* ----a-----b-----c--d------ | ||
* combine((x,y) => x+y) | ||
* ----1a-2a-2b-3b-3c-3d-4d-- | ||
* ``` | ||
* | ||
* @param {Function} project A function of type `(x: T1, y: T2) => R` or | ||
* similar that takes the most recent events `x` and `y` from the input | ||
* streams and returns a value. The output stream will emit that value. The | ||
* number of arguments for this function should match the number of input | ||
* streams. | ||
* @param {Stream} other Another stream to combine together with the input | ||
* stream. There may be more of these arguments. | ||
* @return {Stream} | ||
*/ | ||
this.combine = function combine(project) { | ||
var streams = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
streams[_i - 1] = arguments[_i]; | ||
} | ||
streams.unshift(this); | ||
return Stream.combine.apply(Stream, [project].concat(streams)); | ||
}; | ||
this._prod = producer; | ||
this._prod = producer || NO; | ||
this._ils = []; | ||
this._stopID = NO; | ||
this._target = NO; | ||
this._err = NO; | ||
} | ||
Stream.prototype._n = function (t) { | ||
var a = this._ils; | ||
var len = a.length; | ||
if (len === 1) { | ||
var L = a.length; | ||
if (L == 1) | ||
a[0]._n(t); | ||
} | ||
else { | ||
for (var i = 0; i < len; i++) { | ||
a[i]._n(t); | ||
} | ||
var b = copy(a); | ||
for (var i = 0; i < L; i++) | ||
b[i]._n(t); | ||
} | ||
}; | ||
Stream.prototype._e = function (err) { | ||
if (this._err !== NO) | ||
return; | ||
this._err = err; | ||
var a = this._ils; | ||
var len = a.length; | ||
if (len === 1) { | ||
var L = a.length; | ||
if (L == 1) | ||
a[0]._e(err); | ||
} | ||
else { | ||
for (var i = 0; i < len; i++) { | ||
a[i]._e(err); | ||
} | ||
var b = copy(a); | ||
for (var i = 0; i < L; i++) | ||
b[i]._e(err); | ||
} | ||
@@ -974,10 +965,9 @@ this._x(); | ||
var a = this._ils; | ||
var len = a.length; | ||
if (len === 1) { | ||
var L = a.length; | ||
if (L == 1) | ||
a[0]._c(); | ||
} | ||
else { | ||
for (var i = 0; i < len; i++) { | ||
a[i]._c(); | ||
} | ||
var b = copy(a); | ||
for (var i = 0; i < L; i++) | ||
b[i]._c(); | ||
} | ||
@@ -989,35 +979,27 @@ this._x(); | ||
return; | ||
if (this._prod) | ||
if (this._prod !== NO) | ||
this._prod._stop(); | ||
this._err = NO; | ||
this._ils = []; | ||
}; | ||
/** | ||
* Adds a Listener to the Stream. | ||
* | ||
* @param {Listener<T>} listener | ||
*/ | ||
Stream.prototype.addListener = function (listener) { | ||
listener._n = listener.next; | ||
listener._e = listener.error; | ||
listener._c = listener.complete; | ||
this._add(listener); | ||
Stream.prototype._stopNow = function () { | ||
// WARNING: code that calls this method should | ||
// first check if this._prod is valid (not `NO`) | ||
this._prod._stop(); | ||
this._err = NO; | ||
this._stopID = NO; | ||
}; | ||
/** | ||
* Removes a Listener from the Stream, assuming the Listener was added to it. | ||
* | ||
* @param {Listener<T>} listener | ||
*/ | ||
Stream.prototype.removeListener = function (listener) { | ||
this._remove(listener); | ||
}; | ||
Stream.prototype._add = function (il) { | ||
var ta = this._target; | ||
if (ta !== NO) | ||
return ta._add(il); | ||
var a = this._ils; | ||
a.push(il); | ||
if (a.length === 1) { | ||
if (this._stopID !== empty) { | ||
if (this._stopID !== NO) { | ||
clearTimeout(this._stopID); | ||
this._stopID = empty; | ||
this._stopID = NO; | ||
} | ||
var p = this._prod; | ||
if (p) | ||
if (p !== NO) | ||
p._start(this); | ||
@@ -1027,2 +1009,6 @@ } | ||
Stream.prototype._remove = function (il) { | ||
var _this = this; | ||
var ta = this._target; | ||
if (ta !== NO) | ||
return ta._remove(il); | ||
var a = this._ils; | ||
@@ -1032,9 +1018,75 @@ var i = a.indexOf(il); | ||
a.splice(i, 1); | ||
var p_1 = this._prod; | ||
if (p_1 && a.length <= 0) { | ||
this._stopID = setTimeout(function () { return p_1._stop(); }); | ||
if (this._prod !== NO && a.length <= 0) { | ||
this._err = NO; | ||
this._stopID = setTimeout(function () { return _this._stopNow(); }); | ||
} | ||
else if (a.length === 1) { | ||
this._pruneCycles(); | ||
} | ||
} | ||
}; | ||
// If all paths stemming from `this` stream eventually end at `this` | ||
// stream, then we remove the single listener of `this` stream, to | ||
// force it to end its execution and dispose resources. This method | ||
// assumes as a precondition that this._ils has just one listener. | ||
Stream.prototype._pruneCycles = function () { | ||
if (this._hasNoSinks(this, [])) { | ||
this._remove(this._ils[0]); | ||
} | ||
}; | ||
// Checks whether *there is no* path starting from `x` that leads to an end | ||
// listener (sink) in the stream graph, following edges A->B where B is a | ||
// listener of A. This means these paths constitute a cycle somehow. Is given | ||
// a trace of all visited nodes so far. | ||
Stream.prototype._hasNoSinks = function (x, trace) { | ||
if (trace.indexOf(x) !== -1) { | ||
return true; | ||
} | ||
else if (x.out === this) { | ||
return true; | ||
} | ||
else if (x.out && x.out !== NO) { | ||
return this._hasNoSinks(x.out, trace.concat(x)); | ||
} | ||
else if (x._ils) { | ||
for (var i = 0, N = x._ils.length; i < N; i++) { | ||
if (!this._hasNoSinks(x._ils[i], trace.concat(x))) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
}; | ||
Stream.prototype.ctor = function () { | ||
return this instanceof MemoryStream ? MemoryStream : Stream; | ||
}; | ||
/** | ||
* Adds a Listener to the Stream. | ||
* | ||
* @param {Listener<T>} listener | ||
*/ | ||
Stream.prototype.addListener = function (listener) { | ||
if (typeof listener.next !== 'function' | ||
|| typeof listener.error !== 'function' | ||
|| typeof listener.complete !== 'function') { | ||
throw new Error('stream.addListener() requires all three next, error, ' + | ||
'and complete functions.'); | ||
} | ||
listener._n = listener.next; | ||
listener._e = listener.error; | ||
listener._c = listener.complete; | ||
this._add(listener); | ||
}; | ||
/** | ||
* Removes a Listener from the Stream, assuming the Listener was added to it. | ||
* | ||
* @param {Listener<T>} listener | ||
*/ | ||
Stream.prototype.removeListener = function (listener) { | ||
this._remove(listener); | ||
}; | ||
/** | ||
* Creates a new Stream given a Producer. | ||
@@ -1049,2 +1101,6 @@ * | ||
if (producer) { | ||
if (typeof producer.start !== 'function' | ||
|| typeof producer.stop !== 'function') { | ||
throw new Error('producer requires both start and stop functions'); | ||
} | ||
internalizeProducer(producer); // mutates the input | ||
@@ -1206,30 +1262,15 @@ } | ||
}; | ||
/** | ||
* Blends multiple streams together, emitting events from all of them | ||
* concurrently. | ||
* | ||
* *merge* takes multiple streams as arguments, and creates a stream that | ||
* imitates each of the argument streams, in parallel. | ||
* | ||
* Marble diagram: | ||
* | ||
* ```text | ||
* --1----2-----3--------4--- | ||
* ----a-----b----c---d------ | ||
* merge | ||
* --1-a--2--b--3-c---d--4--- | ||
* ``` | ||
* | ||
* @factory true | ||
* @param {Stream} stream1 A stream to merge together with other streams. | ||
* @param {Stream} stream2 A stream to merge together with other streams. Two | ||
* or more streams may be given as arguments. | ||
* @return {Stream} | ||
*/ | ||
Stream.merge = function () { | ||
var streams = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
streams[_i - 0] = arguments[_i]; | ||
Stream.prototype._map = function (project) { | ||
var p = this._prod; | ||
var ctor = this.ctor(); | ||
if (p instanceof FilterOperator) { | ||
return new ctor(new FilterMapOperator(p.passes, project, p.ins)); | ||
} | ||
return new Stream(new MergeProducer(streams)); | ||
if (p instanceof FilterMapOperator) { | ||
return new ctor(new FilterMapOperator(p.passes, compose2(project, p.project), p.ins)); | ||
} | ||
if (p instanceof MapOperator) { | ||
return new ctor(new MapOperator(compose2(project, p.project), p.ins)); | ||
} | ||
return new ctor(new MapOperator(project, this)); | ||
}; | ||
@@ -1254,13 +1295,3 @@ /** | ||
Stream.prototype.map = function (project) { | ||
var p = this._prod; | ||
if (p instanceof FilterOperator) { | ||
return new Stream(new FilterMapOperator(p.passes, project, p.ins)); | ||
} | ||
if (p instanceof FilterMapOperator) { | ||
return new Stream(new FilterMapOperator(p.passes, compose2(project, p.project), p.ins)); | ||
} | ||
if (p instanceof MapOperator) { | ||
return new Stream(new MapOperator(compose2(project, p.project), p.ins)); | ||
} | ||
return new Stream(new MapOperator(project, this)); | ||
return this._map(project); | ||
}; | ||
@@ -1284,3 +1315,6 @@ /** | ||
Stream.prototype.mapTo = function (projectedValue) { | ||
return new Stream(new MapToOperator(projectedValue, this)); | ||
var s = this.map(function () { return projectedValue; }); | ||
var op = s._prod; | ||
op.type = op.type.replace('map', 'mapTo'); | ||
return s; | ||
}; | ||
@@ -1309,10 +1343,4 @@ /** | ||
var p = this._prod; | ||
if (p instanceof MapOperator) { | ||
return new Stream(new FilterMapOperator(passes, p.project, p.ins)); | ||
} | ||
if (p instanceof FilterMapOperator) { | ||
return new Stream(new FilterMapOperator(compose2(passes, p.passes), p.project, p.ins)); | ||
} | ||
if (p instanceof FilterOperator) { | ||
return new Stream(new FilterOperator(compose2(passes, p.passes), p.ins)); | ||
return new Stream(new FilterOperator(and(p.passes, passes), p.ins)); | ||
} | ||
@@ -1338,3 +1366,3 @@ return new Stream(new FilterOperator(passes, this)); | ||
Stream.prototype.take = function (amount) { | ||
return new Stream(new TakeOperator(amount, this)); | ||
return new (this.ctor())(new TakeOperator(amount, this)); | ||
}; | ||
@@ -1380,3 +1408,4 @@ /** | ||
* Prepends the given `initial` value to the sequence of events emitted by the | ||
* input stream. | ||
* input stream. The returned stream is a MemoryStream, which means it is | ||
* already `remember()`'d. | ||
* | ||
@@ -1392,6 +1421,6 @@ * Marble diagram: | ||
* @param initial The value or event to prepend. | ||
* @return {Stream} | ||
* @return {MemoryStream} | ||
*/ | ||
Stream.prototype.startWith = function (initial) { | ||
return new Stream(new StartWithOperator(this, initial)); | ||
return new MemoryStream(new StartWithOperator(this, initial)); | ||
}; | ||
@@ -1402,4 +1431,4 @@ /** | ||
* When the given `other` stream emits an event or completes, the output | ||
* stream will complete. Before that happens, the output stream will imitate | ||
* whatever happens on the input stream. | ||
* stream will complete. Before that happens, the output stream will behaves | ||
* like the input stream. | ||
* | ||
@@ -1419,3 +1448,3 @@ * Marble diagram: | ||
Stream.prototype.endWhen = function (other) { | ||
return new Stream(new EndWhenOperator(other, this)); | ||
return new (this.ctor())(new EndWhenOperator(other, this)); | ||
}; | ||
@@ -1427,3 +1456,4 @@ /** | ||
* the entire execution of the input stream, allowing you to accumulate them | ||
* together. It's essentially like `Array.prototype.reduce`. | ||
* together. It's essentially like `Array.prototype.reduce`. The returned | ||
* stream is a MemoryStream, which means it is already `remember()`'d. | ||
* | ||
@@ -1449,6 +1479,6 @@ * The output stream starts by emitting the `seed` which you give as argument. | ||
* @param seed The initial accumulated value, of type `R`. | ||
* @return {Stream} | ||
* @return {MemoryStream} | ||
*/ | ||
Stream.prototype.fold = function (accumulate, seed) { | ||
return new Stream(new FoldOperator(accumulate, seed, this)); | ||
return new MemoryStream(new FoldOperator(accumulate, seed, this)); | ||
}; | ||
@@ -1460,5 +1490,5 @@ /** | ||
* that error to the output stream, *replaceError* will call the `replace` | ||
* function which returns the stream that the output stream will imitate. And, | ||
* in case that new stream also emits an error, `replace` will be called again | ||
* to get another stream to start imitating. | ||
* function which returns the stream that the output stream will replicate. | ||
* And, in case that new stream also emits an error, `replace` will be called | ||
* again to get another stream to start replicating. | ||
* | ||
@@ -1474,9 +1504,9 @@ * Marble diagram: | ||
* @param {Function} replace A function of type `(err) => Stream` that takes | ||
* the error that occured on the input stream or on the previous replacement | ||
* stream and returns a new stream. The output stream will imitate the stream | ||
* that this function returns. | ||
* the error that occurred on the input stream or on the previous replacement | ||
* stream and returns a new stream. The output stream will behave like the | ||
* stream that this function returns. | ||
* @return {Stream} | ||
*/ | ||
Stream.prototype.replaceError = function (replace) { | ||
return new Stream(new ReplaceErrorOperator(replace, this)); | ||
return new (this.ctor())(new ReplaceErrorOperator(replace, this)); | ||
}; | ||
@@ -1510,3 +1540,3 @@ /** | ||
var p = this._prod; | ||
return new Stream(p instanceof MapOperator || p instanceof FilterMapOperator ? | ||
return new Stream(p instanceof MapOperator && !(p instanceof FilterMapOperator) ? | ||
new MapFlattenOperator(p) : | ||
@@ -1516,55 +1546,2 @@ new FlattenOperator(this)); | ||
/** | ||
* 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} | ||
*/ | ||
Stream.prototype.flattenConcurrently = function () { | ||
var p = this._prod; | ||
return new Stream(p instanceof MapOperator || p instanceof FilterMapOperator ? | ||
new MapFlattenConcOperator(p) : | ||
new FlattenConcOperator(this)); | ||
}; | ||
/** | ||
* Blends two streams together, emitting events from both. | ||
* | ||
* *merge* takes an `other` stream and returns an output stream that imitates | ||
* both the input stream and the `other` stream. | ||
* | ||
* Marble diagram: | ||
* | ||
* ```text | ||
* --1----2-----3--------4--- | ||
* ----a-----b----c---d------ | ||
* merge | ||
* --1-a--2--b--3-c---d--4--- | ||
* ``` | ||
* | ||
* @param {Stream} other Another stream to merge together with the input | ||
* stream. | ||
* @return {Stream} | ||
*/ | ||
Stream.prototype.merge = function (other) { | ||
return Stream.merge(this, other); | ||
}; | ||
/** | ||
* Passes the input stream to a custom operator, to produce an output stream. | ||
@@ -1584,27 +1561,15 @@ * | ||
/** | ||
* Returns an output stream that imitates the input stream, but also remembers | ||
* the most recent event that happens on the input stream, so that a newly | ||
* added listener will immediately receive that memorised event. | ||
* Returns an output stream that behaves like the input stream, but also | ||
* remembers the most recent event that happens on the input stream, so that a | ||
* newly added listener will immediately receive that memorised event. | ||
* | ||
* @return {Stream} | ||
* @return {MemoryStream} | ||
*/ | ||
Stream.prototype.remember = function () { | ||
return new MemoryStream(this._prod); | ||
return new MemoryStream(new RememberOperator(this)); | ||
}; | ||
/** | ||
* Changes this current stream to imitate the `other` given stream. | ||
* Returns an output stream that identically behaves like the input stream, | ||
* but also runs a `spy` function fo each event, to help you debug your app. | ||
* | ||
* The *imitate* method returns nothing. Instead, it changes the behavior of | ||
* the current stream, making it re-emit whatever events are emitted by the | ||
* given `other` stream. | ||
* @param {Stream} other The stream to imitate on the current one. | ||
*/ | ||
Stream.prototype.imitate = function (other) { | ||
other._add(this); | ||
}; | ||
/** | ||
* Returns an output stream that identically imitates the input stream, but | ||
* also runs a `spy` function fo each event, to help you debug your app. | ||
* | ||
* *debug* takes a `spy` function as argument, and runs that for each event | ||
@@ -1627,11 +1592,87 @@ * happening on the input stream. If you don't provide the `spy` argument, | ||
* | ||
* @param {function} spy A function that takes an event as argument, and | ||
* returns nothing. | ||
* @param {function} labelOrSpy A string to use as the label when printing | ||
* debug information on the console, or a 'spy' function that takes an event | ||
* as argument, and does not need to return anything. | ||
* @return {Stream} | ||
*/ | ||
Stream.prototype.debug = function (spy) { | ||
if (spy === void 0) { spy = null; } | ||
return new Stream(new DebugOperator(spy, this)); | ||
Stream.prototype.debug = function (labelOrSpy) { | ||
return new (this.ctor())(new DebugOperator(labelOrSpy, this)); | ||
}; | ||
/** | ||
* *imitate* changes this current Stream to emit the same events that the | ||
* `other` given Stream does. This method returns nothing. | ||
* | ||
* This method exists to allow one thing: **circular dependency of streams**. | ||
* For instance, let's imagine that for some reason you need to create a | ||
* circular dependency where stream `first$` depends on stream `second$` | ||
* which in turn depends on `first$`: | ||
* | ||
* <!-- skip-example --> | ||
* ```js | ||
* import delay from 'xstream/extra/delay' | ||
* | ||
* var first$ = second$.map(x => x * 10).take(3); | ||
* var second$ = first$.map(x => x + 1).startWith(1).compose(delay(100)); | ||
* ``` | ||
* | ||
* However, that is invalid JavaScript, because `second$` is undefined | ||
* on the first line. This is how *imitate* can help solve it: | ||
* | ||
* ```js | ||
* import delay from 'xstream/extra/delay' | ||
* | ||
* var secondProxy$ = xs.create(); | ||
* var first$ = secondProxy$.map(x => x * 10).take(3); | ||
* var second$ = first$.map(x => x + 1).startWith(1).compose(delay(100)); | ||
* secondProxy$.imitate(second$); | ||
* ``` | ||
* | ||
* We create `secondProxy$` before the others, so it can be used in the | ||
* declaration of `first$`. Then, after both `first$` and `second$` are | ||
* defined, we hook `secondProxy$` with `second$` with `imitate()` to tell | ||
* that they are "the same". `imitate` will not trigger the start of any | ||
* stream, it just binds `secondProxy$` and `second$` together. | ||
* | ||
* The following is an example where `imitate()` is important in Cycle.js | ||
* applications. A parent component contains some child components. A child | ||
* has an action stream which is given to the parent to define its state: | ||
* | ||
* <!-- skip-example --> | ||
* ```js | ||
* const childActionProxy$ = xs.create(); | ||
* const parent = Parent({...sources, childAction$: childActionProxy$}); | ||
* const childAction$ = parent.state$.map(s => s.child.action$).flatten(); | ||
* childActionProxy$.imitate(childAction$); | ||
* ``` | ||
* | ||
* Note, though, that **`imitate()` does not support MemoryStreams**. If we | ||
* would attempt to imitate a MemoryStream in a circular dependency, we would | ||
* either get a race condition (where the symptom would be "nothing happens") | ||
* or an infinite cyclic emission of values. It's useful to think about | ||
* MemoryStreams as cells in a spreadsheet. It doesn't make any sense to | ||
* define a spreadsheet cell `A1` with a formula that depends on `B1` and | ||
* cell `B1` defined with a formula that depends on `A1`. | ||
* | ||
* If you find yourself wanting to use `imitate()` with a | ||
* MemoryStream, you should rework your code around `imitate()` to use a | ||
* Stream instead. Look for the stream in the circular dependency that | ||
* represents an event stream, and that would be a candidate for creating a | ||
* proxy Stream which then imitates the target Stream. | ||
* | ||
* @param {Stream} target The other stream to imitate on the current one. Must | ||
* not be a MemoryStream. | ||
*/ | ||
Stream.prototype.imitate = function (target) { | ||
if (target instanceof MemoryStream) { | ||
throw new Error('A MemoryStream was given to imitate(), but it only ' + | ||
'supports a Stream. Read more about this restriction here: ' + | ||
'https://github.com/staltz/xstream#faq'); | ||
} | ||
this._target = target; | ||
for (var ils = this._ils, N = ils.length, i = 0; i < N; i++) { | ||
target._add(ils[i]); | ||
} | ||
this._ils = []; | ||
}; | ||
/** | ||
* Forces the Stream to emit the given value to its listeners. | ||
@@ -1673,11 +1714,7 @@ * | ||
/** | ||
* Combines multiple streams together to return a stream whose events are | ||
* calculated from the latest events of each of the input streams. | ||
* Blends multiple streams together, emitting events from all of them | ||
* concurrently. | ||
* | ||
* *combine* remembers the most recent event from each of the input streams. | ||
* When any of the input streams emits an event, that event together with all | ||
* the other saved events are combined in the `project` function which should | ||
* return a value. That value will be emitted on the output stream. It's | ||
* essentially a way of mixing the events from multiple streams according to a | ||
* formula. | ||
* *merge* takes multiple streams as arguments, and creates a stream that | ||
* behaves like each of the argument streams, in parallel. | ||
* | ||
@@ -1688,4 +1725,36 @@ * Marble diagram: | ||
* --1----2-----3--------4--- | ||
* ----a-----b----c---d------ | ||
* merge | ||
* --1-a--2--b--3-c---d--4--- | ||
* ``` | ||
* | ||
* @factory true | ||
* @param {Stream} stream1 A stream to merge together with other streams. | ||
* @param {Stream} stream2 A stream to merge together with other streams. Two | ||
* or more streams may be given as arguments. | ||
* @return {Stream} | ||
*/ | ||
Stream.merge = function merge() { | ||
var streams = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
streams[_i - 0] = arguments[_i]; | ||
} | ||
return new Stream(new MergeProducer(streams)); | ||
}; | ||
/** | ||
* Combines multiple input streams together to return a stream whose events | ||
* are arrays that collect the latest events from each input stream. | ||
* | ||
* *combine* internally remembers the most recent event from each of the input | ||
* streams. When any of the input streams emits an event, that event together | ||
* with all the other saved events are combined into an array. That array will | ||
* be emitted on the output stream. It's essentially a way of joining together | ||
* the events from multiple streams. | ||
* | ||
* Marble diagram: | ||
* | ||
* ```text | ||
* --1----2-----3--------4--- | ||
* ----a-----b-----c--d------ | ||
* combine((x,y) => x+y) | ||
* combine | ||
* ----1a-2a-2b-3b-3c-3d-4d-- | ||
@@ -1695,18 +1764,13 @@ * ``` | ||
* @factory true | ||
* @param {Function} project A function of type `(x: T1, y: T2) => R` or | ||
* similar that takes the most recent events `x` and `y` from the input | ||
* streams and returns a value. The output stream will emit that value. The | ||
* number of arguments for this function should match the number of input | ||
* streams. | ||
* @param {Stream} stream1 A stream to combine together with other streams. | ||
* @param {Stream} stream2 A stream to combine together with other streams. | ||
* Two or more streams may be given as arguments. | ||
* Multiple streams, not just two, may be given as arguments. | ||
* @return {Stream} | ||
*/ | ||
Stream.combine = function combine(project) { | ||
Stream.combine = function combine() { | ||
var streams = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
streams[_i - 1] = arguments[_i]; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
streams[_i - 0] = arguments[_i]; | ||
} | ||
return new Stream(new CombineProducer(project, streams)); | ||
return new Stream(new CombineProducer(streams)); | ||
}; | ||
@@ -1723,12 +1787,41 @@ return Stream; | ||
MemoryStream.prototype._n = function (x) { | ||
this._val = x; | ||
this._v = x; | ||
this._has = true; | ||
_super.prototype._n.call(this, x); | ||
}; | ||
MemoryStream.prototype._add = function (listener) { | ||
MemoryStream.prototype._add = function (il) { | ||
if (this._has) { | ||
listener._n(this._val); | ||
il._n(this._v); | ||
} | ||
_super.prototype._add.call(this, listener); | ||
_super.prototype._add.call(this, il); | ||
}; | ||
MemoryStream.prototype._stopNow = function () { | ||
this._has = false; | ||
_super.prototype._stopNow.call(this); | ||
}; | ||
MemoryStream.prototype._x = function () { | ||
this._has = false; | ||
_super.prototype._x.call(this); | ||
}; | ||
MemoryStream.prototype.map = function (project) { | ||
return this._map(project); | ||
}; | ||
MemoryStream.prototype.mapTo = function (projectedValue) { | ||
return _super.prototype.mapTo.call(this, projectedValue); | ||
}; | ||
MemoryStream.prototype.take = function (amount) { | ||
return _super.prototype.take.call(this, amount); | ||
}; | ||
MemoryStream.prototype.endWhen = function (other) { | ||
return _super.prototype.endWhen.call(this, other); | ||
}; | ||
MemoryStream.prototype.replaceError = function (replace) { | ||
return _super.prototype.replaceError.call(this, replace); | ||
}; | ||
MemoryStream.prototype.remember = function () { | ||
return this; | ||
}; | ||
MemoryStream.prototype.debug = function (labelOrSpy) { | ||
return _super.prototype.debug.call(this, labelOrSpy); | ||
}; | ||
return MemoryStream; | ||
@@ -1735,0 +1828,0 @@ }(Stream)); |
@@ -1,1 +0,1 @@ | ||
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.xstream=f()}})(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){"use strict";var xstream_1=require("xstream");function logToConsoleError(err){var target=err.stack||err;if(console&&console.error){console.error(target)}else if(console&&console.log){console.log(target)}}var XStreamAdapter={adapt:function(originStream,originStreamSubscribe){if(XStreamAdapter.isValidStream(originStream)){return originStream}var dispose=null;return xstream_1.default.create({start:function(out){var observer={next:function(value){return out.shamefullySendNext(value)},error:function(err){return out.shamefullySendError(err)},complete:function(){return out.shamefullySendComplete()}};dispose=originStreamSubscribe(originStream,observer)},stop:function(){if(typeof dispose==="function"){dispose()}}})},dispose:function(sinks,sinkProxies,sources){Object.keys(sources).forEach(function(k){if(typeof sources[k].dispose==="function"){sources[k].dispose()}});Object.keys(sinkProxies).forEach(function(k){sinkProxies[k].observer.complete()})},makeHoldSubject:function(){var stream=xstream_1.default.createWithMemory();var observer={next:function(x){stream.shamefullySendNext(x)},error:function(err){logToConsoleError(err);stream.shamefullySendError(err)},complete:function(){stream.shamefullySendComplete()}};return{observer:observer,stream:stream}},isValidStream:function(stream){return typeof stream.addListener==="function"&&typeof stream.imitate==="function"},streamSubscribe:function(stream,observer){stream.addListener(observer);return function(){return stream.removeListener(observer)}}};Object.defineProperty(exports,"__esModule",{value:true});exports.default=XStreamAdapter},{xstream:3}],2:[function(require,module,exports){"use strict";var __extends=this&&this.__extends||function(d,b){for(var p in b)if(b.hasOwnProperty(p))d[p]=b[p];function __(){this.constructor=d}d.prototype=b===null?Object.create(b):(__.prototype=b.prototype,new __)};var empty={};function noop(){}var emptyListener={_n:noop,_e:noop,_c:noop};function internalizeProducer(producer){producer._start=function _start(il){il.next=il._n;il.error=il._e;il.complete=il._c;this.start(il)};producer._stop=producer.stop}function invoke(f,args){switch(args.length){case 0:return f();case 1:return f(args[0]);case 2:return f(args[0],args[1]);case 3:return f(args[0],args[1],args[2]);case 4:return f(args[0],args[1],args[2],args[3]);case 5:return f(args[0],args[1],args[2],args[3],args[4]);default:return f.apply(void 0,args)}}function compose2(f1,f2){return function composedFn(arg){return f1(f2(arg))}}var CombineListener=function(){function CombineListener(i,prod){this.i=i;this.prod=prod;prod.proxies.push(this)}CombineListener.prototype._n=function(t){var prod=this.prod;var vals=prod.vals;prod.hasVal[this.i]=true;vals[this.i]=t;if(!prod.ready){prod.up()}if(prod.ready){try{prod.out._n(invoke(prod.project,vals))}catch(e){prod.out._e(e)}}};CombineListener.prototype._e=function(err){this.prod.out._e(err)};CombineListener.prototype._c=function(){var prod=this.prod;if(--prod.ac===0){prod.out._c()}};return CombineListener}();var CombineProducer=function(){function CombineProducer(project,streams){this.project=project;this.streams=streams;this.out=emptyListener;this.proxies=[];this.ready=false;this.vals=new Array(streams.length);this.hasVal=new Array(streams.length);this.ac=streams.length}CombineProducer.prototype.up=function(){for(var i=this.hasVal.length-1;i>=0;i--){if(!this.hasVal[i]){return}}this.ready=true};CombineProducer.prototype._start=function(out){this.out=out;var streams=this.streams;for(var i=streams.length-1;i>=0;i--){streams[i]._add(new CombineListener(i,this))}};CombineProducer.prototype._stop=function(){var streams=this.streams;for(var i=streams.length-1;i>=0;i--){streams[i]._remove(this.proxies[i])}this.out=null;this.ac=streams.length;this.proxies=[];this.ready=false;this.vals=new Array(streams.length);this.hasVal=new Array(streams.length)};return CombineProducer}();var FromArrayProducer=function(){function FromArrayProducer(a){this.a=a}FromArrayProducer.prototype._start=function(out){var a=this.a;for(var i=0,l=a.length;i<l;i++){out._n(a[i])}out._c()};FromArrayProducer.prototype._stop=function(){};return FromArrayProducer}();var FromPromiseProducer=function(){function FromPromiseProducer(p){this.p=p;this.on=false}FromPromiseProducer.prototype._start=function(out){var prod=this;this.on=true;this.p.then(function(v){if(prod.on){out._n(v);out._c()}},function(e){out._e(e)}).then(null,function(err){setTimeout(function(){throw err})})};FromPromiseProducer.prototype._stop=function(){this.on=false};return FromPromiseProducer}();var MergeProducer=function(){function MergeProducer(streams){this.streams=streams;this.out=emptyListener;this.ac=streams.length}MergeProducer.prototype._start=function(out){this.out=out;var streams=this.streams;for(var i=streams.length-1;i>=0;i--){streams[i]._add(this)}};MergeProducer.prototype._stop=function(){var streams=this.streams;for(var i=streams.length-1;i>=0;i--){streams[i]._remove(this)}this.out=null;this.ac=streams.length};MergeProducer.prototype._n=function(t){this.out._n(t)};MergeProducer.prototype._e=function(err){this.out._e(err)};MergeProducer.prototype._c=function(){if(--this.ac===0){this.out._c()}};return MergeProducer}();var PeriodicProducer=function(){function PeriodicProducer(period){this.period=period;this.intervalID=-1;this.i=0}PeriodicProducer.prototype._start=function(stream){var self=this;function intervalHandler(){stream._n(self.i++)}this.intervalID=setInterval(intervalHandler,this.period)};PeriodicProducer.prototype._stop=function(){if(this.intervalID!==-1)clearInterval(this.intervalID);this.intervalID=-1;this.i=0};return PeriodicProducer}();var DebugOperator=function(){function DebugOperator(spy,ins){if(spy===void 0){spy=null}this.spy=spy;this.ins=ins;this.out=null}DebugOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};DebugOperator.prototype._stop=function(){this.ins._remove(this);this.out=null};DebugOperator.prototype._n=function(t){if(this.spy){try{this.spy(t)}catch(e){this.out._e(e)}}else{console.log(t)}this.out._n(t)};DebugOperator.prototype._e=function(err){this.out._e(err)};DebugOperator.prototype._c=function(){this.out._c()};return DebugOperator}();var DropOperator=function(){function DropOperator(max,ins){this.max=max;this.ins=ins;this.out=null;this.dropped=0}DropOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};DropOperator.prototype._stop=function(){this.ins._remove(this);this.out=null;this.dropped=0};DropOperator.prototype._n=function(t){if(this.dropped++>=this.max)this.out._n(t)};DropOperator.prototype._e=function(err){this.out._e(err)};DropOperator.prototype._c=function(){this.out._c()};return DropOperator}();var OtherListener=function(){function OtherListener(out,op){this.out=out;this.op=op}OtherListener.prototype._n=function(t){this.op.end()};OtherListener.prototype._e=function(err){this.out._e(err)};OtherListener.prototype._c=function(){this.op.end()};return OtherListener}();var EndWhenOperator=function(){function EndWhenOperator(o,ins){this.o=o;this.ins=ins;this.out=null;this.oli=emptyListener}EndWhenOperator.prototype._start=function(out){this.out=out;this.o._add(this.oli=new OtherListener(out,this));this.ins._add(this)};EndWhenOperator.prototype._stop=function(){this.ins._remove(this);this.o._remove(this.oli);this.out=null;this.oli=null};EndWhenOperator.prototype.end=function(){this.out._c()};EndWhenOperator.prototype._n=function(t){this.out._n(t)};EndWhenOperator.prototype._e=function(err){this.out._e(err)};EndWhenOperator.prototype._c=function(){this.end()};return EndWhenOperator}();var FilterOperator=function(){function FilterOperator(passes,ins){this.passes=passes;this.ins=ins;this.out=null}FilterOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};FilterOperator.prototype._stop=function(){this.ins._remove(this);this.out=null};FilterOperator.prototype._n=function(t){try{if(this.passes(t))this.out._n(t)}catch(e){this.out._e(e)}};FilterOperator.prototype._e=function(err){this.out._e(err)};FilterOperator.prototype._c=function(){this.out._c()};return FilterOperator}();var FCInner=function(){function FCInner(out,op){this.out=out;this.op=op}FCInner.prototype._n=function(t){this.out._n(t)};FCInner.prototype._e=function(err){this.out._e(err)};FCInner.prototype._c=function(){this.op.less()};return FCInner}();var FlattenConcOperator=function(){function FlattenConcOperator(ins){this.ins=ins;this.active=1;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){this.out._c()}};FlattenConcOperator.prototype._n=function(s){this.active++;s._add(new FCInner(this.out,this))};FlattenConcOperator.prototype._e=function(err){this.out._e(err)};FlattenConcOperator.prototype._c=function(){this.less()};return FlattenConcOperator}();exports.FlattenConcOperator=FlattenConcOperator;var FInner=function(){function FInner(out,op){this.out=out;this.op=op}FInner.prototype._n=function(t){this.out._n(t)};FInner.prototype._e=function(err){this.out._e(err)};FInner.prototype._c=function(){this.op.curr=null;this.op.less()};return FInner}();var FlattenOperator=function(){function FlattenOperator(ins){this.ins=ins;this.curr=null;this.inner=null;this.open=true;this.out=null}FlattenOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};FlattenOperator.prototype._stop=function(){this.ins._remove(this);this.curr=null;this.inner=null;this.open=true;this.out=null};FlattenOperator.prototype.cut=function(){var _a=this,curr=_a.curr,inner=_a.inner;if(curr&&inner){curr._remove(inner)}};FlattenOperator.prototype.less=function(){if(!this.open&&!this.curr){this.out._c()}};FlattenOperator.prototype._n=function(s){this.cut();(this.curr=s)._add(this.inner=new FInner(this.out,this))};FlattenOperator.prototype._e=function(err){this.out._e(err)};FlattenOperator.prototype._c=function(){this.open=false;this.less()};return FlattenOperator}();exports.FlattenOperator=FlattenOperator;var FoldOperator=function(){function FoldOperator(f,seed,ins){this.f=f;this.seed=seed;this.ins=ins;this.out=null;this.acc=seed}FoldOperator.prototype._start=function(out){this.out=out;out._n(this.acc);this.ins._add(this)};FoldOperator.prototype._stop=function(){this.ins._remove(this);this.out=null;this.acc=this.seed};FoldOperator.prototype._n=function(t){try{this.out._n(this.acc=this.f(this.acc,t))}catch(e){this.out._e(e)}};FoldOperator.prototype._e=function(err){this.out._e(err)};FoldOperator.prototype._c=function(){this.out._c()};return FoldOperator}();var LastOperator=function(){function LastOperator(ins){this.ins=ins;this.out=null;this.has=false;this.val=empty}LastOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};LastOperator.prototype._stop=function(){this.ins._remove(this);this.out=null;this.has=false;this.val=empty};LastOperator.prototype._n=function(t){this.has=true;this.val=t};LastOperator.prototype._e=function(err){this.out._e(err)};LastOperator.prototype._c=function(){var out=this.out;if(this.has){out._n(this.val);out._c()}else{out._e("TODO show proper error")}};return LastOperator}();var MFCInner=function(){function MFCInner(out,op){this.out=out;this.op=op}MFCInner.prototype._n=function(t){this.out._n(t)};MFCInner.prototype._e=function(err){this.out._e(err)};MFCInner.prototype._c=function(){this.op.less()};return MFCInner}();var MapFlattenConcOperator=function(){function MapFlattenConcOperator(mapOp){this.mapOp=mapOp;this.active=1;this.out=null}MapFlattenConcOperator.prototype._start=function(out){this.out=out;this.mapOp.ins._add(this)};MapFlattenConcOperator.prototype._stop=function(){this.mapOp.ins._remove(this);this.active=1;this.out=null};MapFlattenConcOperator.prototype.less=function(){if(--this.active===0){this.out._c()}};MapFlattenConcOperator.prototype._n=function(v){this.active++;try{this.mapOp.project(v)._add(new MFCInner(this.out,this))}catch(e){this.out._e(e)}};MapFlattenConcOperator.prototype._e=function(err){this.out._e(err)};MapFlattenConcOperator.prototype._c=function(){this.less()};return MapFlattenConcOperator}();var MFInner=function(){function MFInner(out,op){this.out=out;this.op=op}MFInner.prototype._n=function(t){this.out._n(t)};MFInner.prototype._e=function(err){this.out._e(err)};MFInner.prototype._c=function(){this.op.curr=null;this.op.less()};return MFInner}();var MapFlattenOperator=function(){function MapFlattenOperator(mapOp){this.mapOp=mapOp;this.curr=null;this.inner=null;this.open=true;this.out=null}MapFlattenOperator.prototype._start=function(out){this.out=out;this.mapOp.ins._add(this)};MapFlattenOperator.prototype._stop=function(){this.mapOp.ins._remove(this);this.curr=null;this.inner=null;this.open=true;this.out=null};MapFlattenOperator.prototype.cut=function(){var _a=this,curr=_a.curr,inner=_a.inner;if(curr&&inner){curr._remove(inner)}};MapFlattenOperator.prototype.less=function(){if(!this.open&&!this.curr){this.out._c()}};MapFlattenOperator.prototype._n=function(v){this.cut();try{(this.curr=this.mapOp.project(v))._add(this.inner=new MFInner(this.out,this))}catch(e){this.out._e(e)}};MapFlattenOperator.prototype._e=function(err){this.out._e(err)};MapFlattenOperator.prototype._c=function(){this.open=false;this.less()};return MapFlattenOperator}();var MapOperator=function(){function MapOperator(project,ins){this.project=project;this.ins=ins;this.out=null}MapOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};MapOperator.prototype._stop=function(){this.ins._remove(this);this.out=null};MapOperator.prototype._n=function(t){try{this.out._n(this.project(t))}catch(e){this.out._e(e)}};MapOperator.prototype._e=function(err){this.out._e(err)};MapOperator.prototype._c=function(){this.out._c()};return MapOperator}();var FilterMapOperator=function(_super){__extends(FilterMapOperator,_super);function FilterMapOperator(passes,project,ins){_super.call(this,project,ins);this.passes=passes}FilterMapOperator.prototype._n=function(v){if(this.passes(v)){_super.prototype._n.call(this,v)}};return FilterMapOperator}(MapOperator);var MapToOperator=function(){function MapToOperator(val,ins){this.val=val;this.ins=ins;this.out=null}MapToOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};MapToOperator.prototype._stop=function(){this.ins._remove(this);this.out=null};MapToOperator.prototype._n=function(t){this.out._n(this.val)};MapToOperator.prototype._e=function(err){this.out._e(err)};MapToOperator.prototype._c=function(){this.out._c()};return MapToOperator}();var ReplaceErrorOperator=function(){function ReplaceErrorOperator(fn,ins){this.fn=fn;this.ins=ins;this.out=empty}ReplaceErrorOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};ReplaceErrorOperator.prototype._stop=function(){this.ins._remove(this);this.out=null};ReplaceErrorOperator.prototype._n=function(t){this.out._n(t)};ReplaceErrorOperator.prototype._e=function(err){try{this.ins._remove(this);(this.ins=this.fn(err))._add(this)}catch(e){this.out._e(e)}};ReplaceErrorOperator.prototype._c=function(){this.out._c()};return ReplaceErrorOperator}();var StartWithOperator=function(){function StartWithOperator(ins,value){this.ins=ins;this.value=value;this.out=emptyListener}StartWithOperator.prototype._start=function(out){this.out=out;this.out._n(this.value);this.ins._add(out)};StartWithOperator.prototype._stop=function(){this.ins._remove(this.out);this.out=null};return StartWithOperator}();var TakeOperator=function(){function TakeOperator(max,ins){this.max=max;this.ins=ins;this.out=null;this.taken=0}TakeOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};TakeOperator.prototype._stop=function(){this.ins._remove(this);this.out=null;this.taken=0};TakeOperator.prototype._n=function(t){var out=this.out;if(this.taken++<this.max-1){out._n(t)}else{out._n(t);out._c();this._stop()}};TakeOperator.prototype._e=function(err){this.out._e(err)};TakeOperator.prototype._c=function(){this.out._c()};return TakeOperator}();var Stream=function(){function Stream(producer){this._stopID=empty;this.combine=function combine(project){var streams=[];for(var _i=1;_i<arguments.length;_i++){streams[_i-1]=arguments[_i]}streams.unshift(this);return Stream.combine.apply(Stream,[project].concat(streams))};this._prod=producer;this._ils=[]}Stream.prototype._n=function(t){var a=this._ils;var len=a.length;if(len===1){a[0]._n(t)}else{for(var i=0;i<len;i++){a[i]._n(t)}}};Stream.prototype._e=function(err){var a=this._ils;var len=a.length;if(len===1){a[0]._e(err)}else{for(var i=0;i<len;i++){a[i]._e(err)}}this._x()};Stream.prototype._c=function(){var a=this._ils;var len=a.length;if(len===1){a[0]._c()}else{for(var i=0;i<len;i++){a[i]._c()}}this._x()};Stream.prototype._x=function(){if(this._ils.length===0)return;if(this._prod)this._prod._stop();this._ils=[]};Stream.prototype.addListener=function(listener){listener._n=listener.next;listener._e=listener.error;listener._c=listener.complete;this._add(listener)};Stream.prototype.removeListener=function(listener){this._remove(listener)};Stream.prototype._add=function(il){var a=this._ils;a.push(il);if(a.length===1){if(this._stopID!==empty){clearTimeout(this._stopID);this._stopID=empty}var p=this._prod;if(p)p._start(this)}};Stream.prototype._remove=function(il){var a=this._ils;var i=a.indexOf(il);if(i>-1){a.splice(i,1);var p_1=this._prod;if(p_1&&a.length<=0){this._stopID=setTimeout(function(){return p_1._stop()})}}};Stream.create=function(producer){if(producer){internalizeProducer(producer)}return new Stream(producer)};Stream.createWithMemory=function(producer){if(producer){internalizeProducer(producer)}return new MemoryStream(producer)};Stream.never=function(){return new Stream({_start:noop,_stop:noop})};Stream.empty=function(){return new Stream({_start:function(il){il._c()},_stop:noop})};Stream.throw=function(error){return new Stream({_start:function(il){il._e(error)},_stop:noop})};Stream.of=function(){var items=[];for(var _i=0;_i<arguments.length;_i++){items[_i-0]=arguments[_i]}return Stream.fromArray(items)};Stream.fromArray=function(array){return new Stream(new FromArrayProducer(array))};Stream.fromPromise=function(promise){return new Stream(new FromPromiseProducer(promise))};Stream.periodic=function(period){return new Stream(new PeriodicProducer(period))};Stream.merge=function(){var streams=[];for(var _i=0;_i<arguments.length;_i++){streams[_i-0]=arguments[_i]}return new Stream(new MergeProducer(streams))};Stream.prototype.map=function(project){var p=this._prod;if(p instanceof FilterOperator){return new Stream(new FilterMapOperator(p.passes,project,p.ins))}if(p instanceof FilterMapOperator){return new Stream(new FilterMapOperator(p.passes,compose2(project,p.project),p.ins))}if(p instanceof MapOperator){return new Stream(new MapOperator(compose2(project,p.project),p.ins))}return new Stream(new MapOperator(project,this))};Stream.prototype.mapTo=function(projectedValue){return new Stream(new MapToOperator(projectedValue,this))};Stream.prototype.filter=function(passes){var p=this._prod;if(p instanceof MapOperator){return new Stream(new FilterMapOperator(passes,p.project,p.ins))}if(p instanceof FilterMapOperator){return new Stream(new FilterMapOperator(compose2(passes,p.passes),p.project,p.ins))}if(p instanceof FilterOperator){return new Stream(new FilterOperator(compose2(passes,p.passes),p.ins))}return new Stream(new FilterOperator(passes,this))};Stream.prototype.take=function(amount){return new Stream(new TakeOperator(amount,this))};Stream.prototype.drop=function(amount){return new Stream(new DropOperator(amount,this))};Stream.prototype.last=function(){return new Stream(new LastOperator(this))};Stream.prototype.startWith=function(initial){return new Stream(new StartWithOperator(this,initial))};Stream.prototype.endWhen=function(other){return new Stream(new EndWhenOperator(other,this))};Stream.prototype.fold=function(accumulate,seed){return new Stream(new FoldOperator(accumulate,seed,this))};Stream.prototype.replaceError=function(replace){return new Stream(new ReplaceErrorOperator(replace,this))};Stream.prototype.flatten=function(){var p=this._prod;return new Stream(p instanceof MapOperator||p instanceof FilterMapOperator?new MapFlattenOperator(p):new FlattenOperator(this))};Stream.prototype.flattenConcurrently=function(){var p=this._prod;return new Stream(p instanceof MapOperator||p instanceof FilterMapOperator?new MapFlattenConcOperator(p):new FlattenConcOperator(this))};Stream.prototype.merge=function(other){return Stream.merge(this,other)};Stream.prototype.compose=function(operator){return operator(this)};Stream.prototype.remember=function(){return new MemoryStream(this._prod)};Stream.prototype.imitate=function(other){other._add(this)};Stream.prototype.debug=function(spy){if(spy===void 0){spy=null}return new Stream(new DebugOperator(spy,this))};Stream.prototype.shamefullySendNext=function(value){this._n(value)};Stream.prototype.shamefullySendError=function(error){this._e(error)};Stream.prototype.shamefullySendComplete=function(){this._c()};Stream.combine=function combine(project){var streams=[];for(var _i=1;_i<arguments.length;_i++){streams[_i-1]=arguments[_i]}return new Stream(new CombineProducer(project,streams))};return Stream}();exports.Stream=Stream;var MemoryStream=function(_super){__extends(MemoryStream,_super);function MemoryStream(producer){_super.call(this,producer);this._has=false}MemoryStream.prototype._n=function(x){this._val=x;this._has=true;_super.prototype._n.call(this,x)};MemoryStream.prototype._add=function(listener){if(this._has){listener._n(this._val)}_super.prototype._add.call(this,listener)};return MemoryStream}(Stream);exports.MemoryStream=MemoryStream;Object.defineProperty(exports,"__esModule",{value:true});exports.default=Stream},{}],3:[function(require,module,exports){"use strict";var core_1=require("./core");exports.Stream=core_1.Stream;exports.MemoryStream=core_1.MemoryStream;Object.defineProperty(exports,"__esModule",{value:true});exports.default=core_1.Stream},{"./core":2}]},{},[1])(1)}); | ||
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.xstream=f()}})(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){"use strict";var xstream_1=require("xstream");var XStreamAdapter={adapt:function(originStream,originStreamSubscribe){if(XStreamAdapter.isValidStream(originStream)){return originStream}var dispose=null;return xstream_1.default.create({start:function(out){var observer=out;dispose=originStreamSubscribe(originStream,observer)},stop:function(){if(typeof dispose==="function"){dispose()}}})},makeSubject:function(){var stream=xstream_1.default.create();var observer={next:function(x){stream.shamefullySendNext(x)},error:function(err){stream.shamefullySendError(err)},complete:function(){stream.shamefullySendComplete()}};return{observer:observer,stream:stream}},remember:function(stream){return stream.remember()},isValidStream:function(stream){return typeof stream.addListener==="function"&&typeof stream.shamefullySendNext==="function"},streamSubscribe:function(stream,observer){stream.addListener(observer);return function(){return stream.removeListener(observer)}}};Object.defineProperty(exports,"__esModule",{value:true});exports.default=XStreamAdapter},{xstream:3}],2:[function(require,module,exports){"use strict";var __extends=this&&this.__extends||function(d,b){for(var p in b)if(b.hasOwnProperty(p))d[p]=b[p];function __(){this.constructor=d}d.prototype=b===null?Object.create(b):(__.prototype=b.prototype,new __)};var NO={};function noop(){}function copy(a){var l=a.length;var b=Array(l);for(var i=0;i<l;++i){b[i]=a[i]}return b}exports.NO_IL={_n:noop,_e:noop,_c:noop};function internalizeProducer(producer){producer._start=function _start(il){il.next=il._n;il.error=il._e;il.complete=il._c;this.start(il)};producer._stop=producer.stop}function compose2(f1,f2){return function composedFn(arg){return f1(f2(arg))}}function and(f1,f2){return function andFn(t){return f1(t)&&f2(t)}}var MergeProducer=function(){function MergeProducer(insArr){this.type="merge";this.insArr=insArr;this.out=NO;this.ac=0}MergeProducer.prototype._start=function(out){this.out=out;var s=this.insArr;var L=s.length;this.ac=L;for(var i=0;i<L;i++){s[i]._add(this)}};MergeProducer.prototype._stop=function(){var s=this.insArr;var L=s.length;for(var i=0;i<L;i++){s[i]._remove(this)}this.out=NO};MergeProducer.prototype._n=function(t){var u=this.out;if(u===NO)return;u._n(t)};MergeProducer.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};MergeProducer.prototype._c=function(){if(--this.ac<=0){var u=this.out;if(u===NO)return;u._c()}};return MergeProducer}();exports.MergeProducer=MergeProducer;var CombineListener=function(){function CombineListener(i,out,p){this.i=i;this.out=out;this.p=p;p.ils.push(this)}CombineListener.prototype._n=function(t){var p=this.p,out=this.out;if(!out)return;if(p.up(t,this.i)){out._n(p.vals)}};CombineListener.prototype._e=function(err){var out=this.out;if(!out)return;out._e(err)};CombineListener.prototype._c=function(){var p=this.p;if(!p.out)return;if(--p.Nc===0){p.out._c()}};return CombineListener}();exports.CombineListener=CombineListener;var CombineProducer=function(){function CombineProducer(insArr){this.type="combine";this.insArr=insArr;this.out=NO;this.ils=[];this.Nc=this.Nn=0;this.vals=[]}CombineProducer.prototype.up=function(t,i){var v=this.vals[i];var Nn=!this.Nn?0:v===NO?--this.Nn:this.Nn;this.vals[i]=t;return Nn===0};CombineProducer.prototype._start=function(out){this.out=out;var s=this.insArr;var n=this.Nc=this.Nn=s.length;var vals=this.vals=new Array(n);if(n===0){out._n([]);out._c()}else{for(var i=0;i<n;i++){vals[i]=NO;s[i]._add(new CombineListener(i,out,this))}}};CombineProducer.prototype._stop=function(){var s=this.insArr;var n=s.length;for(var i=0;i<n;i++){s[i]._remove(this.ils[i])}this.out=NO;this.ils=[];this.vals=[]};return CombineProducer}();exports.CombineProducer=CombineProducer;var FromArrayProducer=function(){function FromArrayProducer(a){this.type="fromArray";this.a=a}FromArrayProducer.prototype._start=function(out){var a=this.a;for(var i=0,l=a.length;i<l;i++){out._n(a[i])}out._c()};FromArrayProducer.prototype._stop=function(){};return FromArrayProducer}();exports.FromArrayProducer=FromArrayProducer;var FromPromiseProducer=function(){function FromPromiseProducer(p){this.type="fromPromise";this.on=false;this.p=p}FromPromiseProducer.prototype._start=function(out){var prod=this;this.on=true;this.p.then(function(v){if(prod.on){out._n(v);out._c()}},function(e){out._e(e)}).then(null,function(err){setTimeout(function(){throw err})})};FromPromiseProducer.prototype._stop=function(){this.on=false};return FromPromiseProducer}();exports.FromPromiseProducer=FromPromiseProducer;var PeriodicProducer=function(){function PeriodicProducer(period){this.type="periodic";this.period=period;this.intervalID=-1;this.i=0}PeriodicProducer.prototype._start=function(stream){var self=this;function intervalHandler(){stream._n(self.i++)}this.intervalID=setInterval(intervalHandler,this.period)};PeriodicProducer.prototype._stop=function(){if(this.intervalID!==-1)clearInterval(this.intervalID);this.intervalID=-1;this.i=0};return PeriodicProducer}();exports.PeriodicProducer=PeriodicProducer;var DebugOperator=function(){function DebugOperator(arg,ins){this.type="debug";this.ins=ins;this.out=NO;this.s=noop;this.l="";if(typeof arg==="string"){this.l=arg}else if(typeof arg==="function"){this.s=arg}}DebugOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};DebugOperator.prototype._stop=function(){this.ins._remove(this);this.out=NO};DebugOperator.prototype._n=function(t){var u=this.out;if(u===NO)return;var s=this.s,l=this.l;if(s!==noop){try{s(t)}catch(e){u._e(e)}}else if(l){console.log(l+":",t)}else{console.log(t)}u._n(t)};DebugOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};DebugOperator.prototype._c=function(){var u=this.out;if(u===NO)return;u._c()};return DebugOperator}();exports.DebugOperator=DebugOperator;var DropOperator=function(){function DropOperator(max,ins){this.type="drop";this.ins=ins;this.out=NO;this.max=max;this.dropped=0}DropOperator.prototype._start=function(out){this.out=out;this.dropped=0;this.ins._add(this)};DropOperator.prototype._stop=function(){this.ins._remove(this);this.out=NO};DropOperator.prototype._n=function(t){var u=this.out;if(u===NO)return;if(this.dropped++>=this.max)u._n(t)};DropOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};DropOperator.prototype._c=function(){var u=this.out;if(u===NO)return;u._c()};return DropOperator}();exports.DropOperator=DropOperator;var OtherIL=function(){function OtherIL(out,op){this.out=out;this.op=op}OtherIL.prototype._n=function(t){this.op.end()};OtherIL.prototype._e=function(err){this.out._e(err)};OtherIL.prototype._c=function(){this.op.end()};return OtherIL}();var EndWhenOperator=function(){function EndWhenOperator(o,ins){this.type="endWhen";this.ins=ins;this.out=NO;this.o=o;this.oil=exports.NO_IL}EndWhenOperator.prototype._start=function(out){this.out=out;this.o._add(this.oil=new OtherIL(out,this));this.ins._add(this)};EndWhenOperator.prototype._stop=function(){this.ins._remove(this);this.o._remove(this.oil);this.out=NO;this.oil=exports.NO_IL};EndWhenOperator.prototype.end=function(){var u=this.out;if(u===NO)return;u._c()};EndWhenOperator.prototype._n=function(t){var u=this.out;if(u===NO)return;u._n(t)};EndWhenOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};EndWhenOperator.prototype._c=function(){this.end()};return EndWhenOperator}();exports.EndWhenOperator=EndWhenOperator;var FilterOperator=function(){function FilterOperator(passes,ins){this.type="filter";this.ins=ins;this.out=NO;this.passes=passes}FilterOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};FilterOperator.prototype._stop=function(){this.ins._remove(this);this.out=NO};FilterOperator.prototype._n=function(t){var u=this.out;if(u===NO)return;try{if(this.passes(t))u._n(t)}catch(e){u._e(e)}};FilterOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};FilterOperator.prototype._c=function(){var u=this.out;if(u===NO)return;u._c()};return FilterOperator}();exports.FilterOperator=FilterOperator;var FlattenListener=function(){function FlattenListener(out,op){this.out=out;this.op=op}FlattenListener.prototype._n=function(t){this.out._n(t)};FlattenListener.prototype._e=function(err){this.out._e(err)};FlattenListener.prototype._c=function(){this.op.inner=NO;this.op.less()};return FlattenListener}();var FlattenOperator=function(){function FlattenOperator(ins){this.type="flatten";this.ins=ins;this.out=NO;this.open=true;this.inner=NO;this.il=exports.NO_IL}FlattenOperator.prototype._start=function(out){this.out=out;this.open=true;this.inner=NO;this.il=exports.NO_IL;this.ins._add(this)};FlattenOperator.prototype._stop=function(){this.ins._remove(this);if(this.inner!==NO)this.inner._remove(this.il);this.out=NO;this.open=true;this.inner=NO;this.il=exports.NO_IL};FlattenOperator.prototype.less=function(){var u=this.out;if(u===NO)return;if(!this.open&&this.inner===NO)u._c()};FlattenOperator.prototype._n=function(s){var u=this.out;if(u===NO)return;var _a=this,inner=_a.inner,il=_a.il;if(s===inner&&s._prod!==NO)s._stopNow();if(inner!==NO&&il!==exports.NO_IL)inner._remove(il);(this.inner=s)._add(this.il=new FlattenListener(u,this))};FlattenOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};FlattenOperator.prototype._c=function(){this.open=false;this.less()};return FlattenOperator}();exports.FlattenOperator=FlattenOperator;var FoldOperator=function(){function FoldOperator(f,seed,ins){this.type="fold";this.ins=ins;this.out=NO;this.f=f;this.acc=this.seed=seed}FoldOperator.prototype._start=function(out){this.out=out;this.acc=this.seed;out._n(this.acc);this.ins._add(this)};FoldOperator.prototype._stop=function(){this.ins._remove(this);this.out=NO;this.acc=this.seed};FoldOperator.prototype._n=function(t){var u=this.out;if(u===NO)return;try{u._n(this.acc=this.f(this.acc,t))}catch(e){u._e(e)}};FoldOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};FoldOperator.prototype._c=function(){var u=this.out;if(u===NO)return;u._c()};return FoldOperator}();exports.FoldOperator=FoldOperator;var LastOperator=function(){function LastOperator(ins){this.type="last";this.ins=ins;this.out=NO;this.has=false;this.val=NO}LastOperator.prototype._start=function(out){this.out=out;this.has=false;this.ins._add(this)};LastOperator.prototype._stop=function(){this.ins._remove(this);this.out=NO;this.val=NO};LastOperator.prototype._n=function(t){this.has=true;this.val=t};LastOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};LastOperator.prototype._c=function(){var u=this.out;if(u===NO)return;if(this.has){u._n(this.val);u._c()}else{u._e("TODO show proper error")}};return LastOperator}();exports.LastOperator=LastOperator;var MapFlattenInner=function(){function MapFlattenInner(out,op){this.out=out;this.op=op}MapFlattenInner.prototype._n=function(r){this.out._n(r)};MapFlattenInner.prototype._e=function(err){this.out._e(err)};MapFlattenInner.prototype._c=function(){this.op.inner=NO;this.op.less()};return MapFlattenInner}();var MapFlattenOperator=function(){function MapFlattenOperator(mapOp){this.type=mapOp.type+"+flatten";this.ins=mapOp.ins;this.out=NO;this.mapOp=mapOp;this.inner=NO;this.il=exports.NO_IL;this.open=true}MapFlattenOperator.prototype._start=function(out){this.out=out;this.inner=NO;this.il=exports.NO_IL;this.open=true;this.mapOp.ins._add(this)};MapFlattenOperator.prototype._stop=function(){this.mapOp.ins._remove(this);if(this.inner!==NO)this.inner._remove(this.il);this.out=NO;this.inner=NO;this.il=exports.NO_IL};MapFlattenOperator.prototype.less=function(){if(!this.open&&this.inner===NO){var u=this.out;if(u===NO)return;u._c()}};MapFlattenOperator.prototype._n=function(v){var u=this.out;if(u===NO)return;var _a=this,inner=_a.inner,il=_a.il;var s;try{s=this.mapOp.project(v)}catch(e){u._e(e);return}if(s===inner&&s._prod!==NO)s._stopNow();if(inner!==NO&&il!==exports.NO_IL)inner._remove(il);(this.inner=s)._add(this.il=new MapFlattenInner(u,this))};MapFlattenOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};MapFlattenOperator.prototype._c=function(){this.open=false;this.less()};return MapFlattenOperator}();exports.MapFlattenOperator=MapFlattenOperator;var MapOperator=function(){function MapOperator(project,ins){this.type="map";this.ins=ins;this.out=NO;this.project=project}MapOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};MapOperator.prototype._stop=function(){this.ins._remove(this);this.out=NO};MapOperator.prototype._n=function(t){var u=this.out;if(u===NO)return;try{u._n(this.project(t))}catch(e){u._e(e)}};MapOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};MapOperator.prototype._c=function(){var u=this.out;if(u===NO)return;u._c()};return MapOperator}();exports.MapOperator=MapOperator;var FilterMapOperator=function(_super){__extends(FilterMapOperator,_super);function FilterMapOperator(passes,project,ins){_super.call(this,project,ins);this.type="filter+map";this.passes=passes}FilterMapOperator.prototype._n=function(v){if(this.passes(v)){_super.prototype._n.call(this,v)}};return FilterMapOperator}(MapOperator);exports.FilterMapOperator=FilterMapOperator;var RememberOperator=function(){function RememberOperator(ins){this.type="remember";this.ins=ins;this.out=NO}RememberOperator.prototype._start=function(out){this.out=out;this.ins._add(out)};RememberOperator.prototype._stop=function(){this.ins._remove(this.out);this.out=NO};return RememberOperator}();exports.RememberOperator=RememberOperator;var ReplaceErrorOperator=function(){function ReplaceErrorOperator(fn,ins){this.type="replaceError";this.ins=ins;this.out=NO;this.fn=fn}ReplaceErrorOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};ReplaceErrorOperator.prototype._stop=function(){this.ins._remove(this);this.out=NO};ReplaceErrorOperator.prototype._n=function(t){var u=this.out;if(u===NO)return;u._n(t)};ReplaceErrorOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;try{this.ins._remove(this);(this.ins=this.fn(err))._add(this)}catch(e){u._e(e)}};ReplaceErrorOperator.prototype._c=function(){var u=this.out;if(u===NO)return;u._c()};return ReplaceErrorOperator}();exports.ReplaceErrorOperator=ReplaceErrorOperator;var StartWithOperator=function(){function StartWithOperator(ins,val){this.type="startWith";this.ins=ins;this.out=NO;this.val=val}StartWithOperator.prototype._start=function(out){this.out=out;this.out._n(this.val);this.ins._add(out)};StartWithOperator.prototype._stop=function(){this.ins._remove(this.out);this.out=NO};return StartWithOperator}();exports.StartWithOperator=StartWithOperator;var TakeOperator=function(){function TakeOperator(max,ins){this.type="take";this.ins=ins;this.out=NO;this.max=max;this.taken=0}TakeOperator.prototype._start=function(out){this.out=out;this.taken=0;this.ins._add(this)};TakeOperator.prototype._stop=function(){this.ins._remove(this);this.out=NO};TakeOperator.prototype._n=function(t){var u=this.out;if(u===NO)return;if(this.taken++<this.max-1){u._n(t)}else{u._n(t);u._c()}};TakeOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};TakeOperator.prototype._c=function(){var u=this.out;if(u===NO)return;u._c()};return TakeOperator}();exports.TakeOperator=TakeOperator;var Stream=function(){function Stream(producer){this._prod=producer||NO;this._ils=[];this._stopID=NO;this._target=NO;this._err=NO}Stream.prototype._n=function(t){var a=this._ils;var L=a.length;if(L==1)a[0]._n(t);else{var b=copy(a);for(var i=0;i<L;i++)b[i]._n(t)}};Stream.prototype._e=function(err){if(this._err!==NO)return;this._err=err;var a=this._ils;var L=a.length;if(L==1)a[0]._e(err);else{var b=copy(a);for(var i=0;i<L;i++)b[i]._e(err)}this._x()};Stream.prototype._c=function(){var a=this._ils;var L=a.length;if(L==1)a[0]._c();else{var b=copy(a);for(var i=0;i<L;i++)b[i]._c()}this._x()};Stream.prototype._x=function(){if(this._ils.length===0)return;if(this._prod!==NO)this._prod._stop();this._err=NO;this._ils=[]};Stream.prototype._stopNow=function(){this._prod._stop();this._err=NO;this._stopID=NO};Stream.prototype._add=function(il){var ta=this._target;if(ta!==NO)return ta._add(il);var a=this._ils;a.push(il);if(a.length===1){if(this._stopID!==NO){clearTimeout(this._stopID);this._stopID=NO}var p=this._prod;if(p!==NO)p._start(this)}};Stream.prototype._remove=function(il){var _this=this;var ta=this._target;if(ta!==NO)return ta._remove(il);var a=this._ils;var i=a.indexOf(il);if(i>-1){a.splice(i,1);if(this._prod!==NO&&a.length<=0){this._err=NO;this._stopID=setTimeout(function(){return _this._stopNow()})}else if(a.length===1){this._pruneCycles()}}};Stream.prototype._pruneCycles=function(){if(this._hasNoSinks(this,[])){this._remove(this._ils[0])}};Stream.prototype._hasNoSinks=function(x,trace){if(trace.indexOf(x)!==-1){return true}else if(x.out===this){return true}else if(x.out&&x.out!==NO){return this._hasNoSinks(x.out,trace.concat(x))}else if(x._ils){for(var i=0,N=x._ils.length;i<N;i++){if(!this._hasNoSinks(x._ils[i],trace.concat(x))){return false}}return true}else{return false}};Stream.prototype.ctor=function(){return this instanceof MemoryStream?MemoryStream:Stream};Stream.prototype.addListener=function(listener){if(typeof listener.next!=="function"||typeof listener.error!=="function"||typeof listener.complete!=="function"){throw new Error("stream.addListener() requires all three next, error, "+"and complete functions.")}listener._n=listener.next;listener._e=listener.error;listener._c=listener.complete;this._add(listener)};Stream.prototype.removeListener=function(listener){this._remove(listener)};Stream.create=function(producer){if(producer){if(typeof producer.start!=="function"||typeof producer.stop!=="function"){throw new Error("producer requires both start and stop functions")}internalizeProducer(producer)}return new Stream(producer)};Stream.createWithMemory=function(producer){if(producer){internalizeProducer(producer)}return new MemoryStream(producer)};Stream.never=function(){return new Stream({_start:noop,_stop:noop})};Stream.empty=function(){return new Stream({_start:function(il){il._c()},_stop:noop})};Stream.throw=function(error){return new Stream({_start:function(il){il._e(error)},_stop:noop})};Stream.of=function(){var items=[];for(var _i=0;_i<arguments.length;_i++){items[_i-0]=arguments[_i]}return Stream.fromArray(items)};Stream.fromArray=function(array){return new Stream(new FromArrayProducer(array))};Stream.fromPromise=function(promise){return new Stream(new FromPromiseProducer(promise))};Stream.periodic=function(period){return new Stream(new PeriodicProducer(period))};Stream.prototype._map=function(project){var p=this._prod;var ctor=this.ctor();if(p instanceof FilterOperator){return new ctor(new FilterMapOperator(p.passes,project,p.ins))}if(p instanceof FilterMapOperator){return new ctor(new FilterMapOperator(p.passes,compose2(project,p.project),p.ins))}if(p instanceof MapOperator){return new ctor(new MapOperator(compose2(project,p.project),p.ins))}return new ctor(new MapOperator(project,this))};Stream.prototype.map=function(project){return this._map(project)};Stream.prototype.mapTo=function(projectedValue){var s=this.map(function(){return projectedValue});var op=s._prod;op.type=op.type.replace("map","mapTo");return s};Stream.prototype.filter=function(passes){var p=this._prod;if(p instanceof FilterOperator){return new Stream(new FilterOperator(and(p.passes,passes),p.ins))}return new Stream(new FilterOperator(passes,this))};Stream.prototype.take=function(amount){return new(this.ctor())(new TakeOperator(amount,this))};Stream.prototype.drop=function(amount){return new Stream(new DropOperator(amount,this))};Stream.prototype.last=function(){return new Stream(new LastOperator(this))};Stream.prototype.startWith=function(initial){return new MemoryStream(new StartWithOperator(this,initial))};Stream.prototype.endWhen=function(other){return new(this.ctor())(new EndWhenOperator(other,this))};Stream.prototype.fold=function(accumulate,seed){return new MemoryStream(new FoldOperator(accumulate,seed,this))};Stream.prototype.replaceError=function(replace){return new(this.ctor())(new ReplaceErrorOperator(replace,this))};Stream.prototype.flatten=function(){var p=this._prod;return new Stream(p instanceof MapOperator&&!(p instanceof FilterMapOperator)?new MapFlattenOperator(p):new FlattenOperator(this))};Stream.prototype.compose=function(operator){return operator(this)};Stream.prototype.remember=function(){return new MemoryStream(new RememberOperator(this))};Stream.prototype.debug=function(labelOrSpy){return new(this.ctor())(new DebugOperator(labelOrSpy,this))};Stream.prototype.imitate=function(target){if(target instanceof MemoryStream){throw new Error("A MemoryStream was given to imitate(), but it only "+"supports a Stream. Read more about this restriction here: "+"https://github.com/staltz/xstream#faq")}this._target=target;for(var ils=this._ils,N=ils.length,i=0;i<N;i++){target._add(ils[i])}this._ils=[]};Stream.prototype.shamefullySendNext=function(value){this._n(value)};Stream.prototype.shamefullySendError=function(error){this._e(error)};Stream.prototype.shamefullySendComplete=function(){this._c()};Stream.merge=function merge(){var streams=[];for(var _i=0;_i<arguments.length;_i++){streams[_i-0]=arguments[_i]}return new Stream(new MergeProducer(streams))};Stream.combine=function combine(){var streams=[];for(var _i=0;_i<arguments.length;_i++){streams[_i-0]=arguments[_i]}return new Stream(new CombineProducer(streams))};return Stream}();exports.Stream=Stream;var MemoryStream=function(_super){__extends(MemoryStream,_super);function MemoryStream(producer){_super.call(this,producer);this._has=false}MemoryStream.prototype._n=function(x){this._v=x;this._has=true;_super.prototype._n.call(this,x)};MemoryStream.prototype._add=function(il){if(this._has){il._n(this._v)}_super.prototype._add.call(this,il)};MemoryStream.prototype._stopNow=function(){this._has=false;_super.prototype._stopNow.call(this)};MemoryStream.prototype._x=function(){this._has=false;_super.prototype._x.call(this)};MemoryStream.prototype.map=function(project){return this._map(project)};MemoryStream.prototype.mapTo=function(projectedValue){return _super.prototype.mapTo.call(this,projectedValue)};MemoryStream.prototype.take=function(amount){return _super.prototype.take.call(this,amount)};MemoryStream.prototype.endWhen=function(other){return _super.prototype.endWhen.call(this,other)};MemoryStream.prototype.replaceError=function(replace){return _super.prototype.replaceError.call(this,replace)};MemoryStream.prototype.remember=function(){return this};MemoryStream.prototype.debug=function(labelOrSpy){return _super.prototype.debug.call(this,labelOrSpy)};return MemoryStream}(Stream);exports.MemoryStream=MemoryStream;Object.defineProperty(exports,"__esModule",{value:true});exports.default=Stream},{}],3:[function(require,module,exports){"use strict";var core_1=require("./core");exports.Stream=core_1.Stream;exports.MemoryStream=core_1.MemoryStream;Object.defineProperty(exports,"__esModule",{value:true});exports.default=core_1.Stream},{"./core":2}]},{},[1])(1)}); |
{ | ||
"name": "@cycle/xstream-adapter", | ||
"version": "3.0.2", | ||
"version": "3.0.3", | ||
"description": "Cycle.js xstream Stream Adapter", | ||
"main": "lib/index.js", | ||
"typings": "lib/index.d.ts", | ||
"scripts": { | ||
"commit": "git-cz", | ||
"lint": "tslint -c tslint.json src/**/*.ts", | ||
"premocha": "npm run lib", | ||
"mocha": "mocha --compilers js:babel-register", | ||
"postmocha": "rm -rf tests/**/*.js", | ||
"test": "npm run lint && npm run mocha", | ||
"prelib": "typings install && rm -rf lib/ && mkdirp lib/", | ||
"lib": "tsc", | ||
"predist": "rm -rf dist/ && mkdirp dist/ && npm run lib", | ||
"dist": "browserify lib/index.js --standalone xstream --outfile dist/xstream.js", | ||
"postdist": "uglifyjs dist/xstream.js -o dist/xstream.min.js", | ||
"start": "npm install && npm prune", | ||
"prepublish": "npm run lib", | ||
"preversion": "npm run dist" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/staltz/xstream.git" | ||
}, | ||
"author": "Andre Staltz <andre+npm@staltz.com> (http://andre.staltz.com/)", | ||
"repository": "https://github.com/cyclejs/cyclejs/tree/master/packages/xstream-adapter", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/staltz/xstream/issues" | ||
}, | ||
"homepage": "https://github.com/staltz/xstream#readme", | ||
"bugs": "https://github.com/cyclejs/cyclejs/issues", | ||
"homepage": "https://cycle.js.org", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@cycle/base": "^4.0.1", | ||
"assert": "^1.3.0", | ||
"babel-preset-es2015": "^6.6.0", | ||
"babel-register": "^6.7.2", | ||
"browserify": "^13.0.0", | ||
"commitizen": "^2.7.3", | ||
"conventional-changelog": "^1.1.0", | ||
"cz-conventional-changelog": "^1.1.5", | ||
"@cycle/base": "4.x.x", | ||
"es6-promise": "^3.1.2", | ||
"ghooks": "^1.0.3", | ||
"markdox": "^0.1.10", | ||
"mkdirp": "^0.5.1", | ||
"mocha": "^2.4.5", | ||
"ts-node": "^0.5.5", | ||
"tslint": "^3.6.0", | ||
"typescript": "^1.8.9", | ||
"typings": "^0.8.0", | ||
"uglify-js": "^2.6.2", | ||
"validate-commit-msg": "^2.4.0", | ||
"xstream": "5.x.x" | ||
}, | ||
"peerDependencies": { | ||
"xstream": "4.x - 5.x" | ||
"xstream": "*" | ||
}, | ||
@@ -66,3 +27,36 @@ "config": { | ||
} | ||
}, | ||
"scripts": { | ||
"lint": "../node_modules/.bin/tslint -c tslint.json src/**/*.ts", | ||
"mocha": "../node_modules/.bin/mocha --compilers js:babel-register", | ||
"test": "npm run lint && npm run lib && npm run mocha", | ||
"test-ci": "npm run test", | ||
"prelib": "../node_modules/.bin/typings install && rm -rf lib/ && mkdir -p lib/", | ||
"lib": "../node_modules/.bin/tsc", | ||
"readme": ":", | ||
"browserify": "../node_modules/.bin/browserify lib/index.js --standalone xstream --outfile dist/xstream.js", | ||
"uglify": "../node_modules/.bin/uglifyjs dist/xstream.js -o dist/xstream.min.js", | ||
"predist": "rm -rf dist/ && mkdir -p dist/", | ||
"dist": "npm run lib && npm run browserify && npm run uglify", | ||
"preversion": "npm test", | ||
"version": "npm run dist && npm run readme && npm run changelog", | ||
"postversion": "git add -A && git commit -m \"release(${PWD##*/}): v$(cat package.json | ../node_modules/.bin/jase version)\" && git push origin master && npm publish", | ||
"release-patch": "npm --no-git-tag-version version patch", | ||
"release-minor": "npm --no-git-tag-version version minor", | ||
"release-major": "npm --no-git-tag-version version major", | ||
"changelog": "node ../.scripts/update-changelogs.js ${PWD##*/}" | ||
}, | ||
"contributors": [ | ||
{ | ||
"name": "Andre Staltz", | ||
"email": "andre@staltz.com" | ||
}, | ||
{ | ||
"name": "Tylor Steinberger", | ||
"email": "tlsteinberger167@gmail.com" | ||
} | ||
], | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
@@ -1,3 +0,7 @@ | ||
# XStreamAdapter | ||
# Cycle.js xstream Stream Adapter | ||
Cycle.js Diversity adapter for XStream | ||
Stream adapter interface for xstream. | ||
``` | ||
npm install @cycle/xstream-adapter | ||
``` |
@@ -19,7 +19,7 @@ { | ||
"files": [ | ||
"typings/main.d.ts", | ||
"typings/index.d.ts", | ||
"src/index.ts" | ||
], | ||
"filesGlob": [ | ||
"typings/main.d.ts", | ||
"typings/index.d.ts", | ||
"src/**/*.ts" | ||
@@ -26,0 +26,0 @@ ], |
@@ -6,6 +6,6 @@ { | ||
"devDependencies": {}, | ||
"ambientDependencies": { | ||
"globalDependencies": { | ||
"es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#6697d6f7dadbf5773cb40ecda35a76027e0783b2" | ||
}, | ||
"ambientDevDependencies": { | ||
"globalDevDependencies": { | ||
"mocha": "github:DefinitelyTyped/DefinitelyTyped/mocha/mocha.d.ts#d6dd320291705694ba8e1a79497a908e9f5e6617", | ||
@@ -12,0 +12,0 @@ "node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts#20e1eb9616922d382d918cc5a21870a9dbe255f5" |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
3
8
217001
22
4879
2
5
1