Comparing version 2.4.0 to 2.4.1
@@ -0,1 +1,12 @@ | ||
<a name="2.4.1"></a> | ||
## [2.4.1](https://github.com/staltz/xstream/compare/v2.4.0...v2.4.1) (2016-05-13) | ||
### Bug Fixes | ||
* **operators:** add safety check against nulls for next() etc ([5d433c3](https://github.com/staltz/xstream/commit/5d433c3)) | ||
* **operators:** improve *type* metadata for operators with fusion ([fb1e81c](https://github.com/staltz/xstream/commit/fb1e81c)) | ||
<a name="2.4.0"></a> | ||
@@ -2,0 +13,0 @@ # [2.4.0](https://github.com/staltz/xstream/compare/v2.3.0...v2.4.0) (2016-05-12) |
@@ -264,14 +264,2 @@ export interface InternalListener<T> { | ||
} | ||
export declare class MapToOperator<T, R> implements Operator<T, R> { | ||
val: R; | ||
ins: Stream<T>; | ||
type: string; | ||
private out; | ||
constructor(val: R, ins: Stream<T>); | ||
_start(out: Stream<R>): void; | ||
_stop(): void; | ||
_n(t: T): void; | ||
_e(err: any): void; | ||
_c(): void; | ||
} | ||
export declare class ReplaceErrorOperator<T> implements Operator<T, T> { | ||
@@ -710,3 +698,3 @@ fn: (err: any) => Stream<T>; | ||
* @param {Function} replace A function of type `(err) => Stream` that takes | ||
* the error that occured on the input stream or on the previous replacement | ||
* the error that occurred on the input stream or on the previous replacement | ||
* stream and returns a new stream. The output stream will imitate the stream | ||
@@ -713,0 +701,0 @@ * that this function returns. |
272
core.js
@@ -212,10 +212,19 @@ "use strict"; | ||
MergeProducer.prototype._n = function (t) { | ||
this.out._n(t); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._n(t); | ||
}; | ||
MergeProducer.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._e(err); | ||
}; | ||
MergeProducer.prototype._c = function () { | ||
if (--this.ac === 0) { | ||
this.out._c(); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._c(); | ||
} | ||
@@ -264,8 +273,12 @@ }; | ||
DebugOperator.prototype._n = function (t) { | ||
if (this.spy) { | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
var spy = this.spy; | ||
if (spy) { | ||
try { | ||
this.spy(t); | ||
spy(t); | ||
} | ||
catch (e) { | ||
this.out._e(e); | ||
u._e(e); | ||
} | ||
@@ -276,9 +289,15 @@ } | ||
} | ||
this.out._n(t); | ||
u._n(t); | ||
}; | ||
DebugOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._e(err); | ||
}; | ||
DebugOperator.prototype._c = function () { | ||
this.out._c(); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._c(); | ||
}; | ||
@@ -306,10 +325,19 @@ return DebugOperator; | ||
DropOperator.prototype._n = function (t) { | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
if (this.dropped++ >= this.max) | ||
this.out._n(t); | ||
u._n(t); | ||
}; | ||
DropOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._e(err); | ||
}; | ||
DropOperator.prototype._c = function () { | ||
this.out._c(); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._c(); | ||
}; | ||
@@ -356,9 +384,18 @@ return DropOperator; | ||
EndWhenOperator.prototype.end = function () { | ||
this.out._c(); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._c(); | ||
}; | ||
EndWhenOperator.prototype._n = function (t) { | ||
this.out._n(t); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._n(t); | ||
}; | ||
EndWhenOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._e(err); | ||
}; | ||
@@ -387,15 +424,24 @@ EndWhenOperator.prototype._c = function () { | ||
FilterOperator.prototype._n = function (t) { | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
try { | ||
if (this.passes(t)) | ||
this.out._n(t); | ||
u._n(t); | ||
} | ||
catch (e) { | ||
this.out._e(e); | ||
u._e(e); | ||
} | ||
}; | ||
FilterOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._e(err); | ||
}; | ||
FilterOperator.prototype._c = function () { | ||
this.out._c(); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._c(); | ||
}; | ||
@@ -439,11 +485,20 @@ return FilterOperator; | ||
if (--this.active === 0) { | ||
this.out._c(); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._c(); | ||
} | ||
}; | ||
FlattenConcOperator.prototype._n = function (s) { | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
this.active++; | ||
s._add(new FCIL(this.out, this)); | ||
s._add(new FCIL(u, this)); | ||
}; | ||
FlattenConcOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._e(err); | ||
}; | ||
@@ -494,13 +549,22 @@ FlattenConcOperator.prototype._c = function () { | ||
FlattenOperator.prototype.less = function () { | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
if (!this.open && !this.inner) | ||
this.out._c(); | ||
u._c(); | ||
}; | ||
FlattenOperator.prototype._n = function (s) { | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
var _a = this, inner = _a.inner, il = _a.il; | ||
if (inner && il) | ||
inner._remove(il); | ||
(this.inner = s)._add(this.il = new FIL(this.out, this)); | ||
(this.inner = s)._add(this.il = new FIL(u, this)); | ||
}; | ||
FlattenOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._e(err); | ||
}; | ||
@@ -534,14 +598,23 @@ FlattenOperator.prototype._c = function () { | ||
FoldOperator.prototype._n = function (t) { | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
try { | ||
this.out._n(this.acc = this.f(this.acc, t)); | ||
u._n(this.acc = this.f(this.acc, t)); | ||
} | ||
catch (e) { | ||
this.out._e(e); | ||
u._e(e); | ||
} | ||
}; | ||
FoldOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._e(err); | ||
}; | ||
FoldOperator.prototype._c = function () { | ||
this.out._c(); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._c(); | ||
}; | ||
@@ -574,12 +647,17 @@ return FoldOperator; | ||
LastOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._e(err); | ||
}; | ||
LastOperator.prototype._c = function () { | ||
var out = this.out; | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
if (this.has) { | ||
out._n(this.val); | ||
out._c(); | ||
u._n(this.val); | ||
u._c(); | ||
} | ||
else { | ||
out._e('TODO show proper error'); | ||
u._e('TODO show proper error'); | ||
} | ||
@@ -609,5 +687,5 @@ }; | ||
this.mapOp = mapOp; | ||
this.type = 'map+flattenConcurrently'; | ||
this.active = 1; // number of outers and inners that have not yet ended | ||
this.out = null; | ||
this.type = mapOp.type + "+flattenConcurrently"; | ||
this.ins = mapOp.ins; | ||
@@ -626,16 +704,25 @@ } | ||
if (--this.active === 0) { | ||
this.out._c(); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._c(); | ||
} | ||
}; | ||
MapFlattenConcOperator.prototype._n = function (v) { | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
this.active++; | ||
try { | ||
this.mapOp.project(v)._add(new MFCIL(this.out, this)); | ||
this.mapOp.project(v)._add(new MFCIL(u, this)); | ||
} | ||
catch (e) { | ||
this.out._e(e); | ||
u._e(e); | ||
} | ||
}; | ||
MapFlattenConcOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._e(err); | ||
}; | ||
@@ -668,3 +755,2 @@ MapFlattenConcOperator.prototype._c = function () { | ||
this.mapOp = mapOp; | ||
this.type = 'map+flatten'; | ||
this.inner = null; // Current inner Stream | ||
@@ -674,2 +760,3 @@ this.il = null; // Current inner InternalListener | ||
this.out = null; | ||
this.type = mapOp.type + "+flatten"; | ||
this.ins = mapOp.ins; | ||
@@ -690,6 +777,12 @@ } | ||
if (!this.open && !this.inner) { | ||
this.out._c(); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._c(); | ||
} | ||
}; | ||
MapFlattenOperator.prototype._n = function (v) { | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
var _a = this, inner = _a.inner, il = _a.il; | ||
@@ -699,10 +792,13 @@ if (inner && il) | ||
try { | ||
(this.inner = this.mapOp.project(v))._add(this.il = new MFIL(this.out, this)); | ||
(this.inner = this.mapOp.project(v))._add(this.il = new MFIL(u, this)); | ||
} | ||
catch (e) { | ||
this.out._e(e); | ||
u._e(e); | ||
} | ||
}; | ||
MapFlattenOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._e(err); | ||
}; | ||
@@ -732,14 +828,23 @@ MapFlattenOperator.prototype._c = function () { | ||
MapOperator.prototype._n = function (t) { | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
try { | ||
this.out._n(this.project(t)); | ||
u._n(this.project(t)); | ||
} | ||
catch (e) { | ||
this.out._e(e); | ||
u._e(e); | ||
} | ||
}; | ||
MapOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._e(err); | ||
}; | ||
MapOperator.prototype._c = function () { | ||
this.out._c(); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._c(); | ||
}; | ||
@@ -765,29 +870,2 @@ return 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 () { | ||
@@ -809,5 +887,11 @@ function ReplaceErrorOperator(fn, ins) { | ||
ReplaceErrorOperator.prototype._n = function (t) { | ||
this.out._n(t); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._n(t); | ||
}; | ||
ReplaceErrorOperator.prototype._e = function (err) { | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
try { | ||
@@ -818,7 +902,10 @@ this.ins._remove(this); | ||
catch (e) { | ||
this.out._e(e); | ||
u._e(e); | ||
} | ||
}; | ||
ReplaceErrorOperator.prototype._c = function () { | ||
this.out._c(); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._c(); | ||
}; | ||
@@ -865,11 +952,11 @@ return ReplaceErrorOperator; | ||
TakeOperator.prototype._n = function (t) { | ||
var out = this.out; | ||
if (!out) | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
if (this.taken++ < this.max - 1) { | ||
out._n(t); | ||
u._n(t); | ||
} | ||
else { | ||
out._n(t); | ||
out._c(); | ||
u._n(t); | ||
u._c(); | ||
this._stop(); | ||
@@ -879,12 +966,12 @@ } | ||
TakeOperator.prototype._e = function (err) { | ||
var out = this.out; | ||
if (!out) | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
out._e(err); | ||
u._e(err); | ||
}; | ||
TakeOperator.prototype._c = function () { | ||
var out = this.out; | ||
if (!out) | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
out._c(); | ||
u._c(); | ||
}; | ||
@@ -1274,3 +1361,6 @@ return TakeOperator; | ||
Stream.prototype.mapTo = function (projectedValue) { | ||
return new Stream(new MapToOperator(projectedValue, this)); | ||
var s = this.map(function () { return projectedValue; }); | ||
var op = s._prod; | ||
op.type = op.type.replace('map', 'mapTo'); | ||
return s; | ||
}; | ||
@@ -1449,3 +1539,3 @@ /** | ||
* @param {Function} replace A function of type `(err) => Stream` that takes | ||
* the error that occured on the input stream or on the previous replacement | ||
* the error that occurred on the input stream or on the previous replacement | ||
* stream and returns a new stream. The output stream will imitate the stream | ||
@@ -1452,0 +1542,0 @@ * that this function returns. |
@@ -213,10 +213,19 @@ (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){ | ||
MergeProducer.prototype._n = function (t) { | ||
this.out._n(t); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._n(t); | ||
}; | ||
MergeProducer.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._e(err); | ||
}; | ||
MergeProducer.prototype._c = function () { | ||
if (--this.ac === 0) { | ||
this.out._c(); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._c(); | ||
} | ||
@@ -265,8 +274,12 @@ }; | ||
DebugOperator.prototype._n = function (t) { | ||
if (this.spy) { | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
var spy = this.spy; | ||
if (spy) { | ||
try { | ||
this.spy(t); | ||
spy(t); | ||
} | ||
catch (e) { | ||
this.out._e(e); | ||
u._e(e); | ||
} | ||
@@ -277,9 +290,15 @@ } | ||
} | ||
this.out._n(t); | ||
u._n(t); | ||
}; | ||
DebugOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._e(err); | ||
}; | ||
DebugOperator.prototype._c = function () { | ||
this.out._c(); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._c(); | ||
}; | ||
@@ -307,10 +326,19 @@ return DebugOperator; | ||
DropOperator.prototype._n = function (t) { | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
if (this.dropped++ >= this.max) | ||
this.out._n(t); | ||
u._n(t); | ||
}; | ||
DropOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._e(err); | ||
}; | ||
DropOperator.prototype._c = function () { | ||
this.out._c(); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._c(); | ||
}; | ||
@@ -357,9 +385,18 @@ return DropOperator; | ||
EndWhenOperator.prototype.end = function () { | ||
this.out._c(); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._c(); | ||
}; | ||
EndWhenOperator.prototype._n = function (t) { | ||
this.out._n(t); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._n(t); | ||
}; | ||
EndWhenOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._e(err); | ||
}; | ||
@@ -388,15 +425,24 @@ EndWhenOperator.prototype._c = function () { | ||
FilterOperator.prototype._n = function (t) { | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
try { | ||
if (this.passes(t)) | ||
this.out._n(t); | ||
u._n(t); | ||
} | ||
catch (e) { | ||
this.out._e(e); | ||
u._e(e); | ||
} | ||
}; | ||
FilterOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._e(err); | ||
}; | ||
FilterOperator.prototype._c = function () { | ||
this.out._c(); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._c(); | ||
}; | ||
@@ -440,11 +486,20 @@ return FilterOperator; | ||
if (--this.active === 0) { | ||
this.out._c(); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._c(); | ||
} | ||
}; | ||
FlattenConcOperator.prototype._n = function (s) { | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
this.active++; | ||
s._add(new FCIL(this.out, this)); | ||
s._add(new FCIL(u, this)); | ||
}; | ||
FlattenConcOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._e(err); | ||
}; | ||
@@ -495,13 +550,22 @@ FlattenConcOperator.prototype._c = function () { | ||
FlattenOperator.prototype.less = function () { | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
if (!this.open && !this.inner) | ||
this.out._c(); | ||
u._c(); | ||
}; | ||
FlattenOperator.prototype._n = function (s) { | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
var _a = this, inner = _a.inner, il = _a.il; | ||
if (inner && il) | ||
inner._remove(il); | ||
(this.inner = s)._add(this.il = new FIL(this.out, this)); | ||
(this.inner = s)._add(this.il = new FIL(u, this)); | ||
}; | ||
FlattenOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._e(err); | ||
}; | ||
@@ -535,14 +599,23 @@ FlattenOperator.prototype._c = function () { | ||
FoldOperator.prototype._n = function (t) { | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
try { | ||
this.out._n(this.acc = this.f(this.acc, t)); | ||
u._n(this.acc = this.f(this.acc, t)); | ||
} | ||
catch (e) { | ||
this.out._e(e); | ||
u._e(e); | ||
} | ||
}; | ||
FoldOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._e(err); | ||
}; | ||
FoldOperator.prototype._c = function () { | ||
this.out._c(); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._c(); | ||
}; | ||
@@ -575,12 +648,17 @@ return FoldOperator; | ||
LastOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._e(err); | ||
}; | ||
LastOperator.prototype._c = function () { | ||
var out = this.out; | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
if (this.has) { | ||
out._n(this.val); | ||
out._c(); | ||
u._n(this.val); | ||
u._c(); | ||
} | ||
else { | ||
out._e('TODO show proper error'); | ||
u._e('TODO show proper error'); | ||
} | ||
@@ -610,5 +688,5 @@ }; | ||
this.mapOp = mapOp; | ||
this.type = 'map+flattenConcurrently'; | ||
this.active = 1; | ||
this.out = null; | ||
this.type = mapOp.type + "+flattenConcurrently"; | ||
this.ins = mapOp.ins; | ||
@@ -627,16 +705,25 @@ } | ||
if (--this.active === 0) { | ||
this.out._c(); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._c(); | ||
} | ||
}; | ||
MapFlattenConcOperator.prototype._n = function (v) { | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
this.active++; | ||
try { | ||
this.mapOp.project(v)._add(new MFCIL(this.out, this)); | ||
this.mapOp.project(v)._add(new MFCIL(u, this)); | ||
} | ||
catch (e) { | ||
this.out._e(e); | ||
u._e(e); | ||
} | ||
}; | ||
MapFlattenConcOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._e(err); | ||
}; | ||
@@ -669,3 +756,2 @@ MapFlattenConcOperator.prototype._c = function () { | ||
this.mapOp = mapOp; | ||
this.type = 'map+flatten'; | ||
this.inner = null; | ||
@@ -675,2 +761,3 @@ this.il = null; | ||
this.out = null; | ||
this.type = mapOp.type + "+flatten"; | ||
this.ins = mapOp.ins; | ||
@@ -691,6 +778,12 @@ } | ||
if (!this.open && !this.inner) { | ||
this.out._c(); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._c(); | ||
} | ||
}; | ||
MapFlattenOperator.prototype._n = function (v) { | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
var _a = this, inner = _a.inner, il = _a.il; | ||
@@ -700,10 +793,13 @@ if (inner && il) | ||
try { | ||
(this.inner = this.mapOp.project(v))._add(this.il = new MFIL(this.out, this)); | ||
(this.inner = this.mapOp.project(v))._add(this.il = new MFIL(u, this)); | ||
} | ||
catch (e) { | ||
this.out._e(e); | ||
u._e(e); | ||
} | ||
}; | ||
MapFlattenOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._e(err); | ||
}; | ||
@@ -733,14 +829,23 @@ MapFlattenOperator.prototype._c = function () { | ||
MapOperator.prototype._n = function (t) { | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
try { | ||
this.out._n(this.project(t)); | ||
u._n(this.project(t)); | ||
} | ||
catch (e) { | ||
this.out._e(e); | ||
u._e(e); | ||
} | ||
}; | ||
MapOperator.prototype._e = function (err) { | ||
this.out._e(err); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._e(err); | ||
}; | ||
MapOperator.prototype._c = function () { | ||
this.out._c(); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._c(); | ||
}; | ||
@@ -766,29 +871,2 @@ return 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 () { | ||
@@ -810,5 +888,11 @@ function ReplaceErrorOperator(fn, ins) { | ||
ReplaceErrorOperator.prototype._n = function (t) { | ||
this.out._n(t); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._n(t); | ||
}; | ||
ReplaceErrorOperator.prototype._e = function (err) { | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
try { | ||
@@ -819,7 +903,10 @@ this.ins._remove(this); | ||
catch (e) { | ||
this.out._e(e); | ||
u._e(e); | ||
} | ||
}; | ||
ReplaceErrorOperator.prototype._c = function () { | ||
this.out._c(); | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
u._c(); | ||
}; | ||
@@ -866,11 +953,11 @@ return ReplaceErrorOperator; | ||
TakeOperator.prototype._n = function (t) { | ||
var out = this.out; | ||
if (!out) | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
if (this.taken++ < this.max - 1) { | ||
out._n(t); | ||
u._n(t); | ||
} | ||
else { | ||
out._n(t); | ||
out._c(); | ||
u._n(t); | ||
u._c(); | ||
this._stop(); | ||
@@ -880,12 +967,12 @@ } | ||
TakeOperator.prototype._e = function (err) { | ||
var out = this.out; | ||
if (!out) | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
out._e(err); | ||
u._e(err); | ||
}; | ||
TakeOperator.prototype._c = function () { | ||
var out = this.out; | ||
if (!out) | ||
var u = this.out; | ||
if (!u) | ||
return; | ||
out._c(); | ||
u._c(); | ||
}; | ||
@@ -1073,3 +1160,6 @@ return TakeOperator; | ||
Stream.prototype.mapTo = function (projectedValue) { | ||
return new Stream(new MapToOperator(projectedValue, this)); | ||
var s = this.map(function () { return projectedValue; }); | ||
var op = s._prod; | ||
op.type = op.type.replace('map', 'mapTo'); | ||
return s; | ||
}; | ||
@@ -1076,0 +1166,0 @@ |
@@ -1,1 +0,1 @@ | ||
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.xstream=f()}})(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){"use strict";var __extends=this&&this.__extends||function(d,b){for(var p in b)if(b.hasOwnProperty(p))d[p]=b[p];function __(){this.constructor=d}d.prototype=b===null?Object.create(b):(__.prototype=b.prototype,new __)};var empty={};function noop(){}function copy(a){var l=a.length;var b=Array(l);for(var i=0;i<l;++i){b[i]=a[i]}return b}exports.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)}); | ||
(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){var u=this.out;if(!u)return;u._n(t)};MergeProducer.prototype._e=function(err){var u=this.out;if(!u)return;u._e(err)};MergeProducer.prototype._c=function(){if(--this.ac===0){var u=this.out;if(!u)return;u._c()}};return MergeProducer}();exports.MergeProducer=MergeProducer;var 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){var u=this.out;if(!u)return;var spy=this.spy;if(spy){try{spy(t)}catch(e){u._e(e)}}else{console.log(t)}u._n(t)};DebugOperator.prototype._e=function(err){var u=this.out;if(!u)return;u._e(err)};DebugOperator.prototype._c=function(){var u=this.out;if(!u)return;u._c()};return DebugOperator}();exports.DebugOperator=DebugOperator;var DropOperator=function(){function DropOperator(max,ins){this.max=max;this.ins=ins;this.type="drop";this.out=null;this.dropped=0}DropOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};DropOperator.prototype._stop=function(){this.ins._remove(this);this.out=null;this.dropped=0};DropOperator.prototype._n=function(t){var u=this.out;if(!u)return;if(this.dropped++>=this.max)u._n(t)};DropOperator.prototype._e=function(err){var u=this.out;if(!u)return;u._e(err)};DropOperator.prototype._c=function(){var u=this.out;if(!u)return;u._c()};return DropOperator}();exports.DropOperator=DropOperator;var OtherIL=function(){function OtherIL(out,op){this.out=out;this.op=op}OtherIL.prototype._n=function(t){this.op.end()};OtherIL.prototype._e=function(err){this.out._e(err)};OtherIL.prototype._c=function(){this.op.end()};return OtherIL}();var EndWhenOperator=function(){function EndWhenOperator(o,ins){this.o=o;this.ins=ins;this.type="endWhen";this.out=null;this.oil=exports.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(){var u=this.out;if(!u)return;u._c()};EndWhenOperator.prototype._n=function(t){var u=this.out;if(!u)return;u._n(t)};EndWhenOperator.prototype._e=function(err){var u=this.out;if(!u)return;u._e(err)};EndWhenOperator.prototype._c=function(){this.end()};return EndWhenOperator}();exports.EndWhenOperator=EndWhenOperator;var FilterOperator=function(){function FilterOperator(passes,ins){this.passes=passes;this.ins=ins;this.type="filter";this.out=null}FilterOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};FilterOperator.prototype._stop=function(){this.ins._remove(this);this.out=null};FilterOperator.prototype._n=function(t){var u=this.out;if(!u)return;try{if(this.passes(t))u._n(t)}catch(e){u._e(e)}};FilterOperator.prototype._e=function(err){var u=this.out;if(!u)return;u._e(err)};FilterOperator.prototype._c=function(){var u=this.out;if(!u)return;u._c()};return FilterOperator}();exports.FilterOperator=FilterOperator;var 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){var u=this.out;if(!u)return;u._c()}};FlattenConcOperator.prototype._n=function(s){var u=this.out;if(!u)return;this.active++;s._add(new FCIL(u,this))};FlattenConcOperator.prototype._e=function(err){var u=this.out;if(!u)return;u._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(){var u=this.out;if(!u)return;if(!this.open&&!this.inner)u._c()};FlattenOperator.prototype._n=function(s){var u=this.out;if(!u)return;var _a=this,inner=_a.inner,il=_a.il;if(inner&&il)inner._remove(il);(this.inner=s)._add(this.il=new FIL(u,this))};FlattenOperator.prototype._e=function(err){var u=this.out;if(!u)return;u._e(err)};FlattenOperator.prototype._c=function(){this.open=false;this.less()};return FlattenOperator}();exports.FlattenOperator=FlattenOperator;var FoldOperator=function(){function FoldOperator(f,seed,ins){this.f=f;this.seed=seed;this.ins=ins;this.type="fold";this.out=null;this.acc=seed}FoldOperator.prototype._start=function(out){this.out=out;out._n(this.acc);this.ins._add(this)};FoldOperator.prototype._stop=function(){this.ins._remove(this);this.out=null;this.acc=this.seed};FoldOperator.prototype._n=function(t){var u=this.out;if(!u)return;try{u._n(this.acc=this.f(this.acc,t))}catch(e){u._e(e)}};FoldOperator.prototype._e=function(err){var u=this.out;if(!u)return;u._e(err)};FoldOperator.prototype._c=function(){var u=this.out;if(!u)return;u._c()};return FoldOperator}();exports.FoldOperator=FoldOperator;var LastOperator=function(){function LastOperator(ins){this.ins=ins;this.type="last";this.out=null;this.has=false;this.val=empty}LastOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};LastOperator.prototype._stop=function(){this.ins._remove(this);this.out=null;this.has=false;this.val=empty};LastOperator.prototype._n=function(t){this.has=true;this.val=t};LastOperator.prototype._e=function(err){var u=this.out;if(!u)return;u._e(err)};LastOperator.prototype._c=function(){var u=this.out;if(!u)return;if(this.has){u._n(this.val);u._c()}else{u._e("TODO show proper error")}};return LastOperator}();exports.LastOperator=LastOperator;var 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.active=1;this.out=null;this.type=mapOp.type+"+flattenConcurrently";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){var u=this.out;if(!u)return;u._c()}};MapFlattenConcOperator.prototype._n=function(v){var u=this.out;if(!u)return;this.active++;try{this.mapOp.project(v)._add(new MFCIL(u,this))}catch(e){u._e(e)}};MapFlattenConcOperator.prototype._e=function(err){var u=this.out;if(!u)return;u._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.inner=null;this.il=null;this.open=true;this.out=null;this.type=mapOp.type+"+flatten";this.ins=mapOp.ins}MapFlattenOperator.prototype._start=function(out){this.out=out;this.mapOp.ins._add(this)};MapFlattenOperator.prototype._stop=function(){this.mapOp.ins._remove(this);this.inner=null;this.il=null;this.open=true;this.out=null};MapFlattenOperator.prototype.less=function(){if(!this.open&&!this.inner){var u=this.out;if(!u)return;u._c()}};MapFlattenOperator.prototype._n=function(v){var u=this.out;if(!u)return;var _a=this,inner=_a.inner,il=_a.il;if(inner&&il)inner._remove(il);try{(this.inner=this.mapOp.project(v))._add(this.il=new MFIL(u,this))}catch(e){u._e(e)}};MapFlattenOperator.prototype._e=function(err){var u=this.out;if(!u)return;u._e(err)};MapFlattenOperator.prototype._c=function(){this.open=false;this.less()};return MapFlattenOperator}();exports.MapFlattenOperator=MapFlattenOperator;var MapOperator=function(){function MapOperator(project,ins){this.project=project;this.ins=ins;this.type="map";this.out=null}MapOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};MapOperator.prototype._stop=function(){this.ins._remove(this);this.out=null};MapOperator.prototype._n=function(t){var u=this.out;if(!u)return;try{u._n(this.project(t))}catch(e){u._e(e)}};MapOperator.prototype._e=function(err){var u=this.out;if(!u)return;u._e(err)};MapOperator.prototype._c=function(){var u=this.out;if(!u)return;u._c()};return MapOperator}();exports.MapOperator=MapOperator;var FilterMapOperator=function(_super){__extends(FilterMapOperator,_super);function FilterMapOperator(passes,project,ins){_super.call(this,project,ins);this.passes=passes;this.type="filter+map"}FilterMapOperator.prototype._n=function(v){if(this.passes(v)){_super.prototype._n.call(this,v)}};return FilterMapOperator}(MapOperator);exports.FilterMapOperator=FilterMapOperator;var ReplaceErrorOperator=function(){function ReplaceErrorOperator(fn,ins){this.fn=fn;this.ins=ins;this.type="replaceError";this.out=empty}ReplaceErrorOperator.prototype._start=function(out){this.out=out;this.ins._add(this)};ReplaceErrorOperator.prototype._stop=function(){this.ins._remove(this);this.out=null};ReplaceErrorOperator.prototype._n=function(t){var u=this.out;if(!u)return;u._n(t)};ReplaceErrorOperator.prototype._e=function(err){var u=this.out;if(!u)return;try{this.ins._remove(this);(this.ins=this.fn(err))._add(this)}catch(e){u._e(e)}};ReplaceErrorOperator.prototype._c=function(){var u=this.out;if(!u)return;u._c()};return ReplaceErrorOperator}();exports.ReplaceErrorOperator=ReplaceErrorOperator;var StartWithOperator=function(){function StartWithOperator(ins,value){this.ins=ins;this.value=value;this.type="startWith";this.out=exports.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 u=this.out;if(!u)return;if(this.taken++<this.max-1){u._n(t)}else{u._n(t);u._c();this._stop()}};TakeOperator.prototype._e=function(err){var u=this.out;if(!u)return;u._e(err)};TakeOperator.prototype._c=function(){var u=this.out;if(!u)return;u._c()};return TakeOperator}();exports.TakeOperator=TakeOperator;var Stream=function(){function Stream(producer){this._stopID=empty;this.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){var s=this.map(function(){return projectedValue});var op=s._prod;op.type=op.type.replace("map","mapTo");return s};Stream.prototype.filter=function(passes){var p=this._prod;if(p instanceof FilterOperator){return new Stream(new FilterOperator(and(passes,p.passes),p.ins))}return new Stream(new FilterOperator(passes,this))};Stream.prototype.take=function(amount){return new 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.4.0", | ||
"version": "2.4.1", | ||
"description": "An extremely intuitive, small, and fast functional reactive stream library for JavaScript", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -778,3 +778,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/. --> | ||
- `replace: Function` A function of type `(err) => Stream` that takes the error that occured on the input stream or on the previous replacement | ||
- `replace: Function` A function of type `(err) => Stream` that takes the error that occurred on the input stream or on the previous replacement | ||
stream and returns a new stream. The output stream will imitate the stream | ||
@@ -1002,2 +1002,13 @@ that this function returns. | ||
# CHANGELOG | ||
<a name="2.4.1"></a> | ||
## [2.4.1](https://github.com/staltz/xstream/compare/v2.4.0...v2.4.1) (2016-05-13) | ||
### Bug Fixes | ||
* **operators:** add safety check against nulls for next() etc ([5d433c3](https://github.com/staltz/xstream/commit/5d433c3)) | ||
* **operators:** improve *type* metadata for operators with fusion ([fb1e81c](https://github.com/staltz/xstream/commit/fb1e81c)) | ||
<a name="2.4.0"></a> | ||
@@ -1004,0 +1015,0 @@ # [2.4.0](https://github.com/staltz/xstream/compare/v2.3.0...v2.4.0) (2016-05-12) |
240
src/core.ts
@@ -312,7 +312,11 @@ import {Promise} from 'es6-promise'; | ||
_n(t: T) { | ||
this.out._n(t); | ||
const u = this.out; | ||
if (!u) return; | ||
u._n(t); | ||
} | ||
_e(err: any) { | ||
this.out._e(err); | ||
const u = this.out; | ||
if (!u) return; | ||
u._e(err); | ||
} | ||
@@ -322,3 +326,5 @@ | ||
if (--this.ac === 0) { | ||
this.out._c(); | ||
const u = this.out; | ||
if (!u) return; | ||
u._c(); | ||
} | ||
@@ -368,7 +374,10 @@ } | ||
_n(t: T) { | ||
if (this.spy) { | ||
const u = this.out; | ||
if (!u) return; | ||
const spy = this.spy; | ||
if (spy) { | ||
try { | ||
this.spy(t); | ||
spy(t); | ||
} catch (e) { | ||
this.out._e(e); | ||
u._e(e); | ||
} | ||
@@ -378,11 +387,15 @@ } else { | ||
} | ||
this.out._n(t); | ||
u._n(t); | ||
} | ||
_e(err: any) { | ||
this.out._e(err); | ||
const u = this.out; | ||
if (!u) return; | ||
u._e(err); | ||
} | ||
_c() { | ||
this.out._c(); | ||
const u = this.out; | ||
if (!u) return; | ||
u._c(); | ||
} | ||
@@ -412,11 +425,17 @@ } | ||
_n(t: T) { | ||
if (this.dropped++ >= this.max) this.out._n(t); | ||
const u = this.out; | ||
if (!u) return; | ||
if (this.dropped++ >= this.max) u._n(t); | ||
} | ||
_e(err: any) { | ||
this.out._e(err); | ||
const u = this.out; | ||
if (!u) return; | ||
u._e(err); | ||
} | ||
_c() { | ||
this.out._c(); | ||
const u = this.out; | ||
if (!u) return; | ||
u._c(); | ||
} | ||
@@ -466,11 +485,17 @@ } | ||
end(): void { | ||
this.out._c(); | ||
const u = this.out; | ||
if (!u) return; | ||
u._c(); | ||
} | ||
_n(t: T) { | ||
this.out._n(t); | ||
const u = this.out; | ||
if (!u) return; | ||
u._n(t); | ||
} | ||
_e(err: any) { | ||
this.out._e(err); | ||
const u = this.out; | ||
if (!u) return; | ||
u._e(err); | ||
} | ||
@@ -502,6 +527,8 @@ | ||
_n(t: T) { | ||
const u = this.out; | ||
if (!u) return; | ||
try { | ||
if (this.passes(t)) this.out._n(t); | ||
if (this.passes(t)) u._n(t); | ||
} catch (e) { | ||
this.out._e(e); | ||
u._e(e); | ||
} | ||
@@ -511,7 +538,11 @@ } | ||
_e(err: any) { | ||
this.out._e(err); | ||
const u = this.out; | ||
if (!u) return; | ||
u._e(err); | ||
} | ||
_c() { | ||
this.out._c(); | ||
const u = this.out; | ||
if (!u) return; | ||
u._c(); | ||
} | ||
@@ -559,3 +590,5 @@ } | ||
if (--this.active === 0) { | ||
this.out._c(); | ||
const u = this.out; | ||
if (!u) return; | ||
u._c(); | ||
} | ||
@@ -565,8 +598,12 @@ } | ||
_n(s: Stream<T>) { | ||
const u = this.out; | ||
if (!u) return; | ||
this.active++; | ||
s._add(new FCIL(this.out, this)); | ||
s._add(new FCIL(u, this)); | ||
} | ||
_e(err: any) { | ||
this.out._e(err); | ||
const u = this.out; | ||
if (!u) return; | ||
u._e(err); | ||
} | ||
@@ -622,13 +659,19 @@ | ||
less(): void { | ||
if (!this.open && !this.inner) this.out._c(); | ||
const u = this.out; | ||
if (!u) return; | ||
if (!this.open && !this.inner) u._c(); | ||
} | ||
_n(s: Stream<T>) { | ||
const u = this.out; | ||
if (!u) return; | ||
const {inner, il} = this; | ||
if (inner && il) inner._remove(il); | ||
(this.inner = s)._add(this.il = new FIL(this.out, this)); | ||
(this.inner = s)._add(this.il = new FIL(u, this)); | ||
} | ||
_e(err: any) { | ||
this.out._e(err); | ||
const u = this.out; | ||
if (!u) return; | ||
u._e(err); | ||
} | ||
@@ -666,6 +709,8 @@ | ||
_n(t: T) { | ||
const u = this.out; | ||
if (!u) return; | ||
try { | ||
this.out._n(this.acc = this.f(this.acc, t)); | ||
u._n(this.acc = this.f(this.acc, t)); | ||
} catch (e) { | ||
this.out._e(e); | ||
u._e(e); | ||
} | ||
@@ -675,7 +720,11 @@ } | ||
_e(err: any) { | ||
this.out._e(err); | ||
const u = this.out; | ||
if (!u) return; | ||
u._e(err); | ||
} | ||
_c() { | ||
this.out._c(); | ||
const u = this.out; | ||
if (!u) return; | ||
u._c(); | ||
} | ||
@@ -711,12 +760,15 @@ } | ||
_e(err: any) { | ||
this.out._e(err); | ||
const u = this.out; | ||
if (!u) return; | ||
u._e(err); | ||
} | ||
_c() { | ||
const out = this.out; | ||
const u = this.out; | ||
if (!u) return; | ||
if (this.has) { | ||
out._n(this.val); | ||
out._c(); | ||
u._n(this.val); | ||
u._c(); | ||
} else { | ||
out._e('TODO show proper error'); | ||
u._e('TODO show proper error'); | ||
} | ||
@@ -745,3 +797,3 @@ } | ||
export class MapFlattenConcOperator<T, R> implements Operator<T, R> { | ||
public type = 'map+flattenConcurrently'; | ||
public type: string; | ||
public ins: Stream<T>; | ||
@@ -752,2 +804,3 @@ private active: number = 1; // number of outers and inners that have not yet ended | ||
constructor(public mapOp: MapOperator<T, Stream<R>>) { | ||
this.type = `${mapOp.type}+flattenConcurrently`; | ||
this.ins = mapOp.ins; | ||
@@ -769,3 +822,5 @@ } | ||
if (--this.active === 0) { | ||
this.out._c(); | ||
const u = this.out; | ||
if (!u) return; | ||
u._c(); | ||
} | ||
@@ -775,7 +830,9 @@ } | ||
_n(v: T) { | ||
const u = this.out; | ||
if (!u) return; | ||
this.active++; | ||
try { | ||
this.mapOp.project(v)._add(new MFCIL(this.out, this)); | ||
this.mapOp.project(v)._add(new MFCIL(u, this)); | ||
} catch (e) { | ||
this.out._e(e); | ||
u._e(e); | ||
} | ||
@@ -785,3 +842,5 @@ } | ||
_e(err: any) { | ||
this.out._e(err); | ||
const u = this.out; | ||
if (!u) return; | ||
u._e(err); | ||
} | ||
@@ -814,3 +873,3 @@ | ||
export class MapFlattenOperator<T, R> implements Operator<T, R> { | ||
public type = 'map+flatten'; | ||
public type: string; | ||
public ins: Stream<T>; | ||
@@ -823,2 +882,3 @@ public inner: Stream<R> = null; // Current inner Stream | ||
constructor(public mapOp: MapOperator<T, Stream<R>>) { | ||
this.type = `${mapOp.type}+flatten`; | ||
this.ins = mapOp.ins; | ||
@@ -842,3 +902,5 @@ } | ||
if (!this.open && !this.inner) { | ||
this.out._c(); | ||
const u = this.out; | ||
if (!u) return; | ||
u._c(); | ||
} | ||
@@ -848,8 +910,10 @@ } | ||
_n(v: T) { | ||
const u = this.out; | ||
if (!u) return; | ||
const {inner, il} = this; | ||
if (inner && il) inner._remove(il); | ||
try { | ||
(this.inner = this.mapOp.project(v))._add(this.il = new MFIL(this.out, this)); | ||
(this.inner = this.mapOp.project(v))._add(this.il = new MFIL(u, this)); | ||
} catch (e) { | ||
this.out._e(e); | ||
u._e(e); | ||
} | ||
@@ -859,3 +923,5 @@ } | ||
_e(err: any) { | ||
this.out._e(err); | ||
const u = this.out; | ||
if (!u) return; | ||
u._e(err); | ||
} | ||
@@ -888,6 +954,8 @@ | ||
_n(t: T) { | ||
const u = this.out; | ||
if (!u) return; | ||
try { | ||
this.out._n(this.project(t)); | ||
u._n(this.project(t)); | ||
} catch (e) { | ||
this.out._e(e); | ||
u._e(e); | ||
} | ||
@@ -897,7 +965,11 @@ } | ||
_e(err: any) { | ||
this.out._e(err); | ||
const u = this.out; | ||
if (!u) return; | ||
u._e(err); | ||
} | ||
_c() { | ||
this.out._c(); | ||
const u = this.out; | ||
if (!u) return; | ||
u._c(); | ||
} | ||
@@ -921,33 +993,2 @@ } | ||
export class MapToOperator<T, R> implements Operator<T, R> { | ||
public type = 'mapTo'; | ||
private out: Stream<R> = null; | ||
constructor(public val: R, | ||
public ins: Stream<T>) { | ||
} | ||
_start(out: Stream<R>): void { | ||
this.out = out; | ||
this.ins._add(this); | ||
} | ||
_stop(): void { | ||
this.ins._remove(this); | ||
this.out = null; | ||
} | ||
_n(t: T) { | ||
this.out._n(this.val); | ||
} | ||
_e(err: any) { | ||
this.out._e(err); | ||
} | ||
_c() { | ||
this.out._c(); | ||
} | ||
} | ||
export class ReplaceErrorOperator<T> implements Operator<T, T> { | ||
@@ -972,6 +1013,10 @@ public type = 'replaceError'; | ||
_n(t: T) { | ||
this.out._n(t); | ||
const u = this.out; | ||
if (!u) return; | ||
u._n(t); | ||
} | ||
_e(err: any) { | ||
const u = this.out; | ||
if (!u) return; | ||
try { | ||
@@ -981,3 +1026,3 @@ this.ins._remove(this); | ||
} catch (e) { | ||
this.out._e(e); | ||
u._e(e); | ||
} | ||
@@ -987,3 +1032,5 @@ } | ||
_c() { | ||
this.out._c(); | ||
const u = this.out; | ||
if (!u) return; | ||
u._c(); | ||
} | ||
@@ -1033,9 +1080,9 @@ } | ||
_n(t: T) { | ||
const out = this.out; | ||
if (!out) return; | ||
const u = this.out; | ||
if (!u) return; | ||
if (this.taken++ < this.max - 1) { | ||
out._n(t); | ||
u._n(t); | ||
} else { | ||
out._n(t); | ||
out._c(); | ||
u._n(t); | ||
u._c(); | ||
this._stop(); | ||
@@ -1046,11 +1093,11 @@ } | ||
_e(err: any) { | ||
const out = this.out; | ||
if (!out) return; | ||
out._e(err); | ||
const u = this.out; | ||
if (!u) return; | ||
u._e(err); | ||
} | ||
_c() { | ||
const out = this.out; | ||
if (!out) return; | ||
out._c(); | ||
const u = this.out; | ||
if (!u) return; | ||
u._c(); | ||
} | ||
@@ -1453,3 +1500,6 @@ } | ||
mapTo<U>(projectedValue: U): Stream<U> { | ||
return new Stream<U>(new MapToOperator(projectedValue, this)); | ||
const s = this.map(() => projectedValue); | ||
const op: Operator<T, U> = <Operator<T, U>> s._prod; | ||
op.type = op.type.replace('map', 'mapTo'); | ||
return s; | ||
} | ||
@@ -1639,3 +1689,3 @@ | ||
* @param {Function} replace A function of type `(err) => Stream` that takes | ||
* the error that occured on the input stream or on the previous replacement | ||
* the error that occurred on the input stream or on the previous replacement | ||
* stream and returns a new stream. The output stream will imitate the stream | ||
@@ -1642,0 +1692,0 @@ * that this function returns. |
@@ -81,2 +81,22 @@ import xs from '../../src/index'; | ||
}); | ||
it('should should have filter+map fusion metadata', (done) => { | ||
const isEven = (x: number) => x % 2 === 0; | ||
const stream = xs.of(1, 2, 3, 4, 5, 6, 7, 8) | ||
.filter(isEven) | ||
.map(x => 10 * x); | ||
assert.strictEqual(stream['_prod']['type'], 'filter+map'); | ||
done(); | ||
}); | ||
it('should should have filter+mapTo fusion metadata', (done) => { | ||
const isEven = (x: number) => x % 2 === 0; | ||
const stream = xs.of(1, 2, 3, 4, 5, 6, 7, 8) | ||
.filter(isEven) | ||
.mapTo(10); | ||
assert.strictEqual(stream['_prod']['type'], 'filter+mapTo'); | ||
done(); | ||
}); | ||
}); |
@@ -142,2 +142,12 @@ import xs, {Stream, Listener} from '../../src/index'; | ||
}); | ||
describe('with mapTo', () => { | ||
it('should have the correct \'type\' metadata on the operator producer', (done) => { | ||
const source: Stream<Stream<number>> = xs.periodic(100).take(3) | ||
.mapTo(xs.of(1, 2, 3)); | ||
const stream: Stream<number> = source.flatten(); | ||
assert.strictEqual(stream['_prod']['type'], 'mapTo+flatten'); | ||
done(); | ||
}); | ||
}); | ||
}); |
@@ -143,2 +143,12 @@ import xs, {Stream, Listener} from '../../src/index'; | ||
}); | ||
describe('with mapTo', () => { | ||
it('should have the correct \'type\' metadata on the operator producer', (done) => { | ||
const source: Stream<Stream<number>> = xs.periodic(100).take(3) | ||
.mapTo(xs.of(1, 2, 3)); | ||
const stream: Stream<number> = source.flattenConcurrently(); | ||
assert.strictEqual(stream['_prod']['type'], 'mapTo+flattenConcurrently'); | ||
done(); | ||
}); | ||
}); | ||
}); |
@@ -21,2 +21,8 @@ import xs from '../../src/index'; | ||
}); | ||
it('should have \'type\' metadata on the operator producer', (done) => { | ||
const stream = xs.periodic(100).mapTo(10); | ||
assert.strictEqual(stream['_prod']['type'], 'mapTo'); | ||
done(); | ||
}); | ||
}); |
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
788829
14273
1291