Comparing version 2.3.0 to 2.4.0
@@ -0,1 +1,16 @@ | ||
<a name="2.4.0"></a> | ||
# [2.4.0](https://github.com/staltz/xstream/compare/v2.3.0...v2.4.0) (2016-05-12) | ||
### Bug Fixes | ||
* **flatten:** add ins field as metadata to flatten ([cbc1f8b](https://github.com/staltz/xstream/commit/cbc1f8b)) | ||
### Features | ||
* **extra:** implement new extra operator: dropUntil ([e06d502](https://github.com/staltz/xstream/commit/e06d502)) | ||
* **extra:** implement new extra operator: split ([84742e8](https://github.com/staltz/xstream/commit/84742e8)) | ||
<a name="2.3.0"></a> | ||
@@ -2,0 +17,0 @@ # [2.3.0](https://github.com/staltz/xstream/compare/v2.2.1...v2.3.0) (2016-05-09) |
@@ -6,2 +6,3 @@ export interface InternalListener<T> { | ||
} | ||
export declare const emptyListener: InternalListener<any>; | ||
export interface InternalProducer<T> { | ||
@@ -12,2 +13,4 @@ _start: (listener: InternalListener<T>) => void; | ||
export interface Operator<T, R> extends InternalProducer<R>, InternalListener<T> { | ||
type: string; | ||
ins: Stream<T>; | ||
_start: (out: Stream<R>) => void; | ||
@@ -18,3 +21,2 @@ _stop: () => void; | ||
_c: () => void; | ||
type: string; | ||
} | ||
@@ -217,9 +219,10 @@ export interface Producer<T> { | ||
} | ||
export declare class MapFlattenConcOperator<T> implements InternalProducer<T>, InternalListener<T> { | ||
mapOp: MapOperator<T, Stream<T>>; | ||
export declare class MapFlattenConcOperator<T, R> implements Operator<T, R> { | ||
mapOp: MapOperator<T, Stream<R>>; | ||
type: string; | ||
ins: Stream<T>; | ||
private active; | ||
private out; | ||
constructor(mapOp: MapOperator<T, Stream<T>>); | ||
_start(out: Stream<T>): void; | ||
constructor(mapOp: MapOperator<T, Stream<R>>); | ||
_start(out: Stream<R>): void; | ||
_stop(): void; | ||
@@ -231,11 +234,12 @@ less(): void; | ||
} | ||
export declare class MapFlattenOperator<T> implements InternalProducer<T>, InternalListener<T> { | ||
mapOp: MapOperator<T, Stream<T>>; | ||
export declare class MapFlattenOperator<T, R> implements Operator<T, R> { | ||
mapOp: MapOperator<T, Stream<R>>; | ||
type: string; | ||
inner: Stream<T>; | ||
ins: Stream<T>; | ||
inner: Stream<R>; | ||
private il; | ||
private open; | ||
private out; | ||
constructor(mapOp: MapOperator<T, Stream<T>>); | ||
_start(out: Stream<T>): void; | ||
constructor(mapOp: MapOperator<T, Stream<R>>); | ||
_start(out: Stream<R>): void; | ||
_stop(): void; | ||
@@ -315,3 +319,3 @@ less(): void; | ||
private _prod; | ||
constructor(producer: InternalProducer<T>); | ||
constructor(producer?: InternalProducer<T>); | ||
_n(t: T): void; | ||
@@ -318,0 +322,0 @@ _e(err: any): void; |
20
core.js
@@ -17,3 +17,3 @@ "use strict"; | ||
} | ||
var emptyListener = { | ||
exports.emptyListener = { | ||
_n: noop, | ||
@@ -96,3 +96,3 @@ _e: noop, | ||
this.type = 'combine'; | ||
this.out = emptyListener; | ||
this.out = exports.emptyListener; | ||
this.ils = []; | ||
@@ -193,3 +193,3 @@ var n = this.ac = this.left = streams.length; | ||
this.type = 'merge'; | ||
this.out = emptyListener; | ||
this.out = exports.emptyListener; | ||
this.ac = streams.length; | ||
@@ -341,3 +341,3 @@ } | ||
this.out = null; | ||
this.oil = emptyListener; // oil = other InternalListener | ||
this.oil = exports.emptyListener; // oil = other InternalListener | ||
} | ||
@@ -589,4 +589,4 @@ EndWhenOperator.prototype._start = function (out) { | ||
} | ||
MFCIL.prototype._n = function (t) { | ||
this.out._n(t); | ||
MFCIL.prototype._n = function (r) { | ||
this.out._n(r); | ||
}; | ||
@@ -607,2 +607,3 @@ MFCIL.prototype._e = function (err) { | ||
this.out = null; | ||
this.ins = mapOp.ins; | ||
} | ||
@@ -646,4 +647,4 @@ MapFlattenConcOperator.prototype._start = function (out) { | ||
} | ||
MFIL.prototype._n = function (t) { | ||
this.out._n(t); | ||
MFIL.prototype._n = function (r) { | ||
this.out._n(r); | ||
}; | ||
@@ -667,2 +668,3 @@ MFIL.prototype._e = function (err) { | ||
this.out = null; | ||
this.ins = mapOp.ins; | ||
} | ||
@@ -819,3 +821,3 @@ MapFlattenOperator.prototype._start = function (out) { | ||
this.type = 'startWith'; | ||
this.out = emptyListener; | ||
this.out = exports.emptyListener; | ||
} | ||
@@ -822,0 +824,0 @@ StartWithOperator.prototype._start = function (out) { |
@@ -18,3 +18,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 emptyListener = { | ||
exports.emptyListener = { | ||
_n: noop, | ||
@@ -97,3 +97,3 @@ _e: noop, | ||
this.type = 'combine'; | ||
this.out = emptyListener; | ||
this.out = exports.emptyListener; | ||
this.ils = []; | ||
@@ -194,3 +194,3 @@ var n = this.ac = this.left = streams.length; | ||
this.type = 'merge'; | ||
this.out = emptyListener; | ||
this.out = exports.emptyListener; | ||
this.ac = streams.length; | ||
@@ -342,3 +342,3 @@ } | ||
this.out = null; | ||
this.oil = emptyListener; | ||
this.oil = exports.emptyListener; | ||
} | ||
@@ -590,4 +590,4 @@ EndWhenOperator.prototype._start = function (out) { | ||
} | ||
MFCIL.prototype._n = function (t) { | ||
this.out._n(t); | ||
MFCIL.prototype._n = function (r) { | ||
this.out._n(r); | ||
}; | ||
@@ -608,2 +608,3 @@ MFCIL.prototype._e = function (err) { | ||
this.out = null; | ||
this.ins = mapOp.ins; | ||
} | ||
@@ -647,4 +648,4 @@ MapFlattenConcOperator.prototype._start = function (out) { | ||
} | ||
MFIL.prototype._n = function (t) { | ||
this.out._n(t); | ||
MFIL.prototype._n = function (r) { | ||
this.out._n(r); | ||
}; | ||
@@ -668,2 +669,3 @@ MFIL.prototype._e = function (err) { | ||
this.out = null; | ||
this.ins = mapOp.ins; | ||
} | ||
@@ -820,3 +822,3 @@ MapFlattenOperator.prototype._start = function (out) { | ||
this.type = 'startWith'; | ||
this.out = emptyListener; | ||
this.out = exports.emptyListener; | ||
} | ||
@@ -823,0 +825,0 @@ StartWithOperator.prototype._start = function (out) { |
@@ -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}var emptyListener={_n:noop,_e:noop,_c:noop};function internalizeProducer(producer){producer._start=function _start(il){il.next=il._n;il.error=il._e;il.complete=il._c;this.start(il)};producer._stop=producer.stop}function invoke(f,args){switch(args.length){case 0:return f();case 1:return f(args[0]);case 2:return f(args[0],args[1]);case 3:return f(args[0],args[1],args[2]);case 4:return f(args[0],args[1],args[2],args[3]);case 5:return f(args[0],args[1],args[2],args[3],args[4]);default:return f.apply(void 0,args)}}function compose2(f1,f2){return function composedFn(arg){return f1(f2(arg))}}function and(f1,f2){return function andFn(t){return f1(t)&&f2(t)}}var CombineListener=function(){function CombineListener(i,p){this.i=i;this.p=p;p.ils.push(this)}CombineListener.prototype._n=function(t){var p=this.p,out=p.out;if(!out)return;if(p.up(t,this.i)){try{out._n(invoke(p.project,p.vals))}catch(e){out._e(e)}}};CombineListener.prototype._e=function(err){var out=this.p.out;if(!out)return;out._e(err)};CombineListener.prototype._c=function(){var p=this.p;if(!p.out)return;if(--p.ac===0){p.out._c()}};return CombineListener}();exports.CombineListener=CombineListener;var CombineProducer=function(){function CombineProducer(project,streams){this.project=project;this.streams=streams;this.type="combine";this.out=emptyListener;this.ils=[];var n=this.ac=this.left=streams.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 left=!this.left?0:v===empty?--this.left:this.left;this.vals[i]=t;return left===0};CombineProducer.prototype._start=function(out){this.out=out;var s=this.streams;var n=s.length;if(n===0)this.zero(out);else{for(var i=0;i<n;i++){s[i]._add(new CombineListener(i,this))}}};CombineProducer.prototype._stop=function(){var s=this.streams;var n=this.ac=this.left=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=[]};CombineProducer.prototype.zero=function(out){try{out._n(this.project());out._c()}catch(e){out._e(e)}};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 MergeProducer=function(){function MergeProducer(streams){this.streams=streams;this.type="merge";this.out=emptyListener;this.ac=streams.length}MergeProducer.prototype._start=function(out){this.out=out;var s=this.streams;var L=s.length;for(var i=0;i<L;i++){s[i]._add(this)}};MergeProducer.prototype._stop=function(){var s=this.streams;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){this.out._n(t)};MergeProducer.prototype._e=function(err){this.out._e(err)};MergeProducer.prototype._c=function(){if(--this.ac===0){this.out._c()}};return MergeProducer}();exports.MergeProducer=MergeProducer;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(spy,ins){if(spy===void 0){spy=null}this.spy=spy;this.ins=ins;this.type="debug";this.out=null}DebugOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};DebugOperator.prototype._stop=function(){this.ins._remove(this);this.out=null};DebugOperator.prototype._n=function(t){if(this.spy){try{this.spy(t)}catch(e){this.out._e(e)}}else{console.log(t)}this.out._n(t)};DebugOperator.prototype._e=function(err){this.out._e(err)};DebugOperator.prototype._c=function(){this.out._c()};return DebugOperator}();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){if(this.dropped++>=this.max)this.out._n(t)};DropOperator.prototype._e=function(err){this.out._e(err)};DropOperator.prototype._c=function(){this.out._c()};return DropOperator}();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=emptyListener}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(){this.out._c()};EndWhenOperator.prototype._n=function(t){this.out._n(t)};EndWhenOperator.prototype._e=function(err){this.out._e(err)};EndWhenOperator.prototype._c=function(){this.end()};return EndWhenOperator}();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){try{if(this.passes(t))this.out._n(t)}catch(e){this.out._e(e)}};FilterOperator.prototype._e=function(err){this.out._e(err)};FilterOperator.prototype._c=function(){this.out._c()};return FilterOperator}();exports.FilterOperator=FilterOperator;var FCIL=function(){function FCIL(out,op){this.out=out;this.op=op}FCIL.prototype._n=function(t){this.out._n(t)};FCIL.prototype._e=function(err){this.out._e(err)};FCIL.prototype._c=function(){this.op.less()};return FCIL}();var FlattenConcOperator=function(){function FlattenConcOperator(ins){this.ins=ins;this.type="flattenConcurrently";this.active=1;this.out=null}FlattenConcOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};FlattenConcOperator.prototype._stop=function(){this.ins._remove(this);this.active=1;this.out=null};FlattenConcOperator.prototype.less=function(){if(--this.active===0){this.out._c()}};FlattenConcOperator.prototype._n=function(s){this.active++;s._add(new FCIL(this.out,this))};FlattenConcOperator.prototype._e=function(err){this.out._e(err)};FlattenConcOperator.prototype._c=function(){this.less()};return FlattenConcOperator}();exports.FlattenConcOperator=FlattenConcOperator;var FIL=function(){function FIL(out,op){this.out=out;this.op=op}FIL.prototype._n=function(t){this.out._n(t)};FIL.prototype._e=function(err){this.out._e(err)};FIL.prototype._c=function(){this.op.inner=null;this.op.less()};return FIL}();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);this.inner=null;this.il=null;this.open=true;this.out=null};FlattenOperator.prototype.less=function(){if(!this.open&&!this.inner)this.out._c()};FlattenOperator.prototype._n=function(s){var _a=this,inner=_a.inner,il=_a.il;if(inner&&il)inner._remove(il);(this.inner=s)._add(this.il=new FIL(this.out,this))};FlattenOperator.prototype._e=function(err){this.out._e(err)};FlattenOperator.prototype._c=function(){this.open=false;this.less()};return FlattenOperator}();exports.FlattenOperator=FlattenOperator;var FoldOperator=function(){function FoldOperator(f,seed,ins){this.f=f;this.seed=seed;this.ins=ins;this.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){try{this.out._n(this.acc=this.f(this.acc,t))}catch(e){this.out._e(e)}};FoldOperator.prototype._e=function(err){this.out._e(err)};FoldOperator.prototype._c=function(){this.out._c()};return FoldOperator}();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){this.out._e(err)};LastOperator.prototype._c=function(){var out=this.out;if(this.has){out._n(this.val);out._c()}else{out._e("TODO show proper error")}};return LastOperator}();exports.LastOperator=LastOperator;var MFCIL=function(){function MFCIL(out,op){this.out=out;this.op=op}MFCIL.prototype._n=function(t){this.out._n(t)};MFCIL.prototype._e=function(err){this.out._e(err)};MFCIL.prototype._c=function(){this.op.less()};return MFCIL}();var MapFlattenConcOperator=function(){function MapFlattenConcOperator(mapOp){this.mapOp=mapOp;this.type="map+flattenConcurrently";this.active=1;this.out=null}MapFlattenConcOperator.prototype._start=function(out){this.out=out;this.mapOp.ins._add(this)};MapFlattenConcOperator.prototype._stop=function(){this.mapOp.ins._remove(this);this.active=1;this.out=null};MapFlattenConcOperator.prototype.less=function(){if(--this.active===0){this.out._c()}};MapFlattenConcOperator.prototype._n=function(v){this.active++;try{this.mapOp.project(v)._add(new MFCIL(this.out,this))}catch(e){this.out._e(e)}};MapFlattenConcOperator.prototype._e=function(err){this.out._e(err)};MapFlattenConcOperator.prototype._c=function(){this.less()};return MapFlattenConcOperator}();exports.MapFlattenConcOperator=MapFlattenConcOperator;var MFIL=function(){function MFIL(out,op){this.out=out;this.op=op}MFIL.prototype._n=function(t){this.out._n(t)};MFIL.prototype._e=function(err){this.out._e(err)};MFIL.prototype._c=function(){this.op.inner=null;this.op.less()};return MFIL}();var MapFlattenOperator=function(){function MapFlattenOperator(mapOp){this.mapOp=mapOp;this.type="map+flatten";this.inner=null;this.il=null;this.open=true;this.out=null}MapFlattenOperator.prototype._start=function(out){this.out=out;this.mapOp.ins._add(this)};MapFlattenOperator.prototype._stop=function(){this.mapOp.ins._remove(this);this.inner=null;this.il=null;this.open=true;this.out=null};MapFlattenOperator.prototype.less=function(){if(!this.open&&!this.inner){this.out._c()}};MapFlattenOperator.prototype._n=function(v){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 MFIL(this.out,this))}catch(e){this.out._e(e)}};MapFlattenOperator.prototype._e=function(err){this.out._e(err)};MapFlattenOperator.prototype._c=function(){this.open=false;this.less()};return MapFlattenOperator}();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){try{this.out._n(this.project(t))}catch(e){this.out._e(e)}};MapOperator.prototype._e=function(err){this.out._e(err)};MapOperator.prototype._c=function(){this.out._c()};return MapOperator}();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 MapToOperator=function(){function MapToOperator(val,ins){this.val=val;this.ins=ins;this.type="mapTo";this.out=null}MapToOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};MapToOperator.prototype._stop=function(){this.ins._remove(this);this.out=null};MapToOperator.prototype._n=function(t){this.out._n(this.val)};MapToOperator.prototype._e=function(err){this.out._e(err)};MapToOperator.prototype._c=function(){this.out._c()};return MapToOperator}();exports.MapToOperator=MapToOperator;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){this.out._n(t)};ReplaceErrorOperator.prototype._e=function(err){try{this.ins._remove(this);(this.ins=this.fn(err))._add(this)}catch(e){this.out._e(e)}};ReplaceErrorOperator.prototype._c=function(){this.out._c()};return ReplaceErrorOperator}();exports.ReplaceErrorOperator=ReplaceErrorOperator;var StartWithOperator=function(){function StartWithOperator(ins,value){this.ins=ins;this.value=value;this.type="startWith";this.out=emptyListener}StartWithOperator.prototype._start=function(out){this.out=out;this.out._n(this.value);this.ins._add(out)};StartWithOperator.prototype._stop=function(){this.ins._remove(this.out);this.out=null};return StartWithOperator}();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 out=this.out;if(!out)return;if(this.taken++<this.max-1){out._n(t)}else{out._n(t);out._c();this._stop()}};TakeOperator.prototype._e=function(err){var out=this.out;if(!out)return;out._e(err)};TakeOperator.prototype._c=function(){var out=this.out;if(!out)return;out._c()};return TakeOperator}();exports.TakeOperator=TakeOperator;var Stream=function(){function Stream(producer){this._stopID=empty;this.combine=function combine(project){var streams=[];for(var _i=1;_i<arguments.length;_i++){streams[_i-1]=arguments[_i]}streams.unshift(this);return Stream.combine.apply(Stream,[project].concat(streams))};this._prod=producer;this._ils=[]}Stream.prototype._n=function(t){var a=this._ils;var 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){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._ils=[]};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.prototype._add=function(il){var a=this._ils;a.push(il);if(a.length===1){if(this._stopID!==empty){clearTimeout(this._stopID);this._stopID=empty}var p=this._prod;if(p)p._start(this)}};Stream.prototype._remove=function(il){var a=this._ils;var i=a.indexOf(il);if(i>-1){a.splice(i,1);var p_1=this._prod;if(p_1&&a.length<=0){this._stopID=setTimeout(function(){return p_1._stop()})}}};Stream.create=function(producer){if(producer){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;if(p instanceof FilterOperator){return new Stream(new FilterMapOperator(p.passes,project,p.ins))}if(p instanceof FilterMapOperator){return new Stream(new FilterMapOperator(p.passes,compose2(project,p.project),p.ins))}if(p instanceof MapOperator){return new Stream(new MapOperator(compose2(project,p.project),p.ins))}return new Stream(new MapOperator(project,this))};Stream.prototype.mapTo=function(projectedValue){return new Stream(new MapToOperator(projectedValue,this))};Stream.prototype.filter=function(passes){var p=this._prod;if(p instanceof 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 Stream(new TakeOperator(amount,this))};Stream.prototype.drop=function(amount){return new Stream(new DropOperator(amount,this))};Stream.prototype.last=function(){return new Stream(new LastOperator(this))};Stream.prototype.startWith=function(initial){return new Stream(new StartWithOperator(this,initial))};Stream.prototype.endWhen=function(other){return new Stream(new EndWhenOperator(other,this))};Stream.prototype.fold=function(accumulate,seed){return new Stream(new FoldOperator(accumulate,seed,this))};Stream.prototype.replaceError=function(replace){return new Stream(new ReplaceErrorOperator(replace,this))};Stream.prototype.flatten=function(){var p=this._prod;return new Stream(p instanceof MapOperator||p instanceof FilterMapOperator?new MapFlattenOperator(p):new FlattenOperator(this))};Stream.prototype.flattenConcurrently=function(){var p=this._prod;return new Stream(p instanceof MapOperator||p instanceof FilterMapOperator?new MapFlattenConcOperator(p):new FlattenConcOperator(this))};Stream.prototype.merge=function(other){return Stream.merge(this,other)};Stream.prototype.compose=function(operator){return operator(this)};Stream.prototype.remember=function(){var _this=this;return new MemoryStream({_start:function(il){_this._prod._start(il)},_stop:function(){_this._prod._stop()}})};Stream.prototype.imitate=function(other){other._add(this)};Stream.prototype.debug=function(spy){if(spy===void 0){spy=null}return new Stream(new DebugOperator(spy,this))};Stream.prototype.shamefullySendNext=function(value){this._n(value)};Stream.prototype.shamefullySendError=function(error){this._e(error)};Stream.prototype.shamefullySendComplete=function(){this._c()};Stream.combine=function combine(project){var streams=[];for(var _i=1;_i<arguments.length;_i++){streams[_i-1]=arguments[_i]}return new Stream(new CombineProducer(project,streams))};return Stream}();exports.Stream=Stream;var MemoryStream=function(_super){__extends(MemoryStream,_super);function MemoryStream(producer){_super.call(this,producer);this._has=false}MemoryStream.prototype._n=function(x){this._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)};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 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.emptyListener={_n:noop,_e:noop,_c:noop};function internalizeProducer(producer){producer._start=function _start(il){il.next=il._n;il.error=il._e;il.complete=il._c;this.start(il)};producer._stop=producer.stop}function invoke(f,args){switch(args.length){case 0:return f();case 1:return f(args[0]);case 2:return f(args[0],args[1]);case 3:return f(args[0],args[1],args[2]);case 4:return f(args[0],args[1],args[2],args[3]);case 5:return f(args[0],args[1],args[2],args[3],args[4]);default:return f.apply(void 0,args)}}function compose2(f1,f2){return function composedFn(arg){return f1(f2(arg))}}function and(f1,f2){return function andFn(t){return f1(t)&&f2(t)}}var CombineListener=function(){function CombineListener(i,p){this.i=i;this.p=p;p.ils.push(this)}CombineListener.prototype._n=function(t){var p=this.p,out=p.out;if(!out)return;if(p.up(t,this.i)){try{out._n(invoke(p.project,p.vals))}catch(e){out._e(e)}}};CombineListener.prototype._e=function(err){var out=this.p.out;if(!out)return;out._e(err)};CombineListener.prototype._c=function(){var p=this.p;if(!p.out)return;if(--p.ac===0){p.out._c()}};return CombineListener}();exports.CombineListener=CombineListener;var CombineProducer=function(){function CombineProducer(project,streams){this.project=project;this.streams=streams;this.type="combine";this.out=exports.emptyListener;this.ils=[];var n=this.ac=this.left=streams.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 left=!this.left?0:v===empty?--this.left:this.left;this.vals[i]=t;return left===0};CombineProducer.prototype._start=function(out){this.out=out;var s=this.streams;var n=s.length;if(n===0)this.zero(out);else{for(var i=0;i<n;i++){s[i]._add(new CombineListener(i,this))}}};CombineProducer.prototype._stop=function(){var s=this.streams;var n=this.ac=this.left=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=[]};CombineProducer.prototype.zero=function(out){try{out._n(this.project());out._c()}catch(e){out._e(e)}};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 MergeProducer=function(){function MergeProducer(streams){this.streams=streams;this.type="merge";this.out=exports.emptyListener;this.ac=streams.length}MergeProducer.prototype._start=function(out){this.out=out;var s=this.streams;var L=s.length;for(var i=0;i<L;i++){s[i]._add(this)}};MergeProducer.prototype._stop=function(){var s=this.streams;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){this.out._n(t)};MergeProducer.prototype._e=function(err){this.out._e(err)};MergeProducer.prototype._c=function(){if(--this.ac===0){this.out._c()}};return MergeProducer}();exports.MergeProducer=MergeProducer;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(spy,ins){if(spy===void 0){spy=null}this.spy=spy;this.ins=ins;this.type="debug";this.out=null}DebugOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};DebugOperator.prototype._stop=function(){this.ins._remove(this);this.out=null};DebugOperator.prototype._n=function(t){if(this.spy){try{this.spy(t)}catch(e){this.out._e(e)}}else{console.log(t)}this.out._n(t)};DebugOperator.prototype._e=function(err){this.out._e(err)};DebugOperator.prototype._c=function(){this.out._c()};return DebugOperator}();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){if(this.dropped++>=this.max)this.out._n(t)};DropOperator.prototype._e=function(err){this.out._e(err)};DropOperator.prototype._c=function(){this.out._c()};return DropOperator}();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.emptyListener}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(){this.out._c()};EndWhenOperator.prototype._n=function(t){this.out._n(t)};EndWhenOperator.prototype._e=function(err){this.out._e(err)};EndWhenOperator.prototype._c=function(){this.end()};return EndWhenOperator}();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){try{if(this.passes(t))this.out._n(t)}catch(e){this.out._e(e)}};FilterOperator.prototype._e=function(err){this.out._e(err)};FilterOperator.prototype._c=function(){this.out._c()};return FilterOperator}();exports.FilterOperator=FilterOperator;var FCIL=function(){function FCIL(out,op){this.out=out;this.op=op}FCIL.prototype._n=function(t){this.out._n(t)};FCIL.prototype._e=function(err){this.out._e(err)};FCIL.prototype._c=function(){this.op.less()};return FCIL}();var FlattenConcOperator=function(){function FlattenConcOperator(ins){this.ins=ins;this.type="flattenConcurrently";this.active=1;this.out=null}FlattenConcOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};FlattenConcOperator.prototype._stop=function(){this.ins._remove(this);this.active=1;this.out=null};FlattenConcOperator.prototype.less=function(){if(--this.active===0){this.out._c()}};FlattenConcOperator.prototype._n=function(s){this.active++;s._add(new FCIL(this.out,this))};FlattenConcOperator.prototype._e=function(err){this.out._e(err)};FlattenConcOperator.prototype._c=function(){this.less()};return FlattenConcOperator}();exports.FlattenConcOperator=FlattenConcOperator;var FIL=function(){function FIL(out,op){this.out=out;this.op=op}FIL.prototype._n=function(t){this.out._n(t)};FIL.prototype._e=function(err){this.out._e(err)};FIL.prototype._c=function(){this.op.inner=null;this.op.less()};return FIL}();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);this.inner=null;this.il=null;this.open=true;this.out=null};FlattenOperator.prototype.less=function(){if(!this.open&&!this.inner)this.out._c()};FlattenOperator.prototype._n=function(s){var _a=this,inner=_a.inner,il=_a.il;if(inner&&il)inner._remove(il);(this.inner=s)._add(this.il=new FIL(this.out,this))};FlattenOperator.prototype._e=function(err){this.out._e(err)};FlattenOperator.prototype._c=function(){this.open=false;this.less()};return FlattenOperator}();exports.FlattenOperator=FlattenOperator;var FoldOperator=function(){function FoldOperator(f,seed,ins){this.f=f;this.seed=seed;this.ins=ins;this.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){try{this.out._n(this.acc=this.f(this.acc,t))}catch(e){this.out._e(e)}};FoldOperator.prototype._e=function(err){this.out._e(err)};FoldOperator.prototype._c=function(){this.out._c()};return FoldOperator}();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){this.out._e(err)};LastOperator.prototype._c=function(){var out=this.out;if(this.has){out._n(this.val);out._c()}else{out._e("TODO show proper error")}};return LastOperator}();exports.LastOperator=LastOperator;var MFCIL=function(){function MFCIL(out,op){this.out=out;this.op=op}MFCIL.prototype._n=function(r){this.out._n(r)};MFCIL.prototype._e=function(err){this.out._e(err)};MFCIL.prototype._c=function(){this.op.less()};return MFCIL}();var MapFlattenConcOperator=function(){function MapFlattenConcOperator(mapOp){this.mapOp=mapOp;this.type="map+flattenConcurrently";this.active=1;this.out=null;this.ins=mapOp.ins}MapFlattenConcOperator.prototype._start=function(out){this.out=out;this.mapOp.ins._add(this)};MapFlattenConcOperator.prototype._stop=function(){this.mapOp.ins._remove(this);this.active=1;this.out=null};MapFlattenConcOperator.prototype.less=function(){if(--this.active===0){this.out._c()}};MapFlattenConcOperator.prototype._n=function(v){this.active++;try{this.mapOp.project(v)._add(new MFCIL(this.out,this))}catch(e){this.out._e(e)}};MapFlattenConcOperator.prototype._e=function(err){this.out._e(err)};MapFlattenConcOperator.prototype._c=function(){this.less()};return MapFlattenConcOperator}();exports.MapFlattenConcOperator=MapFlattenConcOperator;var MFIL=function(){function MFIL(out,op){this.out=out;this.op=op}MFIL.prototype._n=function(r){this.out._n(r)};MFIL.prototype._e=function(err){this.out._e(err)};MFIL.prototype._c=function(){this.op.inner=null;this.op.less()};return MFIL}();var MapFlattenOperator=function(){function MapFlattenOperator(mapOp){this.mapOp=mapOp;this.type="map+flatten";this.inner=null;this.il=null;this.open=true;this.out=null;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);this.inner=null;this.il=null;this.open=true;this.out=null};MapFlattenOperator.prototype.less=function(){if(!this.open&&!this.inner){this.out._c()}};MapFlattenOperator.prototype._n=function(v){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 MFIL(this.out,this))}catch(e){this.out._e(e)}};MapFlattenOperator.prototype._e=function(err){this.out._e(err)};MapFlattenOperator.prototype._c=function(){this.open=false;this.less()};return MapFlattenOperator}();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){try{this.out._n(this.project(t))}catch(e){this.out._e(e)}};MapOperator.prototype._e=function(err){this.out._e(err)};MapOperator.prototype._c=function(){this.out._c()};return MapOperator}();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 MapToOperator=function(){function MapToOperator(val,ins){this.val=val;this.ins=ins;this.type="mapTo";this.out=null}MapToOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};MapToOperator.prototype._stop=function(){this.ins._remove(this);this.out=null};MapToOperator.prototype._n=function(t){this.out._n(this.val)};MapToOperator.prototype._e=function(err){this.out._e(err)};MapToOperator.prototype._c=function(){this.out._c()};return MapToOperator}();exports.MapToOperator=MapToOperator;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){this.out._n(t)};ReplaceErrorOperator.prototype._e=function(err){try{this.ins._remove(this);(this.ins=this.fn(err))._add(this)}catch(e){this.out._e(e)}};ReplaceErrorOperator.prototype._c=function(){this.out._c()};return ReplaceErrorOperator}();exports.ReplaceErrorOperator=ReplaceErrorOperator;var StartWithOperator=function(){function StartWithOperator(ins,value){this.ins=ins;this.value=value;this.type="startWith";this.out=exports.emptyListener}StartWithOperator.prototype._start=function(out){this.out=out;this.out._n(this.value);this.ins._add(out)};StartWithOperator.prototype._stop=function(){this.ins._remove(this.out);this.out=null};return StartWithOperator}();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 out=this.out;if(!out)return;if(this.taken++<this.max-1){out._n(t)}else{out._n(t);out._c();this._stop()}};TakeOperator.prototype._e=function(err){var out=this.out;if(!out)return;out._e(err)};TakeOperator.prototype._c=function(){var out=this.out;if(!out)return;out._c()};return TakeOperator}();exports.TakeOperator=TakeOperator;var Stream=function(){function Stream(producer){this._stopID=empty;this.combine=function combine(project){var streams=[];for(var _i=1;_i<arguments.length;_i++){streams[_i-1]=arguments[_i]}streams.unshift(this);return Stream.combine.apply(Stream,[project].concat(streams))};this._prod=producer;this._ils=[]}Stream.prototype._n=function(t){var a=this._ils;var 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){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._ils=[]};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.prototype._add=function(il){var a=this._ils;a.push(il);if(a.length===1){if(this._stopID!==empty){clearTimeout(this._stopID);this._stopID=empty}var p=this._prod;if(p)p._start(this)}};Stream.prototype._remove=function(il){var a=this._ils;var i=a.indexOf(il);if(i>-1){a.splice(i,1);var p_1=this._prod;if(p_1&&a.length<=0){this._stopID=setTimeout(function(){return p_1._stop()})}}};Stream.create=function(producer){if(producer){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;if(p instanceof FilterOperator){return new Stream(new FilterMapOperator(p.passes,project,p.ins))}if(p instanceof FilterMapOperator){return new Stream(new FilterMapOperator(p.passes,compose2(project,p.project),p.ins))}if(p instanceof MapOperator){return new Stream(new MapOperator(compose2(project,p.project),p.ins))}return new Stream(new MapOperator(project,this))};Stream.prototype.mapTo=function(projectedValue){return new Stream(new MapToOperator(projectedValue,this))};Stream.prototype.filter=function(passes){var p=this._prod;if(p instanceof 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 Stream(new TakeOperator(amount,this))};Stream.prototype.drop=function(amount){return new Stream(new DropOperator(amount,this))};Stream.prototype.last=function(){return new Stream(new LastOperator(this))};Stream.prototype.startWith=function(initial){return new Stream(new StartWithOperator(this,initial))};Stream.prototype.endWhen=function(other){return new Stream(new EndWhenOperator(other,this))};Stream.prototype.fold=function(accumulate,seed){return new Stream(new FoldOperator(accumulate,seed,this))};Stream.prototype.replaceError=function(replace){return new Stream(new ReplaceErrorOperator(replace,this))};Stream.prototype.flatten=function(){var p=this._prod;return new Stream(p instanceof MapOperator||p instanceof FilterMapOperator?new MapFlattenOperator(p):new FlattenOperator(this))};Stream.prototype.flattenConcurrently=function(){var p=this._prod;return new Stream(p instanceof MapOperator||p instanceof FilterMapOperator?new MapFlattenConcOperator(p):new FlattenConcOperator(this))};Stream.prototype.merge=function(other){return Stream.merge(this,other)};Stream.prototype.compose=function(operator){return operator(this)};Stream.prototype.remember=function(){var _this=this;return new MemoryStream({_start:function(il){_this._prod._start(il)},_stop:function(){_this._prod._stop()}})};Stream.prototype.imitate=function(other){other._add(this)};Stream.prototype.debug=function(spy){if(spy===void 0){spy=null}return new Stream(new DebugOperator(spy,this))};Stream.prototype.shamefullySendNext=function(value){this._n(value)};Stream.prototype.shamefullySendError=function(error){this._e(error)};Stream.prototype.shamefullySendComplete=function(){this._c()};Stream.combine=function combine(project){var streams=[];for(var _i=1;_i<arguments.length;_i++){streams[_i-1]=arguments[_i]}return new Stream(new CombineProducer(project,streams))};return Stream}();exports.Stream=Stream;var MemoryStream=function(_super){__extends(MemoryStream,_super);function MemoryStream(producer){_super.call(this,producer);this._has=false}MemoryStream.prototype._n=function(x){this._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)};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)}); |
{ | ||
"name": "xstream", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"description": "An extremely intuitive, small, and fast functional reactive stream library for JavaScript", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1001,2 +1001,17 @@ <!-- This README.md is automatically generated from source code and files in the /markdown directory. Please DO NOT send pull requests to directly modify this README. Instead, edit the JSDoc comments in source code or the md files in /markdown/. --> | ||
# CHANGELOG | ||
<a name="2.4.0"></a> | ||
# [2.4.0](https://github.com/staltz/xstream/compare/v2.3.0...v2.4.0) (2016-05-12) | ||
### Bug Fixes | ||
* **flatten:** add ins field as metadata to flatten ([cbc1f8b](https://github.com/staltz/xstream/commit/cbc1f8b)) | ||
### Features | ||
* **extra:** implement new extra operator: dropUntil ([e06d502](https://github.com/staltz/xstream/commit/e06d502)) | ||
* **extra:** implement new extra operator: split ([84742e8](https://github.com/staltz/xstream/commit/84742e8)) | ||
<a name="2.3.0"></a> | ||
@@ -1003,0 +1018,0 @@ # [2.3.0](https://github.com/staltz/xstream/compare/v2.2.1...v2.3.0) (2016-05-09) |
@@ -21,3 +21,3 @@ import {Promise} from 'es6-promise'; | ||
const emptyListener: InternalListener<any> = { | ||
export const emptyListener: InternalListener<any> = { | ||
_n: noop, | ||
@@ -34,2 +34,4 @@ _e: noop, | ||
export interface Operator<T, R> extends InternalProducer<R>, InternalListener<T> { | ||
type: string; | ||
ins: Stream<T>; | ||
_start: (out: Stream<R>) => void; | ||
@@ -40,3 +42,2 @@ _stop: () => void; | ||
_c: () => void; | ||
type: string; | ||
} | ||
@@ -714,9 +715,9 @@ | ||
class MFCIL<T> implements InternalListener<T> { | ||
constructor(private out: Stream<T>, | ||
private op: MapFlattenConcOperator<T>) { | ||
class MFCIL<R> implements InternalListener<R> { | ||
constructor(private out: Stream<R>, | ||
private op: MapFlattenConcOperator<any, R>) { | ||
} | ||
_n(t: T) { | ||
this.out._n(t); | ||
_n(r: R) { | ||
this.out._n(r); | ||
} | ||
@@ -733,11 +734,13 @@ | ||
export class MapFlattenConcOperator<T> implements InternalProducer<T>, InternalListener<T> { | ||
export class MapFlattenConcOperator<T, R> implements Operator<T, R> { | ||
public type = 'map+flattenConcurrently'; | ||
public ins: Stream<T>; | ||
private active: number = 1; // number of outers and inners that have not yet ended | ||
private out: Stream<T> = null; | ||
private out: Stream<R> = null; | ||
constructor(public mapOp: MapOperator<T, Stream<T>>) { | ||
constructor(public mapOp: MapOperator<T, Stream<R>>) { | ||
this.ins = mapOp.ins; | ||
} | ||
_start(out: Stream<T>): void { | ||
_start(out: Stream<R>): void { | ||
this.out = out; | ||
@@ -777,9 +780,9 @@ this.mapOp.ins._add(this); | ||
class MFIL<T> implements InternalListener<T> { | ||
constructor(private out: Stream<T>, | ||
private op: MapFlattenOperator<T>) { | ||
class MFIL<R> implements InternalListener<R> { | ||
constructor(private out: Stream<R>, | ||
private op: MapFlattenOperator<any, R>) { | ||
} | ||
_n(t: T) { | ||
this.out._n(t); | ||
_n(r: R) { | ||
this.out._n(r); | ||
} | ||
@@ -797,13 +800,15 @@ | ||
export class MapFlattenOperator<T> implements InternalProducer<T>, InternalListener<T> { | ||
export class MapFlattenOperator<T, R> implements Operator<T, R> { | ||
public type = 'map+flatten'; | ||
public inner: Stream<T> = null; // Current inner Stream | ||
private il: InternalListener<T> = null; // Current inner InternalListener | ||
public ins: Stream<T>; | ||
public inner: Stream<R> = null; // Current inner Stream | ||
private il: InternalListener<R> = null; // Current inner InternalListener | ||
private open: boolean = true; | ||
private out: Stream<T> = null; | ||
private out: Stream<R> = null; | ||
constructor(public mapOp: MapOperator<T, Stream<T>>) { | ||
constructor(public mapOp: MapOperator<T, Stream<R>>) { | ||
this.ins = mapOp.ins; | ||
} | ||
_start(out: Stream<T>): void { | ||
_start(out: Stream<R>): void { | ||
this.out = out; | ||
@@ -1034,3 +1039,3 @@ this.mapOp.ins._add(this); | ||
constructor(producer: InternalProducer<T>) { | ||
constructor(producer?: InternalProducer<T>) { | ||
this._prod = producer; | ||
@@ -1647,3 +1652,3 @@ this._ils = []; | ||
p instanceof MapOperator || p instanceof FilterMapOperator ? | ||
new MapFlattenOperator(<MapOperator<R, Stream<R>>> <any> p) : | ||
new MapFlattenOperator(<MapOperator<any, Stream<R>>> <any> p) : | ||
new FlattenOperator(<Stream<Stream<R>>> <any> this) | ||
@@ -1682,3 +1687,3 @@ ); | ||
p instanceof MapOperator || p instanceof FilterMapOperator ? | ||
new MapFlattenConcOperator(<MapOperator<R, Stream<R>>> <any> p) : | ||
new MapFlattenConcOperator(<MapOperator<any, Stream<R>>> <any> p) : | ||
new FlattenConcOperator(<Stream<Stream<R>>> <any> this) | ||
@@ -1685,0 +1690,0 @@ ); |
@@ -24,2 +24,11 @@ import xs, {Stream, Listener} from '../../src/index'; | ||
it('should have an ins field as metadata', (done) => { | ||
const source: Stream<number> = xs.periodic(100).take(3) | ||
const stream: Stream<number> = source | ||
.map((i: number) => xs.of(1 + i, 2 + i, 3 + i)) | ||
.flatten(); | ||
assert.strictEqual(stream['_prod']['ins'], source); | ||
done(); | ||
}); | ||
it('should return a flat stream with correct TypeScript types', (done) => { | ||
@@ -26,0 +35,0 @@ const streamStrings: Stream<string> = Stream.create({ |
@@ -24,2 +24,11 @@ import xs, {Stream, Listener} from '../../src/index'; | ||
it('should have an ins field as metadata', (done) => { | ||
const source: Stream<number> = xs.periodic(100).take(3) | ||
const stream: Stream<number> = source | ||
.map((i: number) => xs.of(1 + i, 2 + i, 3 + i)) | ||
.flattenConcurrently(); | ||
assert.strictEqual(stream['_prod']['ins'], source); | ||
done(); | ||
}); | ||
it('should return a flat stream with correct TypeScript types', (done) => { | ||
@@ -26,0 +35,0 @@ const streamStrings: Stream<string> = Stream.create({ |
@@ -25,5 +25,7 @@ { | ||
"src/extra/dropRepeats.ts", | ||
"src/extra/dropUntil.ts", | ||
"src/extra/flattenSequentially.ts", | ||
"src/extra/fromEvent.ts", | ||
"src/extra/pairwise.ts", | ||
"src/extra/split.ts", | ||
"src/index.ts" | ||
@@ -30,0 +32,0 @@ ], |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
780093
127
14009
1280