Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

xstream

Package Overview
Dependencies
Maintainers
2
Versions
100
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xstream - npm Package Compare versions

Comparing version 5.2.0 to 5.2.1

11

CHANGELOG.md

@@ -0,1 +1,12 @@

<a name="5.2.1"></a>
## [5.2.1](https://github.com/staltz/xstream/compare/v5.2.0...v5.2.1) (2016-07-12)
### Bug Fixes
* **merge:** fix completion and disposal ([5bbcade](https://github.com/staltz/xstream/commit/5bbcade))
* **operators:** improve resistence against disposal bugs ([ff36fbd](https://github.com/staltz/xstream/commit/ff36fbd))
<a name="5.2.0"></a>

@@ -2,0 +13,0 @@ # [5.2.0](https://github.com/staltz/xstream/compare/v5.1.4...v5.2.0) (2016-07-11)

72

core.d.ts

@@ -6,3 +6,3 @@ export interface InternalListener<T> {

}
export declare const emptyIL: InternalListener<any>;
export declare const NO_IL: InternalListener<any>;
export interface InternalProducer<T> {

@@ -35,4 +35,4 @@ _start: (listener: InternalListener<T>) => void;

export declare class MergeProducer<T> implements Aggregator<T, T>, InternalListener<T> {
type: string;
insArr: Array<Stream<T>>;
type: string;
out: Stream<T>;

@@ -67,4 +67,4 @@ private ac;

export declare class CombineProducer<R> implements Aggregator<any, Array<R>> {
type: string;
insArr: Array<Stream<any>>;
type: string;
out: Stream<Array<R>>;

@@ -81,4 +81,4 @@ ils: Array<CombineListener<any>>;

export declare class FromArrayProducer<T> implements InternalProducer<T> {
type: string;
a: Array<T>;
type: string;
constructor(a: Array<T>);

@@ -89,5 +89,5 @@ _start(out: InternalListener<T>): void;

export declare class FromPromiseProducer<T> implements InternalProducer<T> {
p: Promise<T>;
type: string;
on: boolean;
p: Promise<T>;
constructor(p: Promise<T>);

@@ -98,4 +98,4 @@ _start(out: InternalListener<T>): void;

export declare class PeriodicProducer implements InternalProducer<number> {
type: string;
period: number;
type: string;
private intervalID;

@@ -108,4 +108,4 @@ private i;

export declare class DebugOperator<T> implements Operator<T, T> {
type: string;
ins: Stream<T>;
type: string;
out: Stream<T>;

@@ -122,6 +122,6 @@ private s;

export declare class DropOperator<T> implements Operator<T, T> {
max: number;
type: string;
ins: Stream<T>;
type: string;
out: Stream<T>;
max: number;
private dropped;

@@ -136,6 +136,6 @@ constructor(max: number, ins: Stream<T>);

export declare class EndWhenOperator<T> implements Operator<T, T> {
o: Stream<any>;
type: string;
ins: Stream<T>;
type: string;
out: Stream<T>;
o: Stream<any>;
private oil;

@@ -151,6 +151,6 @@ constructor(o: Stream<any>, ins: Stream<T>);

export declare class FilterOperator<T> implements Operator<T, T> {
passes: (t: T) => boolean;
type: string;
ins: Stream<T>;
type: string;
out: Stream<T>;
passes: (t: T) => boolean;
constructor(passes: (t: T) => boolean, ins: Stream<T>);

@@ -164,8 +164,8 @@ _start(out: Stream<T>): void;

export declare class FlattenOperator<T> implements Operator<Stream<T>, T> {
type: string;
ins: Stream<Stream<T>>;
type: string;
out: Stream<T>;
private open;
inner: Stream<T>;
private il;
private open;
out: Stream<T>;
constructor(ins: Stream<Stream<T>>);

@@ -180,7 +180,7 @@ _start(out: Stream<T>): void;

export declare class FoldOperator<T, R> implements Operator<T, R> {
type: string;
ins: Stream<T>;
out: Stream<R>;
f: (acc: R, t: T) => R;
seed: R;
ins: Stream<T>;
type: string;
out: Stream<R>;
private acc;

@@ -195,4 +195,4 @@ constructor(f: (acc: R, t: T) => R, seed: R, ins: Stream<T>);

export declare class LastOperator<T> implements Operator<T, T> {
type: string;
ins: Stream<T>;
type: string;
out: Stream<T>;

@@ -209,9 +209,9 @@ private has;

export declare class MapFlattenOperator<T, R> implements Operator<T, R> {
mapOp: MapOperator<T, Stream<R>>;
type: string;
ins: Stream<T>;
out: Stream<R>;
mapOp: MapOperator<T, Stream<R>>;
inner: Stream<R>;
private il;
private open;
out: Stream<R>;
constructor(mapOp: MapOperator<T, Stream<R>>);

@@ -226,6 +226,6 @@ _start(out: Stream<R>): void;

export declare class MapOperator<T, R> implements Operator<T, R> {
project: (t: T) => R;
type: string;
ins: Stream<T>;
type: string;
out: Stream<R>;
project: (t: T) => R;
constructor(project: (t: T) => R, ins: Stream<T>);

@@ -239,4 +239,4 @@ _start(out: Stream<R>): void;

export declare class FilterMapOperator<T, R> extends MapOperator<T, R> {
type: string;
passes: (t: T) => boolean;
type: string;
constructor(passes: (t: T) => boolean, project: (t: T) => R, ins: Stream<T>);

@@ -246,5 +246,5 @@ _n(v: T): void;

export declare class RememberOperator<T> implements InternalProducer<T> {
type: string;
ins: Stream<T>;
type: string;
out: InternalListener<T>;
out: Stream<T>;
constructor(ins: Stream<T>);

@@ -255,6 +255,6 @@ _start(out: Stream<T>): void;

export declare class ReplaceErrorOperator<T> implements Operator<T, T> {
fn: (err: any) => Stream<T>;
type: string;
ins: Stream<T>;
type: string;
out: Stream<T>;
fn: (err: any) => Stream<T>;
constructor(fn: (err: any) => Stream<T>, ins: Stream<T>);

@@ -268,15 +268,15 @@ _start(out: Stream<T>): void;

export declare class StartWithOperator<T> implements InternalProducer<T> {
type: string;
ins: Stream<T>;
value: T;
type: string;
private out;
constructor(ins: Stream<T>, value: T);
_start(out: InternalListener<T>): void;
out: Stream<T>;
val: T;
constructor(ins: Stream<T>, val: T);
_start(out: Stream<T>): void;
_stop(): void;
}
export declare class TakeOperator<T> implements Operator<T, T> {
max: number;
type: string;
ins: Stream<T>;
type: string;
out: Stream<T>;
max: number;
private taken;

@@ -283,0 +283,0 @@ constructor(max: number, ins: Stream<T>);

@@ -7,3 +7,3 @@ "use strict";

};
var empty = {};
var NO = {};
function noop() { }

@@ -18,3 +18,3 @@ function copy(a) {

}
exports.emptyIL = {
exports.NO_IL = {
_n: noop,

@@ -47,6 +47,6 @@ _e: noop,

function MergeProducer(insArr) {
this.type = 'merge';
this.insArr = insArr;
this.type = 'merge';
this.out = null;
this.ac = insArr.length;
this.out = NO;
this.ac = 0;
}

@@ -57,2 +57,3 @@ MergeProducer.prototype._start = function (out) {

var L = s.length;
this.ac = L;
for (var i = 0; i < L; i++) {

@@ -68,8 +69,7 @@ s[i]._add(this);

}
this.out = null;
this.ac = L;
this.out = NO;
};
MergeProducer.prototype._n = function (t) {
var u = this.out;
if (!u)
if (u === NO)
return;

@@ -80,3 +80,3 @@ u._n(t);

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -86,5 +86,5 @@ u._e(err);

MergeProducer.prototype._c = function () {
if (--this.ac === 0) {
if (--this.ac <= 0) {
var u = this.out;
if (!u)
if (u === NO)
return;

@@ -131,15 +131,12 @@ u._c();

function CombineProducer(insArr) {
this.type = 'combine';
this.insArr = insArr;
this.type = 'combine';
this.out = null;
this.out = NO;
this.ils = [];
var n = this.Nc = this.Nn = insArr.length;
var vals = this.vals = new Array(n);
for (var i = 0; i < n; i++) {
vals[i] = empty;
}
this.Nc = this.Nn = 0;
this.vals = [];
}
CombineProducer.prototype.up = function (t, i) {
var v = this.vals[i];
var Nn = !this.Nn ? 0 : v === empty ? --this.Nn : this.Nn;
var Nn = !this.Nn ? 0 : v === NO ? --this.Nn : this.Nn;
this.vals[i] = t;

@@ -151,3 +148,4 @@ return Nn === 0;

var s = this.insArr;
var n = s.length;
var n = this.Nc = this.Nn = s.length;
var vals = this.vals = new Array(n);
if (n === 0) {

@@ -159,2 +157,3 @@ out._n([]);

for (var i = 0; i < n; i++) {
vals[i] = NO;
s[i]._add(new CombineListener(i, out, this));

@@ -166,10 +165,9 @@ }

var s = this.insArr;
var n = this.Nc = this.Nn = s.length;
var vals = this.vals = new Array(n);
var n = s.length;
for (var i = 0; i < n; i++) {
s[i]._remove(this.ils[i]);
vals[i] = empty;
}
this.out = null;
this.out = NO;
this.ils = [];
this.vals = [];
};

@@ -181,4 +179,4 @@ return CombineProducer;

function FromArrayProducer(a) {
this.type = 'fromArray';
this.a = a;
this.type = 'fromArray';
}

@@ -199,5 +197,5 @@ FromArrayProducer.prototype._start = function (out) {

function FromPromiseProducer(p) {
this.p = p;
this.type = 'fromPromise';
this.on = false;
this.p = p;
}

@@ -226,4 +224,4 @@ FromPromiseProducer.prototype._start = function (out) {

function PeriodicProducer(period) {
this.type = 'periodic';
this.period = period;
this.type = 'periodic';
this.intervalID = -1;

@@ -248,7 +246,7 @@ this.i = 0;

function DebugOperator(arg, ins) {
this.type = 'debug';
this.ins = ins;
this.type = 'debug';
this.out = null;
this.s = null; // spy
this.l = null; // label
this.out = NO;
this.s = noop;
this.l = '';
if (typeof arg === 'string') {

@@ -267,10 +265,10 @@ this.l = arg;

this.ins._remove(this);
this.out = null;
this.out = NO;
};
DebugOperator.prototype._n = function (t) {
var u = this.out;
if (!u)
if (u === NO)
return;
var s = this.s, l = this.l;
if (s) {
if (s !== noop) {
try {

@@ -293,3 +291,3 @@ s(t);

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -300,3 +298,3 @@ u._e(err);

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -310,6 +308,6 @@ u._c();

function DropOperator(max, ins) {
this.type = 'drop';
this.ins = ins;
this.out = NO;
this.max = max;
this.ins = ins;
this.type = 'drop';
this.out = null;
this.dropped = 0;

@@ -319,2 +317,3 @@ }

this.out = out;
this.dropped = 0;
this.ins._add(this);

@@ -324,8 +323,7 @@ };

this.ins._remove(this);
this.out = null;
this.dropped = 0;
this.out = NO;
};
DropOperator.prototype._n = function (t) {
var u = this.out;
if (!u)
if (u === NO)
return;

@@ -337,3 +335,3 @@ if (this.dropped++ >= this.max)

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -344,3 +342,3 @@ u._e(err);

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -369,9 +367,8 @@ u._c();

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.type = 'endWhen';
this.out = null;
this.oil = exports.emptyIL; // oil = other InternalListener
this.oil = exports.NO_IL;
}

@@ -386,8 +383,8 @@ EndWhenOperator.prototype._start = function (out) {

this.o._remove(this.oil);
this.out = null;
this.oil = null;
this.out = NO;
this.oil = exports.NO_IL;
};
EndWhenOperator.prototype.end = function () {
var u = this.out;
if (!u)
if (u === NO)
return;

@@ -398,3 +395,3 @@ u._c();

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -405,3 +402,3 @@ u._n(t);

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -418,6 +415,6 @@ u._e(err);

function FilterOperator(passes, ins) {
this.type = 'filter';
this.ins = ins;
this.out = NO;
this.passes = passes;
this.ins = ins;
this.type = 'filter';
this.out = null;
}

@@ -430,7 +427,7 @@ 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)
if (u === NO)
return;

@@ -447,3 +444,3 @@ try {

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -454,3 +451,3 @@ u._e(err);

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -474,3 +471,3 @@ u._c();

FlattenListener.prototype._c = function () {
this.op.inner = null;
this.op.inner = NO;
this.op.less();

@@ -482,11 +479,14 @@ };

function FlattenOperator(ins) {
this.type = 'flatten';
this.ins = ins;
this.type = 'flatten';
this.inner = null; // Current inner Stream
this.il = 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);

@@ -496,14 +496,14 @@ };

this.ins._remove(this);
if (this.inner)
if (this.inner !== NO)
this.inner._remove(this.il);
this.inner = null;
this.il = null;
this.out = NO;
this.open = true;
this.out = null;
this.inner = NO;
this.il = exports.NO_IL;
};
FlattenOperator.prototype.less = function () {
var u = this.out;
if (!u)
if (u === NO)
return;
if (!this.open && !this.inner)
if (!this.open && this.inner === NO)
u._c();

@@ -513,6 +513,6 @@ };

var u = this.out;
if (!u)
if (u === NO)
return;
var _a = this, inner = _a.inner, il = _a.il;
if (inner && il)
if (inner !== NO && il !== exports.NO_IL)
inner._remove(il);

@@ -523,3 +523,3 @@ (this.inner = s)._add(this.il = new FlattenListener(u, this));

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -537,11 +537,11 @@ u._e(err);

function FoldOperator(f, seed, ins) {
this.type = 'fold';
this.ins = ins;
this.out = NO;
this.f = f;
this.seed = seed;
this.ins = ins;
this.type = 'fold';
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);

@@ -552,3 +552,3 @@ this.ins._add(this);

this.ins._remove(this);
this.out = null;
this.out = NO;
this.acc = this.seed;

@@ -558,3 +558,3 @@ };

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -570,3 +570,3 @@ try {

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -577,3 +577,3 @@ u._e(err);

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -587,10 +587,11 @@ u._c();

function LastOperator(ins) {
this.type = 'last';
this.ins = ins;
this.type = 'last';
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);

@@ -600,5 +601,4 @@ };

this.ins._remove(this);
this.out = null;
this.has = false;
this.val = empty;
this.out = NO;
this.val = NO;
};

@@ -611,3 +611,3 @@ LastOperator.prototype._n = function (t) {

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -618,3 +618,3 @@ u._e(err);

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -644,3 +644,3 @@ if (this.has) {

MapFlattenInner.prototype._c = function () {
this.op.inner = null;
this.op.inner = NO;
this.op.less();

@@ -652,12 +652,15 @@ };

function MapFlattenOperator(mapOp) {
this.type = mapOp.type + "+flatten";
this.ins = mapOp.ins;
this.out = NO;
this.mapOp = mapOp;
this.inner = null; // Current inner Stream
this.il = null; // Current inner InternalListener
this.inner = NO;
this.il = exports.NO_IL;
this.open = true;
this.out = null;
this.type = mapOp.type + "+flatten";
this.ins = mapOp.ins;
}
MapFlattenOperator.prototype._start = function (out) {
this.out = out;
this.inner = NO;
this.il = exports.NO_IL;
this.open = true;
this.mapOp.ins._add(this);

@@ -667,13 +670,12 @@ };

this.mapOp.ins._remove(this);
if (this.inner)
if (this.inner !== NO)
this.inner._remove(this.il);
this.inner = null;
this.il = null;
this.open = true;
this.out = null;
this.out = NO;
this.inner = NO;
this.il = exports.NO_IL;
};
MapFlattenOperator.prototype.less = function () {
if (!this.open && !this.inner) {
if (!this.open && this.inner === NO) {
var u = this.out;
if (!u)
if (u === NO)
return;

@@ -685,6 +687,6 @@ u._c();

var u = this.out;
if (!u)
if (u === NO)
return;
var _a = this, inner = _a.inner, il = _a.il;
if (inner && il)
if (inner !== NO && il !== exports.NO_IL)
inner._remove(il);

@@ -700,3 +702,3 @@ try {

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -714,6 +716,6 @@ u._e(err);

function MapOperator(project, ins) {
this.type = 'map';
this.ins = ins;
this.out = NO;
this.project = project;
this.ins = ins;
this.type = 'map';
this.out = null;
}

@@ -726,7 +728,7 @@ 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)
if (u === NO)
return;

@@ -742,3 +744,3 @@ try {

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -749,3 +751,3 @@ u._e(err);

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -761,4 +763,4 @@ u._c();

_super.call(this, project, ins);
this.type = 'filter+map';
this.passes = passes;
this.type = 'filter+map';
}

@@ -776,5 +778,5 @@ FilterMapOperator.prototype._n = function (v) {

function RememberOperator(ins) {
this.type = 'remember';
this.ins = ins;
this.type = 'remember';
this.out = exports.emptyIL;
this.out = NO;
}

@@ -787,3 +789,3 @@ RememberOperator.prototype._start = function (out) {

this.ins._remove(this.out);
this.out = null;
this.out = NO;
};

@@ -795,6 +797,6 @@ return RememberOperator;

function ReplaceErrorOperator(fn, ins) {
this.type = 'replaceError';
this.ins = ins;
this.out = NO;
this.fn = fn;
this.ins = ins;
this.type = 'replaceError';
this.out = empty;
}

@@ -807,7 +809,7 @@ ReplaceErrorOperator.prototype._start = function (out) {

this.ins._remove(this);
this.out = null;
this.out = NO;
};
ReplaceErrorOperator.prototype._n = function (t) {
var u = this.out;
if (!u)
if (u === NO)
return;

@@ -818,3 +820,3 @@ u._n(t);

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -831,3 +833,3 @@ try {

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -840,11 +842,11 @@ u._c();

var StartWithOperator = (function () {
function StartWithOperator(ins, value) {
function StartWithOperator(ins, val) {
this.type = 'startWith';
this.ins = ins;
this.value = value;
this.type = 'startWith';
this.out = exports.emptyIL;
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);

@@ -854,3 +856,3 @@ };

this.ins._remove(this.out);
this.out = null;
this.out = NO;
};

@@ -862,6 +864,6 @@ return StartWithOperator;

function TakeOperator(max, ins) {
this.type = 'take';
this.ins = ins;
this.out = NO;
this.max = max;
this.ins = ins;
this.type = 'take';
this.out = null;
this.taken = 0;

@@ -871,2 +873,3 @@ }

this.out = out;
this.taken = 0;
this.ins._add(this);

@@ -876,8 +879,7 @@ };

this.ins._remove(this);
this.out = null;
this.taken = 0;
this.out = NO;
};
TakeOperator.prototype._n = function (t) {
var u = this.out;
if (!u)
if (u === NO)
return;

@@ -894,3 +896,3 @@ if (this.taken++ < this.max - 1) {

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -901,3 +903,3 @@ u._e(err);

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -911,7 +913,7 @@ u._c();

function Stream(producer) {
this._stopID = empty;
this._prod = producer;
this._prod = producer || NO;
this._ils = [];
this._target = null;
this._err = null;
this._stopID = NO;
this._target = NO;
this._err = NO;
}

@@ -930,3 +932,3 @@ Stream.prototype._n = function (t) {

Stream.prototype._e = function (err) {
if (this._err)
if (this._err !== NO)
return;

@@ -960,5 +962,5 @@ this._err = err;

return;
if (this._prod)
if (this._prod !== NO)
this._prod._stop();
this._err = null;
this._err = NO;
this._ils = [];

@@ -970,7 +972,8 @@ };

this._prod._stop();
this._err = null;
this._err = NO;
this._stopID = NO;
};
Stream.prototype._add = function (il) {
var ta = this._target;
if (ta)
if (ta !== NO)
return ta._add(il);

@@ -980,8 +983,8 @@ var a = this._ils;

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

@@ -993,3 +996,3 @@ }

var ta = this._target;
if (ta)
if (ta !== NO)
return ta._remove(il);

@@ -1000,4 +1003,4 @@ var a = this._ils;

a.splice(i, 1);
if (this._prod && a.length <= 0) {
this._err = null;
if (this._prod !== NO && a.length <= 0) {
this._err = NO;
this._stopID = setTimeout(function () { return _this._lateStop(); });

@@ -1030,3 +1033,3 @@ }

}
else if (x.out) {
else if (x.out && x.out !== NO) {
return this._hasNoSinks(x.out, trace.concat(x));

@@ -1033,0 +1036,0 @@ }

@@ -8,3 +8,3 @@ (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){

};
var empty = {};
var NO = {};
function noop() { }

@@ -19,3 +19,3 @@ function copy(a) {

}
exports.emptyIL = {
exports.NO_IL = {
_n: noop,

@@ -48,6 +48,6 @@ _e: noop,

function MergeProducer(insArr) {
this.type = 'merge';
this.insArr = insArr;
this.type = 'merge';
this.out = null;
this.ac = insArr.length;
this.out = NO;
this.ac = 0;
}

@@ -58,2 +58,3 @@ MergeProducer.prototype._start = function (out) {

var L = s.length;
this.ac = L;
for (var i = 0; i < L; i++) {

@@ -69,8 +70,7 @@ s[i]._add(this);

}
this.out = null;
this.ac = L;
this.out = NO;
};
MergeProducer.prototype._n = function (t) {
var u = this.out;
if (!u)
if (u === NO)
return;

@@ -81,3 +81,3 @@ u._n(t);

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -87,5 +87,5 @@ u._e(err);

MergeProducer.prototype._c = function () {
if (--this.ac === 0) {
if (--this.ac <= 0) {
var u = this.out;
if (!u)
if (u === NO)
return;

@@ -132,15 +132,12 @@ u._c();

function CombineProducer(insArr) {
this.type = 'combine';
this.insArr = insArr;
this.type = 'combine';
this.out = null;
this.out = NO;
this.ils = [];
var n = this.Nc = this.Nn = insArr.length;
var vals = this.vals = new Array(n);
for (var i = 0; i < n; i++) {
vals[i] = empty;
}
this.Nc = this.Nn = 0;
this.vals = [];
}
CombineProducer.prototype.up = function (t, i) {
var v = this.vals[i];
var Nn = !this.Nn ? 0 : v === empty ? --this.Nn : this.Nn;
var Nn = !this.Nn ? 0 : v === NO ? --this.Nn : this.Nn;
this.vals[i] = t;

@@ -152,3 +149,4 @@ return Nn === 0;

var s = this.insArr;
var n = s.length;
var n = this.Nc = this.Nn = s.length;
var vals = this.vals = new Array(n);
if (n === 0) {

@@ -160,2 +158,3 @@ out._n([]);

for (var i = 0; i < n; i++) {
vals[i] = NO;
s[i]._add(new CombineListener(i, out, this));

@@ -167,10 +166,9 @@ }

var s = this.insArr;
var n = this.Nc = this.Nn = s.length;
var vals = this.vals = new Array(n);
var n = s.length;
for (var i = 0; i < n; i++) {
s[i]._remove(this.ils[i]);
vals[i] = empty;
}
this.out = null;
this.out = NO;
this.ils = [];
this.vals = [];
};

@@ -182,4 +180,4 @@ return CombineProducer;

function FromArrayProducer(a) {
this.type = 'fromArray';
this.a = a;
this.type = 'fromArray';
}

@@ -200,5 +198,5 @@ FromArrayProducer.prototype._start = function (out) {

function FromPromiseProducer(p) {
this.p = p;
this.type = 'fromPromise';
this.on = false;
this.p = p;
}

@@ -227,4 +225,4 @@ FromPromiseProducer.prototype._start = function (out) {

function PeriodicProducer(period) {
this.type = 'periodic';
this.period = period;
this.type = 'periodic';
this.intervalID = -1;

@@ -249,7 +247,7 @@ this.i = 0;

function DebugOperator(arg, ins) {
this.type = 'debug';
this.ins = ins;
this.type = 'debug';
this.out = null;
this.s = null;
this.l = null;
this.out = NO;
this.s = noop;
this.l = '';
if (typeof arg === 'string') {

@@ -268,10 +266,10 @@ this.l = arg;

this.ins._remove(this);
this.out = null;
this.out = NO;
};
DebugOperator.prototype._n = function (t) {
var u = this.out;
if (!u)
if (u === NO)
return;
var s = this.s, l = this.l;
if (s) {
if (s !== noop) {
try {

@@ -294,3 +292,3 @@ s(t);

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -301,3 +299,3 @@ u._e(err);

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -311,6 +309,6 @@ u._c();

function DropOperator(max, ins) {
this.type = 'drop';
this.ins = ins;
this.out = NO;
this.max = max;
this.ins = ins;
this.type = 'drop';
this.out = null;
this.dropped = 0;

@@ -320,2 +318,3 @@ }

this.out = out;
this.dropped = 0;
this.ins._add(this);

@@ -325,8 +324,7 @@ };

this.ins._remove(this);
this.out = null;
this.dropped = 0;
this.out = NO;
};
DropOperator.prototype._n = function (t) {
var u = this.out;
if (!u)
if (u === NO)
return;

@@ -338,3 +336,3 @@ if (this.dropped++ >= this.max)

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -345,3 +343,3 @@ u._e(err);

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -370,9 +368,8 @@ u._c();

var EndWhenOperator = (function () {
function EndWhenOperator(o,
ins) {
function EndWhenOperator(o, ins) {
this.type = 'endWhen';
this.ins = ins;
this.out = NO;
this.o = o;
this.ins = ins;
this.type = 'endWhen';
this.out = null;
this.oil = exports.emptyIL;
this.oil = exports.NO_IL;
}

@@ -387,8 +384,8 @@ EndWhenOperator.prototype._start = function (out) {

this.o._remove(this.oil);
this.out = null;
this.oil = null;
this.out = NO;
this.oil = exports.NO_IL;
};
EndWhenOperator.prototype.end = function () {
var u = this.out;
if (!u)
if (u === NO)
return;

@@ -399,3 +396,3 @@ u._c();

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -406,3 +403,3 @@ u._n(t);

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -419,6 +416,6 @@ u._e(err);

function FilterOperator(passes, ins) {
this.type = 'filter';
this.ins = ins;
this.out = NO;
this.passes = passes;
this.ins = ins;
this.type = 'filter';
this.out = null;
}

@@ -431,7 +428,7 @@ 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)
if (u === NO)
return;

@@ -448,3 +445,3 @@ try {

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -455,3 +452,3 @@ u._e(err);

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -475,3 +472,3 @@ u._c();

FlattenListener.prototype._c = function () {
this.op.inner = null;
this.op.inner = NO;
this.op.less();

@@ -483,11 +480,14 @@ };

function FlattenOperator(ins) {
this.type = 'flatten';
this.ins = ins;
this.type = 'flatten';
this.inner = null;
this.il = null;
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);

@@ -497,14 +497,14 @@ };

this.ins._remove(this);
if (this.inner)
if (this.inner !== NO)
this.inner._remove(this.il);
this.inner = null;
this.il = null;
this.out = NO;
this.open = true;
this.out = null;
this.inner = NO;
this.il = exports.NO_IL;
};
FlattenOperator.prototype.less = function () {
var u = this.out;
if (!u)
if (u === NO)
return;
if (!this.open && !this.inner)
if (!this.open && this.inner === NO)
u._c();

@@ -514,6 +514,6 @@ };

var u = this.out;
if (!u)
if (u === NO)
return;
var _a = this, inner = _a.inner, il = _a.il;
if (inner && il)
if (inner !== NO && il !== exports.NO_IL)
inner._remove(il);

@@ -524,3 +524,3 @@ (this.inner = s)._add(this.il = new FlattenListener(u, this));

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -538,11 +538,11 @@ u._e(err);

function FoldOperator(f, seed, ins) {
this.type = 'fold';
this.ins = ins;
this.out = NO;
this.f = f;
this.seed = seed;
this.ins = ins;
this.type = 'fold';
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);

@@ -553,3 +553,3 @@ this.ins._add(this);

this.ins._remove(this);
this.out = null;
this.out = NO;
this.acc = this.seed;

@@ -559,3 +559,3 @@ };

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -571,3 +571,3 @@ try {

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -578,3 +578,3 @@ u._e(err);

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -588,10 +588,11 @@ u._c();

function LastOperator(ins) {
this.type = 'last';
this.ins = ins;
this.type = 'last';
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);

@@ -601,5 +602,4 @@ };

this.ins._remove(this);
this.out = null;
this.has = false;
this.val = empty;
this.out = NO;
this.val = NO;
};

@@ -612,3 +612,3 @@ LastOperator.prototype._n = function (t) {

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -619,3 +619,3 @@ u._e(err);

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -645,3 +645,3 @@ if (this.has) {

MapFlattenInner.prototype._c = function () {
this.op.inner = null;
this.op.inner = NO;
this.op.less();

@@ -653,12 +653,15 @@ };

function MapFlattenOperator(mapOp) {
this.type = mapOp.type + "+flatten";
this.ins = mapOp.ins;
this.out = NO;
this.mapOp = mapOp;
this.inner = null;
this.il = null;
this.inner = NO;
this.il = exports.NO_IL;
this.open = true;
this.out = null;
this.type = mapOp.type + "+flatten";
this.ins = mapOp.ins;
}
MapFlattenOperator.prototype._start = function (out) {
this.out = out;
this.inner = NO;
this.il = exports.NO_IL;
this.open = true;
this.mapOp.ins._add(this);

@@ -668,13 +671,12 @@ };

this.mapOp.ins._remove(this);
if (this.inner)
if (this.inner !== NO)
this.inner._remove(this.il);
this.inner = null;
this.il = null;
this.open = true;
this.out = null;
this.out = NO;
this.inner = NO;
this.il = exports.NO_IL;
};
MapFlattenOperator.prototype.less = function () {
if (!this.open && !this.inner) {
if (!this.open && this.inner === NO) {
var u = this.out;
if (!u)
if (u === NO)
return;

@@ -686,6 +688,6 @@ u._c();

var u = this.out;
if (!u)
if (u === NO)
return;
var _a = this, inner = _a.inner, il = _a.il;
if (inner && il)
if (inner !== NO && il !== exports.NO_IL)
inner._remove(il);

@@ -701,3 +703,3 @@ try {

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -715,6 +717,6 @@ u._e(err);

function MapOperator(project, ins) {
this.type = 'map';
this.ins = ins;
this.out = NO;
this.project = project;
this.ins = ins;
this.type = 'map';
this.out = null;
}

@@ -727,7 +729,7 @@ 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)
if (u === NO)
return;

@@ -743,3 +745,3 @@ try {

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -750,3 +752,3 @@ u._e(err);

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -762,4 +764,4 @@ u._c();

_super.call(this, project, ins);
this.type = 'filter+map';
this.passes = passes;
this.type = 'filter+map';
}

@@ -777,5 +779,5 @@ FilterMapOperator.prototype._n = function (v) {

function RememberOperator(ins) {
this.type = 'remember';
this.ins = ins;
this.type = 'remember';
this.out = exports.emptyIL;
this.out = NO;
}

@@ -788,3 +790,3 @@ RememberOperator.prototype._start = function (out) {

this.ins._remove(this.out);
this.out = null;
this.out = NO;
};

@@ -796,6 +798,6 @@ return RememberOperator;

function ReplaceErrorOperator(fn, ins) {
this.type = 'replaceError';
this.ins = ins;
this.out = NO;
this.fn = fn;
this.ins = ins;
this.type = 'replaceError';
this.out = empty;
}

@@ -808,7 +810,7 @@ ReplaceErrorOperator.prototype._start = function (out) {

this.ins._remove(this);
this.out = null;
this.out = NO;
};
ReplaceErrorOperator.prototype._n = function (t) {
var u = this.out;
if (!u)
if (u === NO)
return;

@@ -819,3 +821,3 @@ u._n(t);

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -832,3 +834,3 @@ try {

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -841,11 +843,11 @@ u._c();

var StartWithOperator = (function () {
function StartWithOperator(ins, value) {
function StartWithOperator(ins, val) {
this.type = 'startWith';
this.ins = ins;
this.value = value;
this.type = 'startWith';
this.out = exports.emptyIL;
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);

@@ -855,3 +857,3 @@ };

this.ins._remove(this.out);
this.out = null;
this.out = NO;
};

@@ -863,6 +865,6 @@ return StartWithOperator;

function TakeOperator(max, ins) {
this.type = 'take';
this.ins = ins;
this.out = NO;
this.max = max;
this.ins = ins;
this.type = 'take';
this.out = null;
this.taken = 0;

@@ -872,2 +874,3 @@ }

this.out = out;
this.taken = 0;
this.ins._add(this);

@@ -877,8 +880,7 @@ };

this.ins._remove(this);
this.out = null;
this.taken = 0;
this.out = NO;
};
TakeOperator.prototype._n = function (t) {
var u = this.out;
if (!u)
if (u === NO)
return;

@@ -895,3 +897,3 @@ if (this.taken++ < this.max - 1) {

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -902,3 +904,3 @@ u._e(err);

var u = this.out;
if (!u)
if (u === NO)
return;

@@ -912,7 +914,7 @@ u._c();

function Stream(producer) {
this._stopID = empty;
this._prod = producer;
this._prod = producer || NO;
this._ils = [];
this._target = null;
this._err = null;
this._stopID = NO;
this._target = NO;
this._err = NO;
}

@@ -931,3 +933,3 @@ Stream.prototype._n = function (t) {

Stream.prototype._e = function (err) {
if (this._err)
if (this._err !== NO)
return;

@@ -961,5 +963,5 @@ this._err = err;

return;
if (this._prod)
if (this._prod !== NO)
this._prod._stop();
this._err = null;
this._err = NO;
this._ils = [];

@@ -971,7 +973,8 @@ };

this._prod._stop();
this._err = null;
this._err = NO;
this._stopID = NO;
};
Stream.prototype._add = function (il) {
var ta = this._target;
if (ta)
if (ta !== NO)
return ta._add(il);

@@ -981,8 +984,8 @@ var a = this._ils;

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

@@ -994,3 +997,3 @@ }

var ta = this._target;
if (ta)
if (ta !== NO)
return ta._remove(il);

@@ -1001,4 +1004,4 @@ var a = this._ils;

a.splice(i, 1);
if (this._prod && a.length <= 0) {
this._err = null;
if (this._prod !== NO && a.length <= 0) {
this._err = NO;
this._stopID = setTimeout(function () { return _this._lateStop(); });

@@ -1031,3 +1034,3 @@ }

}
else if (x.out) {
else if (x.out && x.out !== NO) {
return this._hasNoSinks(x.out, trace.concat(x));

@@ -1034,0 +1037,0 @@ }

@@ -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 __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(){}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.emptyIL={_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.insArr=insArr;this.type="merge";this.out=null;this.ac=insArr.length}MergeProducer.prototype._start=function(out){this.out=out;var s=this.insArr;var L=s.length;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=null;this.ac=L};MergeProducer.prototype._n=function(t){var u=this.out;if(!u)return;u._n(t)};MergeProducer.prototype._e=function(err){var u=this.out;if(!u)return;u._e(err)};MergeProducer.prototype._c=function(){if(--this.ac===0){var u=this.out;if(!u)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.insArr=insArr;this.type="combine";this.out=null;this.ils=[];var n=this.Nc=this.Nn=insArr.length;var vals=this.vals=new Array(n);for(var i=0;i<n;i++){vals[i]=empty}}CombineProducer.prototype.up=function(t,i){var v=this.vals[i];var Nn=!this.Nn?0:v===empty?--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=s.length;if(n===0){out._n([]);out._c()}else{for(var i=0;i<n;i++){s[i]._add(new CombineListener(i,out,this))}}};CombineProducer.prototype._stop=function(){var s=this.insArr;var n=this.Nc=this.Nn=s.length;var vals=this.vals=new Array(n);for(var i=0;i<n;i++){s[i]._remove(this.ils[i]);vals[i]=empty}this.out=null;this.ils=[]};return CombineProducer}();exports.CombineProducer=CombineProducer;var FromArrayProducer=function(){function FromArrayProducer(a){this.a=a;this.type="fromArray"}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.p=p;this.type="fromPromise";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}();exports.FromPromiseProducer=FromPromiseProducer;var PeriodicProducer=function(){function PeriodicProducer(period){this.period=period;this.type="periodic";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.ins=ins;this.type="debug";this.out=null;this.s=null;this.l=null;if(typeof arg==="string"){this.l=arg}else{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=null};DebugOperator.prototype._n=function(t){var u=this.out;if(!u)return;var s=this.s,l=this.l;if(s){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)return;u._e(err)};DebugOperator.prototype._c=function(){var u=this.out;if(!u)return;u._c()};return DebugOperator}();exports.DebugOperator=DebugOperator;var DropOperator=function(){function DropOperator(max,ins){this.max=max;this.ins=ins;this.type="drop";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){var u=this.out;if(!u)return;if(this.dropped++>=this.max)u._n(t)};DropOperator.prototype._e=function(err){var u=this.out;if(!u)return;u._e(err)};DropOperator.prototype._c=function(){var u=this.out;if(!u)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.o=o;this.ins=ins;this.type="endWhen";this.out=null;this.oil=exports.emptyIL}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=null;this.oil=null};EndWhenOperator.prototype.end=function(){var u=this.out;if(!u)return;u._c()};EndWhenOperator.prototype._n=function(t){var u=this.out;if(!u)return;u._n(t)};EndWhenOperator.prototype._e=function(err){var u=this.out;if(!u)return;u._e(err)};EndWhenOperator.prototype._c=function(){this.end()};return EndWhenOperator}();exports.EndWhenOperator=EndWhenOperator;var FilterOperator=function(){function FilterOperator(passes,ins){this.passes=passes;this.ins=ins;this.type="filter";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){var u=this.out;if(!u)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)return;u._e(err)};FilterOperator.prototype._c=function(){var u=this.out;if(!u)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=null;this.op.less()};return FlattenListener}();var FlattenOperator=function(){function FlattenOperator(ins){this.ins=ins;this.type="flatten";this.inner=null;this.il=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);if(this.inner)this.inner._remove(this.il);this.inner=null;this.il=null;this.open=true;this.out=null};FlattenOperator.prototype.less=function(){var u=this.out;if(!u)return;if(!this.open&&!this.inner)u._c()};FlattenOperator.prototype._n=function(s){var u=this.out;if(!u)return;var _a=this,inner=_a.inner,il=_a.il;if(inner&&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)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.f=f;this.seed=seed;this.ins=ins;this.type="fold";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){var u=this.out;if(!u)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)return;u._e(err)};FoldOperator.prototype._c=function(){var u=this.out;if(!u)return;u._c()};return FoldOperator}();exports.FoldOperator=FoldOperator;var LastOperator=function(){function LastOperator(ins){this.ins=ins;this.type="last";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){var u=this.out;if(!u)return;u._e(err)};LastOperator.prototype._c=function(){var u=this.out;if(!u)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=null;this.op.less()};return MapFlattenInner}();var MapFlattenOperator=function(){function MapFlattenOperator(mapOp){this.mapOp=mapOp;this.inner=null;this.il=null;this.open=true;this.out=null;this.type=mapOp.type+"+flatten";this.ins=mapOp.ins}MapFlattenOperator.prototype._start=function(out){this.out=out;this.mapOp.ins._add(this)};MapFlattenOperator.prototype._stop=function(){this.mapOp.ins._remove(this);if(this.inner)this.inner._remove(this.il);this.inner=null;this.il=null;this.open=true;this.out=null};MapFlattenOperator.prototype.less=function(){if(!this.open&&!this.inner){var u=this.out;if(!u)return;u._c()}};MapFlattenOperator.prototype._n=function(v){var u=this.out;if(!u)return;var _a=this,inner=_a.inner,il=_a.il;if(inner&&il)inner._remove(il);try{(this.inner=this.mapOp.project(v))._add(this.il=new MapFlattenInner(u,this))}catch(e){u._e(e)}};MapFlattenOperator.prototype._e=function(err){var u=this.out;if(!u)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.project=project;this.ins=ins;this.type="map";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){var u=this.out;if(!u)return;try{u._n(this.project(t))}catch(e){u._e(e)}};MapOperator.prototype._e=function(err){var u=this.out;if(!u)return;u._e(err)};MapOperator.prototype._c=function(){var u=this.out;if(!u)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.passes=passes;this.type="filter+map"}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.ins=ins;this.type="remember";this.out=exports.emptyIL}RememberOperator.prototype._start=function(out){this.out=out;this.ins._add(out)};RememberOperator.prototype._stop=function(){this.ins._remove(this.out);this.out=null};return RememberOperator}();exports.RememberOperator=RememberOperator;var ReplaceErrorOperator=function(){function ReplaceErrorOperator(fn,ins){this.fn=fn;this.ins=ins;this.type="replaceError";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){var u=this.out;if(!u)return;u._n(t)};ReplaceErrorOperator.prototype._e=function(err){var u=this.out;if(!u)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)return;u._c()};return ReplaceErrorOperator}();exports.ReplaceErrorOperator=ReplaceErrorOperator;var StartWithOperator=function(){function StartWithOperator(ins,value){this.ins=ins;this.value=value;this.type="startWith";this.out=exports.emptyIL}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}();exports.StartWithOperator=StartWithOperator;var TakeOperator=function(){function TakeOperator(max,ins){this.max=max;this.ins=ins;this.type="take";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 u=this.out;if(!u)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)return;u._e(err)};TakeOperator.prototype._c=function(){var u=this.out;if(!u)return;u._c()};return TakeOperator}();exports.TakeOperator=TakeOperator;var Stream=function(){function Stream(producer){this._stopID=empty;this._prod=producer;this._ils=[];this._target=null;this._err=null}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)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)this._prod._stop();this._err=null;this._ils=[]};Stream.prototype._lateStop=function(){this._prod._stop();this._err=null};Stream.prototype._add=function(il){var ta=this._target;if(ta)return ta._add(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 _this=this;var ta=this._target;if(ta)return ta._remove(il);var a=this._ils;var i=a.indexOf(il);if(i>-1){a.splice(i,1);if(this._prod&&a.length<=0){this._err=null;this._stopID=setTimeout(function(){return _this._lateStop()})}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){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.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;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(passes,p.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.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._lateStop=function(){this._has=false;_super.prototype._lateStop.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.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},{}],2:[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":1}]},{},[2])(2)});
(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 __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{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(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;if(inner!==NO&&il!==exports.NO_IL)inner._remove(il);try{(this.inner=this.mapOp.project(v))._add(this.il=new MapFlattenInner(u,this))}catch(e){u._e(e)}};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._lateStop=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._lateStop()})}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.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;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(passes,p.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.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._lateStop=function(){this._has=false;_super.prototype._lateStop.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.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},{}],2:[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":1}]},{},[2])(2)});

@@ -26,3 +26,3 @@ "use strict";

this.out = null;
this.oil = core_1.emptyIL; // oil = other InternalListener
this.oil = core_1.NO_IL; // oil = other InternalListener
this.on = false;

@@ -29,0 +29,0 @@ }

@@ -28,3 +28,3 @@ "use strict";

this.out = null;
this.sil = core_1.emptyIL; // sil = separator InternalListener
this.sil = core_1.NO_IL; // sil = separator InternalListener
}

@@ -42,3 +42,3 @@ SplitOperator.prototype._start = function (out) {

this.out = null;
this.sil = core_1.emptyIL;
this.sil = core_1.NO_IL;
};

@@ -45,0 +45,0 @@ SplitOperator.prototype.up = function () {

{
"name": "xstream",
"version": "5.2.0",
"version": "5.2.1",
"description": "An extremely intuitive, small, and fast functional reactive stream library for JavaScript",

@@ -5,0 +5,0 @@ "main": "index.js",

import {Promise} from 'es6-promise';
const empty = {};
const NO = {};
function noop() {}

@@ -21,3 +21,3 @@

export const emptyIL: InternalListener<any> = {
export const NO_IL: InternalListener<any> = {
_n: noop,

@@ -86,7 +86,10 @@ _e: noop,

public type = 'merge';
public out: Stream<T> = null;
private ac: number; // ac is activeCount, starts initialized
public insArr: Array<Stream<T>>;
public out: Stream<T>;
private ac: number; // ac is activeCount
constructor(public insArr: Array<Stream<T>>) {
this.ac = insArr.length;
constructor(insArr: Array<Stream<T>>) {
this.insArr = insArr;
this.out = <Stream<T>> NO;
this.ac = 0;
}

@@ -98,2 +101,3 @@

const L = s.length;
this.ac = L;
for (let i = 0; i < L; i++) {

@@ -110,4 +114,3 @@ s[i]._add(this);

}
this.out = null;
this.ac = L;
this.out = <Stream<T>> NO;
}

@@ -117,3 +120,3 @@

const u = this.out;
if (!u) return;
if (u === NO) return;
u._n(t);

@@ -124,3 +127,3 @@ }

const u = this.out;
if (!u) return;
if (u === NO) return;
u._e(err);

@@ -130,5 +133,5 @@ }

_c() {
if (--this.ac === 0) {
if (--this.ac <= 0) {
const u = this.out;
if (!u) return;
if (u === NO) return;
u._c();

@@ -171,5 +174,10 @@ }

export class CombineListener<T> implements InternalListener<T>, OutSender<Array<T>> {
constructor(private i: number,
public out: Stream<Array<T>>,
private p: CombineProducer<T>) {
private i: number;
public out: Stream<Array<T>>;
private p: CombineProducer<T>;
constructor(i: number, out: Stream<Array<T>>, p: CombineProducer<T>) {
this.i = i;
this.out = out;
this.p = p;
p.ils.push(this);

@@ -203,4 +211,5 @@ }

public type = 'combine';
public out: Stream<Array<R>> = null;
public ils: Array<CombineListener<any>> = [];
public insArr: Array<Stream<any>>;
public out: Stream<Array<R>>;
public ils: Array<CombineListener<any>>;
public Nc: number; // *N*umber of streams still to send *c*omplete

@@ -210,8 +219,8 @@ public Nn: number; // *N*umber of streams still to send *n*ext

constructor(public insArr: Array<Stream<any>>) {
const n = this.Nc = this.Nn = insArr.length;
const vals = this.vals = new Array(n);
for (let i = 0; i < n; i++) {
vals[i] = empty;
}
constructor(insArr: Array<Stream<any>>) {
this.insArr = insArr;
this.out = <Stream<Array<R>>> NO;
this.ils = [];
this.Nc = this.Nn = 0;
this.vals = [];
}

@@ -221,3 +230,3 @@

const v = this.vals[i];
const Nn = !this.Nn ? 0 : v === empty ? --this.Nn : this.Nn;
const Nn = !this.Nn ? 0 : v === NO ? --this.Nn : this.Nn;
this.vals[i] = t;

@@ -230,3 +239,4 @@ return Nn === 0;

const s = this.insArr;
const n = s.length;
const n = this.Nc = this.Nn = s.length;
const vals = this.vals = new Array(n);
if (n === 0) {

@@ -237,2 +247,3 @@ out._n([]);

for (let i = 0; i < n; i++) {
vals[i] = NO;
s[i]._add(new CombineListener(i, out, this));

@@ -245,10 +256,9 @@ }

const s = this.insArr;
const n = this.Nc = this.Nn = s.length;
const vals = this.vals = new Array(n);
const n = s.length;
for (let i = 0; i < n; i++) {
s[i]._remove(this.ils[i]);
vals[i] = empty;
}
this.out = null;
this.out = <Stream<Array<R>>> NO;
this.ils = [];
this.vals = [];
}

@@ -259,3 +269,6 @@ }

public type = 'fromArray';
constructor(public a: Array<T>) {
public a: Array<T>;
constructor(a: Array<T>) {
this.a = a;
}

@@ -277,5 +290,8 @@

public type = 'fromPromise';
public on: boolean = false;
public on: boolean;
public p: Promise<T>;
constructor(public p: Promise<T>) {
constructor(p: Promise<T>) {
this.on = false;
this.p = p;
}

@@ -308,6 +324,10 @@

public type = 'periodic';
private intervalID: any = -1;
private i: number = 0;
public period: number;
private intervalID: any;
private i: number;
constructor(public period: number) {
constructor(period: number) {
this.period = period;
this.intervalID = -1;
this.i = 0;
}

@@ -330,8 +350,12 @@

public type = 'debug';
public out: Stream<T> = null;
private s: (t: T) => any = null; // spy
private l: string = null; // label
public ins: Stream<T>;
public out: Stream<T>;
private s: (t: T) => any; // spy
private l: string; // label
constructor(arg: string | ((t: T) => any),
public ins: Stream<T>) {
constructor(arg: string | ((t: T) => any), ins: Stream<T>) {
this.ins = ins;
this.out = <Stream<T>> NO;
this.s = noop;
this.l = '';
if (typeof arg === 'string') {

@@ -351,3 +375,3 @@ this.l = arg;

this.ins._remove(this);
this.out = null;
this.out = <Stream<T>> NO;
}

@@ -357,5 +381,5 @@

const u = this.out;
if (!u) return;
if (u === NO) return;
const s = this.s, l = this.l;
if (s) {
if (s !== noop) {
try {

@@ -376,3 +400,3 @@ s(t);

const u = this.out;
if (!u) return;
if (u === NO) return;
u._e(err);

@@ -383,3 +407,3 @@ }

const u = this.out;
if (!u) return;
if (u === NO) return;
u._c();

@@ -391,7 +415,12 @@ }

public type = 'drop';
public out: Stream<T> = null;
private dropped: number = 0;
public ins: Stream<T>;
public out: Stream<T>;
public max: number;
private dropped: number;
constructor(public max: number,
public ins: Stream<T>) {
constructor(max: number, ins: Stream<T>) {
this.ins = ins;
this.out = <Stream<T>> NO;
this.max = max;
this.dropped = 0;
}

@@ -401,2 +430,3 @@

this.out = out;
this.dropped = 0;
this.ins._add(this);

@@ -407,4 +437,3 @@ }

this.ins._remove(this);
this.out = null;
this.dropped = 0;
this.out = <Stream<T>> NO;
}

@@ -414,3 +443,3 @@

const u = this.out;
if (!u) return;
if (u === NO) return;
if (this.dropped++ >= this.max) u._n(t);

@@ -421,3 +450,3 @@ }

const u = this.out;
if (!u) return;
if (u === NO) return;
u._e(err);

@@ -428,3 +457,3 @@ }

const u = this.out;
if (!u) return;
if (u === NO) return;
u._c();

@@ -435,4 +464,8 @@ }

class OtherIL<T> implements InternalListener<any> {
constructor(private out: Stream<T>,
private op: EndWhenOperator<T>) {
private out: Stream<T>;
private op: EndWhenOperator<T>;
constructor(out: Stream<T>, op: EndWhenOperator<T>) {
this.out = out;
this.op = op;
}

@@ -455,7 +488,12 @@

public type = 'endWhen';
public out: Stream<T> = null;
private oil: InternalListener<any> = emptyIL; // oil = other InternalListener
public ins: Stream<T>;
public out: Stream<T>;
public o: Stream<any>; // o = other
private oil: InternalListener<any>; // oil = other InternalListener
constructor(public o: Stream<any>, // o = other
public ins: Stream<T>) {
constructor(o: Stream<any>, ins: Stream<T>) {
this.ins = ins;
this.out = <Stream<T>> NO;
this.o = o;
this.oil = NO_IL;
}

@@ -472,4 +510,4 @@

this.o._remove(this.oil);
this.out = null;
this.oil = null;
this.out = <Stream<T>> NO;
this.oil = NO_IL;
}

@@ -479,3 +517,3 @@

const u = this.out;
if (!u) return;
if (u === NO) return;
u._c();

@@ -486,3 +524,3 @@ }

const u = this.out;
if (!u) return;
if (u === NO) return;
u._n(t);

@@ -493,3 +531,3 @@ }

const u = this.out;
if (!u) return;
if (u === NO) return;
u._e(err);

@@ -505,6 +543,10 @@ }

public type = 'filter';
public out: Stream<T> = null;
public ins: Stream<T>;
public out: Stream<T>;
public passes: (t: T) => boolean;
constructor(public passes: (t: T) => boolean,
public ins: Stream<T>) {
constructor(passes: (t: T) => boolean, ins: Stream<T>) {
this.ins = ins;
this.out = <Stream<T>> NO;
this.passes = passes;
}

@@ -519,3 +561,3 @@

this.ins._remove(this);
this.out = null;
this.out = <Stream<T>> NO;
}

@@ -525,3 +567,3 @@

const u = this.out;
if (!u) return;
if (u === NO) return;
try {

@@ -536,3 +578,3 @@ if (this.passes(t)) u._n(t);

const u = this.out;
if (!u) return;
if (u === NO) return;
u._e(err);

@@ -543,3 +585,3 @@ }

const u = this.out;
if (!u) return;
if (u === NO) return;
u._c();

@@ -550,4 +592,8 @@ }

class FlattenListener<T> implements InternalListener<T> {
constructor(private out: Stream<T>,
private op: FlattenOperator<T>) {
private out: Stream<T>;
private op: FlattenOperator<T>;
constructor(out: Stream<T>, op: FlattenOperator<T>) {
this.out = out;
this.op = op;
}

@@ -564,3 +610,3 @@

_c() {
this.op.inner = null;
this.op.inner = <Stream<T>> NO;
this.op.less();

@@ -572,8 +618,14 @@ }

public type = 'flatten';
public inner: Stream<T> = null; // Current inner Stream
private il: InternalListener<T> = null; // Current inner InternalListener
private open: boolean = true;
public out: Stream<T> = null;
public ins: Stream<Stream<T>>;
public out: Stream<T>;
private open: boolean;
public inner: Stream<T>; // Current inner Stream
private il: InternalListener<T>; // Current inner InternalListener
constructor(public ins: Stream<Stream<T>>) {
constructor(ins: Stream<Stream<T>>) {
this.ins = ins;
this.out = <Stream<T>> NO;
this.open = true;
this.inner = <Stream<T>> NO;
this.il = NO_IL;
}

@@ -583,2 +635,5 @@

this.out = out;
this.open = true;
this.inner = <Stream<T>> NO;
this.il = NO_IL;
this.ins._add(this);

@@ -589,7 +644,7 @@ }

this.ins._remove(this);
if (this.inner) this.inner._remove(this.il);
this.inner = null;
this.il = null;
if (this.inner !== NO) this.inner._remove(this.il);
this.out = <Stream<T>> NO;
this.open = true;
this.out = null;
this.inner = <Stream<T>> NO;
this.il = NO_IL;
}

@@ -599,4 +654,4 @@

const u = this.out;
if (!u) return;
if (!this.open && !this.inner) u._c();
if (u === NO) return;
if (!this.open && this.inner === NO) u._c();
}

@@ -606,5 +661,5 @@

const u = this.out;
if (!u) return;
if (u === NO) return;
const {inner, il} = this;
if (inner && il) inner._remove(il);
if (inner !== NO && il !== NO_IL) inner._remove(il);
(this.inner = s)._add(this.il = new FlattenListener(u, this));

@@ -615,3 +670,3 @@ }

const u = this.out;
if (!u) return;
if (u === NO) return;
u._e(err);

@@ -628,9 +683,13 @@ }

public type = 'fold';
public out: Stream<R> = null;
public ins: Stream<T>;
public out: Stream<R>;
public f: (acc: R, t: T) => R;
public seed: R;
private acc: R; // initialized as seed
constructor(public f: (acc: R, t: T) => R,
public seed: R,
public ins: Stream<T>) {
this.acc = seed;
constructor(f: (acc: R, t: T) => R, seed: R, ins: Stream<T>) {
this.ins = ins;
this.out = <Stream<R>> NO;
this.f = f;
this.acc = this.seed = seed;
}

@@ -640,2 +699,3 @@

this.out = out;
this.acc = this.seed;
out._n(this.acc);

@@ -647,3 +707,3 @@ this.ins._add(this);

this.ins._remove(this);
this.out = null;
this.out = <Stream<R>> NO;
this.acc = this.seed;

@@ -654,3 +714,3 @@ }

const u = this.out;
if (!u) return;
if (u === NO) return;
try {

@@ -665,3 +725,3 @@ u._n(this.acc = this.f(this.acc, t));

const u = this.out;
if (!u) return;
if (u === NO) return;
u._e(err);

@@ -672,3 +732,3 @@ }

const u = this.out;
if (!u) return;
if (u === NO) return;
u._c();

@@ -680,7 +740,12 @@ }

public type = 'last';
public out: Stream<T> = null;
private has: boolean = false;
private val: T = <T> empty;
public ins: Stream<T>;
public out: Stream<T>;
private has: boolean;
private val: T;
constructor(public ins: Stream<T>) {
constructor(ins: Stream<T>) {
this.ins = ins;
this.out = <Stream<T>> NO;
this.has = false;
this.val = <T> NO;
}

@@ -690,2 +755,3 @@

this.out = out;
this.has = false;
this.ins._add(this);

@@ -696,5 +762,4 @@ }

this.ins._remove(this);
this.out = null;
this.has = false;
this.val = <T> empty;
this.out = <Stream<T>> NO;
this.val = <T> NO;
}

@@ -709,3 +774,3 @@

const u = this.out;
if (!u) return;
if (u === NO) return;
u._e(err);

@@ -716,3 +781,3 @@ }

const u = this.out;
if (!u) return;
if (u === NO) return;
if (this.has) {

@@ -728,4 +793,8 @@ u._n(this.val);

class MapFlattenInner<R> implements InternalListener<R> {
constructor(private out: Stream<R>,
private op: MapFlattenOperator<any, R>) {
private out: Stream<R>;
private op: MapFlattenOperator<any, R>;
constructor(out: Stream<R>, op: MapFlattenOperator<any, R>) {
this.out = out;
this.op = op;
}

@@ -742,3 +811,3 @@

_c() {
this.op.inner = null;
this.op.inner = <Stream<R>> NO;
this.op.less();

@@ -751,10 +820,16 @@ }

public ins: Stream<T>;
public inner: Stream<R> = null; // Current inner Stream
private il: InternalListener<R> = null; // Current inner InternalListener
private open: boolean = true;
public out: Stream<R> = null;
public out: Stream<R>;
public mapOp: MapOperator<T, Stream<R>>;
public inner: Stream<R>; // Current inner Stream
private il: InternalListener<R>; // Current inner InternalListener
private open: boolean;
constructor(public mapOp: MapOperator<T, Stream<R>>) {
constructor(mapOp: MapOperator<T, Stream<R>>) {
this.type = `${mapOp.type}+flatten`;
this.ins = mapOp.ins;
this.out = <Stream<R>> NO;
this.mapOp = mapOp;
this.inner = <Stream<R>> NO;
this.il = NO_IL;
this.open = true;
}

@@ -764,2 +839,5 @@

this.out = out;
this.inner = <Stream<R>> NO;
this.il = NO_IL;
this.open = true;
this.mapOp.ins._add(this);

@@ -770,13 +848,12 @@ }

this.mapOp.ins._remove(this);
if (this.inner) this.inner._remove(this.il);
this.inner = null;
this.il = null;
this.open = true;
this.out = null;
if (this.inner !== NO) this.inner._remove(this.il);
this.out = <Stream<R>> NO;
this.inner = <Stream<R>> NO;
this.il = NO_IL;
}
less(): void {
if (!this.open && !this.inner) {
if (!this.open && this.inner === NO) {
const u = this.out;
if (!u) return;
if (u === NO) return;
u._c();

@@ -788,5 +865,5 @@ }

const u = this.out;
if (!u) return;
if (u === NO) return;
const {inner, il} = this;
if (inner && il) inner._remove(il);
if (inner !== NO && il !== NO_IL) inner._remove(il);
try {

@@ -803,3 +880,3 @@ (this.inner = this.mapOp.project(v))._add(

const u = this.out;
if (!u) return;
if (u === NO) return;
u._e(err);

@@ -816,6 +893,10 @@ }

public type = 'map';
public out: Stream<R> = null;
public ins: Stream<T>;
public out: Stream<R>;
public project: (t: T) => R;
constructor(public project: (t: T) => R,
public ins: Stream<T>) {
constructor(project: (t: T) => R, ins: Stream<T>) {
this.ins = ins;
this.out = <Stream<R>> NO;
this.project = project;
}

@@ -830,3 +911,3 @@

this.ins._remove(this);
this.out = null;
this.out = <Stream<R>> NO;
}

@@ -836,3 +917,3 @@

const u = this.out;
if (!u) return;
if (u === NO) return;
try {

@@ -847,3 +928,3 @@ u._n(this.project(t));

const u = this.out;
if (!u) return;
if (u === NO) return;
u._e(err);

@@ -854,3 +935,3 @@ }

const u = this.out;
if (!u) return;
if (u === NO) return;
u._c();

@@ -862,6 +943,7 @@ }

public type = 'filter+map';
constructor(public passes: (t: T) => boolean,
project: (t: T) => R,
ins: Stream<T>) {
public passes: (t: T) => boolean;
constructor(passes: (t: T) => boolean, project: (t: T) => R, ins: Stream<T>) {
super(project, ins);
this.passes = passes;
}

@@ -878,5 +960,8 @@

public type = 'remember';
public out: InternalListener<T> = emptyIL;
public ins: Stream<T>;
public out: Stream<T>;
constructor(public ins: Stream<T>) {
constructor(ins: Stream<T>) {
this.ins = ins;
this.out = <Stream<T>> NO;
}

@@ -891,3 +976,3 @@

this.ins._remove(this.out);
this.out = null;
this.out = <Stream<T>> NO;
}

@@ -898,6 +983,10 @@ }

public type = 'replaceError';
public out: Stream<T> = <Stream<T>> empty;
public ins: Stream<T>;
public out: Stream<T>;
public fn: (err: any) => Stream<T>;
constructor(public fn: (err: any) => Stream<T>,
public ins: Stream<T>) {
constructor(fn: (err: any) => Stream<T>, ins: Stream<T>) {
this.ins = ins;
this.out = <Stream<T>> NO;
this.fn = fn;
}

@@ -912,3 +1001,3 @@

this.ins._remove(this);
this.out = null;
this.out = <Stream<T>> NO;
}

@@ -918,3 +1007,3 @@

const u = this.out;
if (!u) return;
if (u === NO) return;
u._n(t);

@@ -925,3 +1014,3 @@ }

const u = this.out;
if (!u) return;
if (u === NO) return;
try {

@@ -937,3 +1026,3 @@ this.ins._remove(this);

const u = this.out;
if (!u) return;
if (u === NO) return;
u._c();

@@ -945,11 +1034,15 @@ }

public type = 'startWith';
private out: InternalListener<T> = emptyIL;
public ins: Stream<T>;
public out: Stream<T>;
public val: T;
constructor(public ins: Stream<T>,
public value: T) {
constructor(ins: Stream<T>, val: T) {
this.ins = ins;
this.out = <Stream<T>> NO;
this.val = val;
}
_start(out: InternalListener<T>): void {
_start(out: Stream<T>): void {
this.out = out;
this.out._n(this.value);
this.out._n(this.val);
this.ins._add(out);

@@ -960,3 +1053,3 @@ }

this.ins._remove(this.out);
this.out = null;
this.out = <Stream<T>> NO;
}

@@ -967,7 +1060,12 @@ }

public type = 'take';
public out: Stream<T> = null;
private taken: number = 0;
public ins: Stream<T>;
public out: Stream<T>;
public max: number;
private taken: number;
constructor(public max: number,
public ins: Stream<T>) {
constructor(max: number, ins: Stream<T>) {
this.ins = ins;
this.out = <Stream<T>> NO;
this.max = max;
this.taken = 0;
}

@@ -977,2 +1075,3 @@

this.out = out;
this.taken = 0;
this.ins._add(this);

@@ -983,4 +1082,3 @@ }

this.ins._remove(this);
this.out = null;
this.taken = 0;
this.out = <Stream<T>> NO;
}

@@ -990,3 +1088,3 @@

const u = this.out;
if (!u) return;
if (u === NO) return;
if (this.taken++ < this.max - 1) {

@@ -1002,3 +1100,3 @@ u._n(t);

const u = this.out;
if (!u) return;
if (u === NO) return;
u._e(err);

@@ -1009,3 +1107,3 @@ }

const u = this.out;
if (!u) return;
if (u === NO) return;
u._c();

@@ -1017,3 +1115,3 @@ }

protected _ils: Array<InternalListener<T>>; // 'ils' = Internal listeners
protected _stopID: any = empty;
protected _stopID: any;
protected _prod: InternalProducer<T>;

@@ -1024,6 +1122,7 @@ protected _target: Stream<T>; // imitation target if this Stream will imitate

constructor(producer?: InternalProducer<T>) {
this._prod = producer;
this._prod = producer || <InternalProducer<T>> NO;
this._ils = [];
this._target = null;
this._err = null;
this._stopID = NO;
this._target = <Stream<T>> NO;
this._err = NO;
}

@@ -1041,3 +1140,3 @@

_e(err: any): void {
if (this._err) return;
if (this._err !== NO) return;
this._err = err;

@@ -1065,4 +1164,4 @@ const a = this._ils;

if (this._ils.length === 0) return;
if (this._prod) this._prod._stop();
this._err = null;
if (this._prod !== NO) this._prod._stop();
this._err = NO;
this._ils = [];

@@ -1075,3 +1174,4 @@ }

this._prod._stop();
this._err = null;
this._err = NO;
this._stopID = NO;
}

@@ -1081,12 +1181,12 @@

const ta = this._target;
if (ta) return ta._add(il);
if (ta !== NO) return ta._add(il);
const 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;
}
const p = this._prod;
if (p) p._start(this);
if (p !== NO) p._start(this);
}

@@ -1097,3 +1197,3 @@ }

const ta = this._target;
if (ta) return ta._remove(il);
if (ta !== NO) return ta._remove(il);
const a = this._ils;

@@ -1103,4 +1203,4 @@ const i = a.indexOf(il);

a.splice(i, 1);
if (this._prod && a.length <= 0) {
this._err = null;
if (this._prod !== NO && a.length <= 0) {
this._err = NO;
this._stopID = setTimeout(() => this._lateStop());

@@ -1132,3 +1232,3 @@ } else if (a.length === 1) {

return true;
} else if ((<OutSender<any>><any>x).out) {
} else if ((<OutSender<any>><any>x).out && (<OutSender<any>><any>x).out !== NO) {
return this._hasNoSinks((<OutSender<any>><any>x).out, trace.concat(x));

@@ -1135,0 +1235,0 @@ } else if ((<Stream<any>>x)._ils) {

@@ -1,2 +0,2 @@

import {Operator, InternalListener, Stream, OutSender, emptyIL} from '../core';
import {Operator, InternalListener, Stream, OutSender, NO_IL} from '../core';

@@ -24,3 +24,3 @@ class OtherIL<T> implements InternalListener<any>, OutSender<T> {

public out: Stream<T> = null;
private oil: InternalListener<any> = emptyIL; // oil = other InternalListener
private oil: InternalListener<any> = NO_IL; // oil = other InternalListener
private on: boolean = false;

@@ -27,0 +27,0 @@

@@ -1,2 +0,2 @@

import {Operator, InternalListener, Stream, OutSender, emptyIL} from '../core';
import {Operator, InternalListener, Stream, OutSender, NO_IL} from '../core';

@@ -26,3 +26,3 @@ class SeparatorIL<T> implements InternalListener<any>, OutSender<Stream<T>> {

public out: Stream<Stream<T>> = null;
private sil: InternalListener<any> = emptyIL; // sil = separator InternalListener
private sil: InternalListener<any> = NO_IL; // sil = separator InternalListener

@@ -45,3 +45,3 @@ constructor(public s: Stream<any>, // s = separator

this.out = null;
this.sil = emptyIL;
this.sil = NO_IL;
}

@@ -48,0 +48,0 @@

@@ -42,2 +42,23 @@ /// <reference path="../../typings/globals/mocha/index.d.ts" />

it('should complete properly when stopped asynchronously and restarted synchronously', (done) => {
const initial = xs.of('foo');
// debug here needed to stop MergeProducer asynchronously via _remove
const stream = xs.merge(initial).debug(() => {});
const noop = () => {};
stream.addListener({next: noop, error: noop, complete: noop});
let expected = ['foo'];
stream.addListener({
next: (x) => {
assert.equal(x, expected.shift());
},
error: done,
complete: () => {
assert.equal(expected.length, 0);
done();
}
});
});
it('should return a Stream when merging a MemoryStream with a Stream', (done) => {

@@ -44,0 +65,0 @@ const input1 = xs.periodic(50).take(4).remember();

@@ -58,3 +58,3 @@ /// <reference path="../../typings/globals/mocha/index.d.ts" />

assert.strictEqual(completeCalled, true);
assert.strictEqual(stream['_prod']['out'], null);
assert.strictEqual(JSON.stringify(stream['_prod']['out']), '{}');
done();

@@ -61,0 +61,0 @@ });

/// <reference path="../../typings/globals/mocha/index.d.ts" />
/// <reference path="../../typings/globals/node/index.d.ts" />
import xs, {Stream, Listener} from '../../src/index';
import fromDiagram from '../../src/extra/fromDiagram';
import * as assert from 'assert';

@@ -27,3 +28,3 @@

it('should have an ins field as metadata', (done) => {
const source: Stream<number> = xs.periodic(100).take(3)
const source: Stream<number> = xs.periodic(100).take(3);
const stream: Stream<number> = source

@@ -190,2 +191,30 @@ .map((i: number) => xs.of(1 + i, 2 + i, 3 + i))

});
it('should allow switching inners asynchronously without restarting source', (done) => {
const outer = fromDiagram( '-A---------B----------C------|');
const periodic = fromDiagram('---a-b--c----d--e--f----g--h-|', {
values: { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8 }
});
const stream = outer.map(x => {
if (x === 'A') {
return periodic.map(i => i * 10);
} else if (x === 'B') {
return periodic.map(i => i * 100);
} else if (x === 'C') {
return periodic.map(i => i * 1000);
}
}).flatten();
const expected = [10, 20, 30, 400, 500, 600, 7000, 8000];
stream.addListener({
next: (x: number) => {
assert.equal(x, expected.shift());
},
error: (err: any) => done(err),
complete: () => {
assert.equal(expected.length, 0);
done();
}
});
});
});

@@ -192,0 +221,0 @@

@@ -58,3 +58,3 @@ /// <reference path="../../typings/globals/mocha/index.d.ts" />

assert.strictEqual(completeCalled, true);
assert.strictEqual(stream['_prod']['out'], null);
assert.strictEqual(JSON.stringify(stream['_prod']['out']), '{}');
done();

@@ -99,5 +99,5 @@ });

assert.strictEqual(expected.length, 0);
assert.strictEqual(stream['_prod']['out'], null);
assert.strictEqual(JSON.stringify(stream['_prod']['out']), '{}');
done();
});
});

@@ -18,3 +18,3 @@ /// <reference path="../../typings/globals/mocha/index.d.ts" />

});
it('should return a MemoryStream', (done) => {

@@ -21,0 +21,0 @@ const stream = xs.of(100).startWith(1);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc