UNPKG

34.2 kBJavaScriptView Raw
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(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
2"use strict";
3var __extends = (this && this.__extends) || (function () {
4 var extendStatics = Object.setPrototypeOf ||
5 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7 return function (d, b) {
8 extendStatics(d, b);
9 function __() { this.constructor = d; }
10 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
11 };
12})();
13Object.defineProperty(exports, "__esModule", { value: true });
14var symbol_observable_1 = require("symbol-observable");
15var NO = {};
16exports.NO = NO;
17function noop() { }
18function cp(a) {
19 var l = a.length;
20 var b = Array(l);
21 for (var i = 0; i < l; ++i)
22 b[i] = a[i];
23 return b;
24}
25function and(f1, f2) {
26 return function andFn(t) {
27 return f1(t) && f2(t);
28 };
29}
30function _try(c, t, u) {
31 try {
32 return c.f(t);
33 }
34 catch (e) {
35 u._e(e);
36 return NO;
37 }
38}
39var NO_IL = {
40 _n: noop,
41 _e: noop,
42 _c: noop,
43};
44exports.NO_IL = NO_IL;
45
46function internalizeProducer(producer) {
47 producer._start = function _start(il) {
48 il.next = il._n;
49 il.error = il._e;
50 il.complete = il._c;
51 this.start(il);
52 };
53 producer._stop = producer.stop;
54}
55var StreamSub = (function () {
56 function StreamSub(_stream, _listener) {
57 this._stream = _stream;
58 this._listener = _listener;
59 }
60 StreamSub.prototype.unsubscribe = function () {
61 this._stream.removeListener(this._listener);
62 };
63 return StreamSub;
64}());
65var Observer = (function () {
66 function Observer(_listener) {
67 this._listener = _listener;
68 }
69 Observer.prototype.next = function (value) {
70 this._listener._n(value);
71 };
72 Observer.prototype.error = function (err) {
73 this._listener._e(err);
74 };
75 Observer.prototype.complete = function () {
76 this._listener._c();
77 };
78 return Observer;
79}());
80var FromObservable = (function () {
81 function FromObservable(observable) {
82 this.type = 'fromObservable';
83 this.ins = observable;
84 this.active = false;
85 }
86 FromObservable.prototype._start = function (out) {
87 this.out = out;
88 this.active = true;
89 this._sub = this.ins.subscribe(new Observer(out));
90 if (!this.active)
91 this._sub.unsubscribe();
92 };
93 FromObservable.prototype._stop = function () {
94 if (this._sub)
95 this._sub.unsubscribe();
96 this.active = false;
97 };
98 return FromObservable;
99}());
100var Merge = (function () {
101 function Merge(insArr) {
102 this.type = 'merge';
103 this.insArr = insArr;
104 this.out = NO;
105 this.ac = 0;
106 }
107 Merge.prototype._start = function (out) {
108 this.out = out;
109 var s = this.insArr;
110 var L = s.length;
111 this.ac = L;
112 for (var i = 0; i < L; i++)
113 s[i]._add(this);
114 };
115 Merge.prototype._stop = function () {
116 var s = this.insArr;
117 var L = s.length;
118 for (var i = 0; i < L; i++)
119 s[i]._remove(this);
120 this.out = NO;
121 };
122 Merge.prototype._n = function (t) {
123 var u = this.out;
124 if (u === NO)
125 return;
126 u._n(t);
127 };
128 Merge.prototype._e = function (err) {
129 var u = this.out;
130 if (u === NO)
131 return;
132 u._e(err);
133 };
134 Merge.prototype._c = function () {
135 if (--this.ac <= 0) {
136 var u = this.out;
137 if (u === NO)
138 return;
139 u._c();
140 }
141 };
142 return Merge;
143}());
144var CombineListener = (function () {
145 function CombineListener(i, out, p) {
146 this.i = i;
147 this.out = out;
148 this.p = p;
149 p.ils.push(this);
150 }
151 CombineListener.prototype._n = function (t) {
152 var p = this.p, out = this.out;
153 if (out === NO)
154 return;
155 if (p.up(t, this.i)) {
156 var a = p.vals;
157 var l = a.length;
158 var b = Array(l);
159 for (var i = 0; i < l; ++i)
160 b[i] = a[i];
161 out._n(b);
162 }
163 };
164 CombineListener.prototype._e = function (err) {
165 var out = this.out;
166 if (out === NO)
167 return;
168 out._e(err);
169 };
170 CombineListener.prototype._c = function () {
171 var p = this.p;
172 if (p.out === NO)
173 return;
174 if (--p.Nc === 0)
175 p.out._c();
176 };
177 return CombineListener;
178}());
179var Combine = (function () {
180 function Combine(insArr) {
181 this.type = 'combine';
182 this.insArr = insArr;
183 this.out = NO;
184 this.ils = [];
185 this.Nc = this.Nn = 0;
186 this.vals = [];
187 }
188 Combine.prototype.up = function (t, i) {
189 var v = this.vals[i];
190 var Nn = !this.Nn ? 0 : v === NO ? --this.Nn : this.Nn;
191 this.vals[i] = t;
192 return Nn === 0;
193 };
194 Combine.prototype._start = function (out) {
195 this.out = out;
196 var s = this.insArr;
197 var n = this.Nc = this.Nn = s.length;
198 var vals = this.vals = new Array(n);
199 if (n === 0) {
200 out._n([]);
201 out._c();
202 }
203 else {
204 for (var i = 0; i < n; i++) {
205 vals[i] = NO;
206 s[i]._add(new CombineListener(i, out, this));
207 }
208 }
209 };
210 Combine.prototype._stop = function () {
211 var s = this.insArr;
212 var n = s.length;
213 var ils = this.ils;
214 for (var i = 0; i < n; i++)
215 s[i]._remove(ils[i]);
216 this.out = NO;
217 this.ils = [];
218 this.vals = [];
219 };
220 return Combine;
221}());
222var FromArray = (function () {
223 function FromArray(a) {
224 this.type = 'fromArray';
225 this.a = a;
226 }
227 FromArray.prototype._start = function (out) {
228 var a = this.a;
229 for (var i = 0, n = a.length; i < n; i++)
230 out._n(a[i]);
231 out._c();
232 };
233 FromArray.prototype._stop = function () {
234 };
235 return FromArray;
236}());
237var FromPromise = (function () {
238 function FromPromise(p) {
239 this.type = 'fromPromise';
240 this.on = false;
241 this.p = p;
242 }
243 FromPromise.prototype._start = function (out) {
244 var prod = this;
245 this.on = true;
246 this.p.then(function (v) {
247 if (prod.on) {
248 out._n(v);
249 out._c();
250 }
251 }, function (e) {
252 out._e(e);
253 }).then(noop, function (err) {
254 setTimeout(function () { throw err; });
255 });
256 };
257 FromPromise.prototype._stop = function () {
258 this.on = false;
259 };
260 return FromPromise;
261}());
262var Periodic = (function () {
263 function Periodic(period) {
264 this.type = 'periodic';
265 this.period = period;
266 this.intervalID = -1;
267 this.i = 0;
268 }
269 Periodic.prototype._start = function (out) {
270 var self = this;
271 function intervalHandler() { out._n(self.i++); }
272 this.intervalID = setInterval(intervalHandler, this.period);
273 };
274 Periodic.prototype._stop = function () {
275 if (this.intervalID !== -1)
276 clearInterval(this.intervalID);
277 this.intervalID = -1;
278 this.i = 0;
279 };
280 return Periodic;
281}());
282var Debug = (function () {
283 function Debug(ins, arg) {
284 this.type = 'debug';
285 this.ins = ins;
286 this.out = NO;
287 this.s = noop;
288 this.l = '';
289 if (typeof arg === 'string')
290 this.l = arg;
291 else if (typeof arg === 'function')
292 this.s = arg;
293 }
294 Debug.prototype._start = function (out) {
295 this.out = out;
296 this.ins._add(this);
297 };
298 Debug.prototype._stop = function () {
299 this.ins._remove(this);
300 this.out = NO;
301 };
302 Debug.prototype._n = function (t) {
303 var u = this.out;
304 if (u === NO)
305 return;
306 var s = this.s, l = this.l;
307 if (s !== noop) {
308 try {
309 s(t);
310 }
311 catch (e) {
312 u._e(e);
313 }
314 }
315 else if (l)
316 console.log(l + ':', t);
317 else
318 console.log(t);
319 u._n(t);
320 };
321 Debug.prototype._e = function (err) {
322 var u = this.out;
323 if (u === NO)
324 return;
325 u._e(err);
326 };
327 Debug.prototype._c = function () {
328 var u = this.out;
329 if (u === NO)
330 return;
331 u._c();
332 };
333 return Debug;
334}());
335var Drop = (function () {
336 function Drop(max, ins) {
337 this.type = 'drop';
338 this.ins = ins;
339 this.out = NO;
340 this.max = max;
341 this.dropped = 0;
342 }
343 Drop.prototype._start = function (out) {
344 this.out = out;
345 this.dropped = 0;
346 this.ins._add(this);
347 };
348 Drop.prototype._stop = function () {
349 this.ins._remove(this);
350 this.out = NO;
351 };
352 Drop.prototype._n = function (t) {
353 var u = this.out;
354 if (u === NO)
355 return;
356 if (this.dropped++ >= this.max)
357 u._n(t);
358 };
359 Drop.prototype._e = function (err) {
360 var u = this.out;
361 if (u === NO)
362 return;
363 u._e(err);
364 };
365 Drop.prototype._c = function () {
366 var u = this.out;
367 if (u === NO)
368 return;
369 u._c();
370 };
371 return Drop;
372}());
373var EndWhenListener = (function () {
374 function EndWhenListener(out, op) {
375 this.out = out;
376 this.op = op;
377 }
378 EndWhenListener.prototype._n = function () {
379 this.op.end();
380 };
381 EndWhenListener.prototype._e = function (err) {
382 this.out._e(err);
383 };
384 EndWhenListener.prototype._c = function () {
385 this.op.end();
386 };
387 return EndWhenListener;
388}());
389var EndWhen = (function () {
390 function EndWhen(o, ins) {
391 this.type = 'endWhen';
392 this.ins = ins;
393 this.out = NO;
394 this.o = o;
395 this.oil = NO_IL;
396 }
397 EndWhen.prototype._start = function (out) {
398 this.out = out;
399 this.o._add(this.oil = new EndWhenListener(out, this));
400 this.ins._add(this);
401 };
402 EndWhen.prototype._stop = function () {
403 this.ins._remove(this);
404 this.o._remove(this.oil);
405 this.out = NO;
406 this.oil = NO_IL;
407 };
408 EndWhen.prototype.end = function () {
409 var u = this.out;
410 if (u === NO)
411 return;
412 u._c();
413 };
414 EndWhen.prototype._n = function (t) {
415 var u = this.out;
416 if (u === NO)
417 return;
418 u._n(t);
419 };
420 EndWhen.prototype._e = function (err) {
421 var u = this.out;
422 if (u === NO)
423 return;
424 u._e(err);
425 };
426 EndWhen.prototype._c = function () {
427 this.end();
428 };
429 return EndWhen;
430}());
431var Filter = (function () {
432 function Filter(passes, ins) {
433 this.type = 'filter';
434 this.ins = ins;
435 this.out = NO;
436 this.f = passes;
437 }
438 Filter.prototype._start = function (out) {
439 this.out = out;
440 this.ins._add(this);
441 };
442 Filter.prototype._stop = function () {
443 this.ins._remove(this);
444 this.out = NO;
445 };
446 Filter.prototype._n = function (t) {
447 var u = this.out;
448 if (u === NO)
449 return;
450 var r = _try(this, t, u);
451 if (r === NO || !r)
452 return;
453 u._n(t);
454 };
455 Filter.prototype._e = function (err) {
456 var u = this.out;
457 if (u === NO)
458 return;
459 u._e(err);
460 };
461 Filter.prototype._c = function () {
462 var u = this.out;
463 if (u === NO)
464 return;
465 u._c();
466 };
467 return Filter;
468}());
469var FlattenListener = (function () {
470 function FlattenListener(out, op) {
471 this.out = out;
472 this.op = op;
473 }
474 FlattenListener.prototype._n = function (t) {
475 this.out._n(t);
476 };
477 FlattenListener.prototype._e = function (err) {
478 this.out._e(err);
479 };
480 FlattenListener.prototype._c = function () {
481 this.op.inner = NO;
482 this.op.less();
483 };
484 return FlattenListener;
485}());
486var Flatten = (function () {
487 function Flatten(ins) {
488 this.type = 'flatten';
489 this.ins = ins;
490 this.out = NO;
491 this.open = true;
492 this.inner = NO;
493 this.il = NO_IL;
494 }
495 Flatten.prototype._start = function (out) {
496 this.out = out;
497 this.open = true;
498 this.inner = NO;
499 this.il = NO_IL;
500 this.ins._add(this);
501 };
502 Flatten.prototype._stop = function () {
503 this.ins._remove(this);
504 if (this.inner !== NO)
505 this.inner._remove(this.il);
506 this.out = NO;
507 this.open = true;
508 this.inner = NO;
509 this.il = NO_IL;
510 };
511 Flatten.prototype.less = function () {
512 var u = this.out;
513 if (u === NO)
514 return;
515 if (!this.open && this.inner === NO)
516 u._c();
517 };
518 Flatten.prototype._n = function (s) {
519 var u = this.out;
520 if (u === NO)
521 return;
522 var _a = this, inner = _a.inner, il = _a.il;
523 if (inner !== NO && il !== NO_IL)
524 inner._remove(il);
525 (this.inner = s)._add(this.il = new FlattenListener(u, this));
526 };
527 Flatten.prototype._e = function (err) {
528 var u = this.out;
529 if (u === NO)
530 return;
531 u._e(err);
532 };
533 Flatten.prototype._c = function () {
534 this.open = false;
535 this.less();
536 };
537 return Flatten;
538}());
539var Fold = (function () {
540 function Fold(f, seed, ins) {
541 var _this = this;
542 this.type = 'fold';
543 this.ins = ins;
544 this.out = NO;
545 this.f = function (t) { return f(_this.acc, t); };
546 this.acc = this.seed = seed;
547 }
548 Fold.prototype._start = function (out) {
549 this.out = out;
550 this.acc = this.seed;
551 out._n(this.acc);
552 this.ins._add(this);
553 };
554 Fold.prototype._stop = function () {
555 this.ins._remove(this);
556 this.out = NO;
557 this.acc = this.seed;
558 };
559 Fold.prototype._n = function (t) {
560 var u = this.out;
561 if (u === NO)
562 return;
563 var r = _try(this, t, u);
564 if (r === NO)
565 return;
566 u._n(this.acc = r);
567 };
568 Fold.prototype._e = function (err) {
569 var u = this.out;
570 if (u === NO)
571 return;
572 u._e(err);
573 };
574 Fold.prototype._c = function () {
575 var u = this.out;
576 if (u === NO)
577 return;
578 u._c();
579 };
580 return Fold;
581}());
582var Last = (function () {
583 function Last(ins) {
584 this.type = 'last';
585 this.ins = ins;
586 this.out = NO;
587 this.has = false;
588 this.val = NO;
589 }
590 Last.prototype._start = function (out) {
591 this.out = out;
592 this.has = false;
593 this.ins._add(this);
594 };
595 Last.prototype._stop = function () {
596 this.ins._remove(this);
597 this.out = NO;
598 this.val = NO;
599 };
600 Last.prototype._n = function (t) {
601 this.has = true;
602 this.val = t;
603 };
604 Last.prototype._e = function (err) {
605 var u = this.out;
606 if (u === NO)
607 return;
608 u._e(err);
609 };
610 Last.prototype._c = function () {
611 var u = this.out;
612 if (u === NO)
613 return;
614 if (this.has) {
615 u._n(this.val);
616 u._c();
617 }
618 else
619 u._e(new Error('last() failed because input stream completed'));
620 };
621 return Last;
622}());
623var MapOp = (function () {
624 function MapOp(project, ins) {
625 this.type = 'map';
626 this.ins = ins;
627 this.out = NO;
628 this.f = project;
629 }
630 MapOp.prototype._start = function (out) {
631 this.out = out;
632 this.ins._add(this);
633 };
634 MapOp.prototype._stop = function () {
635 this.ins._remove(this);
636 this.out = NO;
637 };
638 MapOp.prototype._n = function (t) {
639 var u = this.out;
640 if (u === NO)
641 return;
642 var r = _try(this, t, u);
643 if (r === NO)
644 return;
645 u._n(r);
646 };
647 MapOp.prototype._e = function (err) {
648 var u = this.out;
649 if (u === NO)
650 return;
651 u._e(err);
652 };
653 MapOp.prototype._c = function () {
654 var u = this.out;
655 if (u === NO)
656 return;
657 u._c();
658 };
659 return MapOp;
660}());
661var Remember = (function () {
662 function Remember(ins) {
663 this.type = 'remember';
664 this.ins = ins;
665 this.out = NO;
666 }
667 Remember.prototype._start = function (out) {
668 this.out = out;
669 this.ins._add(out);
670 };
671 Remember.prototype._stop = function () {
672 this.ins._remove(this.out);
673 this.out = NO;
674 };
675 return Remember;
676}());
677var ReplaceError = (function () {
678 function ReplaceError(replacer, ins) {
679 this.type = 'replaceError';
680 this.ins = ins;
681 this.out = NO;
682 this.f = replacer;
683 }
684 ReplaceError.prototype._start = function (out) {
685 this.out = out;
686 this.ins._add(this);
687 };
688 ReplaceError.prototype._stop = function () {
689 this.ins._remove(this);
690 this.out = NO;
691 };
692 ReplaceError.prototype._n = function (t) {
693 var u = this.out;
694 if (u === NO)
695 return;
696 u._n(t);
697 };
698 ReplaceError.prototype._e = function (err) {
699 var u = this.out;
700 if (u === NO)
701 return;
702 try {
703 this.ins._remove(this);
704 (this.ins = this.f(err))._add(this);
705 }
706 catch (e) {
707 u._e(e);
708 }
709 };
710 ReplaceError.prototype._c = function () {
711 var u = this.out;
712 if (u === NO)
713 return;
714 u._c();
715 };
716 return ReplaceError;
717}());
718var StartWith = (function () {
719 function StartWith(ins, val) {
720 this.type = 'startWith';
721 this.ins = ins;
722 this.out = NO;
723 this.val = val;
724 }
725 StartWith.prototype._start = function (out) {
726 this.out = out;
727 this.out._n(this.val);
728 this.ins._add(out);
729 };
730 StartWith.prototype._stop = function () {
731 this.ins._remove(this.out);
732 this.out = NO;
733 };
734 return StartWith;
735}());
736var Take = (function () {
737 function Take(max, ins) {
738 this.type = 'take';
739 this.ins = ins;
740 this.out = NO;
741 this.max = max;
742 this.taken = 0;
743 }
744 Take.prototype._start = function (out) {
745 this.out = out;
746 this.taken = 0;
747 if (this.max <= 0)
748 out._c();
749 else
750 this.ins._add(this);
751 };
752 Take.prototype._stop = function () {
753 this.ins._remove(this);
754 this.out = NO;
755 };
756 Take.prototype._n = function (t) {
757 var u = this.out;
758 if (u === NO)
759 return;
760 var m = ++this.taken;
761 if (m < this.max)
762 u._n(t);
763 else if (m === this.max) {
764 u._n(t);
765 u._c();
766 }
767 };
768 Take.prototype._e = function (err) {
769 var u = this.out;
770 if (u === NO)
771 return;
772 u._e(err);
773 };
774 Take.prototype._c = function () {
775 var u = this.out;
776 if (u === NO)
777 return;
778 u._c();
779 };
780 return Take;
781}());
782var Stream = (function () {
783 function Stream(producer) {
784 this._prod = producer || NO;
785 this._ils = [];
786 this._stopID = NO;
787 this._dl = NO;
788 this._d = false;
789 this._target = NO;
790 this._err = NO;
791 }
792 Stream.prototype._n = function (t) {
793 var a = this._ils;
794 var L = a.length;
795 if (this._d)
796 this._dl._n(t);
797 if (L == 1)
798 a[0]._n(t);
799 else if (L == 0)
800 return;
801 else {
802 var b = cp(a);
803 for (var i = 0; i < L; i++)
804 b[i]._n(t);
805 }
806 };
807 Stream.prototype._e = function (err) {
808 if (this._err !== NO)
809 return;
810 this._err = err;
811 var a = this._ils;
812 var L = a.length;
813 this._x();
814 if (this._d)
815 this._dl._e(err);
816 if (L == 1)
817 a[0]._e(err);
818 else if (L == 0)
819 return;
820 else {
821 var b = cp(a);
822 for (var i = 0; i < L; i++)
823 b[i]._e(err);
824 }
825 if (!this._d && L == 0)
826 throw this._err;
827 };
828 Stream.prototype._c = function () {
829 var a = this._ils;
830 var L = a.length;
831 this._x();
832 if (this._d)
833 this._dl._c();
834 if (L == 1)
835 a[0]._c();
836 else if (L == 0)
837 return;
838 else {
839 var b = cp(a);
840 for (var i = 0; i < L; i++)
841 b[i]._c();
842 }
843 };
844 Stream.prototype._x = function () {
845 if (this._ils.length === 0)
846 return;
847 if (this._prod !== NO)
848 this._prod._stop();
849 this._err = NO;
850 this._ils = [];
851 };
852 Stream.prototype._stopNow = function () {
853
854
855 this._prod._stop();
856 this._err = NO;
857 this._stopID = NO;
858 };
859 Stream.prototype._add = function (il) {
860 var ta = this._target;
861 if (ta !== NO)
862 return ta._add(il);
863 var a = this._ils;
864 a.push(il);
865 if (a.length > 1)
866 return;
867 if (this._stopID !== NO) {
868 clearTimeout(this._stopID);
869 this._stopID = NO;
870 }
871 else {
872 var p = this._prod;
873 if (p !== NO)
874 p._start(this);
875 }
876 };
877 Stream.prototype._remove = function (il) {
878 var _this = this;
879 var ta = this._target;
880 if (ta !== NO)
881 return ta._remove(il);
882 var a = this._ils;
883 var i = a.indexOf(il);
884 if (i > -1) {
885 a.splice(i, 1);
886 if (this._prod !== NO && a.length <= 0) {
887 this._err = NO;
888 this._stopID = setTimeout(function () { return _this._stopNow(); });
889 }
890 else if (a.length === 1) {
891 this._pruneCycles();
892 }
893 }
894 };
895
896
897
898
899 Stream.prototype._pruneCycles = function () {
900 if (this._hasNoSinks(this, []))
901 this._remove(this._ils[0]);
902 };
903
904
905
906
907 Stream.prototype._hasNoSinks = function (x, trace) {
908 if (trace.indexOf(x) !== -1)
909 return true;
910 else if (x.out === this)
911 return true;
912 else if (x.out && x.out !== NO)
913 return this._hasNoSinks(x.out, trace.concat(x));
914 else if (x._ils) {
915 for (var i = 0, N = x._ils.length; i < N; i++)
916 if (!this._hasNoSinks(x._ils[i], trace.concat(x)))
917 return false;
918 return true;
919 }
920 else
921 return false;
922 };
923 Stream.prototype.ctor = function () {
924 return this instanceof MemoryStream ? MemoryStream : Stream;
925 };
926
927 Stream.prototype.addListener = function (listener) {
928 listener._n = listener.next || noop;
929 listener._e = listener.error || noop;
930 listener._c = listener.complete || noop;
931 this._add(listener);
932 };
933
934 Stream.prototype.removeListener = function (listener) {
935 this._remove(listener);
936 };
937
938 Stream.prototype.subscribe = function (listener) {
939 this.addListener(listener);
940 return new StreamSub(this, listener);
941 };
942
943 Stream.prototype[symbol_observable_1.default] = function () {
944 return this;
945 };
946
947 Stream.create = function (producer) {
948 if (producer) {
949 if (typeof producer.start !== 'function'
950 || typeof producer.stop !== 'function')
951 throw new Error('producer requires both start and stop functions');
952 internalizeProducer(producer);
953 }
954 return new Stream(producer);
955 };
956
957 Stream.createWithMemory = function (producer) {
958 if (producer)
959 internalizeProducer(producer);
960 return new MemoryStream(producer);
961 };
962
963 Stream.never = function () {
964 return new Stream({ _start: noop, _stop: noop });
965 };
966
967 Stream.empty = function () {
968 return new Stream({
969 _start: function (il) { il._c(); },
970 _stop: noop,
971 });
972 };
973
974 Stream.throw = function (error) {
975 return new Stream({
976 _start: function (il) { il._e(error); },
977 _stop: noop,
978 });
979 };
980
981 Stream.from = function (input) {
982 if (typeof input[symbol_observable_1.default] === 'function')
983 return Stream.fromObservable(input);
984 else if (typeof input.then === 'function')
985 return Stream.fromPromise(input);
986 else if (Array.isArray(input))
987 return Stream.fromArray(input);
988 throw new TypeError("Type of input to from() must be an Array, Promise, or Observable");
989 };
990
991 Stream.of = function () {
992 var items = [];
993 for (var _i = 0; _i < arguments.length; _i++) {
994 items[_i] = arguments[_i];
995 }
996 return Stream.fromArray(items);
997 };
998
999 Stream.fromArray = function (array) {
1000 return new Stream(new FromArray(array));
1001 };
1002
1003 Stream.fromPromise = function (promise) {
1004 return new Stream(new FromPromise(promise));
1005 };
1006
1007 Stream.fromObservable = function (obs) {
1008 if (obs.endWhen)
1009 return obs;
1010 var o = typeof obs[symbol_observable_1.default] === 'function' ? obs[symbol_observable_1.default]() : obs;
1011 return new Stream(new FromObservable(o));
1012 };
1013
1014 Stream.periodic = function (period) {
1015 return new Stream(new Periodic(period));
1016 };
1017 Stream.prototype._map = function (project) {
1018 return new (this.ctor())(new MapOp(project, this));
1019 };
1020
1021 Stream.prototype.map = function (project) {
1022 return this._map(project);
1023 };
1024
1025 Stream.prototype.mapTo = function (projectedValue) {
1026 var s = this.map(function () { return projectedValue; });
1027 var op = s._prod;
1028 op.type = 'mapTo';
1029 return s;
1030 };
1031
1032 Stream.prototype.filter = function (passes) {
1033 var p = this._prod;
1034 if (p instanceof Filter)
1035 return new Stream(new Filter(and(p.f, passes), p.ins));
1036 return new Stream(new Filter(passes, this));
1037 };
1038
1039 Stream.prototype.take = function (amount) {
1040 return new (this.ctor())(new Take(amount, this));
1041 };
1042
1043 Stream.prototype.drop = function (amount) {
1044 return new Stream(new Drop(amount, this));
1045 };
1046
1047 Stream.prototype.last = function () {
1048 return new Stream(new Last(this));
1049 };
1050
1051 Stream.prototype.startWith = function (initial) {
1052 return new MemoryStream(new StartWith(this, initial));
1053 };
1054
1055 Stream.prototype.endWhen = function (other) {
1056 return new (this.ctor())(new EndWhen(other, this));
1057 };
1058
1059 Stream.prototype.fold = function (accumulate, seed) {
1060 return new MemoryStream(new Fold(accumulate, seed, this));
1061 };
1062
1063 Stream.prototype.replaceError = function (replace) {
1064 return new (this.ctor())(new ReplaceError(replace, this));
1065 };
1066
1067 Stream.prototype.flatten = function () {
1068 var p = this._prod;
1069 return new Stream(new Flatten(this));
1070 };
1071
1072 Stream.prototype.compose = function (operator) {
1073 return operator(this);
1074 };
1075
1076 Stream.prototype.remember = function () {
1077 return new MemoryStream(new Remember(this));
1078 };
1079
1080 Stream.prototype.debug = function (labelOrSpy) {
1081 return new (this.ctor())(new Debug(this, labelOrSpy));
1082 };
1083
1084 Stream.prototype.imitate = function (target) {
1085 if (target instanceof MemoryStream)
1086 throw new Error('A MemoryStream was given to imitate(), but it only ' +
1087 'supports a Stream. Read more about this restriction here: ' +
1088 'https://github.com/staltz/xstream#faq');
1089 this._target = target;
1090 for (var ils = this._ils, N = ils.length, i = 0; i < N; i++)
1091 target._add(ils[i]);
1092 this._ils = [];
1093 };
1094
1095 Stream.prototype.shamefullySendNext = function (value) {
1096 this._n(value);
1097 };
1098
1099 Stream.prototype.shamefullySendError = function (error) {
1100 this._e(error);
1101 };
1102
1103 Stream.prototype.shamefullySendComplete = function () {
1104 this._c();
1105 };
1106
1107 Stream.prototype.setDebugListener = function (listener) {
1108 if (!listener) {
1109 this._d = false;
1110 this._dl = NO;
1111 }
1112 else {
1113 this._d = true;
1114 listener._n = listener.next || noop;
1115 listener._e = listener.error || noop;
1116 listener._c = listener.complete || noop;
1117 this._dl = listener;
1118 }
1119 };
1120
1121 Stream.merge = function merge() {
1122 var streams = [];
1123 for (var _i = 0; _i < arguments.length; _i++) {
1124 streams[_i] = arguments[_i];
1125 }
1126 return new Stream(new Merge(streams));
1127 };
1128
1129 Stream.combine = function combine() {
1130 var streams = [];
1131 for (var _i = 0; _i < arguments.length; _i++) {
1132 streams[_i] = arguments[_i];
1133 }
1134 return new Stream(new Combine(streams));
1135 };
1136 return Stream;
1137}());
1138exports.Stream = Stream;
1139var MemoryStream = (function (_super) {
1140 __extends(MemoryStream, _super);
1141 function MemoryStream(producer) {
1142 var _this = _super.call(this, producer) || this;
1143 _this._has = false;
1144 return _this;
1145 }
1146 MemoryStream.prototype._n = function (x) {
1147 this._v = x;
1148 this._has = true;
1149 _super.prototype._n.call(this, x);
1150 };
1151 MemoryStream.prototype._add = function (il) {
1152 var ta = this._target;
1153 if (ta !== NO)
1154 return ta._add(il);
1155 var a = this._ils;
1156 a.push(il);
1157 if (a.length > 1) {
1158 if (this._has)
1159 il._n(this._v);
1160 return;
1161 }
1162 if (this._stopID !== NO) {
1163 if (this._has)
1164 il._n(this._v);
1165 clearTimeout(this._stopID);
1166 this._stopID = NO;
1167 }
1168 else if (this._has)
1169 il._n(this._v);
1170 else {
1171 var p = this._prod;
1172 if (p !== NO)
1173 p._start(this);
1174 }
1175 };
1176 MemoryStream.prototype._stopNow = function () {
1177 this._has = false;
1178 _super.prototype._stopNow.call(this);
1179 };
1180 MemoryStream.prototype._x = function () {
1181 this._has = false;
1182 _super.prototype._x.call(this);
1183 };
1184 MemoryStream.prototype.map = function (project) {
1185 return this._map(project);
1186 };
1187 MemoryStream.prototype.mapTo = function (projectedValue) {
1188 return _super.prototype.mapTo.call(this, projectedValue);
1189 };
1190 MemoryStream.prototype.take = function (amount) {
1191 return _super.prototype.take.call(this, amount);
1192 };
1193 MemoryStream.prototype.endWhen = function (other) {
1194 return _super.prototype.endWhen.call(this, other);
1195 };
1196 MemoryStream.prototype.replaceError = function (replace) {
1197 return _super.prototype.replaceError.call(this, replace);
1198 };
1199 MemoryStream.prototype.remember = function () {
1200 return this;
1201 };
1202 MemoryStream.prototype.debug = function (labelOrSpy) {
1203 return _super.prototype.debug.call(this, labelOrSpy);
1204 };
1205 return MemoryStream;
1206}(Stream));
1207exports.MemoryStream = MemoryStream;
1208var xs = Stream;
1209exports.default = xs;
1210
1211},{"symbol-observable":2}],2:[function(require,module,exports){
1212(function (global){
1213'use strict';
1214
1215Object.defineProperty(exports, "__esModule", {
1216 value: true
1217});
1218
1219var _ponyfill = require('./ponyfill.js');
1220
1221var _ponyfill2 = _interopRequireDefault(_ponyfill);
1222
1223function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
1224
1225var root;
1226
1227
1228if (typeof self !== 'undefined') {
1229 root = self;
1230} else if (typeof window !== 'undefined') {
1231 root = window;
1232} else if (typeof global !== 'undefined') {
1233 root = global;
1234} else if (typeof module !== 'undefined') {
1235 root = module;
1236} else {
1237 root = Function('return this')();
1238}
1239
1240var result = (0, _ponyfill2['default'])(root);
1241exports['default'] = result;
1242}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
1243},{"./ponyfill.js":3}],3:[function(require,module,exports){
1244'use strict';
1245
1246Object.defineProperty(exports, "__esModule", {
1247 value: true
1248});
1249exports['default'] = symbolObservablePonyfill;
1250function symbolObservablePonyfill(root) {
1251 var result;
1252 var _Symbol = root.Symbol;
1253
1254 if (typeof _Symbol === 'function') {
1255 if (_Symbol.observable) {
1256 result = _Symbol.observable;
1257 } else {
1258 result = _Symbol('observable');
1259 _Symbol.observable = result;
1260 }
1261 } else {
1262 result = '@@observable';
1263 }
1264
1265 return result;
1266};
1267},{}]},{},[1])(1)
1268});