1 |
|
2 |
|
3 |
|
4 |
|
5 | (function (global, factory) {
|
6 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
7 | typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
8 | (factory((global.Kefir = global.Kefir || {})));
|
9 | }(this, (function (exports) { 'use strict';
|
10 |
|
11 | function createObj(proto) {
|
12 | var F = function () {};
|
13 | F.prototype = proto;
|
14 | return new F();
|
15 | }
|
16 |
|
17 | function extend(target /*, mixin1, mixin2...*/) {
|
18 | var length = arguments.length,
|
19 | i = void 0,
|
20 | prop = void 0;
|
21 | for (i = 1; i < length; i++) {
|
22 | for (prop in arguments[i]) {
|
23 | target[prop] = arguments[i][prop];
|
24 | }
|
25 | }
|
26 | return target;
|
27 | }
|
28 |
|
29 | function inherit(Child, Parent /*, mixin1, mixin2...*/) {
|
30 | var length = arguments.length,
|
31 | i = void 0;
|
32 | Child.prototype = createObj(Parent.prototype);
|
33 | Child.prototype.constructor = Child;
|
34 | for (i = 2; i < length; i++) {
|
35 | extend(Child.prototype, arguments[i]);
|
36 | }
|
37 | return Child;
|
38 | }
|
39 |
|
40 | var NOTHING = ['<nothing>'];
|
41 | var END = 'end';
|
42 | var VALUE = 'value';
|
43 | var ERROR = 'error';
|
44 | var ANY = 'any';
|
45 |
|
46 | function concat(a, b) {
|
47 | var result = void 0,
|
48 | length = void 0,
|
49 | i = void 0,
|
50 | j = void 0;
|
51 | if (a.length === 0) {
|
52 | return b;
|
53 | }
|
54 | if (b.length === 0) {
|
55 | return a;
|
56 | }
|
57 | j = 0;
|
58 | result = new Array(a.length + b.length);
|
59 | length = a.length;
|
60 | for (i = 0; i < length; i++, j++) {
|
61 | result[j] = a[i];
|
62 | }
|
63 | length = b.length;
|
64 | for (i = 0; i < length; i++, j++) {
|
65 | result[j] = b[i];
|
66 | }
|
67 | return result;
|
68 | }
|
69 |
|
70 | function find(arr, value) {
|
71 | var length = arr.length,
|
72 | i = void 0;
|
73 | for (i = 0; i < length; i++) {
|
74 | if (arr[i] === value) {
|
75 | return i;
|
76 | }
|
77 | }
|
78 | return -1;
|
79 | }
|
80 |
|
81 | function findByPred(arr, pred) {
|
82 | var length = arr.length,
|
83 | i = void 0;
|
84 | for (i = 0; i < length; i++) {
|
85 | if (pred(arr[i])) {
|
86 | return i;
|
87 | }
|
88 | }
|
89 | return -1;
|
90 | }
|
91 |
|
92 | function cloneArray(input) {
|
93 | var length = input.length,
|
94 | result = new Array(length),
|
95 | i = void 0;
|
96 | for (i = 0; i < length; i++) {
|
97 | result[i] = input[i];
|
98 | }
|
99 | return result;
|
100 | }
|
101 |
|
102 | function remove(input, index) {
|
103 | var length = input.length,
|
104 | result = void 0,
|
105 | i = void 0,
|
106 | j = void 0;
|
107 | if (index >= 0 && index < length) {
|
108 | if (length === 1) {
|
109 | return [];
|
110 | } else {
|
111 | result = new Array(length - 1);
|
112 | for (i = 0, j = 0; i < length; i++) {
|
113 | if (i !== index) {
|
114 | result[j] = input[i];
|
115 | j++;
|
116 | }
|
117 | }
|
118 | return result;
|
119 | }
|
120 | } else {
|
121 | return input;
|
122 | }
|
123 | }
|
124 |
|
125 | function map(input, fn) {
|
126 | var length = input.length,
|
127 | result = new Array(length),
|
128 | i = void 0;
|
129 | for (i = 0; i < length; i++) {
|
130 | result[i] = fn(input[i]);
|
131 | }
|
132 | return result;
|
133 | }
|
134 |
|
135 | function forEach(arr, fn) {
|
136 | var length = arr.length,
|
137 | i = void 0;
|
138 | for (i = 0; i < length; i++) {
|
139 | fn(arr[i]);
|
140 | }
|
141 | }
|
142 |
|
143 | function fillArray(arr, value) {
|
144 | var length = arr.length,
|
145 | i = void 0;
|
146 | for (i = 0; i < length; i++) {
|
147 | arr[i] = value;
|
148 | }
|
149 | }
|
150 |
|
151 | function contains(arr, value) {
|
152 | return find(arr, value) !== -1;
|
153 | }
|
154 |
|
155 | function slide(cur, next, max) {
|
156 | var length = Math.min(max, cur.length + 1),
|
157 | offset = cur.length - length + 1,
|
158 | result = new Array(length),
|
159 | i = void 0;
|
160 | for (i = offset; i < length; i++) {
|
161 | result[i - offset] = cur[i];
|
162 | }
|
163 | result[length - 1] = next;
|
164 | return result;
|
165 | }
|
166 |
|
167 | function callSubscriber(type, fn, event) {
|
168 | if (type === ANY) {
|
169 | fn(event);
|
170 | } else if (type === event.type) {
|
171 | if (type === VALUE || type === ERROR) {
|
172 | fn(event.value);
|
173 | } else {
|
174 | fn();
|
175 | }
|
176 | }
|
177 | }
|
178 |
|
179 | function Dispatcher() {
|
180 | this._items = [];
|
181 | this._spies = [];
|
182 | this._inLoop = 0;
|
183 | this._removedItems = null;
|
184 | }
|
185 |
|
186 | extend(Dispatcher.prototype, {
|
187 | add: function (type, fn) {
|
188 | this._items = concat(this._items, [{ type: type, fn: fn }]);
|
189 | return this._items.length;
|
190 | },
|
191 | remove: function (type, fn) {
|
192 | var index = findByPred(this._items, function (x) {
|
193 | return x.type === type && x.fn === fn;
|
194 | });
|
195 |
|
196 |
|
197 |
|
198 | if (this._inLoop !== 0 && index !== -1) {
|
199 | if (this._removedItems === null) {
|
200 | this._removedItems = [];
|
201 | }
|
202 | this._removedItems.push(this._items[index]);
|
203 | }
|
204 |
|
205 | this._items = remove(this._items, index);
|
206 | return this._items.length;
|
207 | },
|
208 | addSpy: function (fn) {
|
209 | this._spies = concat(this._spies, [fn]);
|
210 | return this._spies.length;
|
211 | },
|
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 | removeSpy: function (fn) {
|
218 | this._spies = remove(this._spies, this._spies.indexOf(fn));
|
219 | return this._spies.length;
|
220 | },
|
221 | dispatch: function (event) {
|
222 | this._inLoop++;
|
223 | for (var i = 0, spies = this._spies; this._spies !== null && i < spies.length; i++) {
|
224 | spies[i](event);
|
225 | }
|
226 |
|
227 | for (var _i = 0, items = this._items; _i < items.length; _i++) {
|
228 |
|
229 | if (this._items === null) {
|
230 | break;
|
231 | }
|
232 |
|
233 |
|
234 | if (this._removedItems !== null && contains(this._removedItems, items[_i])) {
|
235 | continue;
|
236 | }
|
237 |
|
238 | callSubscriber(items[_i].type, items[_i].fn, event);
|
239 | }
|
240 | this._inLoop--;
|
241 | if (this._inLoop === 0) {
|
242 | this._removedItems = null;
|
243 | }
|
244 | },
|
245 | cleanup: function () {
|
246 | this._items = null;
|
247 | this._spies = null;
|
248 | }
|
249 | });
|
250 |
|
251 | function Observable() {
|
252 | this._dispatcher = new Dispatcher();
|
253 | this._active = false;
|
254 | this._alive = true;
|
255 | this._activating = false;
|
256 | this._logHandlers = null;
|
257 | this._spyHandlers = null;
|
258 | }
|
259 |
|
260 | extend(Observable.prototype, {
|
261 | _name: 'observable',
|
262 |
|
263 | _onActivation: function () {},
|
264 | _onDeactivation: function () {},
|
265 | _setActive: function (active) {
|
266 | if (this._active !== active) {
|
267 | this._active = active;
|
268 | if (active) {
|
269 | this._activating = true;
|
270 | this._onActivation();
|
271 | this._activating = false;
|
272 | } else {
|
273 | this._onDeactivation();
|
274 | }
|
275 | }
|
276 | },
|
277 | _clear: function () {
|
278 | this._setActive(false);
|
279 | this._dispatcher.cleanup();
|
280 | this._dispatcher = null;
|
281 | this._logHandlers = null;
|
282 | },
|
283 | _emit: function (type, x) {
|
284 | switch (type) {
|
285 | case VALUE:
|
286 | return this._emitValue(x);
|
287 | case ERROR:
|
288 | return this._emitError(x);
|
289 | case END:
|
290 | return this._emitEnd();
|
291 | }
|
292 | },
|
293 | _emitValue: function (value) {
|
294 | if (this._alive) {
|
295 | this._dispatcher.dispatch({ type: VALUE, value: value });
|
296 | }
|
297 | },
|
298 | _emitError: function (value) {
|
299 | if (this._alive) {
|
300 | this._dispatcher.dispatch({ type: ERROR, value: value });
|
301 | }
|
302 | },
|
303 | _emitEnd: function () {
|
304 | if (this._alive) {
|
305 | this._alive = false;
|
306 | this._dispatcher.dispatch({ type: END });
|
307 | this._clear();
|
308 | }
|
309 | },
|
310 | _on: function (type, fn) {
|
311 | if (this._alive) {
|
312 | this._dispatcher.add(type, fn);
|
313 | this._setActive(true);
|
314 | } else {
|
315 | callSubscriber(type, fn, { type: END });
|
316 | }
|
317 | return this;
|
318 | },
|
319 | _off: function (type, fn) {
|
320 | if (this._alive) {
|
321 | var count = this._dispatcher.remove(type, fn);
|
322 | if (count === 0) {
|
323 | this._setActive(false);
|
324 | }
|
325 | }
|
326 | return this;
|
327 | },
|
328 | onValue: function (fn) {
|
329 | return this._on(VALUE, fn);
|
330 | },
|
331 | onError: function (fn) {
|
332 | return this._on(ERROR, fn);
|
333 | },
|
334 | onEnd: function (fn) {
|
335 | return this._on(END, fn);
|
336 | },
|
337 | onAny: function (fn) {
|
338 | return this._on(ANY, fn);
|
339 | },
|
340 | offValue: function (fn) {
|
341 | return this._off(VALUE, fn);
|
342 | },
|
343 | offError: function (fn) {
|
344 | return this._off(ERROR, fn);
|
345 | },
|
346 | offEnd: function (fn) {
|
347 | return this._off(END, fn);
|
348 | },
|
349 | offAny: function (fn) {
|
350 | return this._off(ANY, fn);
|
351 | },
|
352 | observe: function (observerOrOnValue, onError, onEnd) {
|
353 | var _this = this;
|
354 | var closed = false;
|
355 |
|
356 | var observer = !observerOrOnValue || typeof observerOrOnValue === 'function' ? { value: observerOrOnValue, error: onError, end: onEnd } : observerOrOnValue;
|
357 |
|
358 | var handler = function (event) {
|
359 | if (event.type === END) {
|
360 | closed = true;
|
361 | }
|
362 | if (event.type === VALUE && observer.value) {
|
363 | observer.value(event.value);
|
364 | } else if (event.type === ERROR && observer.error) {
|
365 | observer.error(event.value);
|
366 | } else if (event.type === END && observer.end) {
|
367 | observer.end(event.value);
|
368 | }
|
369 | };
|
370 |
|
371 | this.onAny(handler);
|
372 |
|
373 | return {
|
374 | unsubscribe: function () {
|
375 | if (!closed) {
|
376 | _this.offAny(handler);
|
377 | closed = true;
|
378 | }
|
379 | },
|
380 |
|
381 | get closed() {
|
382 | return closed;
|
383 | }
|
384 | };
|
385 | },
|
386 |
|
387 |
|
388 |
|
389 | _ofSameType: function (A, B) {
|
390 | return A.prototype.getType() === this.getType() ? A : B;
|
391 | },
|
392 | setName: function (sourceObs /* optional */, selfName) {
|
393 | this._name = selfName ? sourceObs._name + '.' + selfName : sourceObs;
|
394 | return this;
|
395 | },
|
396 | log: function () {
|
397 | var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.toString();
|
398 |
|
399 | var isCurrent = void 0;
|
400 | var handler = function (event) {
|
401 | var type = '<' + event.type + (isCurrent ? ':current' : '') + '>';
|
402 | if (event.type === END) {
|
403 | console.log(name, type);
|
404 | } else {
|
405 | console.log(name, type, event.value);
|
406 | }
|
407 | };
|
408 |
|
409 | if (this._alive) {
|
410 | if (!this._logHandlers) {
|
411 | this._logHandlers = [];
|
412 | }
|
413 | this._logHandlers.push({ name: name, handler: handler });
|
414 | }
|
415 |
|
416 | isCurrent = true;
|
417 | this.onAny(handler);
|
418 | isCurrent = false;
|
419 |
|
420 | return this;
|
421 | },
|
422 | offLog: function () {
|
423 | var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.toString();
|
424 |
|
425 | if (this._logHandlers) {
|
426 | var handlerIndex = findByPred(this._logHandlers, function (obj) {
|
427 | return obj.name === name;
|
428 | });
|
429 | if (handlerIndex !== -1) {
|
430 | this.offAny(this._logHandlers[handlerIndex].handler);
|
431 | this._logHandlers.splice(handlerIndex, 1);
|
432 | }
|
433 | }
|
434 |
|
435 | return this;
|
436 | },
|
437 | spy: function () {
|
438 | var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.toString();
|
439 |
|
440 | var handler = function (event) {
|
441 | var type = '<' + event.type + '>';
|
442 | if (event.type === END) {
|
443 | console.log(name, type);
|
444 | } else {
|
445 | console.log(name, type, event.value);
|
446 | }
|
447 | };
|
448 | if (this._alive) {
|
449 | if (!this._spyHandlers) {
|
450 | this._spyHandlers = [];
|
451 | }
|
452 | this._spyHandlers.push({ name: name, handler: handler });
|
453 | this._dispatcher.addSpy(handler);
|
454 | }
|
455 | return this;
|
456 | },
|
457 | offSpy: function () {
|
458 | var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.toString();
|
459 |
|
460 | if (this._spyHandlers) {
|
461 | var handlerIndex = findByPred(this._spyHandlers, function (obj) {
|
462 | return obj.name === name;
|
463 | });
|
464 | if (handlerIndex !== -1) {
|
465 | this._dispatcher.removeSpy(this._spyHandlers[handlerIndex].handler);
|
466 | this._spyHandlers.splice(handlerIndex, 1);
|
467 | }
|
468 | }
|
469 | return this;
|
470 | }
|
471 | });
|
472 |
|
473 |
|
474 | Observable.prototype.toString = function () {
|
475 | return '[' + this._name + ']';
|
476 | };
|
477 |
|
478 | function Stream() {
|
479 | Observable.call(this);
|
480 | }
|
481 |
|
482 | inherit(Stream, Observable, {
|
483 | _name: 'stream',
|
484 |
|
485 | getType: function () {
|
486 | return 'stream';
|
487 | }
|
488 | });
|
489 |
|
490 | function Property() {
|
491 | Observable.call(this);
|
492 | this._currentEvent = null;
|
493 | }
|
494 |
|
495 | inherit(Property, Observable, {
|
496 | _name: 'property',
|
497 |
|
498 | _emitValue: function (value) {
|
499 | if (this._alive) {
|
500 | this._currentEvent = { type: VALUE, value: value };
|
501 | if (!this._activating) {
|
502 | this._dispatcher.dispatch({ type: VALUE, value: value });
|
503 | }
|
504 | }
|
505 | },
|
506 | _emitError: function (value) {
|
507 | if (this._alive) {
|
508 | this._currentEvent = { type: ERROR, value: value };
|
509 | if (!this._activating) {
|
510 | this._dispatcher.dispatch({ type: ERROR, value: value });
|
511 | }
|
512 | }
|
513 | },
|
514 | _emitEnd: function () {
|
515 | if (this._alive) {
|
516 | this._alive = false;
|
517 | if (!this._activating) {
|
518 | this._dispatcher.dispatch({ type: END });
|
519 | }
|
520 | this._clear();
|
521 | }
|
522 | },
|
523 | _on: function (type, fn) {
|
524 | if (this._alive) {
|
525 | this._dispatcher.add(type, fn);
|
526 | this._setActive(true);
|
527 | }
|
528 | if (this._currentEvent !== null) {
|
529 | callSubscriber(type, fn, this._currentEvent);
|
530 | }
|
531 | if (!this._alive) {
|
532 | callSubscriber(type, fn, { type: END });
|
533 | }
|
534 | return this;
|
535 | },
|
536 | getType: function () {
|
537 | return 'property';
|
538 | }
|
539 | });
|
540 |
|
541 | var neverS = new Stream();
|
542 | neverS._emitEnd();
|
543 | neverS._name = 'never';
|
544 |
|
545 | function never() {
|
546 | return neverS;
|
547 | }
|
548 |
|
549 | function timeBased(mixin) {
|
550 | function AnonymousStream(wait, options) {
|
551 | var _this = this;
|
552 |
|
553 | Stream.call(this);
|
554 | this._wait = wait;
|
555 | this._intervalId = null;
|
556 | this._$onTick = function () {
|
557 | return _this._onTick();
|
558 | };
|
559 | this._init(options);
|
560 | }
|
561 |
|
562 | inherit(AnonymousStream, Stream, {
|
563 | _init: function () {},
|
564 | _free: function () {},
|
565 | _onTick: function () {},
|
566 | _onActivation: function () {
|
567 | this._intervalId = setInterval(this._$onTick, this._wait);
|
568 | },
|
569 | _onDeactivation: function () {
|
570 | if (this._intervalId !== null) {
|
571 | clearInterval(this._intervalId);
|
572 | this._intervalId = null;
|
573 | }
|
574 | },
|
575 | _clear: function () {
|
576 | Stream.prototype._clear.call(this);
|
577 | this._$onTick = null;
|
578 | this._free();
|
579 | }
|
580 | }, mixin);
|
581 |
|
582 | return AnonymousStream;
|
583 | }
|
584 |
|
585 | var S = timeBased({
|
586 | _name: 'later',
|
587 |
|
588 | _init: function (_ref) {
|
589 | var x = _ref.x;
|
590 |
|
591 | this._x = x;
|
592 | },
|
593 | _free: function () {
|
594 | this._x = null;
|
595 | },
|
596 | _onTick: function () {
|
597 | this._emitValue(this._x);
|
598 | this._emitEnd();
|
599 | }
|
600 | });
|
601 |
|
602 | function later(wait, x) {
|
603 | return new S(wait, { x: x });
|
604 | }
|
605 |
|
606 | var S$1 = timeBased({
|
607 | _name: 'interval',
|
608 |
|
609 | _init: function (_ref) {
|
610 | var x = _ref.x;
|
611 |
|
612 | this._x = x;
|
613 | },
|
614 | _free: function () {
|
615 | this._x = null;
|
616 | },
|
617 | _onTick: function () {
|
618 | this._emitValue(this._x);
|
619 | }
|
620 | });
|
621 |
|
622 | function interval(wait, x) {
|
623 | return new S$1(wait, { x: x });
|
624 | }
|
625 |
|
626 | var S$2 = timeBased({
|
627 | _name: 'sequentially',
|
628 |
|
629 | _init: function (_ref) {
|
630 | var xs = _ref.xs;
|
631 |
|
632 | this._xs = cloneArray(xs);
|
633 | },
|
634 | _free: function () {
|
635 | this._xs = null;
|
636 | },
|
637 | _onTick: function () {
|
638 | if (this._xs.length === 1) {
|
639 | this._emitValue(this._xs[0]);
|
640 | this._emitEnd();
|
641 | } else {
|
642 | this._emitValue(this._xs.shift());
|
643 | }
|
644 | }
|
645 | });
|
646 |
|
647 | function sequentially(wait, xs) {
|
648 | return xs.length === 0 ? never() : new S$2(wait, { xs: xs });
|
649 | }
|
650 |
|
651 | var S$3 = timeBased({
|
652 | _name: 'fromPoll',
|
653 |
|
654 | _init: function (_ref) {
|
655 | var fn = _ref.fn;
|
656 |
|
657 | this._fn = fn;
|
658 | },
|
659 | _free: function () {
|
660 | this._fn = null;
|
661 | },
|
662 | _onTick: function () {
|
663 | var fn = this._fn;
|
664 | this._emitValue(fn());
|
665 | }
|
666 | });
|
667 |
|
668 | function fromPoll(wait, fn) {
|
669 | return new S$3(wait, { fn: fn });
|
670 | }
|
671 |
|
672 | function emitter(obs) {
|
673 | function value(x) {
|
674 | obs._emitValue(x);
|
675 | return obs._active;
|
676 | }
|
677 |
|
678 | function error(x) {
|
679 | obs._emitError(x);
|
680 | return obs._active;
|
681 | }
|
682 |
|
683 | function end() {
|
684 | obs._emitEnd();
|
685 | return obs._active;
|
686 | }
|
687 |
|
688 | function event(e) {
|
689 | obs._emit(e.type, e.value);
|
690 | return obs._active;
|
691 | }
|
692 |
|
693 | return {
|
694 | value: value,
|
695 | error: error,
|
696 | end: end,
|
697 | event: event,
|
698 |
|
699 |
|
700 | emit: value,
|
701 | emitEvent: event
|
702 | };
|
703 | }
|
704 |
|
705 | var S$4 = timeBased({
|
706 | _name: 'withInterval',
|
707 |
|
708 | _init: function (_ref) {
|
709 | var fn = _ref.fn;
|
710 |
|
711 | this._fn = fn;
|
712 | this._emitter = emitter(this);
|
713 | },
|
714 | _free: function () {
|
715 | this._fn = null;
|
716 | this._emitter = null;
|
717 | },
|
718 | _onTick: function () {
|
719 | var fn = this._fn;
|
720 | fn(this._emitter);
|
721 | }
|
722 | });
|
723 |
|
724 | function withInterval(wait, fn) {
|
725 | return new S$4(wait, { fn: fn });
|
726 | }
|
727 |
|
728 | function S$5(fn) {
|
729 | Stream.call(this);
|
730 | this._fn = fn;
|
731 | this._unsubscribe = null;
|
732 | }
|
733 |
|
734 | inherit(S$5, Stream, {
|
735 | _name: 'stream',
|
736 |
|
737 | _onActivation: function () {
|
738 | var fn = this._fn;
|
739 | var unsubscribe = fn(emitter(this));
|
740 | this._unsubscribe = typeof unsubscribe === 'function' ? unsubscribe : null;
|
741 |
|
742 |
|
743 | if (!this._active) {
|
744 | this._callUnsubscribe();
|
745 | }
|
746 | },
|
747 | _callUnsubscribe: function () {
|
748 | if (this._unsubscribe !== null) {
|
749 | this._unsubscribe();
|
750 | this._unsubscribe = null;
|
751 | }
|
752 | },
|
753 | _onDeactivation: function () {
|
754 | this._callUnsubscribe();
|
755 | },
|
756 | _clear: function () {
|
757 | Stream.prototype._clear.call(this);
|
758 | this._fn = null;
|
759 | }
|
760 | });
|
761 |
|
762 | function stream(fn) {
|
763 | return new S$5(fn);
|
764 | }
|
765 |
|
766 | function fromCallback(callbackConsumer) {
|
767 | var called = false;
|
768 |
|
769 | return stream(function (emitter) {
|
770 | if (!called) {
|
771 | callbackConsumer(function (x) {
|
772 | emitter.emit(x);
|
773 | emitter.end();
|
774 | });
|
775 | called = true;
|
776 | }
|
777 | }).setName('fromCallback');
|
778 | }
|
779 |
|
780 | function fromNodeCallback(callbackConsumer) {
|
781 | var called = false;
|
782 |
|
783 | return stream(function (emitter) {
|
784 | if (!called) {
|
785 | callbackConsumer(function (error, x) {
|
786 | if (error) {
|
787 | emitter.error(error);
|
788 | } else {
|
789 | emitter.emit(x);
|
790 | }
|
791 | emitter.end();
|
792 | });
|
793 | called = true;
|
794 | }
|
795 | }).setName('fromNodeCallback');
|
796 | }
|
797 |
|
798 | function spread(fn, length) {
|
799 | switch (length) {
|
800 | case 0:
|
801 | return function () {
|
802 | return fn();
|
803 | };
|
804 | case 1:
|
805 | return function (a) {
|
806 | return fn(a[0]);
|
807 | };
|
808 | case 2:
|
809 | return function (a) {
|
810 | return fn(a[0], a[1]);
|
811 | };
|
812 | case 3:
|
813 | return function (a) {
|
814 | return fn(a[0], a[1], a[2]);
|
815 | };
|
816 | case 4:
|
817 | return function (a) {
|
818 | return fn(a[0], a[1], a[2], a[3]);
|
819 | };
|
820 | default:
|
821 | return function (a) {
|
822 | return fn.apply(null, a);
|
823 | };
|
824 | }
|
825 | }
|
826 |
|
827 | function apply(fn, c, a) {
|
828 | var aLength = a ? a.length : 0;
|
829 | if (c == null) {
|
830 | switch (aLength) {
|
831 | case 0:
|
832 | return fn();
|
833 | case 1:
|
834 | return fn(a[0]);
|
835 | case 2:
|
836 | return fn(a[0], a[1]);
|
837 | case 3:
|
838 | return fn(a[0], a[1], a[2]);
|
839 | case 4:
|
840 | return fn(a[0], a[1], a[2], a[3]);
|
841 | default:
|
842 | return fn.apply(null, a);
|
843 | }
|
844 | } else {
|
845 | switch (aLength) {
|
846 | case 0:
|
847 | return fn.call(c);
|
848 | default:
|
849 | return fn.apply(c, a);
|
850 | }
|
851 | }
|
852 | }
|
853 |
|
854 | function fromSubUnsub(sub, unsub, transformer /* Function | falsey */) {
|
855 | return stream(function (emitter) {
|
856 | var handler = transformer ? function () {
|
857 | emitter.emit(apply(transformer, this, arguments));
|
858 | } : function (x) {
|
859 | emitter.emit(x);
|
860 | };
|
861 |
|
862 | sub(handler);
|
863 | return function () {
|
864 | return unsub(handler);
|
865 | };
|
866 | }).setName('fromSubUnsub');
|
867 | }
|
868 |
|
869 | var pairs = [['addEventListener', 'removeEventListener'], ['addListener', 'removeListener'], ['on', 'off']];
|
870 |
|
871 | function fromEvents(target, eventName, transformer) {
|
872 | var sub = void 0,
|
873 | unsub = void 0;
|
874 |
|
875 | for (var i = 0; i < pairs.length; i++) {
|
876 | if (typeof target[pairs[i][0]] === 'function' && typeof target[pairs[i][1]] === 'function') {
|
877 | sub = pairs[i][0];
|
878 | unsub = pairs[i][1];
|
879 | break;
|
880 | }
|
881 | }
|
882 |
|
883 | if (sub === undefined) {
|
884 | throw new Error("target don't support any of " + 'addEventListener/removeEventListener, addListener/removeListener, on/off method pair');
|
885 | }
|
886 |
|
887 | return fromSubUnsub(function (handler) {
|
888 | return target[sub](eventName, handler);
|
889 | }, function (handler) {
|
890 | return target[unsub](eventName, handler);
|
891 | }, transformer).setName('fromEvents');
|
892 | }
|
893 |
|
894 |
|
895 |
|
896 |
|
897 |
|
898 |
|
899 | function P(value) {
|
900 | this._currentEvent = { type: 'value', value: value, current: true };
|
901 | }
|
902 |
|
903 | inherit(P, Property, {
|
904 | _name: 'constant',
|
905 | _active: false,
|
906 | _activating: false,
|
907 | _alive: false,
|
908 | _dispatcher: null,
|
909 | _logHandlers: null
|
910 | });
|
911 |
|
912 | function constant(x) {
|
913 | return new P(x);
|
914 | }
|
915 |
|
916 |
|
917 |
|
918 |
|
919 |
|
920 |
|
921 | function P$1(value) {
|
922 | this._currentEvent = { type: 'error', value: value, current: true };
|
923 | }
|
924 |
|
925 | inherit(P$1, Property, {
|
926 | _name: 'constantError',
|
927 | _active: false,
|
928 | _activating: false,
|
929 | _alive: false,
|
930 | _dispatcher: null,
|
931 | _logHandlers: null
|
932 | });
|
933 |
|
934 | function constantError(x) {
|
935 | return new P$1(x);
|
936 | }
|
937 |
|
938 | function createConstructor(BaseClass, name) {
|
939 | return function AnonymousObservable(source, options) {
|
940 | var _this = this;
|
941 |
|
942 | BaseClass.call(this);
|
943 | this._source = source;
|
944 | this._name = source._name + '.' + name;
|
945 | this._init(options);
|
946 | this._$handleAny = function (event) {
|
947 | return _this._handleAny(event);
|
948 | };
|
949 | };
|
950 | }
|
951 |
|
952 | function createClassMethods(BaseClass) {
|
953 | return {
|
954 | _init: function () {},
|
955 | _free: function () {},
|
956 | _handleValue: function (x) {
|
957 | this._emitValue(x);
|
958 | },
|
959 | _handleError: function (x) {
|
960 | this._emitError(x);
|
961 | },
|
962 | _handleEnd: function () {
|
963 | this._emitEnd();
|
964 | },
|
965 | _handleAny: function (event) {
|
966 | switch (event.type) {
|
967 | case VALUE:
|
968 | return this._handleValue(event.value);
|
969 | case ERROR:
|
970 | return this._handleError(event.value);
|
971 | case END:
|
972 | return this._handleEnd();
|
973 | }
|
974 | },
|
975 | _onActivation: function () {
|
976 | this._source.onAny(this._$handleAny);
|
977 | },
|
978 | _onDeactivation: function () {
|
979 | this._source.offAny(this._$handleAny);
|
980 | },
|
981 | _clear: function () {
|
982 | BaseClass.prototype._clear.call(this);
|
983 | this._source = null;
|
984 | this._$handleAny = null;
|
985 | this._free();
|
986 | }
|
987 | };
|
988 | }
|
989 |
|
990 | function createStream(name, mixin) {
|
991 | var S = createConstructor(Stream, name);
|
992 | inherit(S, Stream, createClassMethods(Stream), mixin);
|
993 | return S;
|
994 | }
|
995 |
|
996 | function createProperty(name, mixin) {
|
997 | var P = createConstructor(Property, name);
|
998 | inherit(P, Property, createClassMethods(Property), mixin);
|
999 | return P;
|
1000 | }
|
1001 |
|
1002 | var P$2 = createProperty('toProperty', {
|
1003 | _init: function (_ref) {
|
1004 | var fn = _ref.fn;
|
1005 |
|
1006 | this._getInitialCurrent = fn;
|
1007 | },
|
1008 | _onActivation: function () {
|
1009 | if (this._getInitialCurrent !== null) {
|
1010 | var getInitial = this._getInitialCurrent;
|
1011 | this._emitValue(getInitial());
|
1012 | }
|
1013 | this._source.onAny(this._$handleAny);
|
1014 | }
|
1015 | });
|
1016 |
|
1017 | function toProperty(obs) {
|
1018 | var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
1019 |
|
1020 | if (fn !== null && typeof fn !== 'function') {
|
1021 | throw new Error('You should call toProperty() with a function or no arguments.');
|
1022 | }
|
1023 | return new P$2(obs, { fn: fn });
|
1024 | }
|
1025 |
|
1026 | var S$6 = createStream('changes', {
|
1027 | _handleValue: function (x) {
|
1028 | if (!this._activating) {
|
1029 | this._emitValue(x);
|
1030 | }
|
1031 | },
|
1032 | _handleError: function (x) {
|
1033 | if (!this._activating) {
|
1034 | this._emitError(x);
|
1035 | }
|
1036 | }
|
1037 | });
|
1038 |
|
1039 | function changes(obs) {
|
1040 | return new S$6(obs);
|
1041 | }
|
1042 |
|
1043 | function fromPromise(promise) {
|
1044 | var called = false;
|
1045 |
|
1046 | var result = stream(function (emitter) {
|
1047 | if (!called) {
|
1048 | var onValue = function (x) {
|
1049 | emitter.emit(x);
|
1050 | emitter.end();
|
1051 | };
|
1052 | var onError = function (x) {
|
1053 | emitter.error(x);
|
1054 | emitter.end();
|
1055 | };
|
1056 | var _promise = promise.then(onValue, onError);
|
1057 |
|
1058 |
|
1059 | if (_promise && typeof _promise.done === 'function') {
|
1060 | _promise.done();
|
1061 | }
|
1062 |
|
1063 | called = true;
|
1064 | }
|
1065 | });
|
1066 |
|
1067 | return toProperty(result, null).setName('fromPromise');
|
1068 | }
|
1069 |
|
1070 | function getGlodalPromise() {
|
1071 | if (typeof Promise === 'function') {
|
1072 | return Promise;
|
1073 | } else {
|
1074 | throw new Error("There isn't default Promise, use shim or parameter");
|
1075 | }
|
1076 | }
|
1077 |
|
1078 | var toPromise = function (obs) {
|
1079 | var Promise = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getGlodalPromise();
|
1080 |
|
1081 | var last = null;
|
1082 | return new Promise(function (resolve, reject) {
|
1083 | obs.onAny(function (event) {
|
1084 | if (event.type === END && last !== null) {
|
1085 | (last.type === VALUE ? resolve : reject)(last.value);
|
1086 | last = null;
|
1087 | } else {
|
1088 | last = event;
|
1089 | }
|
1090 | });
|
1091 | });
|
1092 | };
|
1093 |
|
1094 | var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
1095 |
|
1096 |
|
1097 |
|
1098 |
|
1099 |
|
1100 | function createCommonjsModule(fn, module) {
|
1101 | return module = { exports: {} }, fn(module, module.exports), module.exports;
|
1102 | }
|
1103 |
|
1104 | var ponyfill = createCommonjsModule(function (module, exports) {
|
1105 | 'use strict';
|
1106 |
|
1107 | Object.defineProperty(exports, "__esModule", {
|
1108 | value: true
|
1109 | });
|
1110 | exports['default'] = symbolObservablePonyfill;
|
1111 | function symbolObservablePonyfill(root) {
|
1112 | var result;
|
1113 | var _Symbol = root.Symbol;
|
1114 |
|
1115 | if (typeof _Symbol === 'function') {
|
1116 | if (_Symbol.observable) {
|
1117 | result = _Symbol.observable;
|
1118 | } else {
|
1119 | result = _Symbol('observable');
|
1120 | _Symbol.observable = result;
|
1121 | }
|
1122 | } else {
|
1123 | result = '@@observable';
|
1124 | }
|
1125 |
|
1126 | return result;
|
1127 | }
|
1128 | });
|
1129 |
|
1130 | var index$1 = createCommonjsModule(function (module, exports) {
|
1131 | 'use strict';
|
1132 |
|
1133 | Object.defineProperty(exports, "__esModule", {
|
1134 | value: true
|
1135 | });
|
1136 |
|
1137 |
|
1138 |
|
1139 | var _ponyfill2 = _interopRequireDefault(ponyfill);
|
1140 |
|
1141 | function _interopRequireDefault(obj) {
|
1142 | return obj && obj.__esModule ? obj : { 'default': obj };
|
1143 | }
|
1144 |
|
1145 | var root;
|
1146 |
|
1147 | if (typeof self !== 'undefined') {
|
1148 | root = self;
|
1149 | } else if (typeof window !== 'undefined') {
|
1150 | root = window;
|
1151 | } else if (typeof commonjsGlobal !== 'undefined') {
|
1152 | root = commonjsGlobal;
|
1153 | } else {
|
1154 | root = module;
|
1155 | }
|
1156 |
|
1157 | var result = (0, _ponyfill2['default'])(root);
|
1158 | exports['default'] = result;
|
1159 | });
|
1160 |
|
1161 | var index = index$1;
|
1162 |
|
1163 |
|
1164 |
|
1165 | var $$observable = index.default ? index.default : index;
|
1166 |
|
1167 | function fromESObservable(_observable) {
|
1168 | var observable = _observable[$$observable] ? _observable[$$observable]() : _observable;
|
1169 | return stream(function (emitter) {
|
1170 | var unsub = observable.subscribe({
|
1171 | error: function (error) {
|
1172 | emitter.error(error);
|
1173 | emitter.end();
|
1174 | },
|
1175 | next: function (value) {
|
1176 | emitter.emit(value);
|
1177 | },
|
1178 | complete: function () {
|
1179 | emitter.end();
|
1180 | }
|
1181 | });
|
1182 |
|
1183 | if (unsub.unsubscribe) {
|
1184 | return function () {
|
1185 | unsub.unsubscribe();
|
1186 | };
|
1187 | } else {
|
1188 | return unsub;
|
1189 | }
|
1190 | }).setName('fromESObservable');
|
1191 | }
|
1192 |
|
1193 | function ESObservable(observable) {
|
1194 | this._observable = observable.takeErrors(1);
|
1195 | }
|
1196 |
|
1197 | extend(ESObservable.prototype, {
|
1198 | subscribe: function (observerOrOnNext, onError, onComplete) {
|
1199 | var _this = this;
|
1200 |
|
1201 | var observer = typeof observerOrOnNext === 'function' ? { next: observerOrOnNext, error: onError, complete: onComplete } : observerOrOnNext;
|
1202 |
|
1203 | var fn = function (event) {
|
1204 | if (event.type === END) {
|
1205 | closed = true;
|
1206 | }
|
1207 |
|
1208 | if (event.type === VALUE && observer.next) {
|
1209 | observer.next(event.value);
|
1210 | } else if (event.type === ERROR && observer.error) {
|
1211 | observer.error(event.value);
|
1212 | } else if (event.type === END && observer.complete) {
|
1213 | observer.complete(event.value);
|
1214 | }
|
1215 | };
|
1216 |
|
1217 | this._observable.onAny(fn);
|
1218 | var closed = false;
|
1219 |
|
1220 | var subscription = {
|
1221 | unsubscribe: function () {
|
1222 | closed = true;
|
1223 | _this._observable.offAny(fn);
|
1224 | },
|
1225 | get closed() {
|
1226 | return closed;
|
1227 | }
|
1228 | };
|
1229 | return subscription;
|
1230 | }
|
1231 | });
|
1232 |
|
1233 |
|
1234 | ESObservable.prototype[$$observable] = function () {
|
1235 | return this;
|
1236 | };
|
1237 |
|
1238 | function toESObservable() {
|
1239 | return new ESObservable(this);
|
1240 | }
|
1241 |
|
1242 | function collect(source, keys, values) {
|
1243 | for (var prop in source) {
|
1244 | if (source.hasOwnProperty(prop)) {
|
1245 | keys.push(prop);
|
1246 | values.push(source[prop]);
|
1247 | }
|
1248 | }
|
1249 | }
|
1250 |
|
1251 | function defaultErrorsCombinator(errors) {
|
1252 | var latestError = void 0;
|
1253 | for (var i = 0; i < errors.length; i++) {
|
1254 | if (errors[i] !== undefined) {
|
1255 | if (latestError === undefined || latestError.index < errors[i].index) {
|
1256 | latestError = errors[i];
|
1257 | }
|
1258 | }
|
1259 | }
|
1260 | return latestError.error;
|
1261 | }
|
1262 |
|
1263 | function Combine(active, passive, combinator) {
|
1264 | var _this = this;
|
1265 |
|
1266 | Stream.call(this);
|
1267 | this._activeCount = active.length;
|
1268 | this._sources = concat(active, passive);
|
1269 | this._combinator = combinator;
|
1270 | this._aliveCount = 0;
|
1271 | this._latestValues = new Array(this._sources.length);
|
1272 | this._latestErrors = new Array(this._sources.length);
|
1273 | fillArray(this._latestValues, NOTHING);
|
1274 | this._emitAfterActivation = false;
|
1275 | this._endAfterActivation = false;
|
1276 | this._latestErrorIndex = 0;
|
1277 |
|
1278 | this._$handlers = [];
|
1279 |
|
1280 | var _loop = function (i) {
|
1281 | _this._$handlers.push(function (event) {
|
1282 | return _this._handleAny(i, event);
|
1283 | });
|
1284 | };
|
1285 |
|
1286 | for (var i = 0; i < this._sources.length; i++) {
|
1287 | _loop(i);
|
1288 | }
|
1289 | }
|
1290 |
|
1291 | inherit(Combine, Stream, {
|
1292 | _name: 'combine',
|
1293 |
|
1294 | _onActivation: function () {
|
1295 | this._aliveCount = this._activeCount;
|
1296 |
|
1297 |
|
1298 |
|
1299 | for (var i = this._activeCount; i < this._sources.length; i++) {
|
1300 | this._sources[i].onAny(this._$handlers[i]);
|
1301 | }
|
1302 | for (var _i = 0; _i < this._activeCount; _i++) {
|
1303 | this._sources[_i].onAny(this._$handlers[_i]);
|
1304 | }
|
1305 |
|
1306 | if (this._emitAfterActivation) {
|
1307 | this._emitAfterActivation = false;
|
1308 | this._emitIfFull();
|
1309 | }
|
1310 | if (this._endAfterActivation) {
|
1311 | this._emitEnd();
|
1312 | }
|
1313 | },
|
1314 | _onDeactivation: function () {
|
1315 | var length = this._sources.length,
|
1316 | i = void 0;
|
1317 | for (i = 0; i < length; i++) {
|
1318 | this._sources[i].offAny(this._$handlers[i]);
|
1319 | }
|
1320 | },
|
1321 | _emitIfFull: function () {
|
1322 | var hasAllValues = true;
|
1323 | var hasErrors = false;
|
1324 | var length = this._latestValues.length;
|
1325 | var valuesCopy = new Array(length);
|
1326 | var errorsCopy = new Array(length);
|
1327 |
|
1328 | for (var i = 0; i < length; i++) {
|
1329 | valuesCopy[i] = this._latestValues[i];
|
1330 | errorsCopy[i] = this._latestErrors[i];
|
1331 |
|
1332 | if (valuesCopy[i] === NOTHING) {
|
1333 | hasAllValues = false;
|
1334 | }
|
1335 |
|
1336 | if (errorsCopy[i] !== undefined) {
|
1337 | hasErrors = true;
|
1338 | }
|
1339 | }
|
1340 |
|
1341 | if (hasAllValues) {
|
1342 | var combinator = this._combinator;
|
1343 | this._emitValue(combinator(valuesCopy));
|
1344 | }
|
1345 | if (hasErrors) {
|
1346 | this._emitError(defaultErrorsCombinator(errorsCopy));
|
1347 | }
|
1348 | },
|
1349 | _handleAny: function (i, event) {
|
1350 | if (event.type === VALUE || event.type === ERROR) {
|
1351 | if (event.type === VALUE) {
|
1352 | this._latestValues[i] = event.value;
|
1353 | this._latestErrors[i] = undefined;
|
1354 | }
|
1355 | if (event.type === ERROR) {
|
1356 | this._latestValues[i] = NOTHING;
|
1357 | this._latestErrors[i] = {
|
1358 | index: this._latestErrorIndex++,
|
1359 | error: event.value
|
1360 | };
|
1361 | }
|
1362 |
|
1363 | if (i < this._activeCount) {
|
1364 | if (this._activating) {
|
1365 | this._emitAfterActivation = true;
|
1366 | } else {
|
1367 | this._emitIfFull();
|
1368 | }
|
1369 | }
|
1370 | } else {
|
1371 |
|
1372 |
|
1373 | if (i < this._activeCount) {
|
1374 | this._aliveCount--;
|
1375 | if (this._aliveCount === 0) {
|
1376 | if (this._activating) {
|
1377 | this._endAfterActivation = true;
|
1378 | } else {
|
1379 | this._emitEnd();
|
1380 | }
|
1381 | }
|
1382 | }
|
1383 | }
|
1384 | },
|
1385 | _clear: function () {
|
1386 | Stream.prototype._clear.call(this);
|
1387 | this._sources = null;
|
1388 | this._latestValues = null;
|
1389 | this._latestErrors = null;
|
1390 | this._combinator = null;
|
1391 | this._$handlers = null;
|
1392 | }
|
1393 | });
|
1394 |
|
1395 | function combineAsArray(active) {
|
1396 | var passive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
1397 | var combinator = arguments[2];
|
1398 |
|
1399 | if (!Array.isArray(passive)) {
|
1400 | throw new Error('Combine can only combine active and passive collections of the same type.');
|
1401 | }
|
1402 |
|
1403 | combinator = combinator ? spread(combinator, active.length + passive.length) : function (x) {
|
1404 | return x;
|
1405 | };
|
1406 | return active.length === 0 ? never() : new Combine(active, passive, combinator);
|
1407 | }
|
1408 |
|
1409 | function combineAsObject(active) {
|
1410 | var passive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
1411 | var combinator = arguments[2];
|
1412 |
|
1413 | if (typeof passive !== 'object' || Array.isArray(passive)) {
|
1414 | throw new Error('Combine can only combine active and passive collections of the same type.');
|
1415 | }
|
1416 |
|
1417 | var keys = [],
|
1418 | activeObservables = [],
|
1419 | passiveObservables = [];
|
1420 |
|
1421 | collect(active, keys, activeObservables);
|
1422 | collect(passive, keys, passiveObservables);
|
1423 |
|
1424 | var objectify = function (values) {
|
1425 | var event = {};
|
1426 | for (var i = values.length - 1; 0 <= i; i--) {
|
1427 | event[keys[i]] = values[i];
|
1428 | }
|
1429 | return combinator ? combinator(event) : event;
|
1430 | };
|
1431 |
|
1432 | return activeObservables.length === 0 ? never() : new Combine(activeObservables, passiveObservables, objectify);
|
1433 | }
|
1434 |
|
1435 | function combine(active, passive, combinator) {
|
1436 | if (typeof passive === 'function') {
|
1437 | combinator = passive;
|
1438 | passive = undefined;
|
1439 | }
|
1440 |
|
1441 | return Array.isArray(active) ? combineAsArray(active, passive, combinator) : combineAsObject(active, passive, combinator);
|
1442 | }
|
1443 |
|
1444 | var Observable$2 = {
|
1445 | empty: function () {
|
1446 | return never();
|
1447 | },
|
1448 |
|
1449 |
|
1450 |
|
1451 | concat: function (a, b) {
|
1452 | return a.merge(b);
|
1453 | },
|
1454 | of: function (x) {
|
1455 | return constant(x);
|
1456 | },
|
1457 | map: function (fn, obs) {
|
1458 | return obs.map(fn);
|
1459 | },
|
1460 | bimap: function (fnErr, fnVal, obs) {
|
1461 | return obs.mapErrors(fnErr).map(fnVal);
|
1462 | },
|
1463 |
|
1464 |
|
1465 |
|
1466 |
|
1467 |
|
1468 |
|
1469 | ap: function (obsFn, obsVal) {
|
1470 | return combine([obsFn, obsVal], function (fn, val) {
|
1471 | return fn(val);
|
1472 | });
|
1473 | },
|
1474 | chain: function (fn, obs) {
|
1475 | return obs.flatMap(fn);
|
1476 | }
|
1477 | };
|
1478 |
|
1479 |
|
1480 |
|
1481 | var staticLand = Object.freeze({
|
1482 | Observable: Observable$2
|
1483 | });
|
1484 |
|
1485 | var mixin = {
|
1486 | _init: function (_ref) {
|
1487 | var fn = _ref.fn;
|
1488 |
|
1489 | this._fn = fn;
|
1490 | },
|
1491 | _free: function () {
|
1492 | this._fn = null;
|
1493 | },
|
1494 | _handleValue: function (x) {
|
1495 | var fn = this._fn;
|
1496 | this._emitValue(fn(x));
|
1497 | }
|
1498 | };
|
1499 |
|
1500 | var S$7 = createStream('map', mixin);
|
1501 | var P$3 = createProperty('map', mixin);
|
1502 |
|
1503 | var id = function (x) {
|
1504 | return x;
|
1505 | };
|
1506 |
|
1507 | function map$1(obs) {
|
1508 | var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : id;
|
1509 |
|
1510 | return new (obs._ofSameType(S$7, P$3))(obs, { fn: fn });
|
1511 | }
|
1512 |
|
1513 | var mixin$1 = {
|
1514 | _init: function (_ref) {
|
1515 | var fn = _ref.fn;
|
1516 |
|
1517 | this._fn = fn;
|
1518 | },
|
1519 | _free: function () {
|
1520 | this._fn = null;
|
1521 | },
|
1522 | _handleValue: function (x) {
|
1523 | var fn = this._fn;
|
1524 | if (fn(x)) {
|
1525 | this._emitValue(x);
|
1526 | }
|
1527 | }
|
1528 | };
|
1529 |
|
1530 | var S$8 = createStream('filter', mixin$1);
|
1531 | var P$4 = createProperty('filter', mixin$1);
|
1532 |
|
1533 | var id$1 = function (x) {
|
1534 | return x;
|
1535 | };
|
1536 |
|
1537 | function filter(obs) {
|
1538 | var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : id$1;
|
1539 |
|
1540 | return new (obs._ofSameType(S$8, P$4))(obs, { fn: fn });
|
1541 | }
|
1542 |
|
1543 | var mixin$2 = {
|
1544 | _init: function (_ref) {
|
1545 | var n = _ref.n;
|
1546 |
|
1547 | this._n = n;
|
1548 | if (n <= 0) {
|
1549 | this._emitEnd();
|
1550 | }
|
1551 | },
|
1552 | _handleValue: function (x) {
|
1553 | if (this._n === 0) {
|
1554 | return;
|
1555 | }
|
1556 | this._n--;
|
1557 | this._emitValue(x);
|
1558 | if (this._n === 0) {
|
1559 | this._emitEnd();
|
1560 | }
|
1561 | }
|
1562 | };
|
1563 |
|
1564 | var S$9 = createStream('take', mixin$2);
|
1565 | var P$5 = createProperty('take', mixin$2);
|
1566 |
|
1567 | function take(obs, n) {
|
1568 | return new (obs._ofSameType(S$9, P$5))(obs, { n: n });
|
1569 | }
|
1570 |
|
1571 | var mixin$3 = {
|
1572 | _init: function (_ref) {
|
1573 | var n = _ref.n;
|
1574 |
|
1575 | this._n = n;
|
1576 | if (n <= 0) {
|
1577 | this._emitEnd();
|
1578 | }
|
1579 | },
|
1580 | _handleError: function (x) {
|
1581 | if (this._n === 0) {
|
1582 | return;
|
1583 | }
|
1584 | this._n--;
|
1585 | this._emitError(x);
|
1586 | if (this._n === 0) {
|
1587 | this._emitEnd();
|
1588 | }
|
1589 | }
|
1590 | };
|
1591 |
|
1592 | var S$10 = createStream('takeErrors', mixin$3);
|
1593 | var P$6 = createProperty('takeErrors', mixin$3);
|
1594 |
|
1595 | function takeErrors(obs, n) {
|
1596 | return new (obs._ofSameType(S$10, P$6))(obs, { n: n });
|
1597 | }
|
1598 |
|
1599 | var mixin$4 = {
|
1600 | _init: function (_ref) {
|
1601 | var fn = _ref.fn;
|
1602 |
|
1603 | this._fn = fn;
|
1604 | },
|
1605 | _free: function () {
|
1606 | this._fn = null;
|
1607 | },
|
1608 | _handleValue: function (x) {
|
1609 | var fn = this._fn;
|
1610 | if (fn(x)) {
|
1611 | this._emitValue(x);
|
1612 | } else {
|
1613 | this._emitEnd();
|
1614 | }
|
1615 | }
|
1616 | };
|
1617 |
|
1618 | var S$11 = createStream('takeWhile', mixin$4);
|
1619 | var P$7 = createProperty('takeWhile', mixin$4);
|
1620 |
|
1621 | var id$2 = function (x) {
|
1622 | return x;
|
1623 | };
|
1624 |
|
1625 | function takeWhile(obs) {
|
1626 | var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : id$2;
|
1627 |
|
1628 | return new (obs._ofSameType(S$11, P$7))(obs, { fn: fn });
|
1629 | }
|
1630 |
|
1631 | var mixin$5 = {
|
1632 | _init: function () {
|
1633 | this._lastValue = NOTHING;
|
1634 | },
|
1635 | _free: function () {
|
1636 | this._lastValue = null;
|
1637 | },
|
1638 | _handleValue: function (x) {
|
1639 | this._lastValue = x;
|
1640 | },
|
1641 | _handleEnd: function () {
|
1642 | if (this._lastValue !== NOTHING) {
|
1643 | this._emitValue(this._lastValue);
|
1644 | }
|
1645 | this._emitEnd();
|
1646 | }
|
1647 | };
|
1648 |
|
1649 | var S$12 = createStream('last', mixin$5);
|
1650 | var P$8 = createProperty('last', mixin$5);
|
1651 |
|
1652 | function last(obs) {
|
1653 | return new (obs._ofSameType(S$12, P$8))(obs);
|
1654 | }
|
1655 |
|
1656 | var mixin$6 = {
|
1657 | _init: function (_ref) {
|
1658 | var n = _ref.n;
|
1659 |
|
1660 | this._n = Math.max(0, n);
|
1661 | },
|
1662 | _handleValue: function (x) {
|
1663 | if (this._n === 0) {
|
1664 | this._emitValue(x);
|
1665 | } else {
|
1666 | this._n--;
|
1667 | }
|
1668 | }
|
1669 | };
|
1670 |
|
1671 | var S$13 = createStream('skip', mixin$6);
|
1672 | var P$9 = createProperty('skip', mixin$6);
|
1673 |
|
1674 | function skip(obs, n) {
|
1675 | return new (obs._ofSameType(S$13, P$9))(obs, { n: n });
|
1676 | }
|
1677 |
|
1678 | var mixin$7 = {
|
1679 | _init: function (_ref) {
|
1680 | var fn = _ref.fn;
|
1681 |
|
1682 | this._fn = fn;
|
1683 | },
|
1684 | _free: function () {
|
1685 | this._fn = null;
|
1686 | },
|
1687 | _handleValue: function (x) {
|
1688 | var fn = this._fn;
|
1689 | if (this._fn !== null && !fn(x)) {
|
1690 | this._fn = null;
|
1691 | }
|
1692 | if (this._fn === null) {
|
1693 | this._emitValue(x);
|
1694 | }
|
1695 | }
|
1696 | };
|
1697 |
|
1698 | var S$14 = createStream('skipWhile', mixin$7);
|
1699 | var P$10 = createProperty('skipWhile', mixin$7);
|
1700 |
|
1701 | var id$3 = function (x) {
|
1702 | return x;
|
1703 | };
|
1704 |
|
1705 | function skipWhile(obs) {
|
1706 | var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : id$3;
|
1707 |
|
1708 | return new (obs._ofSameType(S$14, P$10))(obs, { fn: fn });
|
1709 | }
|
1710 |
|
1711 | var mixin$8 = {
|
1712 | _init: function (_ref) {
|
1713 | var fn = _ref.fn;
|
1714 |
|
1715 | this._fn = fn;
|
1716 | this._prev = NOTHING;
|
1717 | },
|
1718 | _free: function () {
|
1719 | this._fn = null;
|
1720 | this._prev = null;
|
1721 | },
|
1722 | _handleValue: function (x) {
|
1723 | var fn = this._fn;
|
1724 | if (this._prev === NOTHING || !fn(this._prev, x)) {
|
1725 | this._prev = x;
|
1726 | this._emitValue(x);
|
1727 | }
|
1728 | }
|
1729 | };
|
1730 |
|
1731 | var S$15 = createStream('skipDuplicates', mixin$8);
|
1732 | var P$11 = createProperty('skipDuplicates', mixin$8);
|
1733 |
|
1734 | var eq = function (a, b) {
|
1735 | return a === b;
|
1736 | };
|
1737 |
|
1738 | function skipDuplicates(obs) {
|
1739 | var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : eq;
|
1740 |
|
1741 | return new (obs._ofSameType(S$15, P$11))(obs, { fn: fn });
|
1742 | }
|
1743 |
|
1744 | var mixin$9 = {
|
1745 | _init: function (_ref) {
|
1746 | var fn = _ref.fn,
|
1747 | seed = _ref.seed;
|
1748 |
|
1749 | this._fn = fn;
|
1750 | this._prev = seed;
|
1751 | },
|
1752 | _free: function () {
|
1753 | this._prev = null;
|
1754 | this._fn = null;
|
1755 | },
|
1756 | _handleValue: function (x) {
|
1757 | if (this._prev !== NOTHING) {
|
1758 | var fn = this._fn;
|
1759 | this._emitValue(fn(this._prev, x));
|
1760 | }
|
1761 | this._prev = x;
|
1762 | }
|
1763 | };
|
1764 |
|
1765 | var S$16 = createStream('diff', mixin$9);
|
1766 | var P$12 = createProperty('diff', mixin$9);
|
1767 |
|
1768 | function defaultFn(a, b) {
|
1769 | return [a, b];
|
1770 | }
|
1771 |
|
1772 | function diff(obs, fn) {
|
1773 | var seed = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : NOTHING;
|
1774 |
|
1775 | return new (obs._ofSameType(S$16, P$12))(obs, { fn: fn || defaultFn, seed: seed });
|
1776 | }
|
1777 |
|
1778 | var P$13 = createProperty('scan', {
|
1779 | _init: function (_ref) {
|
1780 | var fn = _ref.fn,
|
1781 | seed = _ref.seed;
|
1782 |
|
1783 | this._fn = fn;
|
1784 | this._seed = seed;
|
1785 | if (seed !== NOTHING) {
|
1786 | this._emitValue(seed);
|
1787 | }
|
1788 | },
|
1789 | _free: function () {
|
1790 | this._fn = null;
|
1791 | this._seed = null;
|
1792 | },
|
1793 | _handleValue: function (x) {
|
1794 | var fn = this._fn;
|
1795 | if (this._currentEvent === null || this._currentEvent.type === ERROR) {
|
1796 | this._emitValue(this._seed === NOTHING ? x : fn(this._seed, x));
|
1797 | } else {
|
1798 | this._emitValue(fn(this._currentEvent.value, x));
|
1799 | }
|
1800 | }
|
1801 | });
|
1802 |
|
1803 | function scan(obs, fn) {
|
1804 | var seed = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : NOTHING;
|
1805 |
|
1806 | return new P$13(obs, { fn: fn, seed: seed });
|
1807 | }
|
1808 |
|
1809 | var mixin$10 = {
|
1810 | _init: function (_ref) {
|
1811 | var fn = _ref.fn;
|
1812 |
|
1813 | this._fn = fn;
|
1814 | },
|
1815 | _free: function () {
|
1816 | this._fn = null;
|
1817 | },
|
1818 | _handleValue: function (x) {
|
1819 | var fn = this._fn;
|
1820 | var xs = fn(x);
|
1821 | for (var i = 0; i < xs.length; i++) {
|
1822 | this._emitValue(xs[i]);
|
1823 | }
|
1824 | }
|
1825 | };
|
1826 |
|
1827 | var S$17 = createStream('flatten', mixin$10);
|
1828 |
|
1829 | var id$4 = function (x) {
|
1830 | return x;
|
1831 | };
|
1832 |
|
1833 | function flatten(obs) {
|
1834 | var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : id$4;
|
1835 |
|
1836 | return new S$17(obs, { fn: fn });
|
1837 | }
|
1838 |
|
1839 | var END_MARKER = {};
|
1840 |
|
1841 | var mixin$11 = {
|
1842 | _init: function (_ref) {
|
1843 | var _this = this;
|
1844 |
|
1845 | var wait = _ref.wait;
|
1846 |
|
1847 | this._wait = Math.max(0, wait);
|
1848 | this._buff = [];
|
1849 | this._$shiftBuff = function () {
|
1850 | var value = _this._buff.shift();
|
1851 | if (value === END_MARKER) {
|
1852 | _this._emitEnd();
|
1853 | } else {
|
1854 | _this._emitValue(value);
|
1855 | }
|
1856 | };
|
1857 | },
|
1858 | _free: function () {
|
1859 | this._buff = null;
|
1860 | this._$shiftBuff = null;
|
1861 | },
|
1862 | _handleValue: function (x) {
|
1863 | if (this._activating) {
|
1864 | this._emitValue(x);
|
1865 | } else {
|
1866 | this._buff.push(x);
|
1867 | setTimeout(this._$shiftBuff, this._wait);
|
1868 | }
|
1869 | },
|
1870 | _handleEnd: function () {
|
1871 | if (this._activating) {
|
1872 | this._emitEnd();
|
1873 | } else {
|
1874 | this._buff.push(END_MARKER);
|
1875 | setTimeout(this._$shiftBuff, this._wait);
|
1876 | }
|
1877 | }
|
1878 | };
|
1879 |
|
1880 | var S$18 = createStream('delay', mixin$11);
|
1881 | var P$14 = createProperty('delay', mixin$11);
|
1882 |
|
1883 | function delay(obs, wait) {
|
1884 | return new (obs._ofSameType(S$18, P$14))(obs, { wait: wait });
|
1885 | }
|
1886 |
|
1887 | var now = Date.now ? function () {
|
1888 | return Date.now();
|
1889 | } : function () {
|
1890 | return new Date().getTime();
|
1891 | };
|
1892 |
|
1893 | var mixin$12 = {
|
1894 | _init: function (_ref) {
|
1895 | var _this = this;
|
1896 |
|
1897 | var wait = _ref.wait,
|
1898 | leading = _ref.leading,
|
1899 | trailing = _ref.trailing;
|
1900 |
|
1901 | this._wait = Math.max(0, wait);
|
1902 | this._leading = leading;
|
1903 | this._trailing = trailing;
|
1904 | this._trailingValue = null;
|
1905 | this._timeoutId = null;
|
1906 | this._endLater = false;
|
1907 | this._lastCallTime = 0;
|
1908 | this._$trailingCall = function () {
|
1909 | return _this._trailingCall();
|
1910 | };
|
1911 | },
|
1912 | _free: function () {
|
1913 | this._trailingValue = null;
|
1914 | this._$trailingCall = null;
|
1915 | },
|
1916 | _handleValue: function (x) {
|
1917 | if (this._activating) {
|
1918 | this._emitValue(x);
|
1919 | } else {
|
1920 | var curTime = now();
|
1921 | if (this._lastCallTime === 0 && !this._leading) {
|
1922 | this._lastCallTime = curTime;
|
1923 | }
|
1924 | var remaining = this._wait - (curTime - this._lastCallTime);
|
1925 | if (remaining <= 0) {
|
1926 | this._cancelTrailing();
|
1927 | this._lastCallTime = curTime;
|
1928 | this._emitValue(x);
|
1929 | } else if (this._trailing) {
|
1930 | this._cancelTrailing();
|
1931 | this._trailingValue = x;
|
1932 | this._timeoutId = setTimeout(this._$trailingCall, remaining);
|
1933 | }
|
1934 | }
|
1935 | },
|
1936 | _handleEnd: function () {
|
1937 | if (this._activating) {
|
1938 | this._emitEnd();
|
1939 | } else {
|
1940 | if (this._timeoutId) {
|
1941 | this._endLater = true;
|
1942 | } else {
|
1943 | this._emitEnd();
|
1944 | }
|
1945 | }
|
1946 | },
|
1947 | _cancelTrailing: function () {
|
1948 | if (this._timeoutId !== null) {
|
1949 | clearTimeout(this._timeoutId);
|
1950 | this._timeoutId = null;
|
1951 | }
|
1952 | },
|
1953 | _trailingCall: function () {
|
1954 | this._emitValue(this._trailingValue);
|
1955 | this._timeoutId = null;
|
1956 | this._trailingValue = null;
|
1957 | this._lastCallTime = !this._leading ? 0 : now();
|
1958 | if (this._endLater) {
|
1959 | this._emitEnd();
|
1960 | }
|
1961 | }
|
1962 | };
|
1963 |
|
1964 | var S$19 = createStream('throttle', mixin$12);
|
1965 | var P$15 = createProperty('throttle', mixin$12);
|
1966 |
|
1967 | function throttle(obs, wait) {
|
1968 | var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
|
1969 | _ref2$leading = _ref2.leading,
|
1970 | leading = _ref2$leading === undefined ? true : _ref2$leading,
|
1971 | _ref2$trailing = _ref2.trailing,
|
1972 | trailing = _ref2$trailing === undefined ? true : _ref2$trailing;
|
1973 |
|
1974 | return new (obs._ofSameType(S$19, P$15))(obs, { wait: wait, leading: leading, trailing: trailing });
|
1975 | }
|
1976 |
|
1977 | var mixin$13 = {
|
1978 | _init: function (_ref) {
|
1979 | var _this = this;
|
1980 |
|
1981 | var wait = _ref.wait,
|
1982 | immediate = _ref.immediate;
|
1983 |
|
1984 | this._wait = Math.max(0, wait);
|
1985 | this._immediate = immediate;
|
1986 | this._lastAttempt = 0;
|
1987 | this._timeoutId = null;
|
1988 | this._laterValue = null;
|
1989 | this._endLater = false;
|
1990 | this._$later = function () {
|
1991 | return _this._later();
|
1992 | };
|
1993 | },
|
1994 | _free: function () {
|
1995 | this._laterValue = null;
|
1996 | this._$later = null;
|
1997 | },
|
1998 | _handleValue: function (x) {
|
1999 | if (this._activating) {
|
2000 | this._emitValue(x);
|
2001 | } else {
|
2002 | this._lastAttempt = now();
|
2003 | if (this._immediate && !this._timeoutId) {
|
2004 | this._emitValue(x);
|
2005 | }
|
2006 | if (!this._timeoutId) {
|
2007 | this._timeoutId = setTimeout(this._$later, this._wait);
|
2008 | }
|
2009 | if (!this._immediate) {
|
2010 | this._laterValue = x;
|
2011 | }
|
2012 | }
|
2013 | },
|
2014 | _handleEnd: function () {
|
2015 | if (this._activating) {
|
2016 | this._emitEnd();
|
2017 | } else {
|
2018 | if (this._timeoutId && !this._immediate) {
|
2019 | this._endLater = true;
|
2020 | } else {
|
2021 | this._emitEnd();
|
2022 | }
|
2023 | }
|
2024 | },
|
2025 | _later: function () {
|
2026 | var last = now() - this._lastAttempt;
|
2027 | if (last < this._wait && last >= 0) {
|
2028 | this._timeoutId = setTimeout(this._$later, this._wait - last);
|
2029 | } else {
|
2030 | this._timeoutId = null;
|
2031 | if (!this._immediate) {
|
2032 | this._emitValue(this._laterValue);
|
2033 | this._laterValue = null;
|
2034 | }
|
2035 | if (this._endLater) {
|
2036 | this._emitEnd();
|
2037 | }
|
2038 | }
|
2039 | }
|
2040 | };
|
2041 |
|
2042 | var S$20 = createStream('debounce', mixin$13);
|
2043 | var P$16 = createProperty('debounce', mixin$13);
|
2044 |
|
2045 | function debounce(obs, wait) {
|
2046 | var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
|
2047 | _ref2$immediate = _ref2.immediate,
|
2048 | immediate = _ref2$immediate === undefined ? false : _ref2$immediate;
|
2049 |
|
2050 | return new (obs._ofSameType(S$20, P$16))(obs, { wait: wait, immediate: immediate });
|
2051 | }
|
2052 |
|
2053 | var mixin$14 = {
|
2054 | _init: function (_ref) {
|
2055 | var fn = _ref.fn;
|
2056 |
|
2057 | this._fn = fn;
|
2058 | },
|
2059 | _free: function () {
|
2060 | this._fn = null;
|
2061 | },
|
2062 | _handleError: function (x) {
|
2063 | var fn = this._fn;
|
2064 | this._emitError(fn(x));
|
2065 | }
|
2066 | };
|
2067 |
|
2068 | var S$21 = createStream('mapErrors', mixin$14);
|
2069 | var P$17 = createProperty('mapErrors', mixin$14);
|
2070 |
|
2071 | var id$5 = function (x) {
|
2072 | return x;
|
2073 | };
|
2074 |
|
2075 | function mapErrors(obs) {
|
2076 | var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : id$5;
|
2077 |
|
2078 | return new (obs._ofSameType(S$21, P$17))(obs, { fn: fn });
|
2079 | }
|
2080 |
|
2081 | var mixin$15 = {
|
2082 | _init: function (_ref) {
|
2083 | var fn = _ref.fn;
|
2084 |
|
2085 | this._fn = fn;
|
2086 | },
|
2087 | _free: function () {
|
2088 | this._fn = null;
|
2089 | },
|
2090 | _handleError: function (x) {
|
2091 | var fn = this._fn;
|
2092 | if (fn(x)) {
|
2093 | this._emitError(x);
|
2094 | }
|
2095 | }
|
2096 | };
|
2097 |
|
2098 | var S$22 = createStream('filterErrors', mixin$15);
|
2099 | var P$18 = createProperty('filterErrors', mixin$15);
|
2100 |
|
2101 | var id$6 = function (x) {
|
2102 | return x;
|
2103 | };
|
2104 |
|
2105 | function filterErrors(obs) {
|
2106 | var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : id$6;
|
2107 |
|
2108 | return new (obs._ofSameType(S$22, P$18))(obs, { fn: fn });
|
2109 | }
|
2110 |
|
2111 | var mixin$16 = {
|
2112 | _handleValue: function () {}
|
2113 | };
|
2114 |
|
2115 | var S$23 = createStream('ignoreValues', mixin$16);
|
2116 | var P$19 = createProperty('ignoreValues', mixin$16);
|
2117 |
|
2118 | function ignoreValues(obs) {
|
2119 | return new (obs._ofSameType(S$23, P$19))(obs);
|
2120 | }
|
2121 |
|
2122 | var mixin$17 = {
|
2123 | _handleError: function () {}
|
2124 | };
|
2125 |
|
2126 | var S$24 = createStream('ignoreErrors', mixin$17);
|
2127 | var P$20 = createProperty('ignoreErrors', mixin$17);
|
2128 |
|
2129 | function ignoreErrors(obs) {
|
2130 | return new (obs._ofSameType(S$24, P$20))(obs);
|
2131 | }
|
2132 |
|
2133 | var mixin$18 = {
|
2134 | _handleEnd: function () {}
|
2135 | };
|
2136 |
|
2137 | var S$25 = createStream('ignoreEnd', mixin$18);
|
2138 | var P$21 = createProperty('ignoreEnd', mixin$18);
|
2139 |
|
2140 | function ignoreEnd(obs) {
|
2141 | return new (obs._ofSameType(S$25, P$21))(obs);
|
2142 | }
|
2143 |
|
2144 | var mixin$19 = {
|
2145 | _init: function (_ref) {
|
2146 | var fn = _ref.fn;
|
2147 |
|
2148 | this._fn = fn;
|
2149 | },
|
2150 | _free: function () {
|
2151 | this._fn = null;
|
2152 | },
|
2153 | _handleEnd: function () {
|
2154 | var fn = this._fn;
|
2155 | this._emitValue(fn());
|
2156 | this._emitEnd();
|
2157 | }
|
2158 | };
|
2159 |
|
2160 | var S$26 = createStream('beforeEnd', mixin$19);
|
2161 | var P$22 = createProperty('beforeEnd', mixin$19);
|
2162 |
|
2163 | function beforeEnd(obs, fn) {
|
2164 | return new (obs._ofSameType(S$26, P$22))(obs, { fn: fn });
|
2165 | }
|
2166 |
|
2167 | var mixin$20 = {
|
2168 | _init: function (_ref) {
|
2169 | var min = _ref.min,
|
2170 | max = _ref.max;
|
2171 |
|
2172 | this._max = max;
|
2173 | this._min = min;
|
2174 | this._buff = [];
|
2175 | },
|
2176 | _free: function () {
|
2177 | this._buff = null;
|
2178 | },
|
2179 | _handleValue: function (x) {
|
2180 | this._buff = slide(this._buff, x, this._max);
|
2181 | if (this._buff.length >= this._min) {
|
2182 | this._emitValue(this._buff);
|
2183 | }
|
2184 | }
|
2185 | };
|
2186 |
|
2187 | var S$27 = createStream('slidingWindow', mixin$20);
|
2188 | var P$23 = createProperty('slidingWindow', mixin$20);
|
2189 |
|
2190 | function slidingWindow(obs, max) {
|
2191 | var min = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
2192 |
|
2193 | return new (obs._ofSameType(S$27, P$23))(obs, { min: min, max: max });
|
2194 | }
|
2195 |
|
2196 | var mixin$21 = {
|
2197 | _init: function (_ref) {
|
2198 | var fn = _ref.fn,
|
2199 | flushOnEnd = _ref.flushOnEnd;
|
2200 |
|
2201 | this._fn = fn;
|
2202 | this._flushOnEnd = flushOnEnd;
|
2203 | this._buff = [];
|
2204 | },
|
2205 | _free: function () {
|
2206 | this._buff = null;
|
2207 | },
|
2208 | _flush: function () {
|
2209 | if (this._buff !== null && this._buff.length !== 0) {
|
2210 | this._emitValue(this._buff);
|
2211 | this._buff = [];
|
2212 | }
|
2213 | },
|
2214 | _handleValue: function (x) {
|
2215 | this._buff.push(x);
|
2216 | var fn = this._fn;
|
2217 | if (!fn(x)) {
|
2218 | this._flush();
|
2219 | }
|
2220 | },
|
2221 | _handleEnd: function () {
|
2222 | if (this._flushOnEnd) {
|
2223 | this._flush();
|
2224 | }
|
2225 | this._emitEnd();
|
2226 | }
|
2227 | };
|
2228 |
|
2229 | var S$28 = createStream('bufferWhile', mixin$21);
|
2230 | var P$24 = createProperty('bufferWhile', mixin$21);
|
2231 |
|
2232 | var id$7 = function (x) {
|
2233 | return x;
|
2234 | };
|
2235 |
|
2236 | function bufferWhile(obs, fn) {
|
2237 | var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
|
2238 | _ref2$flushOnEnd = _ref2.flushOnEnd,
|
2239 | flushOnEnd = _ref2$flushOnEnd === undefined ? true : _ref2$flushOnEnd;
|
2240 |
|
2241 | return new (obs._ofSameType(S$28, P$24))(obs, { fn: fn || id$7, flushOnEnd: flushOnEnd });
|
2242 | }
|
2243 |
|
2244 | var mixin$22 = {
|
2245 | _init: function (_ref) {
|
2246 | var count = _ref.count,
|
2247 | flushOnEnd = _ref.flushOnEnd;
|
2248 |
|
2249 | this._count = count;
|
2250 | this._flushOnEnd = flushOnEnd;
|
2251 | this._buff = [];
|
2252 | },
|
2253 | _free: function () {
|
2254 | this._buff = null;
|
2255 | },
|
2256 | _flush: function () {
|
2257 | if (this._buff !== null && this._buff.length !== 0) {
|
2258 | this._emitValue(this._buff);
|
2259 | this._buff = [];
|
2260 | }
|
2261 | },
|
2262 | _handleValue: function (x) {
|
2263 | this._buff.push(x);
|
2264 | if (this._buff.length >= this._count) {
|
2265 | this._flush();
|
2266 | }
|
2267 | },
|
2268 | _handleEnd: function () {
|
2269 | if (this._flushOnEnd) {
|
2270 | this._flush();
|
2271 | }
|
2272 | this._emitEnd();
|
2273 | }
|
2274 | };
|
2275 |
|
2276 | var S$29 = createStream('bufferWithCount', mixin$22);
|
2277 | var P$25 = createProperty('bufferWithCount', mixin$22);
|
2278 |
|
2279 | function bufferWhile$1(obs, count) {
|
2280 | var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
|
2281 | _ref2$flushOnEnd = _ref2.flushOnEnd,
|
2282 | flushOnEnd = _ref2$flushOnEnd === undefined ? true : _ref2$flushOnEnd;
|
2283 |
|
2284 | return new (obs._ofSameType(S$29, P$25))(obs, { count: count, flushOnEnd: flushOnEnd });
|
2285 | }
|
2286 |
|
2287 | var mixin$23 = {
|
2288 | _init: function (_ref) {
|
2289 | var _this = this;
|
2290 |
|
2291 | var wait = _ref.wait,
|
2292 | count = _ref.count,
|
2293 | flushOnEnd = _ref.flushOnEnd;
|
2294 |
|
2295 | this._wait = wait;
|
2296 | this._count = count;
|
2297 | this._flushOnEnd = flushOnEnd;
|
2298 | this._intervalId = null;
|
2299 | this._$onTick = function () {
|
2300 | return _this._flush();
|
2301 | };
|
2302 | this._buff = [];
|
2303 | },
|
2304 | _free: function () {
|
2305 | this._$onTick = null;
|
2306 | this._buff = null;
|
2307 | },
|
2308 | _flush: function () {
|
2309 | if (this._buff !== null) {
|
2310 | this._emitValue(this._buff);
|
2311 | this._buff = [];
|
2312 | }
|
2313 | },
|
2314 | _handleValue: function (x) {
|
2315 | this._buff.push(x);
|
2316 | if (this._buff.length >= this._count) {
|
2317 | clearInterval(this._intervalId);
|
2318 | this._flush();
|
2319 | this._intervalId = setInterval(this._$onTick, this._wait);
|
2320 | }
|
2321 | },
|
2322 | _handleEnd: function () {
|
2323 | if (this._flushOnEnd && this._buff.length !== 0) {
|
2324 | this._flush();
|
2325 | }
|
2326 | this._emitEnd();
|
2327 | },
|
2328 | _onActivation: function () {
|
2329 | this._intervalId = setInterval(this._$onTick, this._wait);
|
2330 | this._source.onAny(this._$handleAny);
|
2331 | },
|
2332 | _onDeactivation: function () {
|
2333 | if (this._intervalId !== null) {
|
2334 | clearInterval(this._intervalId);
|
2335 | this._intervalId = null;
|
2336 | }
|
2337 | this._source.offAny(this._$handleAny);
|
2338 | }
|
2339 | };
|
2340 |
|
2341 | var S$30 = createStream('bufferWithTimeOrCount', mixin$23);
|
2342 | var P$26 = createProperty('bufferWithTimeOrCount', mixin$23);
|
2343 |
|
2344 | function bufferWithTimeOrCount(obs, wait, count) {
|
2345 | var _ref2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
|
2346 | _ref2$flushOnEnd = _ref2.flushOnEnd,
|
2347 | flushOnEnd = _ref2$flushOnEnd === undefined ? true : _ref2$flushOnEnd;
|
2348 |
|
2349 | return new (obs._ofSameType(S$30, P$26))(obs, { wait: wait, count: count, flushOnEnd: flushOnEnd });
|
2350 | }
|
2351 |
|
2352 | function xformForObs(obs) {
|
2353 | return {
|
2354 | '@@transducer/step': function (res, input) {
|
2355 | obs._emitValue(input);
|
2356 | return null;
|
2357 | },
|
2358 | '@@transducer/result': function () {
|
2359 | obs._emitEnd();
|
2360 | return null;
|
2361 | }
|
2362 | };
|
2363 | }
|
2364 |
|
2365 | var mixin$24 = {
|
2366 | _init: function (_ref) {
|
2367 | var transducer = _ref.transducer;
|
2368 |
|
2369 | this._xform = transducer(xformForObs(this));
|
2370 | },
|
2371 | _free: function () {
|
2372 | this._xform = null;
|
2373 | },
|
2374 | _handleValue: function (x) {
|
2375 | if (this._xform['@@transducer/step'](null, x) !== null) {
|
2376 | this._xform['@@transducer/result'](null);
|
2377 | }
|
2378 | },
|
2379 | _handleEnd: function () {
|
2380 | this._xform['@@transducer/result'](null);
|
2381 | }
|
2382 | };
|
2383 |
|
2384 | var S$31 = createStream('transduce', mixin$24);
|
2385 | var P$27 = createProperty('transduce', mixin$24);
|
2386 |
|
2387 | function transduce(obs, transducer) {
|
2388 | return new (obs._ofSameType(S$31, P$27))(obs, { transducer: transducer });
|
2389 | }
|
2390 |
|
2391 | var mixin$25 = {
|
2392 | _init: function (_ref) {
|
2393 | var fn = _ref.fn;
|
2394 |
|
2395 | this._handler = fn;
|
2396 | this._emitter = emitter(this);
|
2397 | },
|
2398 | _free: function () {
|
2399 | this._handler = null;
|
2400 | this._emitter = null;
|
2401 | },
|
2402 | _handleAny: function (event) {
|
2403 | this._handler(this._emitter, event);
|
2404 | }
|
2405 | };
|
2406 |
|
2407 | var S$32 = createStream('withHandler', mixin$25);
|
2408 | var P$28 = createProperty('withHandler', mixin$25);
|
2409 |
|
2410 | function withHandler(obs, fn) {
|
2411 | return new (obs._ofSameType(S$32, P$28))(obs, { fn: fn });
|
2412 | }
|
2413 |
|
2414 | var isArray = Array.isArray || function (xs) {
|
2415 | return Object.prototype.toString.call(xs) === '[object Array]';
|
2416 | };
|
2417 |
|
2418 | function Zip(sources, combinator) {
|
2419 | var _this = this;
|
2420 |
|
2421 | Stream.call(this);
|
2422 |
|
2423 | this._buffers = map(sources, function (source) {
|
2424 | return isArray(source) ? cloneArray(source) : [];
|
2425 | });
|
2426 | this._sources = map(sources, function (source) {
|
2427 | return isArray(source) ? never() : source;
|
2428 | });
|
2429 |
|
2430 | this._combinator = combinator ? spread(combinator, this._sources.length) : function (x) {
|
2431 | return x;
|
2432 | };
|
2433 | this._aliveCount = 0;
|
2434 |
|
2435 | this._$handlers = [];
|
2436 |
|
2437 | var _loop = function (i) {
|
2438 | _this._$handlers.push(function (event) {
|
2439 | return _this._handleAny(i, event);
|
2440 | });
|
2441 | };
|
2442 |
|
2443 | for (var i = 0; i < this._sources.length; i++) {
|
2444 | _loop(i);
|
2445 | }
|
2446 | }
|
2447 |
|
2448 | inherit(Zip, Stream, {
|
2449 | _name: 'zip',
|
2450 |
|
2451 | _onActivation: function () {
|
2452 |
|
2453 | while (this._isFull()) {
|
2454 | this._emit();
|
2455 | }
|
2456 |
|
2457 | var length = this._sources.length;
|
2458 | this._aliveCount = length;
|
2459 | for (var i = 0; i < length && this._active; i++) {
|
2460 | this._sources[i].onAny(this._$handlers[i]);
|
2461 | }
|
2462 | },
|
2463 | _onDeactivation: function () {
|
2464 | for (var i = 0; i < this._sources.length; i++) {
|
2465 | this._sources[i].offAny(this._$handlers[i]);
|
2466 | }
|
2467 | },
|
2468 | _emit: function () {
|
2469 | var values = new Array(this._buffers.length);
|
2470 | for (var i = 0; i < this._buffers.length; i++) {
|
2471 | values[i] = this._buffers[i].shift();
|
2472 | }
|
2473 | var combinator = this._combinator;
|
2474 | this._emitValue(combinator(values));
|
2475 | },
|
2476 | _isFull: function () {
|
2477 | for (var i = 0; i < this._buffers.length; i++) {
|
2478 | if (this._buffers[i].length === 0) {
|
2479 | return false;
|
2480 | }
|
2481 | }
|
2482 | return true;
|
2483 | },
|
2484 | _handleAny: function (i, event) {
|
2485 | if (event.type === VALUE) {
|
2486 | this._buffers[i].push(event.value);
|
2487 | if (this._isFull()) {
|
2488 | this._emit();
|
2489 | }
|
2490 | }
|
2491 | if (event.type === ERROR) {
|
2492 | this._emitError(event.value);
|
2493 | }
|
2494 | if (event.type === END) {
|
2495 | this._aliveCount--;
|
2496 | if (this._aliveCount === 0) {
|
2497 | this._emitEnd();
|
2498 | }
|
2499 | }
|
2500 | },
|
2501 | _clear: function () {
|
2502 | Stream.prototype._clear.call(this);
|
2503 | this._sources = null;
|
2504 | this._buffers = null;
|
2505 | this._combinator = null;
|
2506 | this._$handlers = null;
|
2507 | }
|
2508 | });
|
2509 |
|
2510 | function zip(observables, combinator /* Function | falsey */) {
|
2511 | return observables.length === 0 ? never() : new Zip(observables, combinator);
|
2512 | }
|
2513 |
|
2514 | var id$8 = function (x) {
|
2515 | return x;
|
2516 | };
|
2517 |
|
2518 | function AbstractPool() {
|
2519 | var _this = this;
|
2520 |
|
2521 | var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
2522 | _ref$queueLim = _ref.queueLim,
|
2523 | queueLim = _ref$queueLim === undefined ? 0 : _ref$queueLim,
|
2524 | _ref$concurLim = _ref.concurLim,
|
2525 | concurLim = _ref$concurLim === undefined ? -1 : _ref$concurLim,
|
2526 | _ref$drop = _ref.drop,
|
2527 | drop = _ref$drop === undefined ? 'new' : _ref$drop;
|
2528 |
|
2529 | Stream.call(this);
|
2530 |
|
2531 | this._queueLim = queueLim < 0 ? -1 : queueLim;
|
2532 | this._concurLim = concurLim < 0 ? -1 : concurLim;
|
2533 | this._drop = drop;
|
2534 | this._queue = [];
|
2535 | this._curSources = [];
|
2536 | this._$handleSubAny = function (event) {
|
2537 | return _this._handleSubAny(event);
|
2538 | };
|
2539 | this._$endHandlers = [];
|
2540 | this._currentlyAdding = null;
|
2541 |
|
2542 | if (this._concurLim === 0) {
|
2543 | this._emitEnd();
|
2544 | }
|
2545 | }
|
2546 |
|
2547 | inherit(AbstractPool, Stream, {
|
2548 | _name: 'abstractPool',
|
2549 |
|
2550 | _add: function (obj, toObs /* Function | falsey */) {
|
2551 | toObs = toObs || id$8;
|
2552 | if (this._concurLim === -1 || this._curSources.length < this._concurLim) {
|
2553 | this._addToCur(toObs(obj));
|
2554 | } else {
|
2555 | if (this._queueLim === -1 || this._queue.length < this._queueLim) {
|
2556 | this._addToQueue(toObs(obj));
|
2557 | } else if (this._drop === 'old') {
|
2558 | this._removeOldest();
|
2559 | this._add(obj, toObs);
|
2560 | }
|
2561 | }
|
2562 | },
|
2563 | _addAll: function (obss) {
|
2564 | var _this2 = this;
|
2565 |
|
2566 | forEach(obss, function (obs) {
|
2567 | return _this2._add(obs);
|
2568 | });
|
2569 | },
|
2570 | _remove: function (obs) {
|
2571 | if (this._removeCur(obs) === -1) {
|
2572 | this._removeQueue(obs);
|
2573 | }
|
2574 | },
|
2575 | _addToQueue: function (obs) {
|
2576 | this._queue = concat(this._queue, [obs]);
|
2577 | },
|
2578 | _addToCur: function (obs) {
|
2579 | if (this._active) {
|
2580 |
|
2581 |
|
2582 |
|
2583 |
|
2584 |
|
2585 |
|
2586 |
|
2587 |
|
2588 |
|
2589 |
|
2590 |
|
2591 |
|
2592 |
|
2593 |
|
2594 |
|
2595 |
|
2596 | if (!obs._alive) {
|
2597 | if (obs._currentEvent) {
|
2598 | this._emit(obs._currentEvent.type, obs._currentEvent.value);
|
2599 | }
|
2600 |
|
2601 | if (this._active) {
|
2602 | if (this._queue.length !== 0) {
|
2603 | this._pullQueue();
|
2604 | } else if (this._curSources.length === 0) {
|
2605 | this._onEmpty();
|
2606 | }
|
2607 | }
|
2608 | return;
|
2609 | }
|
2610 |
|
2611 |
|
2612 |
|
2613 |
|
2614 | this._currentlyAdding = obs;
|
2615 | obs.onAny(this._$handleSubAny);
|
2616 | this._currentlyAdding = null;
|
2617 | if (obs._alive) {
|
2618 | this._curSources = concat(this._curSources, [obs]);
|
2619 | if (this._active) {
|
2620 | this._subToEnd(obs);
|
2621 | }
|
2622 | }
|
2623 | } else {
|
2624 | this._curSources = concat(this._curSources, [obs]);
|
2625 | }
|
2626 | },
|
2627 | _subToEnd: function (obs) {
|
2628 | var _this3 = this;
|
2629 |
|
2630 | var onEnd = function () {
|
2631 | return _this3._removeCur(obs);
|
2632 | };
|
2633 | this._$endHandlers.push({ obs: obs, handler: onEnd });
|
2634 | obs.onEnd(onEnd);
|
2635 | },
|
2636 | _subscribe: function (obs) {
|
2637 | obs.onAny(this._$handleSubAny);
|
2638 |
|
2639 |
|
2640 | if (this._active) {
|
2641 | this._subToEnd(obs);
|
2642 | }
|
2643 | },
|
2644 | _unsubscribe: function (obs) {
|
2645 | obs.offAny(this._$handleSubAny);
|
2646 |
|
2647 | var onEndI = findByPred(this._$endHandlers, function (obj) {
|
2648 | return obj.obs === obs;
|
2649 | });
|
2650 | if (onEndI !== -1) {
|
2651 | obs.offEnd(this._$endHandlers[onEndI].handler);
|
2652 | this._$endHandlers.splice(onEndI, 1);
|
2653 | }
|
2654 | },
|
2655 | _handleSubAny: function (event) {
|
2656 | if (event.type === VALUE) {
|
2657 | this._emitValue(event.value);
|
2658 | } else if (event.type === ERROR) {
|
2659 | this._emitError(event.value);
|
2660 | }
|
2661 | },
|
2662 | _removeQueue: function (obs) {
|
2663 | var index = find(this._queue, obs);
|
2664 | this._queue = remove(this._queue, index);
|
2665 | return index;
|
2666 | },
|
2667 | _removeCur: function (obs) {
|
2668 | if (this._active) {
|
2669 | this._unsubscribe(obs);
|
2670 | }
|
2671 | var index = find(this._curSources, obs);
|
2672 | this._curSources = remove(this._curSources, index);
|
2673 | if (index !== -1) {
|
2674 | if (this._queue.length !== 0) {
|
2675 | this._pullQueue();
|
2676 | } else if (this._curSources.length === 0) {
|
2677 | this._onEmpty();
|
2678 | }
|
2679 | }
|
2680 | return index;
|
2681 | },
|
2682 | _removeOldest: function () {
|
2683 | this._removeCur(this._curSources[0]);
|
2684 | },
|
2685 | _pullQueue: function () {
|
2686 | if (this._queue.length !== 0) {
|
2687 | this._queue = cloneArray(this._queue);
|
2688 | this._addToCur(this._queue.shift());
|
2689 | }
|
2690 | },
|
2691 | _onActivation: function () {
|
2692 | for (var i = 0, sources = this._curSources; i < sources.length && this._active; i++) {
|
2693 | this._subscribe(sources[i]);
|
2694 | }
|
2695 | },
|
2696 | _onDeactivation: function () {
|
2697 | for (var i = 0, sources = this._curSources; i < sources.length; i++) {
|
2698 | this._unsubscribe(sources[i]);
|
2699 | }
|
2700 | if (this._currentlyAdding !== null) {
|
2701 | this._unsubscribe(this._currentlyAdding);
|
2702 | }
|
2703 | },
|
2704 | _isEmpty: function () {
|
2705 | return this._curSources.length === 0;
|
2706 | },
|
2707 | _onEmpty: function () {},
|
2708 | _clear: function () {
|
2709 | Stream.prototype._clear.call(this);
|
2710 | this._queue = null;
|
2711 | this._curSources = null;
|
2712 | this._$handleSubAny = null;
|
2713 | this._$endHandlers = null;
|
2714 | }
|
2715 | });
|
2716 |
|
2717 | function Merge(sources) {
|
2718 | AbstractPool.call(this);
|
2719 | this._addAll(sources);
|
2720 | this._initialised = true;
|
2721 | }
|
2722 |
|
2723 | inherit(Merge, AbstractPool, {
|
2724 | _name: 'merge',
|
2725 |
|
2726 | _onEmpty: function () {
|
2727 | if (this._initialised) {
|
2728 | this._emitEnd();
|
2729 | }
|
2730 | }
|
2731 | });
|
2732 |
|
2733 | function merge(observables) {
|
2734 | return observables.length === 0 ? never() : new Merge(observables);
|
2735 | }
|
2736 |
|
2737 | function S$33(generator) {
|
2738 | var _this = this;
|
2739 |
|
2740 | Stream.call(this);
|
2741 | this._generator = generator;
|
2742 | this._source = null;
|
2743 | this._inLoop = false;
|
2744 | this._iteration = 0;
|
2745 | this._$handleAny = function (event) {
|
2746 | return _this._handleAny(event);
|
2747 | };
|
2748 | }
|
2749 |
|
2750 | inherit(S$33, Stream, {
|
2751 | _name: 'repeat',
|
2752 |
|
2753 | _handleAny: function (event) {
|
2754 | if (event.type === END) {
|
2755 | this._source = null;
|
2756 | this._getSource();
|
2757 | } else {
|
2758 | this._emit(event.type, event.value);
|
2759 | }
|
2760 | },
|
2761 | _getSource: function () {
|
2762 | if (!this._inLoop) {
|
2763 | this._inLoop = true;
|
2764 | var generator = this._generator;
|
2765 | while (this._source === null && this._alive && this._active) {
|
2766 | this._source = generator(this._iteration++);
|
2767 | if (this._source) {
|
2768 | this._source.onAny(this._$handleAny);
|
2769 | } else {
|
2770 | this._emitEnd();
|
2771 | }
|
2772 | }
|
2773 | this._inLoop = false;
|
2774 | }
|
2775 | },
|
2776 | _onActivation: function () {
|
2777 | if (this._source) {
|
2778 | this._source.onAny(this._$handleAny);
|
2779 | } else {
|
2780 | this._getSource();
|
2781 | }
|
2782 | },
|
2783 | _onDeactivation: function () {
|
2784 | if (this._source) {
|
2785 | this._source.offAny(this._$handleAny);
|
2786 | }
|
2787 | },
|
2788 | _clear: function () {
|
2789 | Stream.prototype._clear.call(this);
|
2790 | this._generator = null;
|
2791 | this._source = null;
|
2792 | this._$handleAny = null;
|
2793 | }
|
2794 | });
|
2795 |
|
2796 | var repeat = function (generator) {
|
2797 | return new S$33(generator);
|
2798 | };
|
2799 |
|
2800 | function concat$1(observables) {
|
2801 | return repeat(function (index) {
|
2802 | return observables.length > index ? observables[index] : false;
|
2803 | }).setName('concat');
|
2804 | }
|
2805 |
|
2806 | function Pool() {
|
2807 | AbstractPool.call(this);
|
2808 | }
|
2809 |
|
2810 | inherit(Pool, AbstractPool, {
|
2811 | _name: 'pool',
|
2812 |
|
2813 | plug: function (obs) {
|
2814 | this._add(obs);
|
2815 | return this;
|
2816 | },
|
2817 | unplug: function (obs) {
|
2818 | this._remove(obs);
|
2819 | return this;
|
2820 | }
|
2821 | });
|
2822 |
|
2823 | function FlatMap(source, fn, options) {
|
2824 | var _this = this;
|
2825 |
|
2826 | AbstractPool.call(this, options);
|
2827 | this._source = source;
|
2828 | this._fn = fn;
|
2829 | this._mainEnded = false;
|
2830 | this._lastCurrent = null;
|
2831 | this._$handleMain = function (event) {
|
2832 | return _this._handleMain(event);
|
2833 | };
|
2834 | }
|
2835 |
|
2836 | inherit(FlatMap, AbstractPool, {
|
2837 | _onActivation: function () {
|
2838 | AbstractPool.prototype._onActivation.call(this);
|
2839 | if (this._active) {
|
2840 | this._source.onAny(this._$handleMain);
|
2841 | }
|
2842 | },
|
2843 | _onDeactivation: function () {
|
2844 | AbstractPool.prototype._onDeactivation.call(this);
|
2845 | this._source.offAny(this._$handleMain);
|
2846 | this._hadNoEvSinceDeact = true;
|
2847 | },
|
2848 | _handleMain: function (event) {
|
2849 | if (event.type === VALUE) {
|
2850 |
|
2851 |
|
2852 |
|
2853 |
|
2854 | var sameCurr = this._activating && this._hadNoEvSinceDeact && this._lastCurrent === event.value;
|
2855 | if (!sameCurr) {
|
2856 | this._add(event.value, this._fn);
|
2857 | }
|
2858 | this._lastCurrent = event.value;
|
2859 | this._hadNoEvSinceDeact = false;
|
2860 | }
|
2861 |
|
2862 | if (event.type === ERROR) {
|
2863 | this._emitError(event.value);
|
2864 | }
|
2865 |
|
2866 | if (event.type === END) {
|
2867 | if (this._isEmpty()) {
|
2868 | this._emitEnd();
|
2869 | } else {
|
2870 | this._mainEnded = true;
|
2871 | }
|
2872 | }
|
2873 | },
|
2874 | _onEmpty: function () {
|
2875 | if (this._mainEnded) {
|
2876 | this._emitEnd();
|
2877 | }
|
2878 | },
|
2879 | _clear: function () {
|
2880 | AbstractPool.prototype._clear.call(this);
|
2881 | this._source = null;
|
2882 | this._lastCurrent = null;
|
2883 | this._$handleMain = null;
|
2884 | }
|
2885 | });
|
2886 |
|
2887 | function FlatMapErrors(source, fn) {
|
2888 | FlatMap.call(this, source, fn);
|
2889 | }
|
2890 |
|
2891 | inherit(FlatMapErrors, FlatMap, {
|
2892 |
|
2893 | _handleMain: function (event) {
|
2894 | if (event.type === ERROR) {
|
2895 | var sameCurr = this._activating && this._hadNoEvSinceDeact && this._lastCurrent === event.value;
|
2896 | if (!sameCurr) {
|
2897 | this._add(event.value, this._fn);
|
2898 | }
|
2899 | this._lastCurrent = event.value;
|
2900 | this._hadNoEvSinceDeact = false;
|
2901 | }
|
2902 |
|
2903 | if (event.type === VALUE) {
|
2904 | this._emitValue(event.value);
|
2905 | }
|
2906 |
|
2907 | if (event.type === END) {
|
2908 | if (this._isEmpty()) {
|
2909 | this._emitEnd();
|
2910 | } else {
|
2911 | this._mainEnded = true;
|
2912 | }
|
2913 | }
|
2914 | }
|
2915 | });
|
2916 |
|
2917 | function createConstructor$1(BaseClass, name) {
|
2918 | return function AnonymousObservable(primary, secondary, options) {
|
2919 | var _this = this;
|
2920 |
|
2921 | BaseClass.call(this);
|
2922 | this._primary = primary;
|
2923 | this._secondary = secondary;
|
2924 | this._name = primary._name + '.' + name;
|
2925 | this._lastSecondary = NOTHING;
|
2926 | this._$handleSecondaryAny = function (event) {
|
2927 | return _this._handleSecondaryAny(event);
|
2928 | };
|
2929 | this._$handlePrimaryAny = function (event) {
|
2930 | return _this._handlePrimaryAny(event);
|
2931 | };
|
2932 | this._init(options);
|
2933 | };
|
2934 | }
|
2935 |
|
2936 | function createClassMethods$1(BaseClass) {
|
2937 | return {
|
2938 | _init: function () {},
|
2939 | _free: function () {},
|
2940 | _handlePrimaryValue: function (x) {
|
2941 | this._emitValue(x);
|
2942 | },
|
2943 | _handlePrimaryError: function (x) {
|
2944 | this._emitError(x);
|
2945 | },
|
2946 | _handlePrimaryEnd: function () {
|
2947 | this._emitEnd();
|
2948 | },
|
2949 | _handleSecondaryValue: function (x) {
|
2950 | this._lastSecondary = x;
|
2951 | },
|
2952 | _handleSecondaryError: function (x) {
|
2953 | this._emitError(x);
|
2954 | },
|
2955 | _handleSecondaryEnd: function () {},
|
2956 | _handlePrimaryAny: function (event) {
|
2957 | switch (event.type) {
|
2958 | case VALUE:
|
2959 | return this._handlePrimaryValue(event.value);
|
2960 | case ERROR:
|
2961 | return this._handlePrimaryError(event.value);
|
2962 | case END:
|
2963 | return this._handlePrimaryEnd(event.value);
|
2964 | }
|
2965 | },
|
2966 | _handleSecondaryAny: function (event) {
|
2967 | switch (event.type) {
|
2968 | case VALUE:
|
2969 | return this._handleSecondaryValue(event.value);
|
2970 | case ERROR:
|
2971 | return this._handleSecondaryError(event.value);
|
2972 | case END:
|
2973 | this._handleSecondaryEnd(event.value);
|
2974 | this._removeSecondary();
|
2975 | }
|
2976 | },
|
2977 | _removeSecondary: function () {
|
2978 | if (this._secondary !== null) {
|
2979 | this._secondary.offAny(this._$handleSecondaryAny);
|
2980 | this._$handleSecondaryAny = null;
|
2981 | this._secondary = null;
|
2982 | }
|
2983 | },
|
2984 | _onActivation: function () {
|
2985 | if (this._secondary !== null) {
|
2986 | this._secondary.onAny(this._$handleSecondaryAny);
|
2987 | }
|
2988 | if (this._active) {
|
2989 | this._primary.onAny(this._$handlePrimaryAny);
|
2990 | }
|
2991 | },
|
2992 | _onDeactivation: function () {
|
2993 | if (this._secondary !== null) {
|
2994 | this._secondary.offAny(this._$handleSecondaryAny);
|
2995 | }
|
2996 | this._primary.offAny(this._$handlePrimaryAny);
|
2997 | },
|
2998 | _clear: function () {
|
2999 | BaseClass.prototype._clear.call(this);
|
3000 | this._primary = null;
|
3001 | this._secondary = null;
|
3002 | this._lastSecondary = null;
|
3003 | this._$handleSecondaryAny = null;
|
3004 | this._$handlePrimaryAny = null;
|
3005 | this._free();
|
3006 | }
|
3007 | };
|
3008 | }
|
3009 |
|
3010 | function createStream$1(name, mixin) {
|
3011 | var S = createConstructor$1(Stream, name);
|
3012 | inherit(S, Stream, createClassMethods$1(Stream), mixin);
|
3013 | return S;
|
3014 | }
|
3015 |
|
3016 | function createProperty$1(name, mixin) {
|
3017 | var P = createConstructor$1(Property, name);
|
3018 | inherit(P, Property, createClassMethods$1(Property), mixin);
|
3019 | return P;
|
3020 | }
|
3021 |
|
3022 | var mixin$26 = {
|
3023 | _handlePrimaryValue: function (x) {
|
3024 | if (this._lastSecondary !== NOTHING && this._lastSecondary) {
|
3025 | this._emitValue(x);
|
3026 | }
|
3027 | },
|
3028 | _handleSecondaryEnd: function () {
|
3029 | if (this._lastSecondary === NOTHING || !this._lastSecondary) {
|
3030 | this._emitEnd();
|
3031 | }
|
3032 | }
|
3033 | };
|
3034 |
|
3035 | var S$34 = createStream$1('filterBy', mixin$26);
|
3036 | var P$29 = createProperty$1('filterBy', mixin$26);
|
3037 |
|
3038 | function filterBy(primary, secondary) {
|
3039 | return new (primary._ofSameType(S$34, P$29))(primary, secondary);
|
3040 | }
|
3041 |
|
3042 | var id2 = function (_, x) {
|
3043 | return x;
|
3044 | };
|
3045 |
|
3046 | function sampledBy(passive, active, combinator) {
|
3047 | var _combinator = combinator ? function (a, b) {
|
3048 | return combinator(b, a);
|
3049 | } : id2;
|
3050 | return combine([active], [passive], _combinator).setName(passive, 'sampledBy');
|
3051 | }
|
3052 |
|
3053 | var mixin$27 = {
|
3054 | _handlePrimaryValue: function (x) {
|
3055 | if (this._lastSecondary !== NOTHING) {
|
3056 | this._emitValue(x);
|
3057 | }
|
3058 | },
|
3059 | _handleSecondaryEnd: function () {
|
3060 | if (this._lastSecondary === NOTHING) {
|
3061 | this._emitEnd();
|
3062 | }
|
3063 | }
|
3064 | };
|
3065 |
|
3066 | var S$35 = createStream$1('skipUntilBy', mixin$27);
|
3067 | var P$30 = createProperty$1('skipUntilBy', mixin$27);
|
3068 |
|
3069 | function skipUntilBy(primary, secondary) {
|
3070 | return new (primary._ofSameType(S$35, P$30))(primary, secondary);
|
3071 | }
|
3072 |
|
3073 | var mixin$28 = {
|
3074 | _handleSecondaryValue: function () {
|
3075 | this._emitEnd();
|
3076 | }
|
3077 | };
|
3078 |
|
3079 | var S$36 = createStream$1('takeUntilBy', mixin$28);
|
3080 | var P$31 = createProperty$1('takeUntilBy', mixin$28);
|
3081 |
|
3082 | function takeUntilBy(primary, secondary) {
|
3083 | return new (primary._ofSameType(S$36, P$31))(primary, secondary);
|
3084 | }
|
3085 |
|
3086 | var mixin$29 = {
|
3087 | _init: function () {
|
3088 | var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
3089 | _ref$flushOnEnd = _ref.flushOnEnd,
|
3090 | flushOnEnd = _ref$flushOnEnd === undefined ? true : _ref$flushOnEnd;
|
3091 |
|
3092 | this._buff = [];
|
3093 | this._flushOnEnd = flushOnEnd;
|
3094 | },
|
3095 | _free: function () {
|
3096 | this._buff = null;
|
3097 | },
|
3098 | _flush: function () {
|
3099 | if (this._buff !== null) {
|
3100 | this._emitValue(this._buff);
|
3101 | this._buff = [];
|
3102 | }
|
3103 | },
|
3104 | _handlePrimaryEnd: function () {
|
3105 | if (this._flushOnEnd) {
|
3106 | this._flush();
|
3107 | }
|
3108 | this._emitEnd();
|
3109 | },
|
3110 | _onActivation: function () {
|
3111 | this._primary.onAny(this._$handlePrimaryAny);
|
3112 | if (this._alive && this._secondary !== null) {
|
3113 | this._secondary.onAny(this._$handleSecondaryAny);
|
3114 | }
|
3115 | },
|
3116 | _handlePrimaryValue: function (x) {
|
3117 | this._buff.push(x);
|
3118 | },
|
3119 | _handleSecondaryValue: function () {
|
3120 | this._flush();
|
3121 | },
|
3122 | _handleSecondaryEnd: function () {
|
3123 | if (!this._flushOnEnd) {
|
3124 | this._emitEnd();
|
3125 | }
|
3126 | }
|
3127 | };
|
3128 |
|
3129 | var S$37 = createStream$1('bufferBy', mixin$29);
|
3130 | var P$32 = createProperty$1('bufferBy', mixin$29);
|
3131 |
|
3132 | function bufferBy(primary, secondary, options /* optional */) {
|
3133 | return new (primary._ofSameType(S$37, P$32))(primary, secondary, options);
|
3134 | }
|
3135 |
|
3136 | var mixin$30 = {
|
3137 | _init: function () {
|
3138 | var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
3139 | _ref$flushOnEnd = _ref.flushOnEnd,
|
3140 | flushOnEnd = _ref$flushOnEnd === undefined ? true : _ref$flushOnEnd,
|
3141 | _ref$flushOnChange = _ref.flushOnChange,
|
3142 | flushOnChange = _ref$flushOnChange === undefined ? false : _ref$flushOnChange;
|
3143 |
|
3144 | this._buff = [];
|
3145 | this._flushOnEnd = flushOnEnd;
|
3146 | this._flushOnChange = flushOnChange;
|
3147 | },
|
3148 | _free: function () {
|
3149 | this._buff = null;
|
3150 | },
|
3151 | _flush: function () {
|
3152 | if (this._buff !== null) {
|
3153 | this._emitValue(this._buff);
|
3154 | this._buff = [];
|
3155 | }
|
3156 | },
|
3157 | _handlePrimaryEnd: function () {
|
3158 | if (this._flushOnEnd) {
|
3159 | this._flush();
|
3160 | }
|
3161 | this._emitEnd();
|
3162 | },
|
3163 | _handlePrimaryValue: function (x) {
|
3164 | this._buff.push(x);
|
3165 | if (this._lastSecondary !== NOTHING && !this._lastSecondary) {
|
3166 | this._flush();
|
3167 | }
|
3168 | },
|
3169 | _handleSecondaryEnd: function () {
|
3170 | if (!this._flushOnEnd && (this._lastSecondary === NOTHING || this._lastSecondary)) {
|
3171 | this._emitEnd();
|
3172 | }
|
3173 | },
|
3174 | _handleSecondaryValue: function (x) {
|
3175 | if (this._flushOnChange && !x) {
|
3176 | this._flush();
|
3177 | }
|
3178 |
|
3179 |
|
3180 | this._lastSecondary = x;
|
3181 | }
|
3182 | };
|
3183 |
|
3184 | var S$38 = createStream$1('bufferWhileBy', mixin$30);
|
3185 | var P$33 = createProperty$1('bufferWhileBy', mixin$30);
|
3186 |
|
3187 | function bufferWhileBy(primary, secondary, options /* optional */) {
|
3188 | return new (primary._ofSameType(S$38, P$33))(primary, secondary, options);
|
3189 | }
|
3190 |
|
3191 | var f = function () {
|
3192 | return false;
|
3193 | };
|
3194 | var t = function () {
|
3195 | return true;
|
3196 | };
|
3197 |
|
3198 | function awaiting(a, b) {
|
3199 | var result = merge([map$1(a, t), map$1(b, f)]);
|
3200 | result = skipDuplicates(result);
|
3201 | result = toProperty(result, f);
|
3202 | return result.setName(a, 'awaiting');
|
3203 | }
|
3204 |
|
3205 | var mixin$31 = {
|
3206 | _init: function (_ref) {
|
3207 | var fn = _ref.fn;
|
3208 |
|
3209 | this._fn = fn;
|
3210 | },
|
3211 | _free: function () {
|
3212 | this._fn = null;
|
3213 | },
|
3214 | _handleValue: function (x) {
|
3215 | var fn = this._fn;
|
3216 | var result = fn(x);
|
3217 | if (result.convert) {
|
3218 | this._emitError(result.error);
|
3219 | } else {
|
3220 | this._emitValue(x);
|
3221 | }
|
3222 | }
|
3223 | };
|
3224 |
|
3225 | var S$39 = createStream('valuesToErrors', mixin$31);
|
3226 | var P$34 = createProperty('valuesToErrors', mixin$31);
|
3227 |
|
3228 | var defFn = function (x) {
|
3229 | return { convert: true, error: x };
|
3230 | };
|
3231 |
|
3232 | function valuesToErrors(obs) {
|
3233 | var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defFn;
|
3234 |
|
3235 | return new (obs._ofSameType(S$39, P$34))(obs, { fn: fn });
|
3236 | }
|
3237 |
|
3238 | var mixin$32 = {
|
3239 | _init: function (_ref) {
|
3240 | var fn = _ref.fn;
|
3241 |
|
3242 | this._fn = fn;
|
3243 | },
|
3244 | _free: function () {
|
3245 | this._fn = null;
|
3246 | },
|
3247 | _handleError: function (x) {
|
3248 | var fn = this._fn;
|
3249 | var result = fn(x);
|
3250 | if (result.convert) {
|
3251 | this._emitValue(result.value);
|
3252 | } else {
|
3253 | this._emitError(x);
|
3254 | }
|
3255 | }
|
3256 | };
|
3257 |
|
3258 | var S$40 = createStream('errorsToValues', mixin$32);
|
3259 | var P$35 = createProperty('errorsToValues', mixin$32);
|
3260 |
|
3261 | var defFn$1 = function (x) {
|
3262 | return { convert: true, value: x };
|
3263 | };
|
3264 |
|
3265 | function errorsToValues(obs) {
|
3266 | var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defFn$1;
|
3267 |
|
3268 | return new (obs._ofSameType(S$40, P$35))(obs, { fn: fn });
|
3269 | }
|
3270 |
|
3271 | var mixin$33 = {
|
3272 | _handleError: function (x) {
|
3273 | this._emitError(x);
|
3274 | this._emitEnd();
|
3275 | }
|
3276 | };
|
3277 |
|
3278 | var S$41 = createStream('endOnError', mixin$33);
|
3279 | var P$36 = createProperty('endOnError', mixin$33);
|
3280 |
|
3281 | function endOnError(obs) {
|
3282 | return new (obs._ofSameType(S$41, P$36))(obs);
|
3283 | }
|
3284 |
|
3285 |
|
3286 |
|
3287 |
|
3288 |
|
3289 |
|
3290 |
|
3291 |
|
3292 |
|
3293 |
|
3294 |
|
3295 |
|
3296 |
|
3297 |
|
3298 |
|
3299 |
|
3300 |
|
3301 |
|
3302 |
|
3303 |
|
3304 |
|
3305 |
|
3306 |
|
3307 |
|
3308 | Observable.prototype.toProperty = function (fn) {
|
3309 | return toProperty(this, fn);
|
3310 | };
|
3311 |
|
3312 |
|
3313 | Observable.prototype.changes = function () {
|
3314 | return changes(this);
|
3315 | };
|
3316 |
|
3317 |
|
3318 |
|
3319 |
|
3320 |
|
3321 |
|
3322 | Observable.prototype.toPromise = function (Promise) {
|
3323 | return toPromise(this, Promise);
|
3324 | };
|
3325 |
|
3326 |
|
3327 |
|
3328 | Observable.prototype.toESObservable = toESObservable;
|
3329 | Observable.prototype[$$observable] = toESObservable;
|
3330 |
|
3331 |
|
3332 |
|
3333 |
|
3334 |
|
3335 |
|
3336 | Observable.prototype.map = function (fn) {
|
3337 | return map$1(this, fn);
|
3338 | };
|
3339 |
|
3340 |
|
3341 |
|
3342 | Observable.prototype.filter = function (fn) {
|
3343 | return filter(this, fn);
|
3344 | };
|
3345 |
|
3346 |
|
3347 |
|
3348 | Observable.prototype.take = function (n) {
|
3349 | return take(this, n);
|
3350 | };
|
3351 |
|
3352 |
|
3353 |
|
3354 | Observable.prototype.takeErrors = function (n) {
|
3355 | return takeErrors(this, n);
|
3356 | };
|
3357 |
|
3358 |
|
3359 |
|
3360 | Observable.prototype.takeWhile = function (fn) {
|
3361 | return takeWhile(this, fn);
|
3362 | };
|
3363 |
|
3364 |
|
3365 |
|
3366 | Observable.prototype.last = function () {
|
3367 | return last(this);
|
3368 | };
|
3369 |
|
3370 |
|
3371 |
|
3372 | Observable.prototype.skip = function (n) {
|
3373 | return skip(this, n);
|
3374 | };
|
3375 |
|
3376 |
|
3377 |
|
3378 | Observable.prototype.skipWhile = function (fn) {
|
3379 | return skipWhile(this, fn);
|
3380 | };
|
3381 |
|
3382 |
|
3383 |
|
3384 | Observable.prototype.skipDuplicates = function (fn) {
|
3385 | return skipDuplicates(this, fn);
|
3386 | };
|
3387 |
|
3388 |
|
3389 |
|
3390 | Observable.prototype.diff = function (fn, seed) {
|
3391 | return diff(this, fn, seed);
|
3392 | };
|
3393 |
|
3394 |
|
3395 | Observable.prototype.scan = function (fn, seed) {
|
3396 | return scan(this, fn, seed);
|
3397 | };
|
3398 |
|
3399 |
|
3400 |
|
3401 | Observable.prototype.flatten = function (fn) {
|
3402 | return flatten(this, fn);
|
3403 | };
|
3404 |
|
3405 |
|
3406 |
|
3407 | Observable.prototype.delay = function (wait) {
|
3408 | return delay(this, wait);
|
3409 | };
|
3410 |
|
3411 |
|
3412 |
|
3413 |
|
3414 | Observable.prototype.throttle = function (wait, options) {
|
3415 | return throttle(this, wait, options);
|
3416 | };
|
3417 |
|
3418 |
|
3419 |
|
3420 |
|
3421 | Observable.prototype.debounce = function (wait, options) {
|
3422 | return debounce(this, wait, options);
|
3423 | };
|
3424 |
|
3425 |
|
3426 |
|
3427 | Observable.prototype.mapErrors = function (fn) {
|
3428 | return mapErrors(this, fn);
|
3429 | };
|
3430 |
|
3431 |
|
3432 |
|
3433 | Observable.prototype.filterErrors = function (fn) {
|
3434 | return filterErrors(this, fn);
|
3435 | };
|
3436 |
|
3437 |
|
3438 |
|
3439 | Observable.prototype.ignoreValues = function () {
|
3440 | return ignoreValues(this);
|
3441 | };
|
3442 |
|
3443 |
|
3444 |
|
3445 | Observable.prototype.ignoreErrors = function () {
|
3446 | return ignoreErrors(this);
|
3447 | };
|
3448 |
|
3449 |
|
3450 |
|
3451 | Observable.prototype.ignoreEnd = function () {
|
3452 | return ignoreEnd(this);
|
3453 | };
|
3454 |
|
3455 |
|
3456 |
|
3457 | Observable.prototype.beforeEnd = function (fn) {
|
3458 | return beforeEnd(this, fn);
|
3459 | };
|
3460 |
|
3461 |
|
3462 |
|
3463 | Observable.prototype.slidingWindow = function (max, min) {
|
3464 | return slidingWindow(this, max, min);
|
3465 | };
|
3466 |
|
3467 |
|
3468 |
|
3469 |
|
3470 | Observable.prototype.bufferWhile = function (fn, options) {
|
3471 | return bufferWhile(this, fn, options);
|
3472 | };
|
3473 |
|
3474 |
|
3475 |
|
3476 | Observable.prototype.bufferWithCount = function (count, options) {
|
3477 | return bufferWhile$1(this, count, options);
|
3478 | };
|
3479 |
|
3480 |
|
3481 |
|
3482 |
|
3483 | Observable.prototype.bufferWithTimeOrCount = function (wait, count, options) {
|
3484 | return bufferWithTimeOrCount(this, wait, count, options);
|
3485 | };
|
3486 |
|
3487 |
|
3488 |
|
3489 | Observable.prototype.transduce = function (transducer) {
|
3490 | return transduce(this, transducer);
|
3491 | };
|
3492 |
|
3493 |
|
3494 |
|
3495 | Observable.prototype.withHandler = function (fn) {
|
3496 | return withHandler(this, fn);
|
3497 | };
|
3498 |
|
3499 |
|
3500 |
|
3501 | Observable.prototype.thru = function (fn) {
|
3502 | return fn(this);
|
3503 | };
|
3504 |
|
3505 |
|
3506 |
|
3507 |
|
3508 |
|
3509 |
|
3510 | Observable.prototype.combine = function (other, combinator) {
|
3511 | return combine([this, other], combinator);
|
3512 | };
|
3513 |
|
3514 |
|
3515 | Observable.prototype.zip = function (other, combinator) {
|
3516 | return zip([this, other], combinator);
|
3517 | };
|
3518 |
|
3519 |
|
3520 | Observable.prototype.merge = function (other) {
|
3521 | return merge([this, other]);
|
3522 | };
|
3523 |
|
3524 |
|
3525 | Observable.prototype.concat = function (other) {
|
3526 | return concat$1([this, other]);
|
3527 | };
|
3528 |
|
3529 |
|
3530 | var pool = function () {
|
3531 | return new Pool();
|
3532 | };
|
3533 |
|
3534 |
|
3535 |
|
3536 |
|
3537 | Observable.prototype.flatMap = function (fn) {
|
3538 | return new FlatMap(this, fn).setName(this, 'flatMap');
|
3539 | };
|
3540 | Observable.prototype.flatMapLatest = function (fn) {
|
3541 | return new FlatMap(this, fn, { concurLim: 1, drop: 'old' }).setName(this, 'flatMapLatest');
|
3542 | };
|
3543 | Observable.prototype.flatMapFirst = function (fn) {
|
3544 | return new FlatMap(this, fn, { concurLim: 1 }).setName(this, 'flatMapFirst');
|
3545 | };
|
3546 | Observable.prototype.flatMapConcat = function (fn) {
|
3547 | return new FlatMap(this, fn, { queueLim: -1, concurLim: 1 }).setName(this, 'flatMapConcat');
|
3548 | };
|
3549 | Observable.prototype.flatMapConcurLimit = function (fn, limit) {
|
3550 | return new FlatMap(this, fn, { queueLim: -1, concurLim: limit }).setName(this, 'flatMapConcurLimit');
|
3551 | };
|
3552 |
|
3553 |
|
3554 | Observable.prototype.flatMapErrors = function (fn) {
|
3555 | return new FlatMapErrors(this, fn).setName(this, 'flatMapErrors');
|
3556 | };
|
3557 |
|
3558 |
|
3559 |
|
3560 |
|
3561 |
|
3562 |
|
3563 | Observable.prototype.filterBy = function (other) {
|
3564 | return filterBy(this, other);
|
3565 | };
|
3566 |
|
3567 |
|
3568 |
|
3569 | Observable.prototype.sampledBy = function (other, combinator) {
|
3570 | return sampledBy(this, other, combinator);
|
3571 | };
|
3572 |
|
3573 |
|
3574 |
|
3575 | Observable.prototype.skipUntilBy = function (other) {
|
3576 | return skipUntilBy(this, other);
|
3577 | };
|
3578 |
|
3579 |
|
3580 |
|
3581 | Observable.prototype.takeUntilBy = function (other) {
|
3582 | return takeUntilBy(this, other);
|
3583 | };
|
3584 |
|
3585 |
|
3586 |
|
3587 |
|
3588 | Observable.prototype.bufferBy = function (other, options) {
|
3589 | return bufferBy(this, other, options);
|
3590 | };
|
3591 |
|
3592 |
|
3593 |
|
3594 |
|
3595 | Observable.prototype.bufferWhileBy = function (other, options) {
|
3596 | return bufferWhileBy(this, other, options);
|
3597 | };
|
3598 |
|
3599 |
|
3600 |
|
3601 |
|
3602 | var DEPRECATION_WARNINGS = true;
|
3603 | function dissableDeprecationWarnings() {
|
3604 | DEPRECATION_WARNINGS = false;
|
3605 | }
|
3606 |
|
3607 | function warn(msg) {
|
3608 | if (DEPRECATION_WARNINGS && console && typeof console.warn === 'function') {
|
3609 | var msg2 = '\nHere is an Error object for you containing the call stack:';
|
3610 | console.warn(msg, msg2, new Error());
|
3611 | }
|
3612 | }
|
3613 |
|
3614 |
|
3615 | Observable.prototype.awaiting = function (other) {
|
3616 | warn('You are using deprecated .awaiting() method, see https://github.com/kefirjs/kefir/issues/145');
|
3617 | return awaiting(this, other);
|
3618 | };
|
3619 |
|
3620 |
|
3621 |
|
3622 | Observable.prototype.valuesToErrors = function (fn) {
|
3623 | warn('You are using deprecated .valuesToErrors() method, see https://github.com/kefirjs/kefir/issues/149');
|
3624 | return valuesToErrors(this, fn);
|
3625 | };
|
3626 |
|
3627 |
|
3628 |
|
3629 | Observable.prototype.errorsToValues = function (fn) {
|
3630 | warn('You are using deprecated .errorsToValues() method, see https://github.com/kefirjs/kefir/issues/149');
|
3631 | return errorsToValues(this, fn);
|
3632 | };
|
3633 |
|
3634 |
|
3635 |
|
3636 | Observable.prototype.endOnError = function () {
|
3637 | warn('You are using deprecated .endOnError() method, see https://github.com/kefirjs/kefir/issues/150');
|
3638 | return endOnError(this);
|
3639 | };
|
3640 |
|
3641 |
|
3642 |
|
3643 |
|
3644 | var Kefir = {
|
3645 | Observable: Observable,
|
3646 | Stream: Stream,
|
3647 | Property: Property,
|
3648 | never: never,
|
3649 | later: later,
|
3650 | interval: interval,
|
3651 | sequentially: sequentially,
|
3652 | fromPoll: fromPoll,
|
3653 | withInterval: withInterval,
|
3654 | fromCallback: fromCallback,
|
3655 | fromNodeCallback: fromNodeCallback,
|
3656 | fromEvents: fromEvents,
|
3657 | stream: stream,
|
3658 | constant: constant,
|
3659 | constantError: constantError,
|
3660 | fromPromise: fromPromise,
|
3661 | fromESObservable: fromESObservable,
|
3662 | combine: combine,
|
3663 | zip: zip,
|
3664 | merge: merge,
|
3665 | concat: concat$1,
|
3666 | Pool: Pool,
|
3667 | pool: pool,
|
3668 | repeat: repeat,
|
3669 | staticLand: staticLand
|
3670 | };
|
3671 |
|
3672 | Kefir.Kefir = Kefir;
|
3673 |
|
3674 | exports.dissableDeprecationWarnings = dissableDeprecationWarnings;
|
3675 | exports.Kefir = Kefir;
|
3676 | exports.Observable = Observable;
|
3677 | exports.Stream = Stream;
|
3678 | exports.Property = Property;
|
3679 | exports.never = never;
|
3680 | exports.later = later;
|
3681 | exports.interval = interval;
|
3682 | exports.sequentially = sequentially;
|
3683 | exports.fromPoll = fromPoll;
|
3684 | exports.withInterval = withInterval;
|
3685 | exports.fromCallback = fromCallback;
|
3686 | exports.fromNodeCallback = fromNodeCallback;
|
3687 | exports.fromEvents = fromEvents;
|
3688 | exports.stream = stream;
|
3689 | exports.constant = constant;
|
3690 | exports.constantError = constantError;
|
3691 | exports.fromPromise = fromPromise;
|
3692 | exports.fromESObservable = fromESObservable;
|
3693 | exports.combine = combine;
|
3694 | exports.zip = zip;
|
3695 | exports.merge = merge;
|
3696 | exports.concat = concat$1;
|
3697 | exports.Pool = Pool;
|
3698 | exports.pool = pool;
|
3699 | exports.repeat = repeat;
|
3700 | exports.staticLand = staticLand;
|
3701 | exports['default'] = Kefir;
|
3702 |
|
3703 | Object.defineProperty(exports, '__esModule', { value: true });
|
3704 |
|
3705 | })));
|