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 6.6.0 to 7.0.0

.vscode/launch.json

24

CHANGELOG.md

@@ -0,1 +1,25 @@

<a name="7.0.0"></a>
# [7.0.0](https://github.com/staltz/xstream/compare/v6.6.0...v7.0.0) (2016-10-24)
### Bug Fixes
* **map:** remove map+map fusion optimization ([1ca6a5c](https://github.com/staltz/xstream/commit/1ca6a5c)), closes [#98](https://github.com/staltz/xstream/issues/98) [#108](https://github.com/staltz/xstream/issues/108) [#93](https://github.com/staltz/xstream/issues/93)
* **MemoryStream:** fix a leaking execution bug ([47e67ff](https://github.com/staltz/xstream/commit/47e67ff)), closes [#53](https://github.com/staltz/xstream/issues/53)
### BREAKING CHANGES
* map: This change will remove map+map fusions. Your application code may or
may not rely on the bugs that map+map fusion caused, so we advise to
update carefully, testing your application code as you go. Generally
this is very straightforward and safe to update, as there are no visible
API changes.
* MemoryStream: This is generally safe to update, but note that the behavior around
MemoryStream, startWith, take, imitate etc may have slightly changed, so
it is recommended to run tests on your application and see if it is
working, in case your application code was relying on buggy behavior.
<a name="6.6.0"></a>

@@ -2,0 +26,0 @@ # [6.6.0](https://github.com/staltz/xstream/compare/v6.5.0...v6.6.0) (2016-10-19)

2

core.d.ts

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

constructor(passes: (t: T) => boolean, project: (t: T) => R, ins: Stream<T>);
_n(v: T): void;
_n(t: T): void;
}

@@ -268,0 +268,0 @@ export declare class RememberOperator<T> implements InternalProducer<T> {

@@ -34,7 +34,2 @@ "use strict";

}
function compose2(f1, f2) {
return function composedFn(arg) {
return f1(f2(arg));
};
}
function and(f1, f2) {

@@ -758,7 +753,14 @@ return function andFn(t) {

}
FilterMapOperator.prototype._n = function (v) {
if (this.passes(v)) {
_super.prototype._n.call(this, v);
FilterMapOperator.prototype._n = function (t) {
if (!this.passes(t))
return;
var u = this.out;
if (u === NO)
return;
try {
u._n(this.project(t));
}
;
catch (e) {
u._e(e);
}
};

@@ -1281,8 +1283,2 @@ return FilterMapOperator;

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

@@ -1819,6 +1815,25 @@ };

MemoryStream.prototype._add = function (il) {
if (this._has) {
var ta = this._target;
if (ta !== NO)
return ta._add(il);
var a = this._ils;
a.push(il);
if (a.length > 1) {
if (this._has)
il._n(this._v);
return;
}
if (this._stopID !== NO) {
if (this._has)
il._n(this._v);
clearTimeout(this._stopID);
this._stopID = NO;
}
else if (this._has)
il._n(this._v);
else {
var p = this._prod;
if (p !== NO)
p._start(this);
}
_super.prototype._add.call(this, il);
};

@@ -1825,0 +1840,0 @@ MemoryStream.prototype._stopNow = function () {

@@ -35,7 +35,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){

}
function compose2(f1, f2) {
return function composedFn(arg) {
return f1(f2(arg));
};
}
function and(f1, f2) {

@@ -759,7 +754,14 @@ return function andFn(t) {

}
FilterMapOperator.prototype._n = function (v) {
if (this.passes(v)) {
_super.prototype._n.call(this, v);
FilterMapOperator.prototype._n = function (t) {
if (!this.passes(t))
return;
var u = this.out;
if (u === NO)
return;
try {
u._n(this.project(t));
}
;
catch (e) {
u._e(e);
}
};

@@ -1138,8 +1140,2 @@ return FilterMapOperator;

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

@@ -1283,6 +1279,25 @@ };

MemoryStream.prototype._add = function (il) {
if (this._has) {
var ta = this._target;
if (ta !== NO)
return ta._add(il);
var a = this._ils;
a.push(il);
if (a.length > 1) {
if (this._has)
il._n(this._v);
return;
}
if (this._stopID !== NO) {
if (this._has)
il._n(this._v);
clearTimeout(this._stopID);
this._stopID = NO;
}
else if (this._has)
il._n(this._v);
else {
var p = this._prod;
if (p !== NO)
p._start(this);
}
_super.prototype._add.call(this, il);
};

@@ -1289,0 +1304,0 @@ MemoryStream.prototype._stopNow = function () {

@@ -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 symbol_observable_1=require("symbol-observable");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 Subscription=function(){function Subscription(_stream,_listener){this._stream=_stream;this._listener=_listener}Subscription.prototype.unsubscribe=function(){this._stream.removeListener(this._listener)};return Subscription}();exports.Subscription=Subscription;var ObservableProducer=function(){function ObservableProducer(observable){this.type="fromObservable";this.ins=observable}ObservableProducer.prototype._start=function(out){this.out=out;this._subscription=this.ins.subscribe(new ObservableListener(out))};ObservableProducer.prototype._stop=function(){this._subscription.unsubscribe()};return ObservableProducer}();var ObservableListener=function(){function ObservableListener(_listener){this._listener=_listener}ObservableListener.prototype.next=function(value){this._listener._n(value)};ObservableListener.prototype.error=function(err){this._listener._e(err)};ObservableListener.prototype.complete=function(){this._listener._c()};return ObservableListener}();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===NO)return;if(p.up(t,this.i)){out._n(p.vals)}};CombineListener.prototype._e=function(err){var out=this.out;if(out===NO)return;out._e(err)};CombineListener.prototype._c=function(){var p=this.p;if(p.out===NO)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;var ils=this.ils;for(var i=0;i<n;i++){s[i]._remove(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(noop,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(ins,arg){this.type="debug";this.ins=ins;this.out=NO;this.s=noop;this.l="";if(typeof arg==="string"){this.l=arg}else if(typeof arg==="function"){this.s=arg}}DebugOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};DebugOperator.prototype._stop=function(){this.ins._remove(this);this.out=NO};DebugOperator.prototype._n=function(t){var u=this.out;if(u===NO)return;var s=this.s,l=this.l;if(s!==noop){try{s(t)}catch(e){u._e(e)}}else if(l){console.log(l+":",t)}else{console.log(t)}u._n(t)};DebugOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};DebugOperator.prototype._c=function(){var u=this.out;if(u===NO)return;u._c()};return DebugOperator}();exports.DebugOperator=DebugOperator;var DropOperator=function(){function DropOperator(max,ins){this.type="drop";this.ins=ins;this.out=NO;this.max=max;this.dropped=0}DropOperator.prototype._start=function(out){this.out=out;this.dropped=0;this.ins._add(this)};DropOperator.prototype._stop=function(){this.ins._remove(this);this.out=NO};DropOperator.prototype._n=function(t){var u=this.out;if(u===NO)return;if(this.dropped++>=this.max)u._n(t)};DropOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};DropOperator.prototype._c=function(){var u=this.out;if(u===NO)return;u._c()};return DropOperator}();exports.DropOperator=DropOperator;var OtherIL=function(){function OtherIL(out,op){this.out=out;this.op=op}OtherIL.prototype._n=function(t){this.op.end()};OtherIL.prototype._e=function(err){this.out._e(err)};OtherIL.prototype._c=function(){this.op.end()};return OtherIL}();var EndWhenOperator=function(){function EndWhenOperator(o,ins){this.type="endWhen";this.ins=ins;this.out=NO;this.o=o;this.oil=exports.NO_IL}EndWhenOperator.prototype._start=function(out){this.out=out;this.o._add(this.oil=new OtherIL(out,this));this.ins._add(this)};EndWhenOperator.prototype._stop=function(){this.ins._remove(this);this.o._remove(this.oil);this.out=NO;this.oil=exports.NO_IL};EndWhenOperator.prototype.end=function(){var u=this.out;if(u===NO)return;u._c()};EndWhenOperator.prototype._n=function(t){var u=this.out;if(u===NO)return;u._n(t)};EndWhenOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};EndWhenOperator.prototype._c=function(){this.end()};return EndWhenOperator}();exports.EndWhenOperator=EndWhenOperator;var FilterOperator=function(){function FilterOperator(passes,ins){this.type="filter";this.ins=ins;this.out=NO;this.passes=passes}FilterOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};FilterOperator.prototype._stop=function(){this.ins._remove(this);this.out=NO};FilterOperator.prototype._n=function(t){var u=this.out;if(u===NO)return;try{if(this.passes(t))u._n(t)}catch(e){u._e(e)}};FilterOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};FilterOperator.prototype._c=function(){var u=this.out;if(u===NO)return;u._c()};return FilterOperator}();exports.FilterOperator=FilterOperator;var FlattenListener=function(){function FlattenListener(out,op){this.out=out;this.op=op}FlattenListener.prototype._n=function(t){this.out._n(t)};FlattenListener.prototype._e=function(err){this.out._e(err)};FlattenListener.prototype._c=function(){this.op.inner=NO;this.op.less()};return FlattenListener}();var FlattenOperator=function(){function FlattenOperator(ins){this.type="flatten";this.ins=ins;this.out=NO;this.open=true;this.inner=NO;this.il=exports.NO_IL}FlattenOperator.prototype._start=function(out){this.out=out;this.open=true;this.inner=NO;this.il=exports.NO_IL;this.ins._add(this)};FlattenOperator.prototype._stop=function(){this.ins._remove(this);if(this.inner!==NO)this.inner._remove(this.il);this.out=NO;this.open=true;this.inner=NO;this.il=exports.NO_IL};FlattenOperator.prototype.less=function(){var u=this.out;if(u===NO)return;if(!this.open&&this.inner===NO)u._c()};FlattenOperator.prototype._n=function(s){var u=this.out;if(u===NO)return;var _a=this,inner=_a.inner,il=_a.il;if(inner!==NO&&il!==exports.NO_IL)inner._remove(il);(this.inner=s)._add(this.il=new FlattenListener(u,this))};FlattenOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};FlattenOperator.prototype._c=function(){this.open=false;this.less()};return FlattenOperator}();exports.FlattenOperator=FlattenOperator;var FoldOperator=function(){function FoldOperator(f,seed,ins){this.type="fold";this.ins=ins;this.out=NO;this.f=f;this.acc=this.seed=seed}FoldOperator.prototype._start=function(out){this.out=out;this.acc=this.seed;out._n(this.acc);this.ins._add(this)};FoldOperator.prototype._stop=function(){this.ins._remove(this);this.out=NO;this.acc=this.seed};FoldOperator.prototype._n=function(t){var u=this.out;if(u===NO)return;try{u._n(this.acc=this.f(this.acc,t))}catch(e){u._e(e)}};FoldOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};FoldOperator.prototype._c=function(){var u=this.out;if(u===NO)return;u._c()};return FoldOperator}();exports.FoldOperator=FoldOperator;var LastOperator=function(){function LastOperator(ins){this.type="last";this.ins=ins;this.out=NO;this.has=false;this.val=NO}LastOperator.prototype._start=function(out){this.out=out;this.has=false;this.ins._add(this)};LastOperator.prototype._stop=function(){this.ins._remove(this);this.out=NO;this.val=NO};LastOperator.prototype._n=function(t){this.has=true;this.val=t};LastOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};LastOperator.prototype._c=function(){var u=this.out;if(u===NO)return;if(this.has){u._n(this.val);u._c()}else{u._e("TODO show proper error")}};return LastOperator}();exports.LastOperator=LastOperator;var MapFlattenInner=function(){function MapFlattenInner(out,op){this.out=out;this.op=op}MapFlattenInner.prototype._n=function(r){this.out._n(r)};MapFlattenInner.prototype._e=function(err){this.out._e(err)};MapFlattenInner.prototype._c=function(){this.op.inner=NO;this.op.less()};return MapFlattenInner}();var MapFlattenOperator=function(){function MapFlattenOperator(mapOp){this.type=mapOp.type+"+flatten";this.ins=mapOp.ins;this.out=NO;this.mapOp=mapOp;this.inner=NO;this.il=exports.NO_IL;this.open=true}MapFlattenOperator.prototype._start=function(out){this.out=out;this.inner=NO;this.il=exports.NO_IL;this.open=true;this.mapOp.ins._add(this)};MapFlattenOperator.prototype._stop=function(){this.mapOp.ins._remove(this);if(this.inner!==NO)this.inner._remove(this.il);this.out=NO;this.inner=NO;this.il=exports.NO_IL};MapFlattenOperator.prototype.less=function(){if(!this.open&&this.inner===NO){var u=this.out;if(u===NO)return;u._c()}};MapFlattenOperator.prototype._n=function(v){var u=this.out;if(u===NO)return;var _a=this,inner=_a.inner,il=_a.il;var s;try{s=this.mapOp.project(v)}catch(e){u._e(e);return}if(inner!==NO&&il!==exports.NO_IL)inner._remove(il);(this.inner=s)._add(this.il=new MapFlattenInner(u,this))};MapFlattenOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};MapFlattenOperator.prototype._c=function(){this.open=false;this.less()};return MapFlattenOperator}();exports.MapFlattenOperator=MapFlattenOperator;var MapOperator=function(){function MapOperator(project,ins){this.type="map";this.ins=ins;this.out=NO;this.project=project}MapOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};MapOperator.prototype._stop=function(){this.ins._remove(this);this.out=NO};MapOperator.prototype._n=function(t){var u=this.out;if(u===NO)return;try{u._n(this.project(t))}catch(e){u._e(e)}};MapOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};MapOperator.prototype._c=function(){var u=this.out;if(u===NO)return;u._c()};return MapOperator}();exports.MapOperator=MapOperator;var FilterMapOperator=function(_super){__extends(FilterMapOperator,_super);function FilterMapOperator(passes,project,ins){_super.call(this,project,ins);this.type="filter+map";this.passes=passes}FilterMapOperator.prototype._n=function(v){if(this.passes(v)){_super.prototype._n.call(this,v)}};return FilterMapOperator}(MapOperator);exports.FilterMapOperator=FilterMapOperator;var RememberOperator=function(){function RememberOperator(ins){this.type="remember";this.ins=ins;this.out=NO}RememberOperator.prototype._start=function(out){this.out=out;this.ins._add(out)};RememberOperator.prototype._stop=function(){this.ins._remove(this.out);this.out=NO};return RememberOperator}();exports.RememberOperator=RememberOperator;var ReplaceErrorOperator=function(){function ReplaceErrorOperator(fn,ins){this.type="replaceError";this.ins=ins;this.out=NO;this.fn=fn}ReplaceErrorOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};ReplaceErrorOperator.prototype._stop=function(){this.ins._remove(this);this.out=NO};ReplaceErrorOperator.prototype._n=function(t){var u=this.out;if(u===NO)return;u._n(t)};ReplaceErrorOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;try{this.ins._remove(this);(this.ins=this.fn(err))._add(this)}catch(e){u._e(e)}};ReplaceErrorOperator.prototype._c=function(){var u=this.out;if(u===NO)return;u._c()};return ReplaceErrorOperator}();exports.ReplaceErrorOperator=ReplaceErrorOperator;var StartWithOperator=function(){function StartWithOperator(ins,val){this.type="startWith";this.ins=ins;this.out=NO;this.val=val}StartWithOperator.prototype._start=function(out){this.out=out;this.out._n(this.val);this.ins._add(out)};StartWithOperator.prototype._stop=function(){this.ins._remove(this.out);this.out=NO};return StartWithOperator}();exports.StartWithOperator=StartWithOperator;var TakeOperator=function(){function TakeOperator(max,ins){this.type="take";this.ins=ins;this.out=NO;this.max=max;this.taken=0}TakeOperator.prototype._start=function(out){this.out=out;this.taken=0;if(this.max<=0){out._c()}else{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._dl=NO;this._d=false;this._target=NO;this._err=NO}Stream.prototype._n=function(t){var a=this._ils;var L=a.length;if(this._d)this._dl._n(t);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;this._x();if(this._d)this._dl._e(err);if(L==1)a[0]._e(err);else{var b=copy(a);for(var i=0;i<L;i++)b[i]._e(err)}};Stream.prototype._c=function(){var a=this._ils;var L=a.length;this._x();if(this._d)this._dl._c();if(L==1)a[0]._c();else{var b=copy(a);for(var i=0;i<L;i++)b[i]._c()}};Stream.prototype._x=function(){if(this._ils.length===0)return;if(this._prod!==NO)this._prod._stop();this._err=NO;this._ils=[]};Stream.prototype._stopNow=function(){this._prod._stop();this._err=NO;this._stopID=NO};Stream.prototype._add=function(il){var ta=this._target;if(ta!==NO)return ta._add(il);var a=this._ils;a.push(il);if(a.length>1)return;if(this._stopID!==NO){clearTimeout(this._stopID);this._stopID=NO}else{var p=this._prod;if(p!==NO)p._start(this)}};Stream.prototype._remove=function(il){var _this=this;var ta=this._target;if(ta!==NO)return ta._remove(il);var a=this._ils;var i=a.indexOf(il);if(i>-1){a.splice(i,1);if(this._prod!==NO&&a.length<=0){this._err=NO;this._stopID=setTimeout(function(){return _this._stopNow()})}else if(a.length===1){this._pruneCycles()}}};Stream.prototype._pruneCycles=function(){if(this._hasNoSinks(this,[])){this._remove(this._ils[0])}};Stream.prototype._hasNoSinks=function(x,trace){if(trace.indexOf(x)!==-1){return true}else if(x.out===this){return true}else if(x.out&&x.out!==NO){return this._hasNoSinks(x.out,trace.concat(x))}else if(x._ils){for(var i=0,N=x._ils.length;i<N;i++){if(!this._hasNoSinks(x._ils[i],trace.concat(x))){return false}}return true}else{return false}};Stream.prototype.ctor=function(){return this instanceof MemoryStream?MemoryStream:Stream};Stream.prototype.addListener=function(listener){listener._n=listener.next||noop;listener._e=listener.error||noop;listener._c=listener.complete||noop;this._add(listener)};Stream.prototype.removeListener=function(listener){this._remove(listener)};Stream.prototype.subscribe=function(listener){this.addListener(listener);return new Subscription(this,listener)};Stream.prototype[symbol_observable_1.default]=function(){return this};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.from=function(input){if(typeof input[symbol_observable_1.default]==="function"){return Stream.fromObservable(input)}else if(typeof input.then==="function"){return Stream.fromPromise(input)}else if(Array.isArray(input)){return Stream.fromArray(input)}throw new TypeError("Type of input to from() must be an Array, Promise, or Observable")};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.fromObservable=function(observable){return new Stream(new ObservableProducer(observable))};Stream.periodic=function(period){return new Stream(new PeriodicProducer(period))};Stream.prototype._map=function(project){var p=this._prod;var ctor=this.ctor();if(p instanceof FilterOperator){return new ctor(new FilterMapOperator(p.passes,project,p.ins))}if(p instanceof FilterMapOperator){return new ctor(new FilterMapOperator(p.passes,compose2(project,p.project),p.ins))}if(p instanceof MapOperator){return new ctor(new MapOperator(compose2(project,p.project),p.ins))}return new ctor(new MapOperator(project,this))};Stream.prototype.map=function(project){return this._map(project)};Stream.prototype.mapTo=function(projectedValue){var s=this.map(function(){return projectedValue});var op=s._prod;op.type=op.type.replace("map","mapTo");return s};Stream.prototype.filter=function(passes){var p=this._prod;if(p instanceof FilterOperator){return new Stream(new FilterOperator(and(p.passes,passes),p.ins))}return new Stream(new FilterOperator(passes,this))};Stream.prototype.take=function(amount){return new(this.ctor())(new TakeOperator(amount,this))};Stream.prototype.drop=function(amount){return new Stream(new DropOperator(amount,this))};Stream.prototype.last=function(){return new Stream(new LastOperator(this))};Stream.prototype.startWith=function(initial){return new MemoryStream(new StartWithOperator(this,initial))};Stream.prototype.endWhen=function(other){return new(this.ctor())(new EndWhenOperator(other,this))};Stream.prototype.fold=function(accumulate,seed){return new MemoryStream(new FoldOperator(accumulate,seed,this))};Stream.prototype.replaceError=function(replace){return new(this.ctor())(new ReplaceErrorOperator(replace,this))};Stream.prototype.flatten=function(){var p=this._prod;return new Stream(p instanceof MapOperator&&!(p instanceof FilterMapOperator)?new MapFlattenOperator(p):new FlattenOperator(this))};Stream.prototype.compose=function(operator){return operator(this)};Stream.prototype.remember=function(){return new MemoryStream(new RememberOperator(this))};Stream.prototype.debug=function(labelOrSpy){return new(this.ctor())(new DebugOperator(this,labelOrSpy))};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.prototype.setDebugListener=function(listener){if(!listener){this._d=false;this._dl=NO}else{this._d=true;listener._n=listener.next;listener._e=listener.error;listener._c=listener.complete;this._dl=listener}};Stream.merge=function merge(){var streams=[];for(var _i=0;_i<arguments.length;_i++){streams[_i-0]=arguments[_i]}return new Stream(new MergeProducer(streams))};Stream.combine=function combine(){var streams=[];for(var _i=0;_i<arguments.length;_i++){streams[_i-0]=arguments[_i]}return new Stream(new CombineProducer(streams))};return Stream}();exports.Stream=Stream;var MemoryStream=function(_super){__extends(MemoryStream,_super);function MemoryStream(producer){_super.call(this,producer);this._has=false}MemoryStream.prototype._n=function(x){this._v=x;this._has=true;_super.prototype._n.call(this,x)};MemoryStream.prototype._add=function(il){if(this._has){il._n(this._v)}_super.prototype._add.call(this,il)};MemoryStream.prototype._stopNow=function(){this._has=false;_super.prototype._stopNow.call(this)};MemoryStream.prototype._x=function(){this._has=false;_super.prototype._x.call(this)};MemoryStream.prototype.map=function(project){return this._map(project)};MemoryStream.prototype.mapTo=function(projectedValue){return _super.prototype.mapTo.call(this,projectedValue)};MemoryStream.prototype.take=function(amount){return _super.prototype.take.call(this,amount)};MemoryStream.prototype.endWhen=function(other){return _super.prototype.endWhen.call(this,other)};MemoryStream.prototype.replaceError=function(replace){return _super.prototype.replaceError.call(this,replace)};MemoryStream.prototype.remember=function(){return this};MemoryStream.prototype.debug=function(labelOrSpy){return _super.prototype.debug.call(this,labelOrSpy)};return MemoryStream}(Stream);exports.MemoryStream=MemoryStream;Object.defineProperty(exports,"__esModule",{value:true});exports.default=Stream},{"symbol-observable":3}],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}],3:[function(require,module,exports){module.exports=require("./lib/index")},{"./lib/index":4}],4:[function(require,module,exports){(function(global){"use strict";Object.defineProperty(exports,"__esModule",{value:true});var _ponyfill=require("./ponyfill");var _ponyfill2=_interopRequireDefault(_ponyfill);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}var root;if(typeof self!=="undefined"){root=self}else if(typeof window!=="undefined"){root=window}else if(typeof global!=="undefined"){root=global}else if(typeof module!=="undefined"){root=module}else{root=Function("return this")()}var result=(0,_ponyfill2["default"])(root);exports["default"]=result}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./ponyfill":5}],5:[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports["default"]=symbolObservablePonyfill;function symbolObservablePonyfill(root){var result;var _Symbol=root.Symbol;if(typeof _Symbol==="function"){if(_Symbol.observable){result=_Symbol.observable}else{result=_Symbol("observable");_Symbol.observable=result}}else{result="@@observable"}return result}},{}]},{},[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 symbol_observable_1=require("symbol-observable");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 and(f1,f2){return function andFn(t){return f1(t)&&f2(t)}}var Subscription=function(){function Subscription(_stream,_listener){this._stream=_stream;this._listener=_listener}Subscription.prototype.unsubscribe=function(){this._stream.removeListener(this._listener)};return Subscription}();exports.Subscription=Subscription;var ObservableProducer=function(){function ObservableProducer(observable){this.type="fromObservable";this.ins=observable}ObservableProducer.prototype._start=function(out){this.out=out;this._subscription=this.ins.subscribe(new ObservableListener(out))};ObservableProducer.prototype._stop=function(){this._subscription.unsubscribe()};return ObservableProducer}();var ObservableListener=function(){function ObservableListener(_listener){this._listener=_listener}ObservableListener.prototype.next=function(value){this._listener._n(value)};ObservableListener.prototype.error=function(err){this._listener._e(err)};ObservableListener.prototype.complete=function(){this._listener._c()};return ObservableListener}();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===NO)return;if(p.up(t,this.i)){out._n(p.vals)}};CombineListener.prototype._e=function(err){var out=this.out;if(out===NO)return;out._e(err)};CombineListener.prototype._c=function(){var p=this.p;if(p.out===NO)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;var ils=this.ils;for(var i=0;i<n;i++){s[i]._remove(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(noop,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(ins,arg){this.type="debug";this.ins=ins;this.out=NO;this.s=noop;this.l="";if(typeof arg==="string"){this.l=arg}else if(typeof arg==="function"){this.s=arg}}DebugOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};DebugOperator.prototype._stop=function(){this.ins._remove(this);this.out=NO};DebugOperator.prototype._n=function(t){var u=this.out;if(u===NO)return;var s=this.s,l=this.l;if(s!==noop){try{s(t)}catch(e){u._e(e)}}else if(l){console.log(l+":",t)}else{console.log(t)}u._n(t)};DebugOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};DebugOperator.prototype._c=function(){var u=this.out;if(u===NO)return;u._c()};return DebugOperator}();exports.DebugOperator=DebugOperator;var DropOperator=function(){function DropOperator(max,ins){this.type="drop";this.ins=ins;this.out=NO;this.max=max;this.dropped=0}DropOperator.prototype._start=function(out){this.out=out;this.dropped=0;this.ins._add(this)};DropOperator.prototype._stop=function(){this.ins._remove(this);this.out=NO};DropOperator.prototype._n=function(t){var u=this.out;if(u===NO)return;if(this.dropped++>=this.max)u._n(t)};DropOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};DropOperator.prototype._c=function(){var u=this.out;if(u===NO)return;u._c()};return DropOperator}();exports.DropOperator=DropOperator;var OtherIL=function(){function OtherIL(out,op){this.out=out;this.op=op}OtherIL.prototype._n=function(t){this.op.end()};OtherIL.prototype._e=function(err){this.out._e(err)};OtherIL.prototype._c=function(){this.op.end()};return OtherIL}();var EndWhenOperator=function(){function EndWhenOperator(o,ins){this.type="endWhen";this.ins=ins;this.out=NO;this.o=o;this.oil=exports.NO_IL}EndWhenOperator.prototype._start=function(out){this.out=out;this.o._add(this.oil=new OtherIL(out,this));this.ins._add(this)};EndWhenOperator.prototype._stop=function(){this.ins._remove(this);this.o._remove(this.oil);this.out=NO;this.oil=exports.NO_IL};EndWhenOperator.prototype.end=function(){var u=this.out;if(u===NO)return;u._c()};EndWhenOperator.prototype._n=function(t){var u=this.out;if(u===NO)return;u._n(t)};EndWhenOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};EndWhenOperator.prototype._c=function(){this.end()};return EndWhenOperator}();exports.EndWhenOperator=EndWhenOperator;var FilterOperator=function(){function FilterOperator(passes,ins){this.type="filter";this.ins=ins;this.out=NO;this.passes=passes}FilterOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};FilterOperator.prototype._stop=function(){this.ins._remove(this);this.out=NO};FilterOperator.prototype._n=function(t){var u=this.out;if(u===NO)return;try{if(this.passes(t))u._n(t)}catch(e){u._e(e)}};FilterOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};FilterOperator.prototype._c=function(){var u=this.out;if(u===NO)return;u._c()};return FilterOperator}();exports.FilterOperator=FilterOperator;var FlattenListener=function(){function FlattenListener(out,op){this.out=out;this.op=op}FlattenListener.prototype._n=function(t){this.out._n(t)};FlattenListener.prototype._e=function(err){this.out._e(err)};FlattenListener.prototype._c=function(){this.op.inner=NO;this.op.less()};return FlattenListener}();var FlattenOperator=function(){function FlattenOperator(ins){this.type="flatten";this.ins=ins;this.out=NO;this.open=true;this.inner=NO;this.il=exports.NO_IL}FlattenOperator.prototype._start=function(out){this.out=out;this.open=true;this.inner=NO;this.il=exports.NO_IL;this.ins._add(this)};FlattenOperator.prototype._stop=function(){this.ins._remove(this);if(this.inner!==NO)this.inner._remove(this.il);this.out=NO;this.open=true;this.inner=NO;this.il=exports.NO_IL};FlattenOperator.prototype.less=function(){var u=this.out;if(u===NO)return;if(!this.open&&this.inner===NO)u._c()};FlattenOperator.prototype._n=function(s){var u=this.out;if(u===NO)return;var _a=this,inner=_a.inner,il=_a.il;if(inner!==NO&&il!==exports.NO_IL)inner._remove(il);(this.inner=s)._add(this.il=new FlattenListener(u,this))};FlattenOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};FlattenOperator.prototype._c=function(){this.open=false;this.less()};return FlattenOperator}();exports.FlattenOperator=FlattenOperator;var FoldOperator=function(){function FoldOperator(f,seed,ins){this.type="fold";this.ins=ins;this.out=NO;this.f=f;this.acc=this.seed=seed}FoldOperator.prototype._start=function(out){this.out=out;this.acc=this.seed;out._n(this.acc);this.ins._add(this)};FoldOperator.prototype._stop=function(){this.ins._remove(this);this.out=NO;this.acc=this.seed};FoldOperator.prototype._n=function(t){var u=this.out;if(u===NO)return;try{u._n(this.acc=this.f(this.acc,t))}catch(e){u._e(e)}};FoldOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};FoldOperator.prototype._c=function(){var u=this.out;if(u===NO)return;u._c()};return FoldOperator}();exports.FoldOperator=FoldOperator;var LastOperator=function(){function LastOperator(ins){this.type="last";this.ins=ins;this.out=NO;this.has=false;this.val=NO}LastOperator.prototype._start=function(out){this.out=out;this.has=false;this.ins._add(this)};LastOperator.prototype._stop=function(){this.ins._remove(this);this.out=NO;this.val=NO};LastOperator.prototype._n=function(t){this.has=true;this.val=t};LastOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};LastOperator.prototype._c=function(){var u=this.out;if(u===NO)return;if(this.has){u._n(this.val);u._c()}else{u._e("TODO show proper error")}};return LastOperator}();exports.LastOperator=LastOperator;var MapFlattenInner=function(){function MapFlattenInner(out,op){this.out=out;this.op=op}MapFlattenInner.prototype._n=function(r){this.out._n(r)};MapFlattenInner.prototype._e=function(err){this.out._e(err)};MapFlattenInner.prototype._c=function(){this.op.inner=NO;this.op.less()};return MapFlattenInner}();var MapFlattenOperator=function(){function MapFlattenOperator(mapOp){this.type=mapOp.type+"+flatten";this.ins=mapOp.ins;this.out=NO;this.mapOp=mapOp;this.inner=NO;this.il=exports.NO_IL;this.open=true}MapFlattenOperator.prototype._start=function(out){this.out=out;this.inner=NO;this.il=exports.NO_IL;this.open=true;this.mapOp.ins._add(this)};MapFlattenOperator.prototype._stop=function(){this.mapOp.ins._remove(this);if(this.inner!==NO)this.inner._remove(this.il);this.out=NO;this.inner=NO;this.il=exports.NO_IL};MapFlattenOperator.prototype.less=function(){if(!this.open&&this.inner===NO){var u=this.out;if(u===NO)return;u._c()}};MapFlattenOperator.prototype._n=function(v){var u=this.out;if(u===NO)return;var _a=this,inner=_a.inner,il=_a.il;var s;try{s=this.mapOp.project(v)}catch(e){u._e(e);return}if(inner!==NO&&il!==exports.NO_IL)inner._remove(il);(this.inner=s)._add(this.il=new MapFlattenInner(u,this))};MapFlattenOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};MapFlattenOperator.prototype._c=function(){this.open=false;this.less()};return MapFlattenOperator}();exports.MapFlattenOperator=MapFlattenOperator;var MapOperator=function(){function MapOperator(project,ins){this.type="map";this.ins=ins;this.out=NO;this.project=project}MapOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};MapOperator.prototype._stop=function(){this.ins._remove(this);this.out=NO};MapOperator.prototype._n=function(t){var u=this.out;if(u===NO)return;try{u._n(this.project(t))}catch(e){u._e(e)}};MapOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};MapOperator.prototype._c=function(){var u=this.out;if(u===NO)return;u._c()};return MapOperator}();exports.MapOperator=MapOperator;var FilterMapOperator=function(_super){__extends(FilterMapOperator,_super);function FilterMapOperator(passes,project,ins){_super.call(this,project,ins);this.type="filter+map";this.passes=passes}FilterMapOperator.prototype._n=function(t){if(!this.passes(t))return;var u=this.out;if(u===NO)return;try{u._n(this.project(t))}catch(e){u._e(e)}};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;if(this.max<=0){out._c()}else{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._dl=NO;this._d=false;this._target=NO;this._err=NO}Stream.prototype._n=function(t){var a=this._ils;var L=a.length;if(this._d)this._dl._n(t);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;this._x();if(this._d)this._dl._e(err);if(L==1)a[0]._e(err);else{var b=copy(a);for(var i=0;i<L;i++)b[i]._e(err)}};Stream.prototype._c=function(){var a=this._ils;var L=a.length;this._x();if(this._d)this._dl._c();if(L==1)a[0]._c();else{var b=copy(a);for(var i=0;i<L;i++)b[i]._c()}};Stream.prototype._x=function(){if(this._ils.length===0)return;if(this._prod!==NO)this._prod._stop();this._err=NO;this._ils=[]};Stream.prototype._stopNow=function(){this._prod._stop();this._err=NO;this._stopID=NO};Stream.prototype._add=function(il){var ta=this._target;if(ta!==NO)return ta._add(il);var a=this._ils;a.push(il);if(a.length>1)return;if(this._stopID!==NO){clearTimeout(this._stopID);this._stopID=NO}else{var p=this._prod;if(p!==NO)p._start(this)}};Stream.prototype._remove=function(il){var _this=this;var ta=this._target;if(ta!==NO)return ta._remove(il);var a=this._ils;var i=a.indexOf(il);if(i>-1){a.splice(i,1);if(this._prod!==NO&&a.length<=0){this._err=NO;this._stopID=setTimeout(function(){return _this._stopNow()})}else if(a.length===1){this._pruneCycles()}}};Stream.prototype._pruneCycles=function(){if(this._hasNoSinks(this,[])){this._remove(this._ils[0])}};Stream.prototype._hasNoSinks=function(x,trace){if(trace.indexOf(x)!==-1){return true}else if(x.out===this){return true}else if(x.out&&x.out!==NO){return this._hasNoSinks(x.out,trace.concat(x))}else if(x._ils){for(var i=0,N=x._ils.length;i<N;i++){if(!this._hasNoSinks(x._ils[i],trace.concat(x))){return false}}return true}else{return false}};Stream.prototype.ctor=function(){return this instanceof MemoryStream?MemoryStream:Stream};Stream.prototype.addListener=function(listener){listener._n=listener.next||noop;listener._e=listener.error||noop;listener._c=listener.complete||noop;this._add(listener)};Stream.prototype.removeListener=function(listener){this._remove(listener)};Stream.prototype.subscribe=function(listener){this.addListener(listener);return new Subscription(this,listener)};Stream.prototype[symbol_observable_1.default]=function(){return this};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.from=function(input){if(typeof input[symbol_observable_1.default]==="function"){return Stream.fromObservable(input)}else if(typeof input.then==="function"){return Stream.fromPromise(input)}else if(Array.isArray(input)){return Stream.fromArray(input)}throw new TypeError("Type of input to from() must be an Array, Promise, or Observable")};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.fromObservable=function(observable){return new Stream(new ObservableProducer(observable))};Stream.periodic=function(period){return new Stream(new PeriodicProducer(period))};Stream.prototype._map=function(project){var p=this._prod;var ctor=this.ctor();if(p instanceof FilterOperator){return new ctor(new FilterMapOperator(p.passes,project,p.ins))}return new ctor(new MapOperator(project,this))};Stream.prototype.map=function(project){return this._map(project)};Stream.prototype.mapTo=function(projectedValue){var s=this.map(function(){return projectedValue});var op=s._prod;op.type=op.type.replace("map","mapTo");return s};Stream.prototype.filter=function(passes){var p=this._prod;if(p instanceof FilterOperator){return new Stream(new FilterOperator(and(p.passes,passes),p.ins))}return new Stream(new FilterOperator(passes,this))};Stream.prototype.take=function(amount){return new(this.ctor())(new TakeOperator(amount,this))};Stream.prototype.drop=function(amount){return new Stream(new DropOperator(amount,this))};Stream.prototype.last=function(){return new Stream(new LastOperator(this))};Stream.prototype.startWith=function(initial){return new MemoryStream(new StartWithOperator(this,initial))};Stream.prototype.endWhen=function(other){return new(this.ctor())(new EndWhenOperator(other,this))};Stream.prototype.fold=function(accumulate,seed){return new MemoryStream(new FoldOperator(accumulate,seed,this))};Stream.prototype.replaceError=function(replace){return new(this.ctor())(new ReplaceErrorOperator(replace,this))};Stream.prototype.flatten=function(){var p=this._prod;return new Stream(p instanceof MapOperator&&!(p instanceof FilterMapOperator)?new MapFlattenOperator(p):new FlattenOperator(this))};Stream.prototype.compose=function(operator){return operator(this)};Stream.prototype.remember=function(){return new MemoryStream(new RememberOperator(this))};Stream.prototype.debug=function(labelOrSpy){return new(this.ctor())(new DebugOperator(this,labelOrSpy))};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.prototype.setDebugListener=function(listener){if(!listener){this._d=false;this._dl=NO}else{this._d=true;listener._n=listener.next;listener._e=listener.error;listener._c=listener.complete;this._dl=listener}};Stream.merge=function merge(){var streams=[];for(var _i=0;_i<arguments.length;_i++){streams[_i-0]=arguments[_i]}return new Stream(new MergeProducer(streams))};Stream.combine=function combine(){var streams=[];for(var _i=0;_i<arguments.length;_i++){streams[_i-0]=arguments[_i]}return new Stream(new CombineProducer(streams))};return Stream}();exports.Stream=Stream;var MemoryStream=function(_super){__extends(MemoryStream,_super);function MemoryStream(producer){_super.call(this,producer);this._has=false}MemoryStream.prototype._n=function(x){this._v=x;this._has=true;_super.prototype._n.call(this,x)};MemoryStream.prototype._add=function(il){var ta=this._target;if(ta!==NO)return ta._add(il);var a=this._ils;a.push(il);if(a.length>1){if(this._has)il._n(this._v);return}if(this._stopID!==NO){if(this._has)il._n(this._v);clearTimeout(this._stopID);this._stopID=NO}else if(this._has)il._n(this._v);else{var p=this._prod;if(p!==NO)p._start(this)}};MemoryStream.prototype._stopNow=function(){this._has=false;_super.prototype._stopNow.call(this)};MemoryStream.prototype._x=function(){this._has=false;_super.prototype._x.call(this)};MemoryStream.prototype.map=function(project){return this._map(project)};MemoryStream.prototype.mapTo=function(projectedValue){return _super.prototype.mapTo.call(this,projectedValue)};MemoryStream.prototype.take=function(amount){return _super.prototype.take.call(this,amount)};MemoryStream.prototype.endWhen=function(other){return _super.prototype.endWhen.call(this,other)};MemoryStream.prototype.replaceError=function(replace){return _super.prototype.replaceError.call(this,replace)};MemoryStream.prototype.remember=function(){return this};MemoryStream.prototype.debug=function(labelOrSpy){return _super.prototype.debug.call(this,labelOrSpy)};return MemoryStream}(Stream);exports.MemoryStream=MemoryStream;Object.defineProperty(exports,"__esModule",{value:true});exports.default=Stream},{"symbol-observable":3}],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}],3:[function(require,module,exports){module.exports=require("./lib/index")},{"./lib/index":4}],4:[function(require,module,exports){(function(global){"use strict";Object.defineProperty(exports,"__esModule",{value:true});var _ponyfill=require("./ponyfill");var _ponyfill2=_interopRequireDefault(_ponyfill);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}var root;if(typeof self!=="undefined"){root=self}else if(typeof window!=="undefined"){root=window}else if(typeof global!=="undefined"){root=global}else if(typeof module!=="undefined"){root=module}else{root=Function("return this")()}var result=(0,_ponyfill2["default"])(root);exports["default"]=result}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./ponyfill":5}],5:[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports["default"]=symbolObservablePonyfill;function symbolObservablePonyfill(root){var result;var _Symbol=root.Symbol;if(typeof _Symbol==="function"){if(_Symbol.observable){result=_Symbol.observable}else{result=_Symbol("observable");_Symbol.observable=result}}else{result="@@observable"}return result}},{}]},{},[2])(2)});
{
"name": "xstream",
"version": "6.6.0",
"version": "7.0.0",
"description": "An extremely intuitive, small, and fast functional reactive stream library for JavaScript",

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

@@ -84,8 +84,2 @@ import {Promise} from 'es6-promise';

function compose2<T, U>(f1: (t: T) => any, f2: (t: T) => any): (t: T) => any {
return function composedFn(arg: T): any {
return f1(f2(arg));
};
}
function and<T>(f1: (t: T) => boolean, f2: (t: T) => boolean): (t: T) => boolean {

@@ -1051,6 +1045,11 @@ return function andFn(t: T): boolean {

_n(v: T) {
if (this.passes(v)) {
super._n(v);
};
_n(t: T) {
if (!this.passes(t)) return;
const u = this.out;
if (u === NO) return;
try {
u._n(this.project(t));
} catch (e) {
u._e(e);
}
}

@@ -1646,21 +1645,4 @@ }

if (p instanceof FilterOperator) {
return new ctor<U>(new FilterMapOperator<T, U>(
(p as FilterOperator<T>).passes,
project,
(p as FilterOperator<T>).ins
));
return new ctor<U>(new FilterMapOperator<T, U>(p.passes, project, p.ins));
}
if (p instanceof FilterMapOperator) {
return new ctor<U>(new FilterMapOperator<T, U>(
(p as FilterMapOperator<T, U>).passes,
compose2(project, (p as FilterMapOperator<T, U>).project),
(p as FilterMapOperator<T, U>).ins
));
}
if (p instanceof MapOperator) {
return new ctor<U>(new MapOperator<T, U>(
compose2(project, (p as MapOperator<T, U>).project),
(p as MapOperator<T, U>).ins
));
}
return new ctor<U>(new MapOperator<T, U>(project, this));

@@ -2165,4 +2147,18 @@ }

_add(il: InternalListener<T>): void {
if (this._has) { il._n(this._v); }
super._add(il);
const ta = this._target;
if (ta !== NO) return ta._add(il);
const a = this._ils;
a.push(il);
if (a.length > 1) {
if (this._has) il._n(this._v);
return;
}
if (this._stopID !== NO) {
if (this._has) il._n(this._v);
clearTimeout(this._stopID);
this._stopID = NO;
} else if (this._has) il._n(this._v); else {
const p = this._prod;
if (p !== NO) p._start(this);
}
}

@@ -2169,0 +2165,0 @@

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

});
/**
* When an operator listener is about to be added to a memory stream, the
* operator will synchronously receive the remembered value, and may
* synchronously remove itself from the memory stream. This happens in the
* case of e.g. take(). In those cases, the operator should NOT be added AFTER
* it just "got the remembered value and removed itself", because that would
* create leaky executions of the stream. This was reported as bug #53 in
* GitHub.
*/
it('should not allow an operator listener to be indefinitely attached', (done) => {
let debugCalled = 0;
const debugExpected = [42, 0];
const source$ = xs.periodic(100).startWith(42)
.debug(x => {
debugCalled += 1;
assert.strictEqual(debugExpected.length > 0, true);
assert.strictEqual(x, debugExpected.shift());
});
const expectedA = [42, 0];
const expectedB = [42];
let completeCalled = 0;
source$.take(2).addListener({
next: (x) => {
assert.strictEqual(x, expectedA.shift());
},
error: (err) => {},
complete: () => {
completeCalled += 1;
},
});
source$.take(1).addListener({
next: (x) => {
assert.strictEqual(x, expectedB.shift());
},
error: (err) => {},
complete: () => {
completeCalled += 1;
}
});
setTimeout(() => {
assert.strictEqual(debugExpected.length, 0);
assert.strictEqual(expectedA.length, 0);
assert.strictEqual(expectedB.length, 0);
assert.strictEqual(completeCalled, 2);
assert.strictEqual(debugCalled, 2);
done();
}, 500);
});
it('should emit remembered value also when cancelling a stop', (done) => {
const expectedA = [1];
const expectedB = [1, 2];
let completeCalled = 0;
let doneCalled = 0;
const source$ = xs.createWithMemory({
start(listener: Listener<number>) {
listener.next(1);
setTimeout(() => {
listener.next(2);
listener.complete();
}, 100);
},
stop() {
doneCalled += 1;
},
});
const listenerA = {
next: (x: number) => {
assert.strictEqual(x, expectedA.shift());
source$.removeListener(listenerA);
},
error: (err: any) => {},
complete: () => {
completeCalled += 1;
},
};
source$.addListener(listenerA);
source$.addListener({
next: (x) => {
assert.strictEqual(x, expectedB.shift());
},
error: (err) => {},
complete: () => {
completeCalled += 1;
}
});
setTimeout(() => {
assert.strictEqual(expectedA.length, 0);
assert.strictEqual(expectedB.length, 0);
assert.strictEqual(completeCalled, 1);
assert.strictEqual(doneCalled, 1);
done();
}, 300);
});
});

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

});
it('should not repeat the map project function (e.g. no map+map fusion)', (done) => {
const stream = xs.create();
let firstMapCalled = 0;
const source$ = stream.map(x => {
firstMapCalled += 1;
return {a: 10, b: 20, c: 30};
});
const a$ = source$.map(x => x.a);
const b$ = source$.map(x => x.b);
const c$ = source$.map(x => x.c);
const expectedA = [10];
const expectedB = [20];
const expectedC = [30];
a$.addListener({next: a => assert.strictEqual(a, expectedA.shift())});
b$.addListener({next: b => assert.strictEqual(b, expectedB.shift())});
c$.addListener({next: c => assert.strictEqual(c, expectedC.shift())});
stream.shamefullySendNext(1);
setTimeout(() => {
assert.strictEqual(firstMapCalled, 1);
assert.strictEqual(expectedA.length, 0);
assert.strictEqual(expectedB.length, 0);
assert.strictEqual(expectedC.length, 0);
done();
});
});
it('should not repeat the map project function (e.g. no filter+map+map fusion)', (done) => {
const stream = xs.create();
let firstMapCalled = 0;
const source$ = stream.filter(x => x !== 42).map(x => {
firstMapCalled += 1;
return {a: 10, b: 20, c: 30};
});
const a$ = source$.map(x => x.a);
const b$ = source$.map(x => x.b);
const c$ = source$.map(x => x.c);
const expectedA = [10];
const expectedB = [20];
const expectedC = [30];
a$.addListener({next: a => assert.strictEqual(a, expectedA.shift())});
b$.addListener({next: b => assert.strictEqual(b, expectedB.shift())});
c$.addListener({next: c => assert.strictEqual(c, expectedC.shift())});
stream.shamefullySendNext(1);
setTimeout(() => {
assert.strictEqual(firstMapCalled, 1);
assert.strictEqual(expectedA.length, 0);
assert.strictEqual(expectedB.length, 0);
assert.strictEqual(expectedC.length, 0);
done();
});
});
});

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