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