Comparing version 6.0.0 to 6.1.0
@@ -0,1 +1,11 @@ | ||
<a name="6.1.0"></a> | ||
# [6.1.0](https://github.com/staltz/xstream/compare/v6.0.0...v6.1.0) (2016-08-22) | ||
### Features | ||
* **Stream:** add new method setDebugListener on streams ([d0ee240](https://github.com/staltz/xstream/commit/d0ee240)) | ||
<a name="6.0.0"></a> | ||
@@ -2,0 +12,0 @@ # [6.0.0](https://github.com/staltz/xstream/compare/v5.3.6...v6.0.0) (2016-08-20) |
@@ -285,2 +285,4 @@ export interface InternalListener<T> { | ||
protected _stopID: any; | ||
protected _dl: InternalListener<T>; | ||
protected _d: boolean; | ||
protected _target: Stream<T>; | ||
@@ -858,2 +860,23 @@ protected _err: any; | ||
shamefullySendComplete(): void; | ||
/** | ||
* Adds a "debug" listener to the stream. There can only be one debug | ||
* listener, that's why this is 'setDebugListener'. To remove the debug | ||
* listener, just call setDebugListener(null). | ||
* | ||
* A debug listener is like any other listener. The only difference is that a | ||
* debug listener is "stealthy": its presence/absence does not trigger the | ||
* start/stop of the stream (or the producer inside the stream). This is | ||
* useful so you can inspect what is going on without changing the behavior | ||
* of the program. If you have an idle stream and you add a normal listener to | ||
* it, the stream will start executing. But if you set a debug listener on an | ||
* idle stream, it won't start executing (not until the first normal listener | ||
* is added). | ||
* | ||
* As the name indicates, we don't recommend using this method to build app | ||
* logic. In fact, in most cases the debug operator works just fine. Only use | ||
* this one if you know what you're doing. | ||
* | ||
* @param {Listener<T>} listener | ||
*/ | ||
setDebugListener(listener: Listener<T>): void; | ||
} | ||
@@ -860,0 +883,0 @@ export declare class MemoryStream<T> extends Stream<T> { |
41
core.js
@@ -856,2 +856,4 @@ "use strict"; | ||
this._stopID = NO; | ||
this._dl = NO; | ||
this._d = false; | ||
this._target = NO; | ||
@@ -863,2 +865,4 @@ this._err = NO; | ||
var L = a.length; | ||
if (this._d) | ||
this._dl._n(t); | ||
if (L == 1) | ||
@@ -879,2 +883,4 @@ a[0]._n(t); | ||
this._x(); | ||
if (this._d) | ||
this._dl._e(err); | ||
if (L == 1) | ||
@@ -892,2 +898,4 @@ a[0]._e(err); | ||
this._x(); | ||
if (this._d) | ||
this._dl._c(); | ||
if (L == 1) | ||
@@ -1620,2 +1628,35 @@ a[0]._c(); | ||
/** | ||
* Adds a "debug" listener to the stream. There can only be one debug | ||
* listener, that's why this is 'setDebugListener'. To remove the debug | ||
* listener, just call setDebugListener(null). | ||
* | ||
* A debug listener is like any other listener. The only difference is that a | ||
* debug listener is "stealthy": its presence/absence does not trigger the | ||
* start/stop of the stream (or the producer inside the stream). This is | ||
* useful so you can inspect what is going on without changing the behavior | ||
* of the program. If you have an idle stream and you add a normal listener to | ||
* it, the stream will start executing. But if you set a debug listener on an | ||
* idle stream, it won't start executing (not until the first normal listener | ||
* is added). | ||
* | ||
* As the name indicates, we don't recommend using this method to build app | ||
* logic. In fact, in most cases the debug operator works just fine. Only use | ||
* this one if you know what you're doing. | ||
* | ||
* @param {Listener<T>} listener | ||
*/ | ||
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; | ||
} | ||
}; | ||
/** | ||
* Blends multiple streams together, emitting events from all of them | ||
@@ -1622,0 +1663,0 @@ * concurrently. |
@@ -857,2 +857,4 @@ (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){ | ||
this._stopID = NO; | ||
this._dl = NO; | ||
this._d = false; | ||
this._target = NO; | ||
@@ -864,2 +866,4 @@ this._err = NO; | ||
var L = a.length; | ||
if (this._d) | ||
this._dl._n(t); | ||
if (L == 1) | ||
@@ -880,2 +884,4 @@ a[0]._n(t); | ||
this._x(); | ||
if (this._d) | ||
this._dl._e(err); | ||
if (L == 1) | ||
@@ -893,2 +899,4 @@ a[0]._e(err); | ||
this._x(); | ||
if (this._d) | ||
this._dl._c(); | ||
if (L == 1) | ||
@@ -1170,2 +1178,16 @@ a[0]._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() { | ||
@@ -1172,0 +1194,0 @@ var streams = []; |
@@ -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 NO={};function noop(){}function copy(a){var l=a.length;var b=Array(l);for(var i=0;i<l;++i){b[i]=a[i]}return b}exports.NO_IL={_n:noop,_e:noop,_c:noop};function internalizeProducer(producer){producer._start=function _start(il){il.next=il._n;il.error=il._e;il.complete=il._c;this.start(il)};producer._stop=producer.stop}function compose2(f1,f2){return function composedFn(arg){return f1(f2(arg))}}function and(f1,f2){return function andFn(t){return f1(t)&&f2(t)}}var MergeProducer=function(){function MergeProducer(insArr){this.type="merge";this.insArr=insArr;this.out=NO;this.ac=0}MergeProducer.prototype._start=function(out){this.out=out;var s=this.insArr;var L=s.length;this.ac=L;for(var i=0;i<L;i++){s[i]._add(this)}};MergeProducer.prototype._stop=function(){var s=this.insArr;var L=s.length;for(var i=0;i<L;i++){s[i]._remove(this)}this.out=NO};MergeProducer.prototype._n=function(t){var u=this.out;if(u===NO)return;u._n(t)};MergeProducer.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};MergeProducer.prototype._c=function(){if(--this.ac<=0){var u=this.out;if(u===NO)return;u._c()}};return MergeProducer}();exports.MergeProducer=MergeProducer;var CombineListener=function(){function CombineListener(i,out,p){this.i=i;this.out=out;this.p=p;p.ils.push(this)}CombineListener.prototype._n=function(t){var p=this.p,out=this.out;if(!out)return;if(p.up(t,this.i)){out._n(p.vals)}};CombineListener.prototype._e=function(err){var out=this.out;if(!out)return;out._e(err)};CombineListener.prototype._c=function(){var p=this.p;if(!p.out)return;if(--p.Nc===0){p.out._c()}};return CombineListener}();exports.CombineListener=CombineListener;var CombineProducer=function(){function CombineProducer(insArr){this.type="combine";this.insArr=insArr;this.out=NO;this.ils=[];this.Nc=this.Nn=0;this.vals=[]}CombineProducer.prototype.up=function(t,i){var v=this.vals[i];var Nn=!this.Nn?0:v===NO?--this.Nn:this.Nn;this.vals[i]=t;return Nn===0};CombineProducer.prototype._start=function(out){this.out=out;var s=this.insArr;var n=this.Nc=this.Nn=s.length;var vals=this.vals=new Array(n);if(n===0){out._n([]);out._c()}else{for(var i=0;i<n;i++){vals[i]=NO;s[i]._add(new CombineListener(i,out,this))}}};CombineProducer.prototype._stop=function(){var s=this.insArr;var n=s.length;for(var i=0;i<n;i++){s[i]._remove(this.ils[i])}this.out=NO;this.ils=[];this.vals=[]};return CombineProducer}();exports.CombineProducer=CombineProducer;var FromArrayProducer=function(){function FromArrayProducer(a){this.type="fromArray";this.a=a}FromArrayProducer.prototype._start=function(out){var a=this.a;for(var i=0,l=a.length;i<l;i++){out._n(a[i])}out._c()};FromArrayProducer.prototype._stop=function(){};return FromArrayProducer}();exports.FromArrayProducer=FromArrayProducer;var FromPromiseProducer=function(){function FromPromiseProducer(p){this.type="fromPromise";this.on=false;this.p=p}FromPromiseProducer.prototype._start=function(out){var prod=this;this.on=true;this.p.then(function(v){if(prod.on){out._n(v);out._c()}},function(e){out._e(e)}).then(null,function(err){setTimeout(function(){throw err})})};FromPromiseProducer.prototype._stop=function(){this.on=false};return FromPromiseProducer}();exports.FromPromiseProducer=FromPromiseProducer;var PeriodicProducer=function(){function PeriodicProducer(period){this.type="periodic";this.period=period;this.intervalID=-1;this.i=0}PeriodicProducer.prototype._start=function(stream){var self=this;function intervalHandler(){stream._n(self.i++)}this.intervalID=setInterval(intervalHandler,this.period)};PeriodicProducer.prototype._stop=function(){if(this.intervalID!==-1)clearInterval(this.intervalID);this.intervalID=-1;this.i=0};return PeriodicProducer}();exports.PeriodicProducer=PeriodicProducer;var DebugOperator=function(){function DebugOperator(arg,ins){this.type="debug";this.ins=ins;this.out=NO;this.s=noop;this.l="";if(typeof arg==="string"){this.l=arg}else if(typeof arg==="function"){this.s=arg}}DebugOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};DebugOperator.prototype._stop=function(){this.ins._remove(this);this.out=NO};DebugOperator.prototype._n=function(t){var u=this.out;if(u===NO)return;var s=this.s,l=this.l;if(s!==noop){try{s(t)}catch(e){u._e(e)}}else if(l){console.log(l+":",t)}else{console.log(t)}u._n(t)};DebugOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};DebugOperator.prototype._c=function(){var u=this.out;if(u===NO)return;u._c()};return DebugOperator}();exports.DebugOperator=DebugOperator;var DropOperator=function(){function DropOperator(max,ins){this.type="drop";this.ins=ins;this.out=NO;this.max=max;this.dropped=0}DropOperator.prototype._start=function(out){this.out=out;this.dropped=0;this.ins._add(this)};DropOperator.prototype._stop=function(){this.ins._remove(this);this.out=NO};DropOperator.prototype._n=function(t){var u=this.out;if(u===NO)return;if(this.dropped++>=this.max)u._n(t)};DropOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};DropOperator.prototype._c=function(){var u=this.out;if(u===NO)return;u._c()};return DropOperator}();exports.DropOperator=DropOperator;var OtherIL=function(){function OtherIL(out,op){this.out=out;this.op=op}OtherIL.prototype._n=function(t){this.op.end()};OtherIL.prototype._e=function(err){this.out._e(err)};OtherIL.prototype._c=function(){this.op.end()};return OtherIL}();var EndWhenOperator=function(){function EndWhenOperator(o,ins){this.type="endWhen";this.ins=ins;this.out=NO;this.o=o;this.oil=exports.NO_IL}EndWhenOperator.prototype._start=function(out){this.out=out;this.o._add(this.oil=new OtherIL(out,this));this.ins._add(this)};EndWhenOperator.prototype._stop=function(){this.ins._remove(this);this.o._remove(this.oil);this.out=NO;this.oil=exports.NO_IL};EndWhenOperator.prototype.end=function(){var u=this.out;if(u===NO)return;u._c()};EndWhenOperator.prototype._n=function(t){var u=this.out;if(u===NO)return;u._n(t)};EndWhenOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};EndWhenOperator.prototype._c=function(){this.end()};return EndWhenOperator}();exports.EndWhenOperator=EndWhenOperator;var FilterOperator=function(){function FilterOperator(passes,ins){this.type="filter";this.ins=ins;this.out=NO;this.passes=passes}FilterOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};FilterOperator.prototype._stop=function(){this.ins._remove(this);this.out=NO};FilterOperator.prototype._n=function(t){var u=this.out;if(u===NO)return;try{if(this.passes(t))u._n(t)}catch(e){u._e(e)}};FilterOperator.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};FilterOperator.prototype._c=function(){var u=this.out;if(u===NO)return;u._c()};return FilterOperator}();exports.FilterOperator=FilterOperator;var FlattenListener=function(){function FlattenListener(out,op){this.out=out;this.op=op}FlattenListener.prototype._n=function(t){this.out._n(t)};FlattenListener.prototype._e=function(err){this.out._e(err)};FlattenListener.prototype._c=function(){this.op.inner=NO;this.op.less()};return FlattenListener}();var FlattenOperator=function(){function FlattenOperator(ins){this.type="flatten";this.ins=ins;this.out=NO;this.open=true;this.inner=NO;this.il=exports.NO_IL}FlattenOperator.prototype._start=function(out){this.out=out;this.open=true;this.inner=NO;this.il=exports.NO_IL;this.ins._add(this)};FlattenOperator.prototype._stop=function(){this.ins._remove(this);if(this.inner!==NO)this.inner._remove(this.il);this.out=NO;this.open=true;this.inner=NO;this.il=exports.NO_IL};FlattenOperator.prototype.less=function(){var u=this.out;if(u===NO)return;if(!this.open&&this.inner===NO)u._c()};FlattenOperator.prototype._n=function(s){var u=this.out;if(u===NO)return;var _a=this,inner=_a.inner,il=_a.il;if(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._target=NO;this._err=NO}Stream.prototype._n=function(t){var a=this._ils;var L=a.length;if(L==1)a[0]._n(t);else{var b=copy(a);for(var i=0;i<L;i++)b[i]._n(t)}};Stream.prototype._e=function(err){if(this._err!==NO)return;this._err=err;var a=this._ils;var L=a.length;this._x();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(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){if(typeof listener.next!=="function"||typeof listener.error!=="function"||typeof listener.complete!=="function"){throw new Error("stream.addListener() requires all three next, error, "+"and complete functions.")}listener._n=listener.next;listener._e=listener.error;listener._c=listener.complete;this._add(listener)};Stream.prototype.removeListener=function(listener){this._remove(listener)};Stream.create=function(producer){if(producer){if(typeof producer.start!=="function"||typeof producer.stop!=="function"){throw new Error("producer requires both start and stop functions")}internalizeProducer(producer)}return new Stream(producer)};Stream.createWithMemory=function(producer){if(producer){internalizeProducer(producer)}return new MemoryStream(producer)};Stream.never=function(){return new Stream({_start:noop,_stop:noop})};Stream.empty=function(){return new Stream({_start:function(il){il._c()},_stop:noop})};Stream.throw=function(error){return new Stream({_start:function(il){il._e(error)},_stop:noop})};Stream.of=function(){var items=[];for(var _i=0;_i<arguments.length;_i++){items[_i-0]=arguments[_i]}return Stream.fromArray(items)};Stream.fromArray=function(array){return new Stream(new FromArrayProducer(array))};Stream.fromPromise=function(promise){return new Stream(new FromPromiseProducer(promise))};Stream.periodic=function(period){return new Stream(new PeriodicProducer(period))};Stream.prototype._map=function(project){var p=this._prod;var ctor=this.ctor();if(p instanceof FilterOperator){return new ctor(new FilterMapOperator(p.passes,project,p.ins))}if(p instanceof FilterMapOperator){return new ctor(new FilterMapOperator(p.passes,compose2(project,p.project),p.ins))}if(p instanceof MapOperator){return new ctor(new MapOperator(compose2(project,p.project),p.ins))}return new ctor(new MapOperator(project,this))};Stream.prototype.map=function(project){return this._map(project)};Stream.prototype.mapTo=function(projectedValue){var s=this.map(function(){return projectedValue});var op=s._prod;op.type=op.type.replace("map","mapTo");return s};Stream.prototype.filter=function(passes){var p=this._prod;if(p instanceof FilterOperator){return new Stream(new FilterOperator(and(p.passes,passes),p.ins))}return new Stream(new FilterOperator(passes,this))};Stream.prototype.take=function(amount){return new(this.ctor())(new TakeOperator(amount,this))};Stream.prototype.drop=function(amount){return new Stream(new DropOperator(amount,this))};Stream.prototype.last=function(){return new Stream(new LastOperator(this))};Stream.prototype.startWith=function(initial){return new MemoryStream(new StartWithOperator(this,initial))};Stream.prototype.endWhen=function(other){return new(this.ctor())(new EndWhenOperator(other,this))};Stream.prototype.fold=function(accumulate,seed){return new MemoryStream(new FoldOperator(accumulate,seed,this))};Stream.prototype.replaceError=function(replace){return new(this.ctor())(new ReplaceErrorOperator(replace,this))};Stream.prototype.flatten=function(){var p=this._prod;return new Stream(p instanceof MapOperator&&!(p instanceof FilterMapOperator)?new MapFlattenOperator(p):new FlattenOperator(this))};Stream.prototype.compose=function(operator){return operator(this)};Stream.prototype.remember=function(){return new MemoryStream(new RememberOperator(this))};Stream.prototype.debug=function(labelOrSpy){return new(this.ctor())(new DebugOperator(labelOrSpy,this))};Stream.prototype.imitate=function(target){if(target instanceof MemoryStream){throw new Error("A MemoryStream was given to imitate(), but it only "+"supports a Stream. Read more about this restriction here: "+"https://github.com/staltz/xstream#faq")}this._target=target;for(var ils=this._ils,N=ils.length,i=0;i<N;i++){target._add(ils[i])}this._ils=[]};Stream.prototype.shamefullySendNext=function(value){this._n(value)};Stream.prototype.shamefullySendError=function(error){this._e(error)};Stream.prototype.shamefullySendComplete=function(){this._c()};Stream.merge=function merge(){var streams=[];for(var _i=0;_i<arguments.length;_i++){streams[_i-0]=arguments[_i]}return new Stream(new MergeProducer(streams))};Stream.combine=function combine(){var streams=[];for(var _i=0;_i<arguments.length;_i++){streams[_i-0]=arguments[_i]}return new Stream(new CombineProducer(streams))};return Stream}();exports.Stream=Stream;var MemoryStream=function(_super){__extends(MemoryStream,_super);function MemoryStream(producer){_super.call(this,producer);this._has=false}MemoryStream.prototype._n=function(x){this._v=x;this._has=true;_super.prototype._n.call(this,x)};MemoryStream.prototype._add=function(il){if(this._has){il._n(this._v)}_super.prototype._add.call(this,il)};MemoryStream.prototype._stopNow=function(){this._has=false;_super.prototype._stopNow.call(this)};MemoryStream.prototype._x=function(){this._has=false;_super.prototype._x.call(this)};MemoryStream.prototype.map=function(project){return this._map(project)};MemoryStream.prototype.mapTo=function(projectedValue){return _super.prototype.mapTo.call(this,projectedValue)};MemoryStream.prototype.take=function(amount){return _super.prototype.take.call(this,amount)};MemoryStream.prototype.endWhen=function(other){return _super.prototype.endWhen.call(this,other)};MemoryStream.prototype.replaceError=function(replace){return _super.prototype.replaceError.call(this,replace)};MemoryStream.prototype.remember=function(){return this};MemoryStream.prototype.debug=function(labelOrSpy){return _super.prototype.debug.call(this,labelOrSpy)};return MemoryStream}(Stream);exports.MemoryStream=MemoryStream;Object.defineProperty(exports,"__esModule",{value:true});exports.default=Stream},{}],2:[function(require,module,exports){"use strict";var core_1=require("./core");exports.Stream=core_1.Stream;exports.MemoryStream=core_1.MemoryStream;Object.defineProperty(exports,"__esModule",{value:true});exports.default=core_1.Stream},{"./core":1}]},{},[2])(2)}); | ||
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.xstream=f()}})(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){"use strict";var __extends=this&&this.__extends||function(d,b){for(var p in b)if(b.hasOwnProperty(p))d[p]=b[p];function __(){this.constructor=d}d.prototype=b===null?Object.create(b):(__.prototype=b.prototype,new __)};var NO={};function noop(){}function copy(a){var l=a.length;var b=Array(l);for(var i=0;i<l;++i){b[i]=a[i]}return b}exports.NO_IL={_n:noop,_e:noop,_c:noop};function internalizeProducer(producer){producer._start=function _start(il){il.next=il._n;il.error=il._e;il.complete=il._c;this.start(il)};producer._stop=producer.stop}function compose2(f1,f2){return function composedFn(arg){return f1(f2(arg))}}function and(f1,f2){return function andFn(t){return f1(t)&&f2(t)}}var MergeProducer=function(){function MergeProducer(insArr){this.type="merge";this.insArr=insArr;this.out=NO;this.ac=0}MergeProducer.prototype._start=function(out){this.out=out;var s=this.insArr;var L=s.length;this.ac=L;for(var i=0;i<L;i++){s[i]._add(this)}};MergeProducer.prototype._stop=function(){var s=this.insArr;var L=s.length;for(var i=0;i<L;i++){s[i]._remove(this)}this.out=NO};MergeProducer.prototype._n=function(t){var u=this.out;if(u===NO)return;u._n(t)};MergeProducer.prototype._e=function(err){var u=this.out;if(u===NO)return;u._e(err)};MergeProducer.prototype._c=function(){if(--this.ac<=0){var u=this.out;if(u===NO)return;u._c()}};return MergeProducer}();exports.MergeProducer=MergeProducer;var CombineListener=function(){function CombineListener(i,out,p){this.i=i;this.out=out;this.p=p;p.ils.push(this)}CombineListener.prototype._n=function(t){var p=this.p,out=this.out;if(!out)return;if(p.up(t,this.i)){out._n(p.vals)}};CombineListener.prototype._e=function(err){var out=this.out;if(!out)return;out._e(err)};CombineListener.prototype._c=function(){var p=this.p;if(!p.out)return;if(--p.Nc===0){p.out._c()}};return CombineListener}();exports.CombineListener=CombineListener;var CombineProducer=function(){function CombineProducer(insArr){this.type="combine";this.insArr=insArr;this.out=NO;this.ils=[];this.Nc=this.Nn=0;this.vals=[]}CombineProducer.prototype.up=function(t,i){var v=this.vals[i];var Nn=!this.Nn?0:v===NO?--this.Nn:this.Nn;this.vals[i]=t;return Nn===0};CombineProducer.prototype._start=function(out){this.out=out;var s=this.insArr;var n=this.Nc=this.Nn=s.length;var vals=this.vals=new Array(n);if(n===0){out._n([]);out._c()}else{for(var i=0;i<n;i++){vals[i]=NO;s[i]._add(new CombineListener(i,out,this))}}};CombineProducer.prototype._stop=function(){var s=this.insArr;var n=s.length;for(var i=0;i<n;i++){s[i]._remove(this.ils[i])}this.out=NO;this.ils=[];this.vals=[]};return CombineProducer}();exports.CombineProducer=CombineProducer;var FromArrayProducer=function(){function FromArrayProducer(a){this.type="fromArray";this.a=a}FromArrayProducer.prototype._start=function(out){var a=this.a;for(var i=0,l=a.length;i<l;i++){out._n(a[i])}out._c()};FromArrayProducer.prototype._stop=function(){};return FromArrayProducer}();exports.FromArrayProducer=FromArrayProducer;var FromPromiseProducer=function(){function FromPromiseProducer(p){this.type="fromPromise";this.on=false;this.p=p}FromPromiseProducer.prototype._start=function(out){var prod=this;this.on=true;this.p.then(function(v){if(prod.on){out._n(v);out._c()}},function(e){out._e(e)}).then(null,function(err){setTimeout(function(){throw err})})};FromPromiseProducer.prototype._stop=function(){this.on=false};return FromPromiseProducer}();exports.FromPromiseProducer=FromPromiseProducer;var PeriodicProducer=function(){function PeriodicProducer(period){this.type="periodic";this.period=period;this.intervalID=-1;this.i=0}PeriodicProducer.prototype._start=function(stream){var self=this;function intervalHandler(){stream._n(self.i++)}this.intervalID=setInterval(intervalHandler,this.period)};PeriodicProducer.prototype._stop=function(){if(this.intervalID!==-1)clearInterval(this.intervalID);this.intervalID=-1;this.i=0};return PeriodicProducer}();exports.PeriodicProducer=PeriodicProducer;var DebugOperator=function(){function DebugOperator(arg,ins){this.type="debug";this.ins=ins;this.out=NO;this.s=noop;this.l="";if(typeof arg==="string"){this.l=arg}else 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){if(typeof listener.next!=="function"||typeof listener.error!=="function"||typeof listener.complete!=="function"){throw new Error("stream.addListener() requires all three next, error, "+"and complete functions.")}listener._n=listener.next;listener._e=listener.error;listener._c=listener.complete;this._add(listener)};Stream.prototype.removeListener=function(listener){this._remove(listener)};Stream.create=function(producer){if(producer){if(typeof producer.start!=="function"||typeof producer.stop!=="function"){throw new Error("producer requires both start and stop functions")}internalizeProducer(producer)}return new Stream(producer)};Stream.createWithMemory=function(producer){if(producer){internalizeProducer(producer)}return new MemoryStream(producer)};Stream.never=function(){return new Stream({_start:noop,_stop:noop})};Stream.empty=function(){return new Stream({_start:function(il){il._c()},_stop:noop})};Stream.throw=function(error){return new Stream({_start:function(il){il._e(error)},_stop:noop})};Stream.of=function(){var items=[];for(var _i=0;_i<arguments.length;_i++){items[_i-0]=arguments[_i]}return Stream.fromArray(items)};Stream.fromArray=function(array){return new Stream(new FromArrayProducer(array))};Stream.fromPromise=function(promise){return new Stream(new FromPromiseProducer(promise))};Stream.periodic=function(period){return new Stream(new PeriodicProducer(period))};Stream.prototype._map=function(project){var p=this._prod;var ctor=this.ctor();if(p instanceof FilterOperator){return new ctor(new FilterMapOperator(p.passes,project,p.ins))}if(p instanceof FilterMapOperator){return new ctor(new FilterMapOperator(p.passes,compose2(project,p.project),p.ins))}if(p instanceof MapOperator){return new ctor(new MapOperator(compose2(project,p.project),p.ins))}return new ctor(new MapOperator(project,this))};Stream.prototype.map=function(project){return this._map(project)};Stream.prototype.mapTo=function(projectedValue){var s=this.map(function(){return projectedValue});var op=s._prod;op.type=op.type.replace("map","mapTo");return s};Stream.prototype.filter=function(passes){var p=this._prod;if(p instanceof FilterOperator){return new Stream(new FilterOperator(and(p.passes,passes),p.ins))}return new Stream(new FilterOperator(passes,this))};Stream.prototype.take=function(amount){return new(this.ctor())(new TakeOperator(amount,this))};Stream.prototype.drop=function(amount){return new Stream(new DropOperator(amount,this))};Stream.prototype.last=function(){return new Stream(new LastOperator(this))};Stream.prototype.startWith=function(initial){return new MemoryStream(new StartWithOperator(this,initial))};Stream.prototype.endWhen=function(other){return new(this.ctor())(new EndWhenOperator(other,this))};Stream.prototype.fold=function(accumulate,seed){return new MemoryStream(new FoldOperator(accumulate,seed,this))};Stream.prototype.replaceError=function(replace){return new(this.ctor())(new ReplaceErrorOperator(replace,this))};Stream.prototype.flatten=function(){var p=this._prod;return new Stream(p instanceof MapOperator&&!(p instanceof FilterMapOperator)?new MapFlattenOperator(p):new FlattenOperator(this))};Stream.prototype.compose=function(operator){return operator(this)};Stream.prototype.remember=function(){return new MemoryStream(new RememberOperator(this))};Stream.prototype.debug=function(labelOrSpy){return new(this.ctor())(new DebugOperator(labelOrSpy,this))};Stream.prototype.imitate=function(target){if(target instanceof MemoryStream){throw new Error("A MemoryStream was given to imitate(), but it only "+"supports a Stream. Read more about this restriction here: "+"https://github.com/staltz/xstream#faq")}this._target=target;for(var ils=this._ils,N=ils.length,i=0;i<N;i++){target._add(ils[i])}this._ils=[]};Stream.prototype.shamefullySendNext=function(value){this._n(value)};Stream.prototype.shamefullySendError=function(error){this._e(error)};Stream.prototype.shamefullySendComplete=function(){this._c()};Stream.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},{}],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": "6.0.0", | ||
"version": "6.1.0", | ||
"description": "An extremely intuitive, small, and fast functional reactive stream library for JavaScript", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -17,11 +17,11 @@ { | ||
"dependencies": { | ||
"@reactivex/rxjs": "^5.0.0-beta.6", | ||
"baconjs": "^0.7.84", | ||
"@reactivex/rxjs": "^5.0.0-beta.11", | ||
"baconjs": "^0.7.85", | ||
"benchmark": "github:bestiejs/benchmark.js#master", | ||
"highland": "^2.7.4", | ||
"kefir": "^3.2.1", | ||
"lodash": "^4.11.0", | ||
"most": "^0.18.8", | ||
"highland": "^2.9.0", | ||
"kefir": "^3.4.0", | ||
"lodash": "^4.15.0", | ||
"most": "^1.0.1", | ||
"rx": "^4.1.0" | ||
} | ||
} |
@@ -105,2 +105,3 @@ <!-- 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/. --> | ||
- [`shamefullySendComplete`](#shamefullySendComplete) | ||
- [`setDebugListener`](#setDebugListener) | ||
@@ -898,2 +899,27 @@ # Overview | ||
### <a id="setDebugListener"></a> `setDebugListener(listener)` | ||
Adds a "debug" listener to the stream. There can only be one debug | ||
listener, that's why this is 'setDebugListener'. To remove the debug | ||
listener, just call setDebugListener(null). | ||
A debug listener is like any other listener. The only difference is that a | ||
debug listener is "stealthy": its presence/absence does not trigger the | ||
start/stop of the stream (or the producer inside the stream). This is | ||
useful so you can inspect what is going on without changing the behavior | ||
of the program. If you have an idle stream and you add a normal listener to | ||
it, the stream will start executing. But if you set a debug listener on an | ||
idle stream, it won't start executing (not until the first normal listener | ||
is added). | ||
As the name indicates, we don't recommend using this method to build app | ||
logic. In fact, in most cases the debug operator works just fine. Only use | ||
this one if you know what you're doing. | ||
#### Arguments: | ||
- `listener: Listener\<T>` | ||
- - - | ||
# Extra operators and factories | ||
@@ -900,0 +926,0 @@ |
252
src/core.ts
@@ -61,10 +61,10 @@ import {Promise} from 'es6-promise'; | ||
function internalizeProducer<T>(producer: Producer<T>) { | ||
(<InternalProducer<T>> (<any> producer))._start = | ||
(producer as InternalProducer<T> & Producer<T>)._start = | ||
function _start(il: InternalListener<T>) { | ||
(<Listener<T>> (<any> il)).next = il._n; | ||
(<Listener<T>> (<any> il)).error = il._e; | ||
(<Listener<T>> (<any> il)).complete = il._c; | ||
this.start(<Listener<T>> (<any> il)); | ||
(il as InternalListener<T> & Listener<T>).next = il._n; | ||
(il as InternalListener<T> & Listener<T>).error = il._e; | ||
(il as InternalListener<T> & Listener<T>).complete = il._c; | ||
this.start(il as InternalListener<T> & Listener<T>); | ||
}; | ||
(<InternalProducer<T>> (<any> producer))._stop = producer.stop; | ||
(producer as InternalProducer<T> & Producer<T>)._stop = producer.stop; | ||
} | ||
@@ -92,3 +92,3 @@ | ||
this.insArr = insArr; | ||
this.out = <Stream<T>> NO; | ||
this.out = NO as Stream<T>; | ||
this.ac = 0; | ||
@@ -113,3 +113,3 @@ } | ||
} | ||
this.out = <Stream<T>> NO; | ||
this.out = NO as Stream<T>; | ||
} | ||
@@ -246,3 +246,3 @@ | ||
this.insArr = insArr; | ||
this.out = <Stream<Array<R>>> NO; | ||
this.out = NO as Stream<Array<R>>; | ||
this.ils = []; | ||
@@ -282,3 +282,3 @@ this.Nc = this.Nn = 0; | ||
} | ||
this.out = <Stream<Array<R>>> NO; | ||
this.out = NO as Stream<Array<R>>; | ||
this.ils = []; | ||
@@ -376,3 +376,3 @@ this.vals = []; | ||
this.ins = ins; | ||
this.out = <Stream<T>> NO; | ||
this.out = NO as Stream<T>; | ||
this.s = noop; | ||
@@ -394,3 +394,3 @@ this.l = ''; | ||
this.ins._remove(this); | ||
this.out = <Stream<T>> NO; | ||
this.out = NO as Stream<T>; | ||
} | ||
@@ -438,3 +438,3 @@ | ||
this.ins = ins; | ||
this.out = <Stream<T>> NO; | ||
this.out = NO as Stream<T>; | ||
this.max = max; | ||
@@ -452,3 +452,3 @@ this.dropped = 0; | ||
this.ins._remove(this); | ||
this.out = <Stream<T>> NO; | ||
this.out = NO as Stream<T>; | ||
} | ||
@@ -506,3 +506,3 @@ | ||
this.ins = ins; | ||
this.out = <Stream<T>> NO; | ||
this.out = NO as Stream<T>; | ||
this.o = o; | ||
@@ -521,3 +521,3 @@ this.oil = NO_IL; | ||
this.o._remove(this.oil); | ||
this.out = <Stream<T>> NO; | ||
this.out = NO as Stream<T>; | ||
this.oil = NO_IL; | ||
@@ -557,3 +557,3 @@ } | ||
this.ins = ins; | ||
this.out = <Stream<T>> NO; | ||
this.out = NO as Stream<T>; | ||
this.passes = passes; | ||
@@ -569,3 +569,3 @@ } | ||
this.ins._remove(this); | ||
this.out = <Stream<T>> NO; | ||
this.out = NO as Stream<T>; | ||
} | ||
@@ -614,3 +614,3 @@ | ||
_c() { | ||
this.op.inner = <Stream<T>> NO; | ||
this.op.inner = NO as Stream<T>; | ||
this.op.less(); | ||
@@ -630,5 +630,5 @@ } | ||
this.ins = ins; | ||
this.out = <Stream<T>> NO; | ||
this.out = NO as Stream<T>; | ||
this.open = true; | ||
this.inner = <Stream<T>> NO; | ||
this.inner = NO as Stream<T>; | ||
this.il = NO_IL; | ||
@@ -640,3 +640,3 @@ } | ||
this.open = true; | ||
this.inner = <Stream<T>> NO; | ||
this.inner = NO as Stream<T>; | ||
this.il = NO_IL; | ||
@@ -649,5 +649,5 @@ this.ins._add(this); | ||
if (this.inner !== NO) this.inner._remove(this.il); | ||
this.out = <Stream<T>> NO; | ||
this.out = NO as Stream<T>; | ||
this.open = true; | ||
this.inner = <Stream<T>> NO; | ||
this.inner = NO as Stream<T>; | ||
this.il = NO_IL; | ||
@@ -692,3 +692,3 @@ } | ||
this.ins = ins; | ||
this.out = <Stream<R>> NO; | ||
this.out = NO as Stream<R>; | ||
this.f = f; | ||
@@ -707,3 +707,3 @@ this.acc = this.seed = seed; | ||
this.ins._remove(this); | ||
this.out = <Stream<R>> NO; | ||
this.out = NO as Stream<R>; | ||
this.acc = this.seed; | ||
@@ -744,5 +744,5 @@ } | ||
this.ins = ins; | ||
this.out = <Stream<T>> NO; | ||
this.out = NO as Stream<T>; | ||
this.has = false; | ||
this.val = <T> NO; | ||
this.val = NO as T; | ||
} | ||
@@ -758,4 +758,4 @@ | ||
this.ins._remove(this); | ||
this.out = <Stream<T>> NO; | ||
this.val = <T> NO; | ||
this.out = NO as Stream<T>; | ||
this.val = NO as T; | ||
} | ||
@@ -804,3 +804,3 @@ | ||
_c() { | ||
this.op.inner = <Stream<R>> NO; | ||
this.op.inner = NO as Stream<R>; | ||
this.op.less(); | ||
@@ -822,5 +822,5 @@ } | ||
this.ins = mapOp.ins; | ||
this.out = <Stream<R>> NO; | ||
this.out = NO as Stream<R>; | ||
this.mapOp = mapOp; | ||
this.inner = <Stream<R>> NO; | ||
this.inner = NO as Stream<R>; | ||
this.il = NO_IL; | ||
@@ -832,3 +832,3 @@ this.open = true; | ||
this.out = out; | ||
this.inner = <Stream<R>> NO; | ||
this.inner = NO as Stream<R>; | ||
this.il = NO_IL; | ||
@@ -842,4 +842,4 @@ this.open = true; | ||
if (this.inner !== NO) this.inner._remove(this.il); | ||
this.out = <Stream<R>> NO; | ||
this.inner = <Stream<R>> NO; | ||
this.out = NO as Stream<R>; | ||
this.inner = NO as Stream<R>; | ||
this.il = NO_IL; | ||
@@ -891,3 +891,3 @@ } | ||
this.ins = ins; | ||
this.out = <Stream<R>> NO; | ||
this.out = NO as Stream<R>; | ||
this.project = project; | ||
@@ -903,3 +903,3 @@ } | ||
this.ins._remove(this); | ||
this.out = <Stream<R>> NO; | ||
this.out = NO as Stream<R>; | ||
} | ||
@@ -953,3 +953,3 @@ | ||
this.ins = ins; | ||
this.out = <Stream<T>> NO; | ||
this.out = NO as Stream<T>; | ||
} | ||
@@ -964,3 +964,3 @@ | ||
this.ins._remove(this.out); | ||
this.out = <Stream<T>> NO; | ||
this.out = NO as Stream<T>; | ||
} | ||
@@ -977,3 +977,3 @@ } | ||
this.ins = ins; | ||
this.out = <Stream<T>> NO; | ||
this.out = NO as Stream<T>; | ||
this.fn = fn; | ||
@@ -989,3 +989,3 @@ } | ||
this.ins._remove(this); | ||
this.out = <Stream<T>> NO; | ||
this.out = NO as Stream<T>; | ||
} | ||
@@ -1025,3 +1025,3 @@ | ||
this.ins = ins; | ||
this.out = <Stream<T>> NO; | ||
this.out = NO as Stream<T>; | ||
this.val = val; | ||
@@ -1038,3 +1038,3 @@ } | ||
this.ins._remove(this.out); | ||
this.out = <Stream<T>> NO; | ||
this.out = NO as Stream<T>; | ||
} | ||
@@ -1052,3 +1052,3 @@ } | ||
this.ins = ins; | ||
this.out = <Stream<T>> NO; | ||
this.out = NO as Stream<T>; | ||
this.max = max; | ||
@@ -1070,3 +1070,3 @@ this.taken = 0; | ||
this.ins._remove(this); | ||
this.out = <Stream<T>> NO; | ||
this.out = NO as Stream<T>; | ||
} | ||
@@ -1102,2 +1102,4 @@ | ||
protected _stopID: any; | ||
protected _dl: InternalListener<T>; // the debug listener | ||
protected _d: boolean; // flag indicating the existence of the debug listener | ||
protected _target: Stream<T>; // imitation target if this Stream will imitate | ||
@@ -1107,6 +1109,8 @@ protected _err: any; | ||
constructor(producer?: InternalProducer<T>) { | ||
this._prod = producer || <InternalProducer<T>> NO; | ||
this._prod = producer || NO as InternalProducer<T>; | ||
this._ils = []; | ||
this._stopID = NO; | ||
this._target = <Stream<T>> NO; | ||
this._dl = NO as InternalListener<T>; | ||
this._d = false; | ||
this._target = NO as Stream<T>; | ||
this._err = NO; | ||
@@ -1118,2 +1122,3 @@ } | ||
const L = a.length; | ||
if (this._d) this._dl._n(t); | ||
if (L == 1) a[0]._n(t); else { | ||
@@ -1131,2 +1136,3 @@ const b = copy(a); | ||
this._x(); | ||
if (this._d) this._dl._e(err); | ||
if (L == 1) a[0]._e(err); else { | ||
@@ -1142,2 +1148,3 @@ const b = copy(a); | ||
this._x(); | ||
if (this._d) this._dl._c(); | ||
if (L == 1) a[0]._c(); else { | ||
@@ -1212,9 +1219,9 @@ const b = copy(a); | ||
return true; | ||
} else if ((<OutSender<any>><any>x).out === this) { | ||
} else if ((x as any as OutSender<any>).out === this) { | ||
return true; | ||
} else if ((<OutSender<any>><any>x).out && (<OutSender<any>><any>x).out !== NO) { | ||
return this._hasNoSinks((<OutSender<any>><any>x).out, trace.concat(x)); | ||
} else if ((<Stream<any>>x)._ils) { | ||
for (let i = 0, N = (<Stream<any>>x)._ils.length; i < N; i++) { | ||
if (!this._hasNoSinks((<Stream<any>>x)._ils[i], trace.concat(x))) { | ||
} else if ((x as any as OutSender<any>).out && (x as any as OutSender<any>).out !== NO) { | ||
return this._hasNoSinks((x as any as OutSender<any>).out, trace.concat(x)); | ||
} else if ((x as Stream<any>)._ils) { | ||
for (let i = 0, N = (x as Stream<any>)._ils.length; i < N; i++) { | ||
if (!this._hasNoSinks((x as Stream<any>)._ils[i], trace.concat(x))) { | ||
return false; | ||
@@ -1245,6 +1252,6 @@ } | ||
} | ||
(<InternalListener<T>> (<any> listener))._n = listener.next; | ||
(<InternalListener<T>> (<any> listener))._e = listener.error; | ||
(<InternalListener<T>> (<any> listener))._c = listener.complete; | ||
this._add(<InternalListener<T>> (<any> listener)); | ||
(listener as InternalListener<T> & Listener<T>)._n = listener.next; | ||
(listener as InternalListener<T> & Listener<T>)._e = listener.error; | ||
(listener as InternalListener<T> & Listener<T>)._c = listener.complete; | ||
this._add(listener as InternalListener<T> & Listener<T>); | ||
} | ||
@@ -1258,3 +1265,3 @@ | ||
removeListener(listener: Listener<T>): void { | ||
this._remove(<InternalListener<T>> (<any> listener)); | ||
this._remove(listener as InternalListener<T> & Listener<T>); | ||
} | ||
@@ -1278,3 +1285,3 @@ | ||
} | ||
return new Stream(<InternalProducer<T>> (<any> producer)); | ||
return new Stream(producer as InternalProducer<T> & Producer<T>); | ||
} | ||
@@ -1294,3 +1301,3 @@ | ||
} | ||
return new MemoryStream<T>(<InternalProducer<T>> (<any> producer)); | ||
return new MemoryStream<T>(producer as InternalProducer<T> & Producer<T>); | ||
} | ||
@@ -1377,3 +1384,3 @@ | ||
static of<T>(...items: Array<T>): Stream<T> { | ||
return Stream.fromArray(items); | ||
return Stream.fromArray<T>(items); | ||
} | ||
@@ -1397,3 +1404,3 @@ | ||
static fromArray<T>(array: Array<T>): Stream<T> { | ||
return new Stream<T>(new FromArrayProducer(array)); | ||
return new Stream<T>(new FromArrayProducer<T>(array)); | ||
} | ||
@@ -1418,3 +1425,3 @@ | ||
static fromPromise<T>(promise: Promise<T>): Stream<T> { | ||
return new Stream<T>(new FromPromiseProducer(promise)); | ||
return new Stream<T>(new FromPromiseProducer<T>(promise)); | ||
} | ||
@@ -1464,6 +1471,5 @@ | ||
*/ | ||
static merge: MergeSignature = <MergeSignature> | ||
function merge(...streams: Array<Stream<any>>): Stream<any> { | ||
return new Stream<any>(new MergeProducer(streams)); | ||
}; | ||
static merge: MergeSignature = function merge(...streams: Array<Stream<any>>) { | ||
return new Stream<any>(new MergeProducer(streams)); | ||
} as MergeSignature; | ||
@@ -1495,6 +1501,5 @@ /** | ||
*/ | ||
static combine: CombineSignature = <CombineSignature> | ||
function combine(...streams: Array<Stream<any>>): Stream<Array<any>> { | ||
return new Stream<Array<any>>(new CombineProducer<any>(streams)); | ||
}; | ||
static combine: CombineSignature = function combine(...streams: Array<Stream<any>>) { | ||
return new Stream<Array<any>>(new CombineProducer<any>(streams)); | ||
} as CombineSignature; | ||
@@ -1505,22 +1510,22 @@ protected _map<U>(project: (t: T) => U): Stream<U> | MemoryStream<U> { | ||
if (p instanceof FilterOperator) { | ||
return new ctor<U>(new FilterMapOperator( | ||
(<FilterOperator<T>> p).passes, | ||
return new ctor<U>(new FilterMapOperator<T, U>( | ||
(p as FilterOperator<T>).passes, | ||
project, | ||
(<FilterOperator<T>> p).ins | ||
(p as FilterOperator<T>).ins | ||
)); | ||
} | ||
if (p instanceof FilterMapOperator) { | ||
return new ctor<U>(new FilterMapOperator( | ||
(<FilterMapOperator<T, T>> p).passes, | ||
compose2(project, (<FilterMapOperator<T, T>> p).project), | ||
(<FilterMapOperator<T, T>> p).ins | ||
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( | ||
compose2(project, (<MapOperator<T, T>> p).project), | ||
(<MapOperator<T, T>> p).ins | ||
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(project, this)); | ||
return new ctor<U>(new MapOperator<T, U>(project, this)); | ||
} | ||
@@ -1567,3 +1572,3 @@ | ||
const s = this.map(() => projectedValue); | ||
const op: Operator<T, U> = <Operator<T, U>> s._prod; | ||
const op: Operator<T, U> = s._prod as Operator<T, U>; | ||
op.type = op.type.replace('map', 'mapTo'); | ||
@@ -1596,8 +1601,8 @@ return s; | ||
if (p instanceof FilterOperator) { | ||
return new Stream<T>(new FilterOperator( | ||
and((<FilterOperator<T>> p).passes, passes), | ||
(<FilterOperator<T>> p).ins | ||
return new Stream<T>(new FilterOperator<T>( | ||
and((p as FilterOperator<T>).passes, passes), | ||
(p as FilterOperator<T>).ins | ||
)); | ||
} | ||
return new Stream<T>(new FilterOperator(passes, this)); | ||
return new Stream<T>(new FilterOperator<T>(passes, this)); | ||
} | ||
@@ -1622,3 +1627,3 @@ | ||
take(amount: number): Stream<T> { | ||
return new (this.ctor())<T>(new TakeOperator(amount, this)); | ||
return new (this.ctor())<T>(new TakeOperator<T>(amount, this)); | ||
} | ||
@@ -1644,3 +1649,3 @@ | ||
drop(amount: number): Stream<T> { | ||
return new Stream<T>(new DropOperator(amount, this)); | ||
return new Stream<T>(new DropOperator<T>(amount, this)); | ||
} | ||
@@ -1663,3 +1668,3 @@ | ||
last(): Stream<T> { | ||
return new Stream<T>(new LastOperator(this)); | ||
return new Stream<T>(new LastOperator<T>(this)); | ||
} | ||
@@ -1684,3 +1689,3 @@ | ||
startWith(initial: T): MemoryStream<T> { | ||
return new MemoryStream<T>(new StartWithOperator(this, initial)); | ||
return new MemoryStream<T>(new StartWithOperator<T>(this, initial)); | ||
} | ||
@@ -1708,3 +1713,3 @@ | ||
endWhen(other: Stream<any>): Stream<T> { | ||
return new (this.ctor())<T>(new EndWhenOperator(other, this)); | ||
return new (this.ctor())<T>(new EndWhenOperator<T>(other, this)); | ||
} | ||
@@ -1742,3 +1747,3 @@ | ||
fold<R>(accumulate: (acc: R, t: T) => R, seed: R): MemoryStream<R> { | ||
return new MemoryStream<R>(new FoldOperator(accumulate, seed, this)); | ||
return new MemoryStream<R>(new FoldOperator<T, R>(accumulate, seed, this)); | ||
} | ||
@@ -1770,3 +1775,3 @@ | ||
replaceError(replace: (err: any) => Stream<T>): Stream<T> { | ||
return new (this.ctor())<T>(new ReplaceErrorOperator(replace, this)); | ||
return new (this.ctor())<T>(new ReplaceErrorOperator<T>(replace, this)); | ||
} | ||
@@ -1801,7 +1806,7 @@ | ||
const p = this._prod; | ||
return <T> <any> new Stream<R>( | ||
return new Stream<R>( | ||
p instanceof MapOperator && !(p instanceof FilterMapOperator) ? | ||
new MapFlattenOperator(<MapOperator<any, Stream<R>>> <any> p) : | ||
new FlattenOperator(<Stream<Stream<R>>> <any> this) | ||
); | ||
new MapFlattenOperator(p as MapOperator<any, Stream<R>>) : | ||
new FlattenOperator(this as any as Stream<Stream<R>>) | ||
) as T & Stream<R>; | ||
} | ||
@@ -1832,3 +1837,3 @@ | ||
remember(): MemoryStream<T> { | ||
return new MemoryStream<T>(new RememberOperator(this)); | ||
return new MemoryStream<T>(new RememberOperator<T>(this)); | ||
} | ||
@@ -1863,3 +1868,3 @@ | ||
debug(labelOrSpy?: string | ((t: T) => void)): Stream<T> { | ||
return new (this.ctor())<T>(new DebugOperator(labelOrSpy, this)); | ||
return new (this.ctor())<T>(new DebugOperator<T>(labelOrSpy, this)); | ||
} | ||
@@ -1982,2 +1987,35 @@ | ||
} | ||
/** | ||
* Adds a "debug" listener to the stream. There can only be one debug | ||
* listener, that's why this is 'setDebugListener'. To remove the debug | ||
* listener, just call setDebugListener(null). | ||
* | ||
* A debug listener is like any other listener. The only difference is that a | ||
* debug listener is "stealthy": its presence/absence does not trigger the | ||
* start/stop of the stream (or the producer inside the stream). This is | ||
* useful so you can inspect what is going on without changing the behavior | ||
* of the program. If you have an idle stream and you add a normal listener to | ||
* it, the stream will start executing. But if you set a debug listener on an | ||
* idle stream, it won't start executing (not until the first normal listener | ||
* is added). | ||
* | ||
* As the name indicates, we don't recommend using this method to build app | ||
* logic. In fact, in most cases the debug operator works just fine. Only use | ||
* this one if you know what you're doing. | ||
* | ||
* @param {Listener<T>} listener | ||
*/ | ||
setDebugListener(listener: Listener<T>) { | ||
if (!listener) { | ||
this._d = false; | ||
this._dl = NO as InternalListener<T>; | ||
} else { | ||
this._d = true; | ||
(listener as InternalListener<T> & Listener<T>)._n = listener.next; | ||
(listener as InternalListener<T> & Listener<T>)._e = listener.error; | ||
(listener as InternalListener<T> & Listener<T>)._c = listener.complete; | ||
this._dl = listener as InternalListener<T> & Listener<T>; | ||
} | ||
} | ||
} | ||
@@ -2014,19 +2052,19 @@ | ||
map<U>(project: (t: T) => U): MemoryStream<U> { | ||
return <MemoryStream<U>> this._map(project); | ||
return this._map(project) as MemoryStream<U>; | ||
} | ||
mapTo<U>(projectedValue: U): MemoryStream<U> { | ||
return <MemoryStream<U>> super.mapTo(projectedValue); | ||
return super.mapTo(projectedValue) as MemoryStream<U>; | ||
} | ||
take(amount: number): MemoryStream<T> { | ||
return <MemoryStream<T>> super.take(amount); | ||
return super.take(amount) as MemoryStream<T>; | ||
} | ||
endWhen(other: Stream<any>): MemoryStream<T> { | ||
return <MemoryStream<T>> super.endWhen(other); | ||
return super.endWhen(other) as MemoryStream<T>; | ||
} | ||
replaceError(replace: (err: any) => Stream<T>): MemoryStream<T> { | ||
return <MemoryStream<T>> super.replaceError(replace); | ||
return super.replaceError(replace) as MemoryStream<T>; | ||
} | ||
@@ -2039,3 +2077,3 @@ | ||
debug(labelOrSpy?: string | ((t: T) => void)): MemoryStream<T> { | ||
return <MemoryStream<T>> super.debug(labelOrSpy); | ||
return super.debug(labelOrSpy) as MemoryStream<T>; | ||
} | ||
@@ -2042,0 +2080,0 @@ } |
@@ -21,3 +21,3 @@ import {Operator, Stream} from '../core'; | ||
this.out = null; | ||
this.v = <any> empty; | ||
this.v = empty as any; | ||
} | ||
@@ -34,3 +34,3 @@ | ||
if (v !== empty && this.isEq(t, v)) return; | ||
this.v = Array.isArray(t) ? <T> <any> (<Array<any>> <any> t).slice() : t; | ||
this.v = Array.isArray(t) ? (t as any as Array<any>).slice() as any as T : t; | ||
u._n(t); | ||
@@ -37,0 +37,0 @@ } |
@@ -33,3 +33,3 @@ /// <reference path="../../typings/globals/node/index.d.ts" /> | ||
this.listener = (...args: Array<any>) => { | ||
return (args.length > 1) ? out._n(args) : out._n(args[0]); | ||
return (args.length > 1) ? out._n(args) : out._n(args[0]); | ||
}; | ||
@@ -46,3 +46,3 @@ this.node.addListener(this.eventName, this.listener); | ||
function isEmitter(element: any): boolean { | ||
return element.emit && element.addListener; | ||
return element.emit && element.addListener; | ||
} | ||
@@ -138,6 +138,6 @@ | ||
if (isEmitter(element)) { | ||
return new Stream<any>(new NodeEventProducer(<EventEmitter> element, eventName)); | ||
return new Stream<any>(new NodeEventProducer(element as EventEmitter, eventName)); | ||
} else { | ||
return new Stream<Event>(new DOMEventProducer(<EventTarget> element, eventName, useCapture)); | ||
return new Stream<Event>(new DOMEventProducer(element as EventTarget, eventName, useCapture)); | ||
} | ||
} |
@@ -314,2 +314,39 @@ /// <reference path="../typings/globals/mocha/index.d.ts" /> | ||
describe('setDebugListener', () => { | ||
it('should not trigger a stream execution', (done) => { | ||
const stream = xs.of(1, 2, 3); | ||
const listener: Listener<number> = { | ||
next: () => done('should not be called'), | ||
error: () => done('should not be called'), | ||
complete: () => done('should not be called'), | ||
}; | ||
stream.setDebugListener(listener); | ||
setTimeout(() => done(), 200); | ||
}); | ||
it('should spy an existing stream execution', (done) => { | ||
const stream = xs.periodic(200).take(8); | ||
const listener = { next: () => { }, error: () => { }, complete: () => { } }; | ||
const expected = [0, 1, 2]; | ||
const debugListener: Listener<number> = { | ||
next: (x: number) => { | ||
assert.strictEqual(x, expected.shift()); | ||
}, | ||
error: () => done('should not be called'), | ||
complete: () => done('should not be called') | ||
}; | ||
stream.setDebugListener(debugListener); | ||
stream.addListener(listener); | ||
setTimeout(() => stream.removeListener(listener), 700); | ||
setTimeout(() => { | ||
assert.strictEqual(expected.length, 0); | ||
done(); | ||
}, 1000); | ||
}); | ||
}); | ||
describe('addListener', () => { | ||
@@ -316,0 +353,0 @@ it('throws a helpful error if you forget the next function', (done) => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
858961
16559
969