rxjs-rails 2.3.0 → 2.3.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rxjs/rails/version.rb +1 -1
- data/vendor/assets/javascripts/rx.aggregates.js +115 -27
- data/vendor/assets/javascripts/rx.aggregates.min.js +1 -1
- data/vendor/assets/javascripts/rx.all.compat.js +2751 -2702
- data/vendor/assets/javascripts/rx.all.compat.min.js +3 -3
- data/vendor/assets/javascripts/rx.all.js +2605 -2589
- data/vendor/assets/javascripts/rx.all.min.js +3 -3
- data/vendor/assets/javascripts/rx.async.compat.js +41 -22
- data/vendor/assets/javascripts/rx.async.compat.min.js +1 -1
- data/vendor/assets/javascripts/rx.async.js +41 -22
- data/vendor/assets/javascripts/rx.async.min.js +1 -1
- data/vendor/assets/javascripts/rx.backpressure.js +41 -45
- data/vendor/assets/javascripts/rx.backpressure.min.js +1 -1
- data/vendor/assets/javascripts/rx.binding.js +81 -111
- data/vendor/assets/javascripts/rx.binding.min.js +1 -1
- data/vendor/assets/javascripts/rx.coincidence.js +567 -486
- data/vendor/assets/javascripts/rx.coincidence.min.js +1 -1
- data/vendor/assets/javascripts/rx.compat.js +1430 -1532
- data/vendor/assets/javascripts/rx.compat.min.js +2 -2
- data/vendor/assets/javascripts/rx.core.compat.js +76 -127
- data/vendor/assets/javascripts/rx.core.compat.min.js +1 -1
- data/vendor/assets/javascripts/rx.core.js +76 -127
- data/vendor/assets/javascripts/rx.core.min.js +1 -1
- data/vendor/assets/javascripts/rx.experimental.js +36 -36
- data/vendor/assets/javascripts/rx.experimental.min.js +1 -1
- data/vendor/assets/javascripts/rx.joinpatterns.js +281 -281
- data/vendor/assets/javascripts/rx.js +1286 -1421
- data/vendor/assets/javascripts/rx.lite.compat.js +1443 -1749
- data/vendor/assets/javascripts/rx.lite.compat.min.js +2 -2
- data/vendor/assets/javascripts/rx.lite.extras.js +133 -205
- data/vendor/assets/javascripts/rx.lite.extras.min.js +1 -1
- data/vendor/assets/javascripts/rx.lite.js +1319 -1658
- data/vendor/assets/javascripts/rx.lite.min.js +2 -2
- data/vendor/assets/javascripts/rx.min.js +2 -2
- data/vendor/assets/javascripts/rx.testing.js +302 -322
- data/vendor/assets/javascripts/rx.testing.min.js +1 -1
- data/vendor/assets/javascripts/rx.time.js +90 -75
- data/vendor/assets/javascripts/rx.time.min.js +1 -1
- data/vendor/assets/javascripts/rx.virtualtime.js +264 -279
- data/vendor/assets/javascripts/rx.virtualtime.min.js +1 -1
- metadata +10 -11
@@ -1,4 +1,4 @@
|
|
1
|
-
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
1
|
+
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
2
2
|
|
3
3
|
;(function (undefined) {
|
4
4
|
|
@@ -41,7 +41,7 @@
|
|
41
41
|
defaultSubComparer = Rx.helpers.defaultSubComparer = function (x, y) { return x > y ? 1 : (x < y ? -1 : 0); },
|
42
42
|
defaultKeySerializer = Rx.helpers.defaultKeySerializer = function (x) { return x.toString(); },
|
43
43
|
defaultError = Rx.helpers.defaultError = function (err) { throw err; },
|
44
|
-
isPromise = Rx.helpers.isPromise = function (p) { return !!p && typeof p.then === 'function'
|
44
|
+
isPromise = Rx.helpers.isPromise = function (p) { return !!p && typeof p.then === 'function'; },
|
45
45
|
asArray = Rx.helpers.asArray = function () { return Array.prototype.slice.call(arguments); },
|
46
46
|
not = Rx.helpers.not = function (a) { return !a; };
|
47
47
|
|
@@ -82,9 +82,9 @@
|
|
82
82
|
propertyIsEnumerable = objectProto.propertyIsEnumerable;
|
83
83
|
|
84
84
|
try {
|
85
|
-
|
85
|
+
suportNodeClass = !(toString.call(document) == objectClass && !({ 'toString': 0 } + ''));
|
86
86
|
} catch(e) {
|
87
|
-
|
87
|
+
suportNodeClass = true;
|
88
88
|
}
|
89
89
|
|
90
90
|
var shadowedProps = [
|
@@ -395,309 +395,320 @@
|
|
395
395
|
return a;
|
396
396
|
}
|
397
397
|
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
return bound;
|
419
|
-
};
|
420
|
-
}
|
398
|
+
// Utilities
|
399
|
+
if (!Function.prototype.bind) {
|
400
|
+
Function.prototype.bind = function (that) {
|
401
|
+
var target = this,
|
402
|
+
args = slice.call(arguments, 1);
|
403
|
+
var bound = function () {
|
404
|
+
if (this instanceof bound) {
|
405
|
+
function F() { }
|
406
|
+
F.prototype = target.prototype;
|
407
|
+
var self = new F();
|
408
|
+
var result = target.apply(self, args.concat(slice.call(arguments)));
|
409
|
+
if (Object(result) === result) {
|
410
|
+
return result;
|
411
|
+
}
|
412
|
+
return self;
|
413
|
+
} else {
|
414
|
+
return target.apply(that, args.concat(slice.call(arguments)));
|
415
|
+
}
|
416
|
+
};
|
421
417
|
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
Array.prototype.every = function every(fun /*, thisp */) {
|
426
|
-
var object = Object(this),
|
427
|
-
self = splitString && {}.toString.call(this) == stringClass ?
|
428
|
-
this.split("") :
|
429
|
-
object,
|
430
|
-
length = self.length >>> 0,
|
431
|
-
thisp = arguments[1];
|
432
|
-
|
433
|
-
if ({}.toString.call(fun) != funcClass) {
|
434
|
-
throw new TypeError(fun + " is not a function");
|
435
|
-
}
|
418
|
+
return bound;
|
419
|
+
};
|
420
|
+
}
|
436
421
|
|
437
|
-
|
438
|
-
if (i in self && !fun.call(thisp, self[i], i, object)) {
|
439
|
-
return false;
|
440
|
-
}
|
441
|
-
}
|
442
|
-
return true;
|
443
|
-
};
|
444
|
-
}
|
422
|
+
if (!Array.prototype.forEach) {
|
445
423
|
|
446
|
-
|
447
|
-
|
448
|
-
var object = Object(this),
|
449
|
-
self = splitString && {}.toString.call(this) == stringClass ?
|
450
|
-
this.split("") :
|
451
|
-
object,
|
452
|
-
length = self.length >>> 0,
|
453
|
-
result = Array(length),
|
454
|
-
thisp = arguments[1];
|
455
|
-
|
456
|
-
if ({}.toString.call(fun) != funcClass) {
|
457
|
-
throw new TypeError(fun + " is not a function");
|
458
|
-
}
|
424
|
+
Array.prototype.forEach = function (callback, thisArg) {
|
425
|
+
var T, k;
|
459
426
|
|
460
|
-
|
461
|
-
|
462
|
-
result[i] = fun.call(thisp, self[i], i, object);
|
463
|
-
}
|
464
|
-
return result;
|
465
|
-
};
|
427
|
+
if (this == null) {
|
428
|
+
throw new TypeError(" this is null or not defined");
|
466
429
|
}
|
467
430
|
|
468
|
-
|
469
|
-
|
470
|
-
var results = [], item, t = new Object(this);
|
471
|
-
for (var i = 0, len = t.length >>> 0; i < len; i++) {
|
472
|
-
item = t[i];
|
473
|
-
if (i in t && predicate.call(arguments[1], item, i, t)) {
|
474
|
-
results.push(item);
|
475
|
-
}
|
476
|
-
}
|
477
|
-
return results;
|
478
|
-
};
|
479
|
-
}
|
431
|
+
var O = Object(this);
|
432
|
+
var len = O.length >>> 0;
|
480
433
|
|
481
|
-
if (
|
482
|
-
|
483
|
-
return Object.prototype.toString.call(arg) == arrayClass;
|
484
|
-
};
|
434
|
+
if (typeof callback !== "function") {
|
435
|
+
throw new TypeError(callback + " is not a function");
|
485
436
|
}
|
486
437
|
|
487
|
-
if (
|
488
|
-
|
489
|
-
var t = Object(this);
|
490
|
-
var len = t.length >>> 0;
|
491
|
-
if (len === 0) {
|
492
|
-
return -1;
|
493
|
-
}
|
494
|
-
var n = 0;
|
495
|
-
if (arguments.length > 1) {
|
496
|
-
n = Number(arguments[1]);
|
497
|
-
if (n !== n) {
|
498
|
-
n = 0;
|
499
|
-
} else if (n !== 0 && n != Infinity && n !== -Infinity) {
|
500
|
-
n = (n > 0 || -1) * Math.floor(Math.abs(n));
|
501
|
-
}
|
502
|
-
}
|
503
|
-
if (n >= len) {
|
504
|
-
return -1;
|
505
|
-
}
|
506
|
-
var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
|
507
|
-
for (; k < len; k++) {
|
508
|
-
if (k in t && t[k] === searchElement) {
|
509
|
-
return k;
|
510
|
-
}
|
511
|
-
}
|
512
|
-
return -1;
|
513
|
-
};
|
438
|
+
if (arguments.length > 1) {
|
439
|
+
T = thisArg;
|
514
440
|
}
|
515
441
|
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
442
|
+
k = 0;
|
443
|
+
while (k < len) {
|
444
|
+
var kValue;
|
445
|
+
if (k in O) {
|
446
|
+
kValue = O[k];
|
447
|
+
callback.call(T, kValue, k, O);
|
448
|
+
}
|
449
|
+
k++;
|
450
|
+
}
|
451
|
+
};
|
452
|
+
}
|
453
|
+
|
454
|
+
var boxedString = Object("a"),
|
455
|
+
splitString = boxedString[0] != "a" || !(0 in boxedString);
|
456
|
+
if (!Array.prototype.every) {
|
457
|
+
Array.prototype.every = function every(fun /*, thisp */) {
|
458
|
+
var object = Object(this),
|
459
|
+
self = splitString && {}.toString.call(this) == stringClass ?
|
460
|
+
this.split("") :
|
461
|
+
object,
|
462
|
+
length = self.length >>> 0,
|
463
|
+
thisp = arguments[1];
|
464
|
+
|
465
|
+
if ({}.toString.call(fun) != funcClass) {
|
466
|
+
throw new TypeError(fun + " is not a function");
|
467
|
+
}
|
521
468
|
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
c = this.id - other.id;
|
469
|
+
for (var i = 0; i < length; i++) {
|
470
|
+
if (i in self && !fun.call(thisp, self[i], i, object)) {
|
471
|
+
return false;
|
526
472
|
}
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
// Priority Queue for Scheduling
|
531
|
-
var PriorityQueue = Rx.internals.PriorityQueue = function (capacity) {
|
532
|
-
this.items = new Array(capacity);
|
533
|
-
this.length = 0;
|
473
|
+
}
|
474
|
+
return true;
|
534
475
|
};
|
476
|
+
}
|
535
477
|
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
478
|
+
if (!Array.prototype.map) {
|
479
|
+
Array.prototype.map = function map(fun /*, thisp*/) {
|
480
|
+
var object = Object(this),
|
481
|
+
self = splitString && {}.toString.call(this) == stringClass ?
|
482
|
+
this.split("") :
|
483
|
+
object,
|
484
|
+
length = self.length >>> 0,
|
485
|
+
result = Array(length),
|
486
|
+
thisp = arguments[1];
|
487
|
+
|
488
|
+
if ({}.toString.call(fun) != funcClass) {
|
489
|
+
throw new TypeError(fun + " is not a function");
|
490
|
+
}
|
540
491
|
|
541
|
-
|
542
|
-
if (
|
543
|
-
|
544
|
-
}
|
545
|
-
var parent = index - 1 >> 1;
|
546
|
-
if (parent < 0 || parent === index) {
|
547
|
-
return;
|
548
|
-
}
|
549
|
-
if (this.isHigherPriority(index, parent)) {
|
550
|
-
var temp = this.items[index];
|
551
|
-
this.items[index] = this.items[parent];
|
552
|
-
this.items[parent] = temp;
|
553
|
-
this.percolate(parent);
|
492
|
+
for (var i = 0; i < length; i++) {
|
493
|
+
if (i in self) {
|
494
|
+
result[i] = fun.call(thisp, self[i], i, object);
|
554
495
|
}
|
496
|
+
}
|
497
|
+
return result;
|
555
498
|
};
|
499
|
+
}
|
556
500
|
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
var left = 2 * index + 1,
|
565
|
-
right = 2 * index + 2,
|
566
|
-
first = index;
|
567
|
-
if (left < this.length && this.isHigherPriority(left, first)) {
|
568
|
-
first = left;
|
501
|
+
if (!Array.prototype.filter) {
|
502
|
+
Array.prototype.filter = function (predicate) {
|
503
|
+
var results = [], item, t = new Object(this);
|
504
|
+
for (var i = 0, len = t.length >>> 0; i < len; i++) {
|
505
|
+
item = t[i];
|
506
|
+
if (i in t && predicate.call(arguments[1], item, i, t)) {
|
507
|
+
results.push(item);
|
569
508
|
}
|
570
|
-
|
571
|
-
|
572
|
-
}
|
573
|
-
if (first !== index) {
|
574
|
-
var temp = this.items[index];
|
575
|
-
this.items[index] = this.items[first];
|
576
|
-
this.items[first] = temp;
|
577
|
-
this.heapify(first);
|
578
|
-
}
|
579
|
-
};
|
580
|
-
|
581
|
-
priorityProto.peek = function () { return this.items[0].value; };
|
582
|
-
|
583
|
-
priorityProto.removeAt = function (index) {
|
584
|
-
this.items[index] = this.items[--this.length];
|
585
|
-
delete this.items[this.length];
|
586
|
-
this.heapify();
|
587
|
-
};
|
588
|
-
|
589
|
-
priorityProto.dequeue = function () {
|
590
|
-
var result = this.peek();
|
591
|
-
this.removeAt(0);
|
592
|
-
return result;
|
509
|
+
}
|
510
|
+
return results;
|
593
511
|
};
|
512
|
+
}
|
594
513
|
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
this.percolate(index);
|
514
|
+
if (!Array.isArray) {
|
515
|
+
Array.isArray = function (arg) {
|
516
|
+
return {}.toString.call(arg) == arrayClass;
|
599
517
|
};
|
518
|
+
}
|
600
519
|
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
520
|
+
if (!Array.prototype.indexOf) {
|
521
|
+
Array.prototype.indexOf = function indexOf(searchElement) {
|
522
|
+
var t = Object(this);
|
523
|
+
var len = t.length >>> 0;
|
524
|
+
if (len === 0) {
|
525
|
+
return -1;
|
526
|
+
}
|
527
|
+
var n = 0;
|
528
|
+
if (arguments.length > 1) {
|
529
|
+
n = Number(arguments[1]);
|
530
|
+
if (n !== n) {
|
531
|
+
n = 0;
|
532
|
+
} else if (n !== 0 && n != Infinity && n !== -Infinity) {
|
533
|
+
n = (n > 0 || -1) * Math.floor(Math.abs(n));
|
607
534
|
}
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
this.disposables = argsOrArray(arguments, 0);
|
617
|
-
this.isDisposed = false;
|
618
|
-
this.length = this.disposables.length;
|
619
|
-
};
|
620
|
-
|
621
|
-
var CompositeDisposablePrototype = CompositeDisposable.prototype;
|
622
|
-
|
623
|
-
/**
|
624
|
-
* Adds a disposable to the CompositeDisposable or disposes the disposable if the CompositeDisposable is disposed.
|
625
|
-
* @param {Mixed} item Disposable to add.
|
626
|
-
*/
|
627
|
-
CompositeDisposablePrototype.add = function (item) {
|
628
|
-
if (this.isDisposed) {
|
629
|
-
item.dispose();
|
630
|
-
} else {
|
631
|
-
this.disposables.push(item);
|
632
|
-
this.length++;
|
535
|
+
}
|
536
|
+
if (n >= len) {
|
537
|
+
return -1;
|
538
|
+
}
|
539
|
+
var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
|
540
|
+
for (; k < len; k++) {
|
541
|
+
if (k in t && t[k] === searchElement) {
|
542
|
+
return k;
|
633
543
|
}
|
544
|
+
}
|
545
|
+
return -1;
|
634
546
|
};
|
547
|
+
}
|
635
548
|
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
};
|
549
|
+
// Collections
|
550
|
+
var IndexedItem = function (id, value) {
|
551
|
+
this.id = id;
|
552
|
+
this.value = value;
|
553
|
+
};
|
554
|
+
|
555
|
+
IndexedItem.prototype.compareTo = function (other) {
|
556
|
+
var c = this.value.compareTo(other.value);
|
557
|
+
if (c === 0) {
|
558
|
+
c = this.id - other.id;
|
559
|
+
}
|
560
|
+
return c;
|
561
|
+
};
|
562
|
+
|
563
|
+
// Priority Queue for Scheduling
|
564
|
+
var PriorityQueue = Rx.internals.PriorityQueue = function (capacity) {
|
565
|
+
this.items = new Array(capacity);
|
566
|
+
this.length = 0;
|
567
|
+
};
|
568
|
+
|
569
|
+
var priorityProto = PriorityQueue.prototype;
|
570
|
+
priorityProto.isHigherPriority = function (left, right) {
|
571
|
+
return this.items[left].compareTo(this.items[right]) < 0;
|
572
|
+
};
|
573
|
+
|
574
|
+
priorityProto.percolate = function (index) {
|
575
|
+
if (index >= this.length || index < 0) {
|
576
|
+
return;
|
577
|
+
}
|
578
|
+
var parent = index - 1 >> 1;
|
579
|
+
if (parent < 0 || parent === index) {
|
580
|
+
return;
|
581
|
+
}
|
582
|
+
if (this.isHigherPriority(index, parent)) {
|
583
|
+
var temp = this.items[index];
|
584
|
+
this.items[index] = this.items[parent];
|
585
|
+
this.items[parent] = temp;
|
586
|
+
this.percolate(parent);
|
587
|
+
}
|
588
|
+
};
|
589
|
+
|
590
|
+
priorityProto.heapify = function (index) {
|
591
|
+
if (index === undefined) {
|
592
|
+
index = 0;
|
593
|
+
}
|
594
|
+
if (index >= this.length || index < 0) {
|
595
|
+
return;
|
596
|
+
}
|
597
|
+
var left = 2 * index + 1,
|
598
|
+
right = 2 * index + 2,
|
599
|
+
first = index;
|
600
|
+
if (left < this.length && this.isHigherPriority(left, first)) {
|
601
|
+
first = left;
|
602
|
+
}
|
603
|
+
if (right < this.length && this.isHigherPriority(right, first)) {
|
604
|
+
first = right;
|
605
|
+
}
|
606
|
+
if (first !== index) {
|
607
|
+
var temp = this.items[index];
|
608
|
+
this.items[index] = this.items[first];
|
609
|
+
this.items[first] = temp;
|
610
|
+
this.heapify(first);
|
611
|
+
}
|
612
|
+
};
|
613
|
+
|
614
|
+
priorityProto.peek = function () { return this.items[0].value; };
|
615
|
+
|
616
|
+
priorityProto.removeAt = function (index) {
|
617
|
+
this.items[index] = this.items[--this.length];
|
618
|
+
delete this.items[this.length];
|
619
|
+
this.heapify();
|
620
|
+
};
|
621
|
+
|
622
|
+
priorityProto.dequeue = function () {
|
623
|
+
var result = this.peek();
|
624
|
+
this.removeAt(0);
|
625
|
+
return result;
|
626
|
+
};
|
627
|
+
|
628
|
+
priorityProto.enqueue = function (item) {
|
629
|
+
var index = this.length++;
|
630
|
+
this.items[index] = new IndexedItem(PriorityQueue.count++, item);
|
631
|
+
this.percolate(index);
|
632
|
+
};
|
633
|
+
|
634
|
+
priorityProto.remove = function (item) {
|
635
|
+
for (var i = 0; i < this.length; i++) {
|
636
|
+
if (this.items[i].value === item) {
|
637
|
+
this.removeAt(i);
|
638
|
+
return true;
|
639
|
+
}
|
640
|
+
}
|
641
|
+
return false;
|
642
|
+
};
|
643
|
+
PriorityQueue.count = 0;
|
644
|
+
/**
|
645
|
+
* Represents a group of disposable resources that are disposed together.
|
646
|
+
* @constructor
|
647
|
+
*/
|
648
|
+
var CompositeDisposable = Rx.CompositeDisposable = function () {
|
649
|
+
this.disposables = argsOrArray(arguments, 0);
|
650
|
+
this.isDisposed = false;
|
651
|
+
this.length = this.disposables.length;
|
652
|
+
};
|
655
653
|
|
656
|
-
|
657
|
-
* Disposes all disposables in the group and removes them from the group.
|
658
|
-
*/
|
659
|
-
CompositeDisposablePrototype.dispose = function () {
|
660
|
-
if (!this.isDisposed) {
|
661
|
-
this.isDisposed = true;
|
662
|
-
var currentDisposables = this.disposables.slice(0);
|
663
|
-
this.disposables = [];
|
664
|
-
this.length = 0;
|
654
|
+
var CompositeDisposablePrototype = CompositeDisposable.prototype;
|
665
655
|
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
656
|
+
/**
|
657
|
+
* Adds a disposable to the CompositeDisposable or disposes the disposable if the CompositeDisposable is disposed.
|
658
|
+
* @param {Mixed} item Disposable to add.
|
659
|
+
*/
|
660
|
+
CompositeDisposablePrototype.add = function (item) {
|
661
|
+
if (this.isDisposed) {
|
662
|
+
item.dispose();
|
663
|
+
} else {
|
664
|
+
this.disposables.push(item);
|
665
|
+
this.length++;
|
666
|
+
}
|
667
|
+
};
|
671
668
|
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
669
|
+
/**
|
670
|
+
* Removes and disposes the first occurrence of a disposable from the CompositeDisposable.
|
671
|
+
* @param {Mixed} item Disposable to remove.
|
672
|
+
* @returns {Boolean} true if found; false otherwise.
|
673
|
+
*/
|
674
|
+
CompositeDisposablePrototype.remove = function (item) {
|
675
|
+
var shouldDispose = false;
|
676
|
+
if (!this.isDisposed) {
|
677
|
+
var idx = this.disposables.indexOf(item);
|
678
|
+
if (idx !== -1) {
|
679
|
+
shouldDispose = true;
|
680
|
+
this.disposables.splice(idx, 1);
|
681
|
+
this.length--;
|
682
|
+
item.dispose();
|
683
|
+
}
|
684
|
+
}
|
685
|
+
return shouldDispose;
|
686
|
+
};
|
683
687
|
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
688
|
+
/**
|
689
|
+
* Disposes all disposables in the group and removes them from the group.
|
690
|
+
*/
|
691
|
+
CompositeDisposablePrototype.dispose = function () {
|
692
|
+
if (!this.isDisposed) {
|
693
|
+
this.isDisposed = true;
|
694
|
+
var currentDisposables = this.disposables.slice(0);
|
695
|
+
this.disposables = [];
|
696
|
+
this.length = 0;
|
697
|
+
|
698
|
+
for (var i = 0, len = currentDisposables.length; i < len; i++) {
|
699
|
+
currentDisposables[i].dispose();
|
700
|
+
}
|
701
|
+
}
|
702
|
+
};
|
692
703
|
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
704
|
+
/**
|
705
|
+
* Converts the existing CompositeDisposable to an array of disposables
|
706
|
+
* @returns {Array} An array of disposable objects.
|
707
|
+
*/
|
708
|
+
CompositeDisposablePrototype.toArray = function () {
|
709
|
+
return this.disposables.slice(0);
|
710
|
+
};
|
711
|
+
|
701
712
|
/**
|
702
713
|
* Provides a set of static methods for creating Disposables.
|
703
714
|
*
|
@@ -729,90 +740,52 @@
|
|
729
740
|
*/
|
730
741
|
var disposableEmpty = Disposable.empty = { dispose: noop };
|
731
742
|
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
var booleanDisposablePrototype = BooleanDisposable.prototype;
|
740
|
-
|
741
|
-
/**
|
742
|
-
* Gets the underlying disposable.
|
743
|
-
* @return The underlying disposable.
|
744
|
-
*/
|
745
|
-
booleanDisposablePrototype.getDisposable = function () {
|
746
|
-
return this.current;
|
747
|
-
};
|
748
|
-
|
749
|
-
/**
|
750
|
-
* Sets the underlying disposable.
|
751
|
-
* @param {Disposable} value The new underlying disposable.
|
752
|
-
*/
|
753
|
-
booleanDisposablePrototype.setDisposable = function (value) {
|
754
|
-
if (this.current && this.isSingle) {
|
755
|
-
throw new Error('Disposable has already been assigned');
|
756
|
-
}
|
757
|
-
|
758
|
-
var shouldDispose = this.isDisposed, old;
|
759
|
-
if (!shouldDispose) {
|
760
|
-
old = this.current;
|
761
|
-
this.current = value;
|
762
|
-
}
|
763
|
-
if (old) {
|
764
|
-
old.dispose();
|
765
|
-
}
|
766
|
-
if (shouldDispose && value) {
|
767
|
-
value.dispose();
|
768
|
-
}
|
769
|
-
};
|
770
|
-
|
771
|
-
/**
|
772
|
-
* Disposes the underlying disposable as well as all future replacements.
|
773
|
-
*/
|
774
|
-
booleanDisposablePrototype.dispose = function () {
|
775
|
-
var old;
|
776
|
-
if (!this.isDisposed) {
|
777
|
-
this.isDisposed = true;
|
778
|
-
old = this.current;
|
779
|
-
this.current = null;
|
780
|
-
}
|
781
|
-
if (old) {
|
782
|
-
old.dispose();
|
783
|
-
}
|
784
|
-
};
|
743
|
+
var SingleAssignmentDisposable = Rx.SingleAssignmentDisposable =
|
744
|
+
SerialDisposable = Rx.SerialDisposable = (function () {
|
745
|
+
function BooleanDisposable () {
|
746
|
+
this.isDisposed = false;
|
747
|
+
this.current = null;
|
748
|
+
}
|
785
749
|
|
786
|
-
|
787
|
-
}());
|
750
|
+
var booleanDisposablePrototype = BooleanDisposable.prototype;
|
788
751
|
|
789
752
|
/**
|
790
|
-
*
|
791
|
-
*
|
753
|
+
* Gets the underlying disposable.
|
754
|
+
* @return The underlying disposable.
|
792
755
|
*/
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
function SingleAssignmentDisposable() {
|
797
|
-
super_.call(this, true);
|
798
|
-
}
|
799
|
-
|
800
|
-
return SingleAssignmentDisposable;
|
801
|
-
}(BooleanDisposable));
|
756
|
+
booleanDisposablePrototype.getDisposable = function () {
|
757
|
+
return this.current;
|
758
|
+
};
|
802
759
|
|
803
760
|
/**
|
804
|
-
*
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
761
|
+
* Sets the underlying disposable.
|
762
|
+
* @param {Disposable} value The new underlying disposable.
|
763
|
+
*/
|
764
|
+
booleanDisposablePrototype.setDisposable = function (value) {
|
765
|
+
var shouldDispose = this.isDisposed, old;
|
766
|
+
if (!shouldDispose) {
|
767
|
+
old = this.current;
|
768
|
+
this.current = value;
|
769
|
+
}
|
770
|
+
old && old.dispose();
|
771
|
+
shouldDispose && value && value.dispose();
|
772
|
+
};
|
812
773
|
|
813
|
-
|
814
|
-
|
774
|
+
/**
|
775
|
+
* Disposes the underlying disposable as well as all future replacements.
|
776
|
+
*/
|
777
|
+
booleanDisposablePrototype.dispose = function () {
|
778
|
+
var old;
|
779
|
+
if (!this.isDisposed) {
|
780
|
+
this.isDisposed = true;
|
781
|
+
old = this.current;
|
782
|
+
this.current = null;
|
783
|
+
}
|
784
|
+
old && old.dispose();
|
785
|
+
};
|
815
786
|
|
787
|
+
return BooleanDisposable;
|
788
|
+
}());
|
816
789
|
/**
|
817
790
|
* Represents a disposable resource that only disposes its underlying disposable resource when all dependent disposable objects have been disposed.
|
818
791
|
*/
|
@@ -875,394 +848,433 @@
|
|
875
848
|
return RefCountDisposable;
|
876
849
|
})();
|
877
850
|
|
878
|
-
var ScheduledItem = Rx.internals.ScheduledItem = function (scheduler, state, action, dueTime, comparer) {
|
879
|
-
this.scheduler = scheduler;
|
880
|
-
this.state = state;
|
881
|
-
this.action = action;
|
882
|
-
this.dueTime = dueTime;
|
883
|
-
this.comparer = comparer || defaultSubComparer;
|
884
|
-
this.disposable = new SingleAssignmentDisposable();
|
851
|
+
var ScheduledItem = Rx.internals.ScheduledItem = function (scheduler, state, action, dueTime, comparer) {
|
852
|
+
this.scheduler = scheduler;
|
853
|
+
this.state = state;
|
854
|
+
this.action = action;
|
855
|
+
this.dueTime = dueTime;
|
856
|
+
this.comparer = comparer || defaultSubComparer;
|
857
|
+
this.disposable = new SingleAssignmentDisposable();
|
858
|
+
}
|
859
|
+
|
860
|
+
ScheduledItem.prototype.invoke = function () {
|
861
|
+
this.disposable.setDisposable(this.invokeCore());
|
862
|
+
};
|
863
|
+
|
864
|
+
ScheduledItem.prototype.compareTo = function (other) {
|
865
|
+
return this.comparer(this.dueTime, other.dueTime);
|
866
|
+
};
|
867
|
+
|
868
|
+
ScheduledItem.prototype.isCancelled = function () {
|
869
|
+
return this.disposable.isDisposed;
|
870
|
+
};
|
871
|
+
|
872
|
+
ScheduledItem.prototype.invokeCore = function () {
|
873
|
+
return this.action(this.scheduler, this.state);
|
874
|
+
};
|
875
|
+
|
876
|
+
/** Provides a set of static properties to access commonly used schedulers. */
|
877
|
+
var Scheduler = Rx.Scheduler = (function () {
|
878
|
+
|
879
|
+
function Scheduler(now, schedule, scheduleRelative, scheduleAbsolute) {
|
880
|
+
this.now = now;
|
881
|
+
this._schedule = schedule;
|
882
|
+
this._scheduleRelative = scheduleRelative;
|
883
|
+
this._scheduleAbsolute = scheduleAbsolute;
|
885
884
|
}
|
886
885
|
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
ScheduledItem.prototype.invokeCore = function () {
|
900
|
-
return this.action(this.scheduler, this.state);
|
901
|
-
};
|
902
|
-
|
903
|
-
/** Provides a set of static properties to access commonly used schedulers. */
|
904
|
-
var Scheduler = Rx.Scheduler = (function () {
|
905
|
-
|
906
|
-
function Scheduler(now, schedule, scheduleRelative, scheduleAbsolute) {
|
907
|
-
this.now = now;
|
908
|
-
this._schedule = schedule;
|
909
|
-
this._scheduleRelative = scheduleRelative;
|
910
|
-
this._scheduleAbsolute = scheduleAbsolute;
|
911
|
-
}
|
912
|
-
|
913
|
-
function invokeRecImmediate(scheduler, pair) {
|
914
|
-
var state = pair.first, action = pair.second, group = new CompositeDisposable(),
|
915
|
-
recursiveAction = function (state1) {
|
916
|
-
action(state1, function (state2) {
|
917
|
-
var isAdded = false, isDone = false,
|
918
|
-
d = scheduler.scheduleWithState(state2, function (scheduler1, state3) {
|
919
|
-
if (isAdded) {
|
920
|
-
group.remove(d);
|
921
|
-
} else {
|
922
|
-
isDone = true;
|
923
|
-
}
|
924
|
-
recursiveAction(state3);
|
925
|
-
return disposableEmpty;
|
926
|
-
});
|
927
|
-
if (!isDone) {
|
928
|
-
group.add(d);
|
929
|
-
isAdded = true;
|
930
|
-
}
|
931
|
-
});
|
932
|
-
};
|
933
|
-
recursiveAction(state);
|
934
|
-
return group;
|
935
|
-
}
|
936
|
-
|
937
|
-
function invokeRecDate(scheduler, pair, method) {
|
938
|
-
var state = pair.first, action = pair.second, group = new CompositeDisposable(),
|
939
|
-
recursiveAction = function (state1) {
|
940
|
-
action(state1, function (state2, dueTime1) {
|
941
|
-
var isAdded = false, isDone = false,
|
942
|
-
d = scheduler[method].call(scheduler, state2, dueTime1, function (scheduler1, state3) {
|
943
|
-
if (isAdded) {
|
944
|
-
group.remove(d);
|
945
|
-
} else {
|
946
|
-
isDone = true;
|
947
|
-
}
|
948
|
-
recursiveAction(state3);
|
949
|
-
return disposableEmpty;
|
950
|
-
});
|
951
|
-
if (!isDone) {
|
952
|
-
group.add(d);
|
953
|
-
isAdded = true;
|
954
|
-
}
|
955
|
-
});
|
956
|
-
};
|
957
|
-
recursiveAction(state);
|
958
|
-
return group;
|
959
|
-
}
|
960
|
-
|
961
|
-
function invokeAction(scheduler, action) {
|
962
|
-
action();
|
886
|
+
function invokeRecImmediate(scheduler, pair) {
|
887
|
+
var state = pair.first, action = pair.second, group = new CompositeDisposable(),
|
888
|
+
recursiveAction = function (state1) {
|
889
|
+
action(state1, function (state2) {
|
890
|
+
var isAdded = false, isDone = false,
|
891
|
+
d = scheduler.scheduleWithState(state2, function (scheduler1, state3) {
|
892
|
+
if (isAdded) {
|
893
|
+
group.remove(d);
|
894
|
+
} else {
|
895
|
+
isDone = true;
|
896
|
+
}
|
897
|
+
recursiveAction(state3);
|
963
898
|
return disposableEmpty;
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
schedulerProto.schedulePeriodic = function (period, action) {
|
975
|
-
return this.schedulePeriodicWithState(null, period, function () {
|
976
|
-
action();
|
977
|
-
});
|
978
|
-
};
|
979
|
-
|
980
|
-
/**
|
981
|
-
* Schedules a periodic piece of work by dynamically discovering the scheduler's capabilities. The periodic task will be scheduled using window.setInterval for the base implementation.
|
982
|
-
* @param {Mixed} state Initial state passed to the action upon the first iteration.
|
983
|
-
* @param {Number} period Period for running the work periodically.
|
984
|
-
* @param {Function} action Action to be executed, potentially updating the state.
|
985
|
-
* @returns {Disposable} The disposable object used to cancel the scheduled recurring action (best effort).
|
986
|
-
*/
|
987
|
-
schedulerProto.schedulePeriodicWithState = function (state, period, action) {
|
988
|
-
var s = state, id = setInterval(function () {
|
989
|
-
s = action(s);
|
990
|
-
}, period);
|
991
|
-
return disposableCreate(function () {
|
992
|
-
clearInterval(id);
|
993
|
-
});
|
994
|
-
};
|
899
|
+
});
|
900
|
+
if (!isDone) {
|
901
|
+
group.add(d);
|
902
|
+
isAdded = true;
|
903
|
+
}
|
904
|
+
});
|
905
|
+
};
|
906
|
+
recursiveAction(state);
|
907
|
+
return group;
|
908
|
+
}
|
995
909
|
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
910
|
+
function invokeRecDate(scheduler, pair, method) {
|
911
|
+
var state = pair.first, action = pair.second, group = new CompositeDisposable(),
|
912
|
+
recursiveAction = function (state1) {
|
913
|
+
action(state1, function (state2, dueTime1) {
|
914
|
+
var isAdded = false, isDone = false,
|
915
|
+
d = scheduler[method].call(scheduler, state2, dueTime1, function (scheduler1, state3) {
|
916
|
+
if (isAdded) {
|
917
|
+
group.remove(d);
|
918
|
+
} else {
|
919
|
+
isDone = true;
|
920
|
+
}
|
921
|
+
recursiveAction(state3);
|
922
|
+
return disposableEmpty;
|
923
|
+
});
|
924
|
+
if (!isDone) {
|
925
|
+
group.add(d);
|
926
|
+
isAdded = true;
|
927
|
+
}
|
928
|
+
});
|
929
|
+
};
|
930
|
+
recursiveAction(state);
|
931
|
+
return group;
|
932
|
+
}
|
1004
933
|
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
1010
|
-
*/
|
1011
|
-
schedulerProto.scheduleWithState = function (state, action) {
|
1012
|
-
return this._schedule(state, action);
|
1013
|
-
};
|
934
|
+
function invokeAction(scheduler, action) {
|
935
|
+
action();
|
936
|
+
return disposableEmpty;
|
937
|
+
}
|
1014
938
|
|
1015
|
-
|
1016
|
-
* Schedules an action to be executed after the specified relative due time.
|
1017
|
-
* @param {Function} action Action to execute.
|
1018
|
-
* @param {Number} dueTime Relative time after which to execute the action.
|
1019
|
-
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
1020
|
-
*/
|
1021
|
-
schedulerProto.scheduleWithRelative = function (dueTime, action) {
|
1022
|
-
return this._scheduleRelative(action, dueTime, invokeAction);
|
1023
|
-
};
|
939
|
+
var schedulerProto = Scheduler.prototype;
|
1024
940
|
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
return this._scheduleRelative(state, dueTime, action);
|
1034
|
-
};
|
941
|
+
/**
|
942
|
+
* Schedules an action to be executed.
|
943
|
+
* @param {Function} action Action to execute.
|
944
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
945
|
+
*/
|
946
|
+
schedulerProto.schedule = function (action) {
|
947
|
+
return this._schedule(action, invokeAction);
|
948
|
+
};
|
1035
949
|
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
950
|
+
/**
|
951
|
+
* Schedules an action to be executed.
|
952
|
+
* @param state State passed to the action to be executed.
|
953
|
+
* @param {Function} action Action to be executed.
|
954
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
955
|
+
*/
|
956
|
+
schedulerProto.scheduleWithState = function (state, action) {
|
957
|
+
return this._schedule(state, action);
|
958
|
+
};
|
1045
959
|
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
};
|
960
|
+
/**
|
961
|
+
* Schedules an action to be executed after the specified relative due time.
|
962
|
+
* @param {Function} action Action to execute.
|
963
|
+
* @param {Number} dueTime Relative time after which to execute the action.
|
964
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
965
|
+
*/
|
966
|
+
schedulerProto.scheduleWithRelative = function (dueTime, action) {
|
967
|
+
return this._scheduleRelative(action, dueTime, invokeAction);
|
968
|
+
};
|
1056
969
|
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
});
|
1068
|
-
};
|
970
|
+
/**
|
971
|
+
* Schedules an action to be executed after dueTime.
|
972
|
+
* @param state State passed to the action to be executed.
|
973
|
+
* @param {Function} action Action to be executed.
|
974
|
+
* @param {Number} dueTime Relative time after which to execute the action.
|
975
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
976
|
+
*/
|
977
|
+
schedulerProto.scheduleWithRelativeAndState = function (state, dueTime, action) {
|
978
|
+
return this._scheduleRelative(state, dueTime, action);
|
979
|
+
};
|
1069
980
|
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
});
|
1080
|
-
};
|
981
|
+
/**
|
982
|
+
* Schedules an action to be executed at the specified absolute due time.
|
983
|
+
* @param {Function} action Action to execute.
|
984
|
+
* @param {Number} dueTime Absolute time at which to execute the action.
|
985
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
986
|
+
*/
|
987
|
+
schedulerProto.scheduleWithAbsolute = function (dueTime, action) {
|
988
|
+
return this._scheduleAbsolute(action, dueTime, invokeAction);
|
989
|
+
};
|
1081
990
|
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
});
|
1093
|
-
});
|
1094
|
-
};
|
991
|
+
/**
|
992
|
+
* Schedules an action to be executed at dueTime.
|
993
|
+
* @param {Mixed} state State passed to the action to be executed.
|
994
|
+
* @param {Function} action Action to be executed.
|
995
|
+
* @param {Number}dueTime Absolute time at which to execute the action.
|
996
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
997
|
+
*/
|
998
|
+
schedulerProto.scheduleWithAbsoluteAndState = function (state, dueTime, action) {
|
999
|
+
return this._scheduleAbsolute(state, dueTime, action);
|
1000
|
+
};
|
1095
1001
|
|
1096
|
-
|
1097
|
-
|
1098
|
-
* @param {Mixed} state State passed to the action to be executed.
|
1099
|
-
* @param {Function} action Action to execute recursively. The last parameter passed to the action is used to trigger recursive scheduling of the action, passing in the recursive due time and invocation state.
|
1100
|
-
* @param {Number}dueTime Relative time after which to execute the action for the first time.
|
1101
|
-
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
1102
|
-
*/
|
1103
|
-
schedulerProto.scheduleRecursiveWithRelativeAndState = function (state, dueTime, action) {
|
1104
|
-
return this._scheduleRelative({ first: state, second: action }, dueTime, function (s, p) {
|
1105
|
-
return invokeRecDate(s, p, 'scheduleWithRelativeAndState');
|
1106
|
-
});
|
1107
|
-
};
|
1002
|
+
/** Gets the current time according to the local machine's system clock. */
|
1003
|
+
Scheduler.now = defaultNow;
|
1108
1004
|
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
self(_action, dt);
|
1119
|
-
});
|
1120
|
-
});
|
1121
|
-
};
|
1005
|
+
/**
|
1006
|
+
* Normalizes the specified TimeSpan value to a positive value.
|
1007
|
+
* @param {Number} timeSpan The time span value to normalize.
|
1008
|
+
* @returns {Number} The specified TimeSpan value if it is zero or positive; otherwise, 0
|
1009
|
+
*/
|
1010
|
+
Scheduler.normalize = function (timeSpan) {
|
1011
|
+
timeSpan < 0 && (timeSpan = 0);
|
1012
|
+
return timeSpan;
|
1013
|
+
};
|
1122
1014
|
|
1123
|
-
|
1124
|
-
|
1125
|
-
* @param {Mixed} state State passed to the action to be executed.
|
1126
|
-
* @param {Function} action Action to execute recursively. The last parameter passed to the action is used to trigger recursive scheduling of the action, passing in the recursive due time and invocation state.
|
1127
|
-
* @param {Number}dueTime Absolute time at which to execute the action for the first time.
|
1128
|
-
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
1129
|
-
*/
|
1130
|
-
schedulerProto.scheduleRecursiveWithAbsoluteAndState = function (state, dueTime, action) {
|
1131
|
-
return this._scheduleAbsolute({ first: state, second: action }, dueTime, function (s, p) {
|
1132
|
-
return invokeRecDate(s, p, 'scheduleWithAbsoluteAndState');
|
1133
|
-
});
|
1134
|
-
};
|
1015
|
+
return Scheduler;
|
1016
|
+
}());
|
1135
1017
|
|
1136
|
-
|
1137
|
-
|
1018
|
+
var normalizeTime = Scheduler.normalize;
|
1019
|
+
|
1020
|
+
(function (schedulerProto) {
|
1021
|
+
function invokeRecImmediate(scheduler, pair) {
|
1022
|
+
var state = pair.first, action = pair.second, group = new CompositeDisposable(),
|
1023
|
+
recursiveAction = function (state1) {
|
1024
|
+
action(state1, function (state2) {
|
1025
|
+
var isAdded = false, isDone = false,
|
1026
|
+
d = scheduler.scheduleWithState(state2, function (scheduler1, state3) {
|
1027
|
+
if (isAdded) {
|
1028
|
+
group.remove(d);
|
1029
|
+
} else {
|
1030
|
+
isDone = true;
|
1031
|
+
}
|
1032
|
+
recursiveAction(state3);
|
1033
|
+
return disposableEmpty;
|
1034
|
+
});
|
1035
|
+
if (!isDone) {
|
1036
|
+
group.add(d);
|
1037
|
+
isAdded = true;
|
1038
|
+
}
|
1039
|
+
});
|
1040
|
+
};
|
1041
|
+
recursiveAction(state);
|
1042
|
+
return group;
|
1043
|
+
}
|
1138
1044
|
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
if (
|
1146
|
-
|
1045
|
+
function invokeRecDate(scheduler, pair, method) {
|
1046
|
+
var state = pair.first, action = pair.second, group = new CompositeDisposable(),
|
1047
|
+
recursiveAction = function (state1) {
|
1048
|
+
action(state1, function (state2, dueTime1) {
|
1049
|
+
var isAdded = false, isDone = false,
|
1050
|
+
d = scheduler[method].call(scheduler, state2, dueTime1, function (scheduler1, state3) {
|
1051
|
+
if (isAdded) {
|
1052
|
+
group.remove(d);
|
1053
|
+
} else {
|
1054
|
+
isDone = true;
|
1147
1055
|
}
|
1148
|
-
|
1149
|
-
|
1056
|
+
recursiveAction(state3);
|
1057
|
+
return disposableEmpty;
|
1058
|
+
});
|
1059
|
+
if (!isDone) {
|
1060
|
+
group.add(d);
|
1061
|
+
isAdded = true;
|
1062
|
+
}
|
1063
|
+
});
|
1064
|
+
};
|
1065
|
+
recursiveAction(state);
|
1066
|
+
return group;
|
1067
|
+
}
|
1150
1068
|
|
1151
|
-
|
1152
|
-
|
1069
|
+
function scheduleInnerRecursive(action, self) {
|
1070
|
+
action(function(dt) { self(action, dt); });
|
1071
|
+
}
|
1153
1072
|
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1073
|
+
/**
|
1074
|
+
* Schedules an action to be executed recursively.
|
1075
|
+
* @param {Function} action Action to execute recursively. The parameter passed to the action is used to trigger recursive scheduling of the action.
|
1076
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
1077
|
+
*/
|
1078
|
+
schedulerProto.scheduleRecursive = function (action) {
|
1079
|
+
return this.scheduleRecursiveWithState(action, function (_action, self) {
|
1080
|
+
_action(function () { self(_action); }); });
|
1081
|
+
};
|
1160
1082
|
|
1161
|
-
|
1083
|
+
/**
|
1084
|
+
* Schedules an action to be executed recursively.
|
1085
|
+
* @param {Mixed} state State passed to the action to be executed.
|
1086
|
+
* @param {Function} action Action to execute recursively. The last parameter passed to the action is used to trigger recursive scheduling of the action, passing in recursive invocation state.
|
1087
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
1088
|
+
*/
|
1089
|
+
schedulerProto.scheduleRecursiveWithState = function (state, action) {
|
1090
|
+
return this.scheduleWithState({ first: state, second: action }, invokeRecImmediate);
|
1091
|
+
};
|
1162
1092
|
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1093
|
+
/**
|
1094
|
+
* Schedules an action to be executed recursively after a specified relative due time.
|
1095
|
+
* @param {Function} action Action to execute recursively. The parameter passed to the action is used to trigger recursive scheduling of the action at the specified relative time.
|
1096
|
+
* @param {Number}dueTime Relative time after which to execute the action for the first time.
|
1097
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
1098
|
+
*/
|
1099
|
+
schedulerProto.scheduleRecursiveWithRelative = function (dueTime, action) {
|
1100
|
+
return this.scheduleRecursiveWithRelativeAndState(action, dueTime, scheduleInnerRecursive);
|
1101
|
+
};
|
1168
1102
|
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1103
|
+
/**
|
1104
|
+
* Schedules an action to be executed recursively after a specified relative due time.
|
1105
|
+
* @param {Mixed} state State passed to the action to be executed.
|
1106
|
+
* @param {Function} action Action to execute recursively. The last parameter passed to the action is used to trigger recursive scheduling of the action, passing in the recursive due time and invocation state.
|
1107
|
+
* @param {Number}dueTime Relative time after which to execute the action for the first time.
|
1108
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
1109
|
+
*/
|
1110
|
+
schedulerProto.scheduleRecursiveWithRelativeAndState = function (state, dueTime, action) {
|
1111
|
+
return this._scheduleRelative({ first: state, second: action }, dueTime, function (s, p) {
|
1112
|
+
return invokeRecDate(s, p, 'scheduleWithRelativeAndState');
|
1113
|
+
});
|
1114
|
+
};
|
1172
1115
|
|
1173
|
-
|
1174
|
-
|
1116
|
+
/**
|
1117
|
+
* Schedules an action to be executed recursively at a specified absolute due time.
|
1118
|
+
* @param {Function} action Action to execute recursively. The parameter passed to the action is used to trigger recursive scheduling of the action at the specified absolute time.
|
1119
|
+
* @param {Number}dueTime Absolute time at which to execute the action for the first time.
|
1120
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
1121
|
+
*/
|
1122
|
+
schedulerProto.scheduleRecursiveWithAbsolute = function (dueTime, action) {
|
1123
|
+
return this.scheduleRecursiveWithAbsoluteAndState(action, dueTime, scheduleInnerRecursive);
|
1124
|
+
};
|
1175
1125
|
|
1176
|
-
/**
|
1177
|
-
*
|
1126
|
+
/**
|
1127
|
+
* Schedules an action to be executed recursively at a specified absolute due time.
|
1128
|
+
* @param {Mixed} state State passed to the action to be executed.
|
1129
|
+
* @param {Function} action Action to execute recursively. The last parameter passed to the action is used to trigger recursive scheduling of the action, passing in the recursive due time and invocation state.
|
1130
|
+
* @param {Number}dueTime Absolute time at which to execute the action for the first time.
|
1131
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
1178
1132
|
*/
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
item = q.dequeue();
|
1186
|
-
if (!item.isCancelled()) {
|
1187
|
-
// Note, do not schedule blocking work!
|
1188
|
-
while (item.dueTime - Scheduler.now() > 0) {
|
1189
|
-
}
|
1190
|
-
if (!item.isCancelled()) {
|
1191
|
-
item.invoke();
|
1192
|
-
}
|
1193
|
-
}
|
1194
|
-
}
|
1195
|
-
}
|
1133
|
+
schedulerProto.scheduleRecursiveWithAbsoluteAndState = function (state, dueTime, action) {
|
1134
|
+
return this._scheduleAbsolute({ first: state, second: action }, dueTime, function (s, p) {
|
1135
|
+
return invokeRecDate(s, p, 'scheduleWithAbsoluteAndState');
|
1136
|
+
});
|
1137
|
+
};
|
1138
|
+
}(Scheduler.prototype));
|
1196
1139
|
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1140
|
+
(function (schedulerProto) {
|
1141
|
+
/**
|
1142
|
+
* Schedules a periodic piece of work by dynamically discovering the scheduler's capabilities. The periodic task will be scheduled using window.setInterval for the base implementation.
|
1143
|
+
* @param {Number} period Period for running the work periodically.
|
1144
|
+
* @param {Function} action Action to be executed.
|
1145
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled recurring action (best effort).
|
1146
|
+
*/
|
1147
|
+
Scheduler.prototype.schedulePeriodic = function (period, action) {
|
1148
|
+
return this.schedulePeriodicWithState(null, period, action);
|
1149
|
+
};
|
1200
1150
|
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1151
|
+
/**
|
1152
|
+
* Schedules a periodic piece of work by dynamically discovering the scheduler's capabilities. The periodic task will be scheduled using window.setInterval for the base implementation.
|
1153
|
+
* @param {Mixed} state Initial state passed to the action upon the first iteration.
|
1154
|
+
* @param {Number} period Period for running the work periodically.
|
1155
|
+
* @param {Function} action Action to be executed, potentially updating the state.
|
1156
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled recurring action (best effort).
|
1157
|
+
*/
|
1158
|
+
Scheduler.prototype.schedulePeriodicWithState = function (state, period, action) {
|
1159
|
+
var s = state;
|
1160
|
+
|
1161
|
+
var id = setInterval(function () {
|
1162
|
+
s = action(s);
|
1163
|
+
}, period);
|
1164
|
+
|
1165
|
+
return disposableCreate(function () {
|
1166
|
+
clearInterval(id);
|
1167
|
+
});
|
1168
|
+
};
|
1169
|
+
}(Scheduler.prototype));
|
1170
|
+
|
1171
|
+
/**
|
1172
|
+
* Gets a scheduler that schedules work immediately on the current thread.
|
1173
|
+
*/
|
1174
|
+
var immediateScheduler = Scheduler.immediate = (function () {
|
1175
|
+
|
1176
|
+
function scheduleNow(state, action) { return action(this, state); }
|
1177
|
+
|
1178
|
+
function scheduleRelative(state, dueTime, action) {
|
1179
|
+
var dt = normalizeTime(dt);
|
1180
|
+
while (dt - this.now() > 0) { }
|
1181
|
+
return action(this, state);
|
1182
|
+
}
|
1183
|
+
|
1184
|
+
function scheduleAbsolute(state, dueTime, action) {
|
1185
|
+
return this.scheduleWithRelativeAndState(state, dueTime - this.now(), action);
|
1186
|
+
}
|
1187
|
+
|
1188
|
+
return new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
|
1189
|
+
}());
|
1220
1190
|
|
1221
|
-
|
1222
|
-
|
1191
|
+
/**
|
1192
|
+
* Gets a scheduler that schedules work as soon as possible on the current thread.
|
1193
|
+
*/
|
1194
|
+
var currentThreadScheduler = Scheduler.currentThread = (function () {
|
1195
|
+
var queue;
|
1196
|
+
|
1197
|
+
function runTrampoline (q) {
|
1198
|
+
var item;
|
1199
|
+
while (q.length > 0) {
|
1200
|
+
item = q.dequeue();
|
1201
|
+
if (!item.isCancelled()) {
|
1202
|
+
// Note, do not schedule blocking work!
|
1203
|
+
while (item.dueTime - Scheduler.now() > 0) {
|
1204
|
+
}
|
1205
|
+
if (!item.isCancelled()) {
|
1206
|
+
item.invoke();
|
1207
|
+
}
|
1223
1208
|
}
|
1209
|
+
}
|
1210
|
+
}
|
1224
1211
|
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
if (queue === null) {
|
1229
|
-
return this.schedule(action);
|
1230
|
-
} else {
|
1231
|
-
return action();
|
1232
|
-
}
|
1233
|
-
};
|
1212
|
+
function scheduleNow(state, action) {
|
1213
|
+
return this.scheduleWithRelativeAndState(state, 0, action);
|
1214
|
+
}
|
1234
1215
|
|
1235
|
-
|
1236
|
-
|
1216
|
+
function scheduleRelative(state, dueTime, action) {
|
1217
|
+
var dt = this.now() + Scheduler.normalize(dueTime),
|
1218
|
+
si = new ScheduledItem(this, state, action, dt);
|
1237
1219
|
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1220
|
+
if (!queue) {
|
1221
|
+
queue = new PriorityQueue(4);
|
1222
|
+
queue.enqueue(si);
|
1223
|
+
try {
|
1224
|
+
runTrampoline(queue);
|
1225
|
+
} catch (e) {
|
1226
|
+
throw e;
|
1227
|
+
} finally {
|
1228
|
+
queue = null;
|
1247
1229
|
}
|
1230
|
+
} else {
|
1231
|
+
queue.enqueue(si);
|
1232
|
+
}
|
1233
|
+
return si.disposable;
|
1234
|
+
}
|
1248
1235
|
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
this._period = period;
|
1253
|
-
this._action = action;
|
1254
|
-
}
|
1236
|
+
function scheduleAbsolute(state, dueTime, action) {
|
1237
|
+
return this.scheduleWithRelativeAndState(state, dueTime - this.now(), action);
|
1238
|
+
}
|
1255
1239
|
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1240
|
+
var currentScheduler = new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
|
1241
|
+
|
1242
|
+
currentScheduler.scheduleRequired = function () { return !queue; };
|
1243
|
+
currentScheduler.ensureTrampoline = function (action) {
|
1244
|
+
if (!queue) { this.schedule(action); } else { action(); }
|
1245
|
+
};
|
1260
1246
|
|
1261
|
-
|
1262
|
-
|
1247
|
+
return currentScheduler;
|
1248
|
+
}());
|
1263
1249
|
|
1264
|
-
|
1265
|
-
|
1250
|
+
var SchedulePeriodicRecursive = Rx.internals.SchedulePeriodicRecursive = (function () {
|
1251
|
+
function tick(command, recurse) {
|
1252
|
+
recurse(0, this._period);
|
1253
|
+
try {
|
1254
|
+
this._state = this._action(this._state);
|
1255
|
+
} catch (e) {
|
1256
|
+
this._cancel.dispose();
|
1257
|
+
throw e;
|
1258
|
+
}
|
1259
|
+
}
|
1260
|
+
|
1261
|
+
function SchedulePeriodicRecursive(scheduler, state, period, action) {
|
1262
|
+
this._scheduler = scheduler;
|
1263
|
+
this._state = state;
|
1264
|
+
this._period = period;
|
1265
|
+
this._action = action;
|
1266
|
+
}
|
1267
|
+
|
1268
|
+
SchedulePeriodicRecursive.prototype.start = function () {
|
1269
|
+
var d = new SingleAssignmentDisposable();
|
1270
|
+
this._cancel = d;
|
1271
|
+
d.setDisposable(this._scheduler.scheduleRecursiveWithRelativeAndState(0, this._period, tick.bind(this)));
|
1272
|
+
|
1273
|
+
return d;
|
1274
|
+
};
|
1275
|
+
|
1276
|
+
return SchedulePeriodicRecursive;
|
1277
|
+
}());
|
1266
1278
|
|
1267
1279
|
|
1268
1280
|
var scheduleMethod, clearMethod = noop;
|
@@ -1508,150 +1520,150 @@
|
|
1508
1520
|
};
|
1509
1521
|
}());
|
1510
1522
|
|
1511
|
-
var Enumerator = Rx.internals.Enumerator = function (next) {
|
1512
|
-
this._next = next;
|
1513
|
-
};
|
1514
|
-
|
1515
|
-
Enumerator.prototype.next = function () {
|
1516
|
-
return this._next();
|
1517
|
-
};
|
1518
|
-
|
1519
|
-
Enumerator.prototype[$iterator$] = function () { return this; }
|
1520
|
-
|
1521
|
-
var Enumerable = Rx.internals.Enumerable = function (iterator) {
|
1522
|
-
this._iterator = iterator;
|
1523
|
-
};
|
1524
|
-
|
1525
|
-
Enumerable.prototype[$iterator$] = function () {
|
1526
|
-
return this._iterator();
|
1527
|
-
};
|
1528
|
-
|
1529
|
-
Enumerable.prototype.concat = function () {
|
1530
|
-
var sources = this;
|
1531
|
-
return new AnonymousObservable(function (observer) {
|
1532
|
-
var e;
|
1533
|
-
try {
|
1534
|
-
e = sources[$iterator$]();
|
1535
|
-
} catch(err) {
|
1536
|
-
observer.onError();
|
1537
|
-
return;
|
1538
|
-
}
|
1539
|
-
|
1540
|
-
var isDisposed,
|
1541
|
-
subscription = new SerialDisposable();
|
1542
|
-
var cancelable = immediateScheduler.scheduleRecursive(function (self) {
|
1543
|
-
var currentItem;
|
1544
|
-
if (isDisposed) { return; }
|
1545
|
-
|
1546
|
-
try {
|
1547
|
-
currentItem = e.next();
|
1548
|
-
} catch (ex) {
|
1549
|
-
observer.onError(ex);
|
1550
|
-
return;
|
1551
|
-
}
|
1552
|
-
|
1553
|
-
if (currentItem.done) {
|
1554
|
-
observer.onCompleted();
|
1555
|
-
return;
|
1556
|
-
}
|
1557
|
-
|
1558
|
-
// Check if promise
|
1559
|
-
var currentValue = currentItem.value;
|
1560
|
-
isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
|
1561
|
-
|
1562
|
-
var d = new SingleAssignmentDisposable();
|
1563
|
-
subscription.setDisposable(d);
|
1564
|
-
d.setDisposable(currentValue.subscribe(
|
1565
|
-
observer.onNext.bind(observer),
|
1566
|
-
observer.onError.bind(observer),
|
1567
|
-
function () { self(); })
|
1568
|
-
);
|
1569
|
-
});
|
1570
|
-
|
1571
|
-
return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
|
1572
|
-
isDisposed = true;
|
1573
|
-
}));
|
1574
|
-
});
|
1575
|
-
};
|
1576
|
-
|
1577
|
-
Enumerable.prototype.catchException = function () {
|
1578
|
-
var sources = this;
|
1579
|
-
return new AnonymousObservable(function (observer) {
|
1580
|
-
var e;
|
1581
|
-
try {
|
1582
|
-
e = sources[$iterator$]();
|
1583
|
-
} catch(err) {
|
1584
|
-
observer.onError();
|
1585
|
-
return;
|
1586
|
-
}
|
1587
|
-
|
1588
|
-
var isDisposed,
|
1589
|
-
lastException,
|
1590
|
-
subscription = new SerialDisposable();
|
1591
|
-
var cancelable = immediateScheduler.scheduleRecursive(function (self) {
|
1592
|
-
if (isDisposed) { return; }
|
1593
|
-
|
1594
|
-
var currentItem;
|
1595
|
-
try {
|
1596
|
-
currentItem = e.next();
|
1597
|
-
} catch (ex) {
|
1598
|
-
observer.onError(ex);
|
1599
|
-
return;
|
1600
|
-
}
|
1601
|
-
|
1602
|
-
if (currentItem.done) {
|
1603
|
-
if (lastException) {
|
1604
|
-
observer.onError(lastException);
|
1605
|
-
} else {
|
1606
|
-
observer.onCompleted();
|
1607
|
-
}
|
1608
|
-
return;
|
1609
|
-
}
|
1610
|
-
|
1611
|
-
// Check if promise
|
1612
|
-
var currentValue = currentItem.value;
|
1613
|
-
isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
|
1614
|
-
|
1615
|
-
var d = new SingleAssignmentDisposable();
|
1616
|
-
subscription.setDisposable(d);
|
1617
|
-
d.setDisposable(currentValue.subscribe(
|
1618
|
-
observer.onNext.bind(observer),
|
1619
|
-
function (exn) {
|
1620
|
-
lastException = exn;
|
1621
|
-
self();
|
1622
|
-
},
|
1623
|
-
observer.onCompleted.bind(observer)));
|
1624
|
-
});
|
1625
|
-
return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
|
1626
|
-
isDisposed = true;
|
1627
|
-
}));
|
1628
|
-
});
|
1629
|
-
};
|
1630
|
-
|
1631
|
-
var enumerableRepeat = Enumerable.repeat = function (value, repeatCount) {
|
1632
|
-
if (repeatCount == null) { repeatCount = -1; }
|
1633
|
-
return new Enumerable(function () {
|
1634
|
-
var left = repeatCount;
|
1635
|
-
return new Enumerator(function () {
|
1636
|
-
if (left === 0) { return doneEnumerator; }
|
1637
|
-
if (left > 0) { left--; }
|
1638
|
-
return { done: false, value: value };
|
1639
|
-
});
|
1640
|
-
});
|
1641
|
-
};
|
1642
|
-
|
1643
|
-
var enumerableFor = Enumerable.forEach = function (source, selector, thisArg) {
|
1644
|
-
selector || (selector = identity);
|
1645
|
-
return new Enumerable(function () {
|
1646
|
-
var index = -1;
|
1647
|
-
return new Enumerator(
|
1648
|
-
function () {
|
1649
|
-
return ++index < source.length ?
|
1650
|
-
{ done: false, value: selector.call(thisArg, source[index], index, source) } :
|
1651
|
-
doneEnumerator;
|
1652
|
-
});
|
1653
|
-
});
|
1654
|
-
};
|
1523
|
+
var Enumerator = Rx.internals.Enumerator = function (next) {
|
1524
|
+
this._next = next;
|
1525
|
+
};
|
1526
|
+
|
1527
|
+
Enumerator.prototype.next = function () {
|
1528
|
+
return this._next();
|
1529
|
+
};
|
1530
|
+
|
1531
|
+
Enumerator.prototype[$iterator$] = function () { return this; }
|
1532
|
+
|
1533
|
+
var Enumerable = Rx.internals.Enumerable = function (iterator) {
|
1534
|
+
this._iterator = iterator;
|
1535
|
+
};
|
1536
|
+
|
1537
|
+
Enumerable.prototype[$iterator$] = function () {
|
1538
|
+
return this._iterator();
|
1539
|
+
};
|
1540
|
+
|
1541
|
+
Enumerable.prototype.concat = function () {
|
1542
|
+
var sources = this;
|
1543
|
+
return new AnonymousObservable(function (observer) {
|
1544
|
+
var e;
|
1545
|
+
try {
|
1546
|
+
e = sources[$iterator$]();
|
1547
|
+
} catch(err) {
|
1548
|
+
observer.onError();
|
1549
|
+
return;
|
1550
|
+
}
|
1551
|
+
|
1552
|
+
var isDisposed,
|
1553
|
+
subscription = new SerialDisposable();
|
1554
|
+
var cancelable = immediateScheduler.scheduleRecursive(function (self) {
|
1555
|
+
var currentItem;
|
1556
|
+
if (isDisposed) { return; }
|
1557
|
+
|
1558
|
+
try {
|
1559
|
+
currentItem = e.next();
|
1560
|
+
} catch (ex) {
|
1561
|
+
observer.onError(ex);
|
1562
|
+
return;
|
1563
|
+
}
|
1564
|
+
|
1565
|
+
if (currentItem.done) {
|
1566
|
+
observer.onCompleted();
|
1567
|
+
return;
|
1568
|
+
}
|
1569
|
+
|
1570
|
+
// Check if promise
|
1571
|
+
var currentValue = currentItem.value;
|
1572
|
+
isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
|
1573
|
+
|
1574
|
+
var d = new SingleAssignmentDisposable();
|
1575
|
+
subscription.setDisposable(d);
|
1576
|
+
d.setDisposable(currentValue.subscribe(
|
1577
|
+
observer.onNext.bind(observer),
|
1578
|
+
observer.onError.bind(observer),
|
1579
|
+
function () { self(); })
|
1580
|
+
);
|
1581
|
+
});
|
1582
|
+
|
1583
|
+
return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
|
1584
|
+
isDisposed = true;
|
1585
|
+
}));
|
1586
|
+
});
|
1587
|
+
};
|
1588
|
+
|
1589
|
+
Enumerable.prototype.catchException = function () {
|
1590
|
+
var sources = this;
|
1591
|
+
return new AnonymousObservable(function (observer) {
|
1592
|
+
var e;
|
1593
|
+
try {
|
1594
|
+
e = sources[$iterator$]();
|
1595
|
+
} catch(err) {
|
1596
|
+
observer.onError();
|
1597
|
+
return;
|
1598
|
+
}
|
1599
|
+
|
1600
|
+
var isDisposed,
|
1601
|
+
lastException,
|
1602
|
+
subscription = new SerialDisposable();
|
1603
|
+
var cancelable = immediateScheduler.scheduleRecursive(function (self) {
|
1604
|
+
if (isDisposed) { return; }
|
1605
|
+
|
1606
|
+
var currentItem;
|
1607
|
+
try {
|
1608
|
+
currentItem = e.next();
|
1609
|
+
} catch (ex) {
|
1610
|
+
observer.onError(ex);
|
1611
|
+
return;
|
1612
|
+
}
|
1613
|
+
|
1614
|
+
if (currentItem.done) {
|
1615
|
+
if (lastException) {
|
1616
|
+
observer.onError(lastException);
|
1617
|
+
} else {
|
1618
|
+
observer.onCompleted();
|
1619
|
+
}
|
1620
|
+
return;
|
1621
|
+
}
|
1622
|
+
|
1623
|
+
// Check if promise
|
1624
|
+
var currentValue = currentItem.value;
|
1625
|
+
isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
|
1626
|
+
|
1627
|
+
var d = new SingleAssignmentDisposable();
|
1628
|
+
subscription.setDisposable(d);
|
1629
|
+
d.setDisposable(currentValue.subscribe(
|
1630
|
+
observer.onNext.bind(observer),
|
1631
|
+
function (exn) {
|
1632
|
+
lastException = exn;
|
1633
|
+
self();
|
1634
|
+
},
|
1635
|
+
observer.onCompleted.bind(observer)));
|
1636
|
+
});
|
1637
|
+
return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
|
1638
|
+
isDisposed = true;
|
1639
|
+
}));
|
1640
|
+
});
|
1641
|
+
};
|
1642
|
+
|
1643
|
+
var enumerableRepeat = Enumerable.repeat = function (value, repeatCount) {
|
1644
|
+
if (repeatCount == null) { repeatCount = -1; }
|
1645
|
+
return new Enumerable(function () {
|
1646
|
+
var left = repeatCount;
|
1647
|
+
return new Enumerator(function () {
|
1648
|
+
if (left === 0) { return doneEnumerator; }
|
1649
|
+
if (left > 0) { left--; }
|
1650
|
+
return { done: false, value: value };
|
1651
|
+
});
|
1652
|
+
});
|
1653
|
+
};
|
1654
|
+
|
1655
|
+
var enumerableFor = Enumerable.forEach = function (source, selector, thisArg) {
|
1656
|
+
selector || (selector = identity);
|
1657
|
+
return new Enumerable(function () {
|
1658
|
+
var index = -1;
|
1659
|
+
return new Enumerator(
|
1660
|
+
function () {
|
1661
|
+
return ++index < source.length ?
|
1662
|
+
{ done: false, value: selector.call(thisArg, source[index], index, source) } :
|
1663
|
+
doneEnumerator;
|
1664
|
+
});
|
1665
|
+
});
|
1666
|
+
};
|
1655
1667
|
|
1656
1668
|
/**
|
1657
1669
|
* Supports push-style iteration over an observable sequence.
|
@@ -1957,20 +1969,20 @@
|
|
1957
1969
|
});
|
1958
1970
|
};
|
1959
1971
|
|
1960
|
-
|
1961
|
-
|
1962
|
-
|
1963
|
-
|
1964
|
-
|
1965
|
-
|
1966
|
-
|
1967
|
-
|
1968
|
-
|
1969
|
-
|
1970
|
-
|
1971
|
-
|
1972
|
-
|
1973
|
-
|
1972
|
+
/**
|
1973
|
+
* Creates an observable sequence from a specified subscribe method implementation.
|
1974
|
+
*
|
1975
|
+
* @example
|
1976
|
+
* var res = Rx.Observable.create(function (observer) { return function () { } );
|
1977
|
+
* var res = Rx.Observable.create(function (observer) { return Rx.Disposable.empty; } );
|
1978
|
+
* var res = Rx.Observable.create(function (observer) { } );
|
1979
|
+
*
|
1980
|
+
* @param {Function} subscribe Implementation of the resulting observable sequence's subscribe method, returning a function that will be wrapped in a Disposable.
|
1981
|
+
* @returns {Observable} The observable sequence with the specified implementation for the Subscribe method.
|
1982
|
+
*/
|
1983
|
+
Observable.create = Observable.createWithDisposable = function (subscribe) {
|
1984
|
+
return new AnonymousObservable(subscribe);
|
1985
|
+
};
|
1974
1986
|
|
1975
1987
|
/**
|
1976
1988
|
* Returns an observable sequence that invokes the specified factory function whenever a new observer subscribes.
|
@@ -2124,49 +2136,6 @@
|
|
2124
2136
|
});
|
2125
2137
|
};
|
2126
2138
|
|
2127
|
-
/**
|
2128
|
-
* Generates an observable sequence by running a state-driven loop producing the sequence's elements, using the specified scheduler to send out observer messages.
|
2129
|
-
*
|
2130
|
-
* @example
|
2131
|
-
* var res = Rx.Observable.generate(0, function (x) { return x < 10; }, function (x) { return x + 1; }, function (x) { return x; });
|
2132
|
-
* var res = Rx.Observable.generate(0, function (x) { return x < 10; }, function (x) { return x + 1; }, function (x) { return x; }, Rx.Scheduler.timeout);
|
2133
|
-
* @param {Mixed} initialState Initial state.
|
2134
|
-
* @param {Function} condition Condition to terminate generation (upon returning false).
|
2135
|
-
* @param {Function} iterate Iteration step function.
|
2136
|
-
* @param {Function} resultSelector Selector function for results produced in the sequence.
|
2137
|
-
* @param {Scheduler} [scheduler] Scheduler on which to run the generator loop. If not provided, defaults to Scheduler.currentThread.
|
2138
|
-
* @returns {Observable} The generated sequence.
|
2139
|
-
*/
|
2140
|
-
Observable.generate = function (initialState, condition, iterate, resultSelector, scheduler) {
|
2141
|
-
isScheduler(scheduler) || (scheduler = currentThreadScheduler);
|
2142
|
-
return new AnonymousObservable(function (observer) {
|
2143
|
-
var first = true, state = initialState;
|
2144
|
-
return scheduler.scheduleRecursive(function (self) {
|
2145
|
-
var hasResult, result;
|
2146
|
-
try {
|
2147
|
-
if (first) {
|
2148
|
-
first = false;
|
2149
|
-
} else {
|
2150
|
-
state = iterate(state);
|
2151
|
-
}
|
2152
|
-
hasResult = condition(state);
|
2153
|
-
if (hasResult) {
|
2154
|
-
result = resultSelector(state);
|
2155
|
-
}
|
2156
|
-
} catch (exception) {
|
2157
|
-
observer.onError(exception);
|
2158
|
-
return;
|
2159
|
-
}
|
2160
|
-
if (hasResult) {
|
2161
|
-
observer.onNext(result);
|
2162
|
-
self();
|
2163
|
-
} else {
|
2164
|
-
observer.onCompleted();
|
2165
|
-
}
|
2166
|
-
});
|
2167
|
-
});
|
2168
|
-
};
|
2169
|
-
|
2170
2139
|
/**
|
2171
2140
|
* Returns a non-terminating observable sequence, which can be used to denote an infinite duration (e.g. when using reactive joins).
|
2172
2141
|
* @returns {Observable} An observable sequence whose observers will never get called.
|
@@ -2455,63 +2424,53 @@
|
|
2455
2424
|
return this.merge(1);
|
2456
2425
|
};
|
2457
2426
|
|
2458
|
-
|
2459
|
-
|
2460
|
-
|
2461
|
-
|
2462
|
-
|
2463
|
-
|
2464
|
-
|
2465
|
-
|
2466
|
-
|
2467
|
-
|
2468
|
-
|
2469
|
-
|
2470
|
-
|
2427
|
+
/**
|
2428
|
+
* Merges an observable sequence of observable sequences into an observable sequence, limiting the number of concurrent subscriptions to inner sequences.
|
2429
|
+
* Or merges two observable sequences into a single observable sequence.
|
2430
|
+
*
|
2431
|
+
* @example
|
2432
|
+
* 1 - merged = sources.merge(1);
|
2433
|
+
* 2 - merged = source.merge(otherSource);
|
2434
|
+
* @param {Mixed} [maxConcurrentOrOther] Maximum number of inner observable sequences being subscribed to concurrently or the second observable sequence.
|
2435
|
+
* @returns {Observable} The observable sequence that merges the elements of the inner sequences.
|
2436
|
+
*/
|
2437
|
+
observableProto.merge = function (maxConcurrentOrOther) {
|
2438
|
+
if (typeof maxConcurrentOrOther !== 'number') { return observableMerge(this, maxConcurrentOrOther); }
|
2439
|
+
var sources = this;
|
2440
|
+
return new AnonymousObservable(function (observer) {
|
2441
|
+
var activeCount = 0, group = new CompositeDisposable(), isStopped = false, q = [];
|
2442
|
+
|
2443
|
+
function subscribe(xs) {
|
2444
|
+
var subscription = new SingleAssignmentDisposable();
|
2445
|
+
group.add(subscription);
|
2446
|
+
|
2447
|
+
// Check for promises support
|
2448
|
+
isPromise(xs) && (xs = observableFromPromise(xs));
|
2449
|
+
|
2450
|
+
subscription.setDisposable(xs.subscribe(observer.onNext.bind(observer), observer.onError.bind(observer), function () {
|
2451
|
+
group.remove(subscription);
|
2452
|
+
if (q.length > 0) {
|
2453
|
+
subscribe(q.shift());
|
2454
|
+
} else {
|
2455
|
+
activeCount--;
|
2456
|
+
isStopped && activeCount === 0 && observer.onCompleted();
|
2457
|
+
}
|
2458
|
+
}));
|
2459
|
+
}
|
2460
|
+
group.add(sources.subscribe(function (innerSource) {
|
2461
|
+
if (activeCount < maxConcurrentOrOther) {
|
2462
|
+
activeCount++;
|
2463
|
+
subscribe(innerSource);
|
2464
|
+
} else {
|
2465
|
+
q.push(innerSource);
|
2471
2466
|
}
|
2472
|
-
|
2473
|
-
|
2474
|
-
|
2475
|
-
|
2476
|
-
|
2477
|
-
|
2478
|
-
|
2479
|
-
var subscription = new SingleAssignmentDisposable();
|
2480
|
-
group.add(subscription);
|
2481
|
-
|
2482
|
-
// Check for promises support
|
2483
|
-
if (isPromise(xs)) { xs = observableFromPromise(xs); }
|
2484
|
-
|
2485
|
-
subscription.setDisposable(xs.subscribe(observer.onNext.bind(observer), observer.onError.bind(observer), function () {
|
2486
|
-
var s;
|
2487
|
-
group.remove(subscription);
|
2488
|
-
if (q.length > 0) {
|
2489
|
-
s = q.shift();
|
2490
|
-
subscribe(s);
|
2491
|
-
} else {
|
2492
|
-
activeCount--;
|
2493
|
-
if (isStopped && activeCount === 0) {
|
2494
|
-
observer.onCompleted();
|
2495
|
-
}
|
2496
|
-
}
|
2497
|
-
}));
|
2498
|
-
};
|
2499
|
-
group.add(sources.subscribe(function (innerSource) {
|
2500
|
-
if (activeCount < maxConcurrentOrOther) {
|
2501
|
-
activeCount++;
|
2502
|
-
subscribe(innerSource);
|
2503
|
-
} else {
|
2504
|
-
q.push(innerSource);
|
2505
|
-
}
|
2506
|
-
}, observer.onError.bind(observer), function () {
|
2507
|
-
isStopped = true;
|
2508
|
-
if (activeCount === 0) {
|
2509
|
-
observer.onCompleted();
|
2510
|
-
}
|
2511
|
-
}));
|
2512
|
-
return group;
|
2513
|
-
});
|
2514
|
-
};
|
2467
|
+
}, observer.onError.bind(observer), function () {
|
2468
|
+
isStopped = true;
|
2469
|
+
activeCount === 0 && observer.onCompleted();
|
2470
|
+
}));
|
2471
|
+
return group;
|
2472
|
+
});
|
2473
|
+
};
|
2515
2474
|
|
2516
2475
|
/**
|
2517
2476
|
* Merges all the observable sequences into a single observable sequence.
|
@@ -2862,84 +2821,84 @@
|
|
2862
2821
|
var comparerEquals = false, key;
|
2863
2822
|
try {
|
2864
2823
|
key = keySelector(value);
|
2865
|
-
} catch (exception) {
|
2866
|
-
observer.onError(exception);
|
2867
|
-
return;
|
2868
|
-
}
|
2869
|
-
if (hasCurrentKey) {
|
2870
|
-
try {
|
2871
|
-
comparerEquals = comparer(currentKey, key);
|
2872
|
-
} catch (exception) {
|
2873
|
-
observer.onError(exception);
|
2874
|
-
return;
|
2875
|
-
}
|
2876
|
-
}
|
2877
|
-
if (!hasCurrentKey || !comparerEquals) {
|
2878
|
-
hasCurrentKey = true;
|
2879
|
-
currentKey = key;
|
2880
|
-
observer.onNext(value);
|
2881
|
-
}
|
2882
|
-
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
2883
|
-
});
|
2884
|
-
};
|
2885
|
-
|
2886
|
-
/**
|
2887
|
-
* Invokes an action for each element in the observable sequence and invokes an action upon graceful or exceptional termination of the observable sequence.
|
2888
|
-
* This method can be used for debugging, logging, etc. of query behavior by intercepting the message stream to run arbitrary actions for messages on the pipeline.
|
2889
|
-
*
|
2890
|
-
* @example
|
2891
|
-
* var res = observable.doAction(observer);
|
2892
|
-
* var res = observable.doAction(onNext);
|
2893
|
-
* var res = observable.doAction(onNext, onError);
|
2894
|
-
* var res = observable.doAction(onNext, onError, onCompleted);
|
2895
|
-
* @param {Mixed} observerOrOnNext Action to invoke for each element in the observable sequence or an observer.
|
2896
|
-
* @param {Function} [onError] Action to invoke upon exceptional termination of the observable sequence. Used if only the observerOrOnNext parameter is also a function.
|
2897
|
-
* @param {Function} [onCompleted] Action to invoke upon graceful termination of the observable sequence. Used if only the observerOrOnNext parameter is also a function.
|
2898
|
-
* @returns {Observable} The source sequence with the side-effecting behavior applied.
|
2899
|
-
*/
|
2900
|
-
observableProto['do'] = observableProto.doAction = function (observerOrOnNext, onError, onCompleted) {
|
2901
|
-
var source = this, onNextFunc;
|
2902
|
-
if (typeof observerOrOnNext === 'function') {
|
2903
|
-
onNextFunc = observerOrOnNext;
|
2904
|
-
} else {
|
2905
|
-
onNextFunc = observerOrOnNext.onNext.bind(observerOrOnNext);
|
2906
|
-
onError = observerOrOnNext.onError.bind(observerOrOnNext);
|
2907
|
-
onCompleted = observerOrOnNext.onCompleted.bind(observerOrOnNext);
|
2908
|
-
}
|
2909
|
-
return new AnonymousObservable(function (observer) {
|
2910
|
-
return source.subscribe(function (x) {
|
2911
|
-
try {
|
2912
|
-
onNextFunc(x);
|
2913
|
-
} catch (e) {
|
2914
|
-
observer.onError(e);
|
2915
|
-
}
|
2916
|
-
observer.onNext(x);
|
2917
|
-
}, function (exception) {
|
2918
|
-
if (!onError) {
|
2919
|
-
observer.onError(exception);
|
2920
|
-
} else {
|
2921
|
-
try {
|
2922
|
-
onError(exception);
|
2923
|
-
} catch (e) {
|
2924
|
-
observer.onError(e);
|
2925
|
-
}
|
2824
|
+
} catch (exception) {
|
2926
2825
|
observer.onError(exception);
|
2826
|
+
return;
|
2927
2827
|
}
|
2928
|
-
|
2929
|
-
if (!onCompleted) {
|
2930
|
-
observer.onCompleted();
|
2931
|
-
} else {
|
2828
|
+
if (hasCurrentKey) {
|
2932
2829
|
try {
|
2933
|
-
|
2934
|
-
} catch (
|
2935
|
-
observer.onError(
|
2830
|
+
comparerEquals = comparer(currentKey, key);
|
2831
|
+
} catch (exception) {
|
2832
|
+
observer.onError(exception);
|
2833
|
+
return;
|
2936
2834
|
}
|
2937
|
-
observer.onCompleted();
|
2938
2835
|
}
|
2939
|
-
|
2836
|
+
if (!hasCurrentKey || !comparerEquals) {
|
2837
|
+
hasCurrentKey = true;
|
2838
|
+
currentKey = key;
|
2839
|
+
observer.onNext(value);
|
2840
|
+
}
|
2841
|
+
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
2940
2842
|
});
|
2941
2843
|
};
|
2942
2844
|
|
2845
|
+
/**
|
2846
|
+
* Invokes an action for each element in the observable sequence and invokes an action upon graceful or exceptional termination of the observable sequence.
|
2847
|
+
* This method can be used for debugging, logging, etc. of query behavior by intercepting the message stream to run arbitrary actions for messages on the pipeline.
|
2848
|
+
*
|
2849
|
+
* @example
|
2850
|
+
* var res = observable.do(observer);
|
2851
|
+
* var res = observable.do(onNext);
|
2852
|
+
* var res = observable.do(onNext, onError);
|
2853
|
+
* var res = observable.do(onNext, onError, onCompleted);
|
2854
|
+
* @param {Function | Observer} observerOrOnNext Action to invoke for each element in the observable sequence or an observer.
|
2855
|
+
* @param {Function} [onError] Action to invoke upon exceptional termination of the observable sequence. Used if only the observerOrOnNext parameter is also a function.
|
2856
|
+
* @param {Function} [onCompleted] Action to invoke upon graceful termination of the observable sequence. Used if only the observerOrOnNext parameter is also a function.
|
2857
|
+
* @returns {Observable} The source sequence with the side-effecting behavior applied.
|
2858
|
+
*/
|
2859
|
+
observableProto['do'] = observableProto.doAction = observableProto.tap = function (observerOrOnNext, onError, onCompleted) {
|
2860
|
+
var source = this, onNextFunc;
|
2861
|
+
if (typeof observerOrOnNext === 'function') {
|
2862
|
+
onNextFunc = observerOrOnNext;
|
2863
|
+
} else {
|
2864
|
+
onNextFunc = observerOrOnNext.onNext.bind(observerOrOnNext);
|
2865
|
+
onError = observerOrOnNext.onError.bind(observerOrOnNext);
|
2866
|
+
onCompleted = observerOrOnNext.onCompleted.bind(observerOrOnNext);
|
2867
|
+
}
|
2868
|
+
return new AnonymousObservable(function (observer) {
|
2869
|
+
return source.subscribe(function (x) {
|
2870
|
+
try {
|
2871
|
+
onNextFunc(x);
|
2872
|
+
} catch (e) {
|
2873
|
+
observer.onError(e);
|
2874
|
+
}
|
2875
|
+
observer.onNext(x);
|
2876
|
+
}, function (err) {
|
2877
|
+
if (!onError) {
|
2878
|
+
observer.onError(err);
|
2879
|
+
} else {
|
2880
|
+
try {
|
2881
|
+
onError(err);
|
2882
|
+
} catch (e) {
|
2883
|
+
observer.onError(e);
|
2884
|
+
}
|
2885
|
+
observer.onError(err);
|
2886
|
+
}
|
2887
|
+
}, function () {
|
2888
|
+
if (!onCompleted) {
|
2889
|
+
observer.onCompleted();
|
2890
|
+
} else {
|
2891
|
+
try {
|
2892
|
+
onCompleted();
|
2893
|
+
} catch (e) {
|
2894
|
+
observer.onError(e);
|
2895
|
+
}
|
2896
|
+
observer.onCompleted();
|
2897
|
+
}
|
2898
|
+
});
|
2899
|
+
});
|
2900
|
+
};
|
2901
|
+
|
2943
2902
|
/**
|
2944
2903
|
* Invokes a specified action after the source observable sequence terminates gracefully or exceptionally.
|
2945
2904
|
*
|
@@ -3121,96 +3080,59 @@
|
|
3121
3080
|
return enumerableFor([observableFromArray(values, scheduler), this]).concat();
|
3122
3081
|
};
|
3123
3082
|
|
3124
|
-
|
3125
|
-
|
3126
|
-
|
3127
|
-
|
3128
|
-
|
3129
|
-
|
3130
|
-
|
3131
|
-
|
3132
|
-
|
3133
|
-
|
3134
|
-
|
3135
|
-
|
3136
|
-
|
3137
|
-
|
3138
|
-
|
3139
|
-
|
3140
|
-
|
3141
|
-
|
3142
|
-
|
3143
|
-
|
3144
|
-
|
3145
|
-
|
3146
|
-
|
3147
|
-
|
3148
|
-
|
3149
|
-
* @returns {Observable} An observable sequence containing a single array with the specified number of elements from the end of the source sequence.
|
3150
|
-
*/
|
3151
|
-
observableProto.takeLastBuffer = function (count) {
|
3152
|
-
var source = this;
|
3153
|
-
return new AnonymousObservable(function (observer) {
|
3154
|
-
var q = [];
|
3155
|
-
return source.subscribe(function (x) {
|
3156
|
-
q.push(x);
|
3157
|
-
if (q.length > count) {
|
3158
|
-
q.shift();
|
3159
|
-
}
|
3160
|
-
}, observer.onError.bind(observer), function () {
|
3161
|
-
observer.onNext(q);
|
3162
|
-
observer.onCompleted();
|
3163
|
-
});
|
3164
|
-
});
|
3165
|
-
};
|
3083
|
+
/**
|
3084
|
+
* Returns a specified number of contiguous elements from the end of an observable sequence.
|
3085
|
+
*
|
3086
|
+
* @example
|
3087
|
+
* var res = source.takeLast(5);
|
3088
|
+
*
|
3089
|
+
* @description
|
3090
|
+
* This operator accumulates a buffer with a length enough to store elements count elements. Upon completion of
|
3091
|
+
* the source sequence, this buffer is drained on the result sequence. This causes the elements to be delayed.
|
3092
|
+
* @param {Number} count Number of elements to take from the end of the source sequence.
|
3093
|
+
* @returns {Observable} An observable sequence containing the specified number of elements from the end of the source sequence.
|
3094
|
+
*/
|
3095
|
+
observableProto.takeLast = function (count) {
|
3096
|
+
var source = this;
|
3097
|
+
return new AnonymousObservable(function (observer) {
|
3098
|
+
var q = [];
|
3099
|
+
return source.subscribe(function (x) {
|
3100
|
+
q.push(x);
|
3101
|
+
q.length > count && q.shift();
|
3102
|
+
}, observer.onError.bind(observer), function () {
|
3103
|
+
while(q.length > 0) { observer.onNext(q.shift()); }
|
3104
|
+
observer.onCompleted();
|
3105
|
+
});
|
3106
|
+
});
|
3107
|
+
};
|
3166
3108
|
|
3167
|
-
function concatMap(selector) {
|
3168
|
-
return
|
3169
|
-
var result = selector(x, i);
|
3109
|
+
function concatMap(source, selector, thisArg) {
|
3110
|
+
return source.map(function (x, i) {
|
3111
|
+
var result = selector.call(thisArg, x, i);
|
3170
3112
|
return isPromise(result) ? observableFromPromise(result) : result;
|
3171
3113
|
}).concatAll();
|
3172
3114
|
}
|
3173
3115
|
|
3174
|
-
function concatMapObserver(onNext, onError, onCompleted) {
|
3175
|
-
var source = this;
|
3176
|
-
return new AnonymousObservable(function (observer) {
|
3177
|
-
var index = 0;
|
3178
|
-
|
3179
|
-
return source.subscribe(
|
3180
|
-
function (x) {
|
3181
|
-
observer.onNext(onNext(x, index++));
|
3182
|
-
},
|
3183
|
-
function (err) {
|
3184
|
-
observer.onNext(onError(err));
|
3185
|
-
observer.completed();
|
3186
|
-
},
|
3187
|
-
function () {
|
3188
|
-
observer.onNext(onCompleted());
|
3189
|
-
observer.onCompleted();
|
3190
|
-
});
|
3191
|
-
}).concatAll();
|
3192
|
-
}
|
3193
|
-
|
3194
3116
|
/**
|
3195
3117
|
* One of the Following:
|
3196
3118
|
* Projects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
|
3197
3119
|
*
|
3198
3120
|
* @example
|
3199
|
-
* var res = source.
|
3121
|
+
* var res = source.concatMap(function (x) { return Rx.Observable.range(0, x); });
|
3200
3122
|
* Or:
|
3201
3123
|
* Projects each element of an observable sequence to an observable sequence, invokes the result selector for the source element and each of the corresponding inner sequence's elements, and merges the results into one observable sequence.
|
3202
3124
|
*
|
3203
|
-
* var res = source.
|
3125
|
+
* var res = source.concatMap(function (x) { return Rx.Observable.range(0, x); }, function (x, y) { return x + y; });
|
3204
3126
|
* Or:
|
3205
3127
|
* Projects each element of the source observable sequence to the other observable sequence and merges the resulting observable sequences into one observable sequence.
|
3206
3128
|
*
|
3207
|
-
* var res = source.
|
3129
|
+
* var res = source.concatMap(Rx.Observable.fromArray([1,2,3]));
|
3208
3130
|
* @param selector A transform function to apply to each element or an observable sequence to project each element from the
|
3209
3131
|
* source sequence onto which could be either an observable or Promise.
|
3210
3132
|
* @param {Function} [resultSelector] A transform function to apply to each element of the intermediate sequence.
|
3211
3133
|
* @returns {Observable} An observable sequence whose elements are the result of invoking the one-to-many transform function collectionSelector on each element of the input sequence and then mapping each of those sequence elements and their corresponding source element to a result element.
|
3212
3134
|
*/
|
3213
|
-
observableProto.selectConcat = observableProto.concatMap = function (selector, resultSelector) {
|
3135
|
+
observableProto.selectConcat = observableProto.concatMap = function (selector, resultSelector, thisArg) {
|
3214
3136
|
if (resultSelector) {
|
3215
3137
|
return this.concatMap(function (x, i) {
|
3216
3138
|
var selectorResult = selector(x, i),
|
@@ -3221,12 +3143,9 @@
|
|
3221
3143
|
});
|
3222
3144
|
});
|
3223
3145
|
}
|
3224
|
-
|
3225
|
-
|
3226
|
-
|
3227
|
-
return concatMap.call(this, function () {
|
3228
|
-
return selector;
|
3229
|
-
});
|
3146
|
+
return typeof selector === 'function' ?
|
3147
|
+
concatMap(this, selector, thisArg) :
|
3148
|
+
concatMap(this, function () { return selector; });
|
3230
3149
|
};
|
3231
3150
|
|
3232
3151
|
/**
|
@@ -3261,33 +3180,13 @@
|
|
3261
3180
|
return this.select(function (x) { return x[property]; });
|
3262
3181
|
};
|
3263
3182
|
|
3264
|
-
function
|
3265
|
-
return
|
3266
|
-
var result = selector(x, i);
|
3183
|
+
function flatMap(source, selector, thisArg) {
|
3184
|
+
return source.map(function (x, i) {
|
3185
|
+
var result = selector.call(thisArg, x, i);
|
3267
3186
|
return isPromise(result) ? observableFromPromise(result) : result;
|
3268
3187
|
}).mergeObservable();
|
3269
3188
|
}
|
3270
3189
|
|
3271
|
-
function selectManyObserver(onNext, onError, onCompleted) {
|
3272
|
-
var source = this;
|
3273
|
-
return new AnonymousObservable(function (observer) {
|
3274
|
-
var index = 0;
|
3275
|
-
|
3276
|
-
return source.subscribe(
|
3277
|
-
function (x) {
|
3278
|
-
observer.onNext(onNext(x, index++));
|
3279
|
-
},
|
3280
|
-
function (err) {
|
3281
|
-
observer.onNext(onError(err));
|
3282
|
-
observer.completed();
|
3283
|
-
},
|
3284
|
-
function () {
|
3285
|
-
observer.onNext(onCompleted());
|
3286
|
-
observer.onCompleted();
|
3287
|
-
});
|
3288
|
-
}).mergeAll();
|
3289
|
-
}
|
3290
|
-
|
3291
3190
|
/**
|
3292
3191
|
* One of the Following:
|
3293
3192
|
* Projects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
|
@@ -3305,25 +3204,23 @@
|
|
3305
3204
|
* @param selector A transform function to apply to each element or an observable sequence to project each element from the
|
3306
3205
|
* source sequence onto which could be either an observable or Promise.
|
3307
3206
|
* @param {Function} [resultSelector] A transform function to apply to each element of the intermediate sequence.
|
3207
|
+
* @param {Any} [thisArg] Object to use as this when executing callback.
|
3308
3208
|
* @returns {Observable} An observable sequence whose elements are the result of invoking the one-to-many transform function collectionSelector on each element of the input sequence and then mapping each of those sequence elements and their corresponding source element to a result element.
|
3309
3209
|
*/
|
3310
|
-
observableProto.selectMany = observableProto.flatMap = function (selector, resultSelector) {
|
3210
|
+
observableProto.selectMany = observableProto.flatMap = function (selector, resultSelector, thisArg) {
|
3311
3211
|
if (resultSelector) {
|
3312
|
-
return this.
|
3212
|
+
return this.flatMap(function (x, i) {
|
3313
3213
|
var selectorResult = selector(x, i),
|
3314
3214
|
result = isPromise(selectorResult) ? observableFromPromise(selectorResult) : selectorResult;
|
3315
3215
|
|
3316
|
-
return result.
|
3216
|
+
return result.map(function (y) {
|
3317
3217
|
return resultSelector(x, y, i);
|
3318
3218
|
});
|
3319
|
-
});
|
3219
|
+
}, thisArg);
|
3320
3220
|
}
|
3321
|
-
|
3322
|
-
|
3323
|
-
|
3324
|
-
return selectMany.call(this, function () {
|
3325
|
-
return selector;
|
3326
|
-
});
|
3221
|
+
return typeof selector === 'function' ?
|
3222
|
+
flatMap(this, selector, thisArg) :
|
3223
|
+
flatMap(this, function () { return selector; });
|
3327
3224
|
};
|
3328
3225
|
|
3329
3226
|
/**
|
@@ -3521,7 +3418,7 @@
|
|
3521
3418
|
|
3522
3419
|
args.push(handler);
|
3523
3420
|
func.apply(context, args);
|
3524
|
-
});
|
3421
|
+
}).publishLast().refCount();
|
3525
3422
|
};
|
3526
3423
|
};
|
3527
3424
|
|
@@ -3566,7 +3463,7 @@
|
|
3566
3463
|
|
3567
3464
|
args.push(handler);
|
3568
3465
|
func.apply(context, args);
|
3569
|
-
});
|
3466
|
+
}).publishLast().refCount();
|
3570
3467
|
};
|
3571
3468
|
};
|
3572
3469
|
|
@@ -3624,13 +3521,6 @@
|
|
3624
3521
|
}
|
3625
3522
|
|
3626
3523
|
function createListener (element, name, handler) {
|
3627
|
-
// Node.js specific
|
3628
|
-
if (element.addListener) {
|
3629
|
-
element.addListener(name, handler);
|
3630
|
-
return disposableCreate(function () {
|
3631
|
-
element.removeListener(name, handler);
|
3632
|
-
});
|
3633
|
-
}
|
3634
3524
|
// Standards compliant
|
3635
3525
|
if (element.addEventListener) {
|
3636
3526
|
element.addEventListener(name, handler, false);
|
@@ -3659,7 +3549,7 @@
|
|
3659
3549
|
var disposables = new CompositeDisposable();
|
3660
3550
|
|
3661
3551
|
// Asume NodeList
|
3662
|
-
if (
|
3552
|
+
if (Object.prototype.toString.call(el) === '[object NodeList]') {
|
3663
3553
|
for (var i = 0, len = el.length; i < len; i++) {
|
3664
3554
|
disposables.add(createEventListener(el.item(i), eventName, handler));
|
3665
3555
|
}
|
@@ -3670,6 +3560,11 @@
|
|
3670
3560
|
return disposables;
|
3671
3561
|
}
|
3672
3562
|
|
3563
|
+
/**
|
3564
|
+
* Configuration option to determine whether to use native events only
|
3565
|
+
*/
|
3566
|
+
Rx.config.useNativeEvents = false;
|
3567
|
+
|
3673
3568
|
// Check for Angular/jQuery/Zepto support
|
3674
3569
|
var jq =
|
3675
3570
|
!!root.angular && !!angular.element ? angular.element :
|
@@ -3678,6 +3573,10 @@
|
|
3678
3573
|
|
3679
3574
|
// Check for ember
|
3680
3575
|
var ember = !!root.Ember && typeof root.Ember.addListener === 'function';
|
3576
|
+
|
3577
|
+
// Check for Backbone.Marionette. Note if using AMD add Marionette as a dependency of rxjs
|
3578
|
+
// for proper loading order!
|
3579
|
+
var marionette = !!root.Backbone && !!root.Backbone.Marionette;
|
3681
3580
|
|
3682
3581
|
/**
|
3683
3582
|
* Creates an observable sequence by adding an event listener to the matching DOMElement or each item in the NodeList.
|
@@ -3691,18 +3590,35 @@
|
|
3691
3590
|
* @returns {Observable} An observable sequence of events from the specified element and the specified event.
|
3692
3591
|
*/
|
3693
3592
|
Observable.fromEvent = function (element, eventName, selector) {
|
3694
|
-
|
3695
|
-
|
3696
|
-
function (h) { Ember.addListener(element, eventName, h); },
|
3697
|
-
function (h) { Ember.removeListener(element, eventName, h); },
|
3698
|
-
selector);
|
3699
|
-
}
|
3700
|
-
if (jq) {
|
3701
|
-
var $elem = jq(element);
|
3593
|
+
// Node.js specific
|
3594
|
+
if (element.addListener) {
|
3702
3595
|
return fromEventPattern(
|
3703
|
-
function (h) {
|
3704
|
-
function (h) {
|
3596
|
+
function (h) { element.addListener(eventName, h); },
|
3597
|
+
function (h) { element.removeListener(eventName, h); },
|
3705
3598
|
selector);
|
3599
|
+
}
|
3600
|
+
|
3601
|
+
// Use only if non-native events are allowed
|
3602
|
+
if (!Rx.config.useNativeEvents) {
|
3603
|
+
if (marionette) {
|
3604
|
+
return fromEventPattern(
|
3605
|
+
function (h) { element.on(eventName, h); },
|
3606
|
+
function (h) { element.off(eventName, h); },
|
3607
|
+
selector);
|
3608
|
+
}
|
3609
|
+
if (ember) {
|
3610
|
+
return fromEventPattern(
|
3611
|
+
function (h) { Ember.addListener(element, eventName, h); },
|
3612
|
+
function (h) { Ember.removeListener(element, eventName, h); },
|
3613
|
+
selector);
|
3614
|
+
}
|
3615
|
+
if (jq) {
|
3616
|
+
var $elem = jq(element);
|
3617
|
+
return fromEventPattern(
|
3618
|
+
function (h) { $elem.on(eventName, h); },
|
3619
|
+
function (h) { $elem.off(eventName, h); },
|
3620
|
+
selector);
|
3621
|
+
}
|
3706
3622
|
}
|
3707
3623
|
return new AnonymousObservable(function (observer) {
|
3708
3624
|
return createEventListener(
|
@@ -3762,21 +3678,19 @@
|
|
3762
3678
|
* @returns {Observable} An Observable sequence which wraps the existing promise success and failure.
|
3763
3679
|
*/
|
3764
3680
|
var observableFromPromise = Observable.fromPromise = function (promise) {
|
3765
|
-
return
|
3681
|
+
return observableDefer(function () {
|
3682
|
+
var subject = new Rx.AsyncSubject();
|
3683
|
+
|
3766
3684
|
promise.then(
|
3767
3685
|
function (value) {
|
3768
|
-
|
3769
|
-
|
3770
|
-
|
3771
|
-
|
3772
|
-
|
3773
|
-
|
3686
|
+
if (!subject.isDisposed) {
|
3687
|
+
subject.onNext(value);
|
3688
|
+
subject.onCompleted();
|
3689
|
+
}
|
3690
|
+
},
|
3691
|
+
subject.onError.bind(subject));
|
3774
3692
|
|
3775
|
-
return
|
3776
|
-
if (promise && promise.abort) {
|
3777
|
-
promise.abort();
|
3778
|
-
}
|
3779
|
-
}
|
3693
|
+
return subject;
|
3780
3694
|
});
|
3781
3695
|
};
|
3782
3696
|
/*
|
@@ -3826,32 +3740,32 @@
|
|
3826
3740
|
return observableFromPromise(promise);
|
3827
3741
|
}
|
3828
3742
|
|
3829
|
-
|
3830
|
-
|
3831
|
-
|
3832
|
-
|
3833
|
-
|
3834
|
-
|
3835
|
-
|
3836
|
-
|
3837
|
-
|
3838
|
-
|
3839
|
-
|
3840
|
-
|
3841
|
-
|
3842
|
-
|
3843
|
-
|
3844
|
-
|
3845
|
-
|
3846
|
-
|
3847
|
-
|
3848
|
-
|
3849
|
-
|
3850
|
-
|
3851
|
-
|
3852
|
-
|
3853
|
-
|
3854
|
-
|
3743
|
+
/**
|
3744
|
+
* Multicasts the source sequence notifications through an instantiated subject into all uses of the sequence within a selector function. Each
|
3745
|
+
* subscription to the resulting sequence causes a separate multicast invocation, exposing the sequence resulting from the selector function's
|
3746
|
+
* invocation. For specializations with fixed subject types, see Publish, PublishLast, and Replay.
|
3747
|
+
*
|
3748
|
+
* @example
|
3749
|
+
* 1 - res = source.multicast(observable);
|
3750
|
+
* 2 - res = source.multicast(function () { return new Subject(); }, function (x) { return x; });
|
3751
|
+
*
|
3752
|
+
* @param {Function|Subject} subjectOrSubjectSelector
|
3753
|
+
* Factory function to create an intermediate subject through which the source sequence's elements will be multicast to the selector function.
|
3754
|
+
* Or:
|
3755
|
+
* Subject to push source elements into.
|
3756
|
+
*
|
3757
|
+
* @param {Function} [selector] Optional selector function which can use the multicasted source sequence subject to the policies enforced by the created subject. Specified only if <paramref name="subjectOrSubjectSelector" is a factory function.
|
3758
|
+
* @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
|
3759
|
+
*/
|
3760
|
+
observableProto.multicast = function (subjectOrSubjectSelector, selector) {
|
3761
|
+
var source = this;
|
3762
|
+
return typeof subjectOrSubjectSelector === 'function' ?
|
3763
|
+
new AnonymousObservable(function (observer) {
|
3764
|
+
var connectable = source.multicast(subjectOrSubjectSelector());
|
3765
|
+
return new CompositeDisposable(selector(connectable).subscribe(observer), connectable.connect());
|
3766
|
+
}) :
|
3767
|
+
new ConnectableObservable(source, subjectOrSubjectSelector);
|
3768
|
+
};
|
3855
3769
|
|
3856
3770
|
/**
|
3857
3771
|
* Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence.
|
@@ -3982,108 +3896,59 @@
|
|
3982
3896
|
return this.replay(null, bufferSize, window, scheduler).refCount();
|
3983
3897
|
};
|
3984
3898
|
|
3985
|
-
|
3986
|
-
|
3987
|
-
|
3988
|
-
|
3989
|
-
|
3990
|
-
|
3991
|
-
|
3992
|
-
|
3993
|
-
|
3994
|
-
|
3995
|
-
|
3996
|
-
|
3997
|
-
|
3998
|
-
|
3999
|
-
|
4000
|
-
|
4001
|
-
|
4002
|
-
|
4003
|
-
|
4004
|
-
|
4005
|
-
|
4006
|
-
|
4007
|
-
|
4008
|
-
|
4009
|
-
|
4010
|
-
|
4011
|
-
|
4012
|
-
|
4013
|
-
|
4014
|
-
|
4015
|
-
|
4016
|
-
|
4017
|
-
|
4018
|
-
|
4019
|
-
|
4020
|
-
|
4021
|
-
|
4022
|
-
|
4023
|
-
|
4024
|
-
|
4025
|
-
|
4026
|
-
* @memberOf ConnectableObservable
|
4027
|
-
*/
|
4028
|
-
ConnectableObservable.prototype.refCount = function () {
|
4029
|
-
var connectableSubscription = null, count = 0, source = this;
|
4030
|
-
return new AnonymousObservable(function (observer) {
|
4031
|
-
var shouldConnect, subscription;
|
4032
|
-
count++;
|
4033
|
-
shouldConnect = count === 1;
|
4034
|
-
subscription = source.subscribe(observer);
|
4035
|
-
if (shouldConnect) {
|
4036
|
-
connectableSubscription = source.connect();
|
4037
|
-
}
|
4038
|
-
return disposableCreate(function () {
|
4039
|
-
subscription.dispose();
|
4040
|
-
count--;
|
4041
|
-
if (count === 0) {
|
4042
|
-
connectableSubscription.dispose();
|
4043
|
-
}
|
4044
|
-
});
|
4045
|
-
});
|
4046
|
-
};
|
4047
|
-
|
4048
|
-
return ConnectableObservable;
|
4049
|
-
}(Observable));
|
4050
|
-
|
4051
|
-
function observableTimerTimeSpan(dueTime, scheduler) {
|
4052
|
-
var d = normalizeTime(dueTime);
|
4053
|
-
return new AnonymousObservable(function (observer) {
|
4054
|
-
return scheduler.scheduleWithRelative(d, function () {
|
4055
|
-
observer.onNext(0);
|
4056
|
-
observer.onCompleted();
|
4057
|
-
});
|
4058
|
-
});
|
4059
|
-
}
|
4060
|
-
|
4061
|
-
function observableTimerTimeSpanAndPeriod(dueTime, period, scheduler) {
|
4062
|
-
if (dueTime === period) {
|
4063
|
-
return new AnonymousObservable(function (observer) {
|
4064
|
-
return scheduler.schedulePeriodicWithState(0, period, function (count) {
|
4065
|
-
observer.onNext(count);
|
4066
|
-
return count + 1;
|
4067
|
-
});
|
3899
|
+
var ConnectableObservable = Rx.ConnectableObservable = (function (__super__) {
|
3900
|
+
inherits(ConnectableObservable, __super__);
|
3901
|
+
|
3902
|
+
function ConnectableObservable(source, subject) {
|
3903
|
+
var hasSubscription = false,
|
3904
|
+
subscription,
|
3905
|
+
sourceObservable = source.asObservable();
|
3906
|
+
|
3907
|
+
this.connect = function () {
|
3908
|
+
if (!hasSubscription) {
|
3909
|
+
hasSubscription = true;
|
3910
|
+
subscription = new CompositeDisposable(sourceObservable.subscribe(subject), disposableCreate(function () {
|
3911
|
+
hasSubscription = false;
|
3912
|
+
}));
|
3913
|
+
}
|
3914
|
+
return subscription;
|
3915
|
+
};
|
3916
|
+
|
3917
|
+
__super__.call(this, subject.subscribe.bind(subject));
|
3918
|
+
}
|
3919
|
+
|
3920
|
+
ConnectableObservable.prototype.refCount = function () {
|
3921
|
+
var connectableSubscription, count = 0, source = this;
|
3922
|
+
return new AnonymousObservable(function (observer) {
|
3923
|
+
var shouldConnect = ++count === 1,
|
3924
|
+
subscription = source.subscribe(observer);
|
3925
|
+
shouldConnect && (connectableSubscription = source.connect());
|
3926
|
+
return function () {
|
3927
|
+
subscription.dispose();
|
3928
|
+
--count === 0 && connectableSubscription.dispose();
|
3929
|
+
};
|
3930
|
+
});
|
3931
|
+
};
|
3932
|
+
|
3933
|
+
return ConnectableObservable;
|
3934
|
+
}(Observable));
|
3935
|
+
function observableTimerDate(dueTime, scheduler) {
|
3936
|
+
return new AnonymousObservable(function (observer) {
|
3937
|
+
return scheduler.scheduleWithAbsolute(dueTime, function () {
|
3938
|
+
observer.onNext(0);
|
3939
|
+
observer.onCompleted();
|
4068
3940
|
});
|
4069
|
-
}
|
4070
|
-
return observableDefer(function () {
|
4071
|
-
return observableTimerDateAndPeriod(scheduler.now() + dueTime, period, scheduler);
|
4072
3941
|
});
|
4073
3942
|
}
|
4074
3943
|
|
4075
3944
|
function observableTimerDateAndPeriod(dueTime, period, scheduler) {
|
4076
|
-
var p = normalizeTime(period);
|
4077
3945
|
return new AnonymousObservable(function (observer) {
|
4078
|
-
var count = 0, d = dueTime;
|
3946
|
+
var count = 0, d = dueTime, p = normalizeTime(period);
|
4079
3947
|
return scheduler.scheduleRecursiveWithAbsolute(d, function (self) {
|
4080
|
-
var now;
|
4081
3948
|
if (p > 0) {
|
4082
|
-
now = scheduler.now();
|
3949
|
+
var now = scheduler.now();
|
4083
3950
|
d = d + p;
|
4084
|
-
|
4085
|
-
d = now + p;
|
4086
|
-
}
|
3951
|
+
d <= now && (d = now + p);
|
4087
3952
|
}
|
4088
3953
|
observer.onNext(count++);
|
4089
3954
|
self(d);
|
@@ -4091,6 +3956,28 @@
|
|
4091
3956
|
});
|
4092
3957
|
}
|
4093
3958
|
|
3959
|
+
function observableTimerTimeSpan(dueTime, scheduler) {
|
3960
|
+
return new AnonymousObservable(function (observer) {
|
3961
|
+
return scheduler.scheduleWithRelative(normalizeTime(dueTime), function () {
|
3962
|
+
observer.onNext(0);
|
3963
|
+
observer.onCompleted();
|
3964
|
+
});
|
3965
|
+
});
|
3966
|
+
}
|
3967
|
+
|
3968
|
+
function observableTimerTimeSpanAndPeriod(dueTime, period, scheduler) {
|
3969
|
+
return dueTime === period ?
|
3970
|
+
new AnonymousObservable(function (observer) {
|
3971
|
+
return scheduler.schedulePeriodicWithState(0, period, function (count) {
|
3972
|
+
observer.onNext(count);
|
3973
|
+
return count + 1;
|
3974
|
+
});
|
3975
|
+
}) :
|
3976
|
+
observableDefer(function () {
|
3977
|
+
return observableTimerDateAndPeriod(scheduler.now() + dueTime, period, scheduler);
|
3978
|
+
});
|
3979
|
+
}
|
3980
|
+
|
4094
3981
|
/**
|
4095
3982
|
* Returns an observable sequence that produces a value after each period.
|
4096
3983
|
*
|
@@ -4110,12 +3997,17 @@
|
|
4110
3997
|
* Returns an observable sequence that produces a value after dueTime has elapsed and then after each period.
|
4111
3998
|
*
|
4112
3999
|
* @example
|
4113
|
-
*
|
4114
|
-
*
|
4115
|
-
*
|
4116
|
-
*
|
4000
|
+
* 1 - res = Rx.Observable.timer(new Date());
|
4001
|
+
* 2 - res = Rx.Observable.timer(new Date(), 1000);
|
4002
|
+
* 3 - res = Rx.Observable.timer(new Date(), Rx.Scheduler.timeout);
|
4003
|
+
* 4 - res = Rx.Observable.timer(new Date(), 1000, Rx.Scheduler.timeout);
|
4117
4004
|
*
|
4118
|
-
*
|
4005
|
+
* 5 - res = Rx.Observable.timer(5000);
|
4006
|
+
* 6 - res = Rx.Observable.timer(5000, 1000);
|
4007
|
+
* 7 - res = Rx.Observable.timer(5000, Rx.Scheduler.timeout);
|
4008
|
+
* 8 - res = Rx.Observable.timer(5000, 1000, Rx.Scheduler.timeout);
|
4009
|
+
*
|
4010
|
+
* @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) at which to produce the first value.
|
4119
4011
|
* @param {Mixed} [periodOrScheduler] Period to produce subsequent values (specified as an integer denoting milliseconds), or the scheduler to run the timer on. If not specified, the resulting timer is not recurring.
|
4120
4012
|
* @param {Scheduler} [scheduler] Scheduler to run the timer on. If not specified, the timeout scheduler is used.
|
4121
4013
|
* @returns {Observable} An observable sequence that produces a value after due time has elapsed and then each period.
|
@@ -4123,30 +4015,24 @@
|
|
4123
4015
|
var observableTimer = Observable.timer = function (dueTime, periodOrScheduler, scheduler) {
|
4124
4016
|
var period;
|
4125
4017
|
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
4126
|
-
if (typeof periodOrScheduler === 'number') {
|
4018
|
+
if (periodOrScheduler !== undefined && typeof periodOrScheduler === 'number') {
|
4127
4019
|
period = periodOrScheduler;
|
4128
|
-
} else if (
|
4020
|
+
} else if (periodOrScheduler !== undefined && typeof periodOrScheduler === 'object') {
|
4129
4021
|
scheduler = periodOrScheduler;
|
4130
4022
|
}
|
4131
|
-
|
4023
|
+
if (dueTime instanceof Date && period === undefined) {
|
4024
|
+
return observableTimerDate(dueTime.getTime(), scheduler);
|
4025
|
+
}
|
4026
|
+
if (dueTime instanceof Date && period !== undefined) {
|
4027
|
+
period = periodOrScheduler;
|
4028
|
+
return observableTimerDateAndPeriod(dueTime.getTime(), period, scheduler);
|
4029
|
+
}
|
4030
|
+
return period === undefined ?
|
4132
4031
|
observableTimerTimeSpan(dueTime, scheduler) :
|
4133
4032
|
observableTimerTimeSpanAndPeriod(dueTime, period, scheduler);
|
4134
4033
|
};
|
4135
4034
|
|
4136
|
-
|
4137
|
-
* Time shifts the observable sequence by dueTime. The relative time intervals between the values are preserved.
|
4138
|
-
*
|
4139
|
-
* @example
|
4140
|
-
* var res = Rx.Observable.delay(5000);
|
4141
|
-
* var res = Rx.Observable.delay(5000, 1000, Rx.Scheduler.timeout);
|
4142
|
-
* @memberOf Observable#
|
4143
|
-
* @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) by which to shift the observable sequence.
|
4144
|
-
* @param {Scheduler} [scheduler] Scheduler to run the delay timers on. If not specified, the timeout scheduler is used.
|
4145
|
-
* @returns {Observable} Time-shifted sequence.
|
4146
|
-
*/
|
4147
|
-
observableProto.delay = function (dueTime, scheduler) {
|
4148
|
-
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
4149
|
-
var source = this;
|
4035
|
+
function observableDelayTimeSpan(source, dueTime, scheduler) {
|
4150
4036
|
return new AnonymousObservable(function (observer) {
|
4151
4037
|
var active = false,
|
4152
4038
|
cancelable = new SerialDisposable(),
|
@@ -4174,9 +4060,9 @@
|
|
4174
4060
|
cancelable.setDisposable(d);
|
4175
4061
|
d.setDisposable(scheduler.scheduleRecursiveWithRelative(dueTime, function (self) {
|
4176
4062
|
var e, recurseDueTime, result, shouldRecurse;
|
4177
|
-
|
4178
|
-
|
4179
|
-
|
4063
|
+
if (exception !== null) {
|
4064
|
+
return;
|
4065
|
+
}
|
4180
4066
|
running = true;
|
4181
4067
|
do {
|
4182
4068
|
result = null;
|
@@ -4187,7 +4073,6 @@
|
|
4187
4073
|
result.accept(observer);
|
4188
4074
|
}
|
4189
4075
|
} while (result !== null);
|
4190
|
-
|
4191
4076
|
shouldRecurse = false;
|
4192
4077
|
recurseDueTime = 0;
|
4193
4078
|
if (q.length > 0) {
|
@@ -4209,6 +4094,33 @@
|
|
4209
4094
|
});
|
4210
4095
|
return new CompositeDisposable(subscription, cancelable);
|
4211
4096
|
});
|
4097
|
+
}
|
4098
|
+
|
4099
|
+
function observableDelayDate(source, dueTime, scheduler) {
|
4100
|
+
return observableDefer(function () {
|
4101
|
+
return observableDelayTimeSpan(source, dueTime - scheduler.now(), scheduler);
|
4102
|
+
});
|
4103
|
+
}
|
4104
|
+
|
4105
|
+
/**
|
4106
|
+
* Time shifts the observable sequence by dueTime. The relative time intervals between the values are preserved.
|
4107
|
+
*
|
4108
|
+
* @example
|
4109
|
+
* 1 - res = Rx.Observable.delay(new Date());
|
4110
|
+
* 2 - res = Rx.Observable.delay(new Date(), Rx.Scheduler.timeout);
|
4111
|
+
*
|
4112
|
+
* 3 - res = Rx.Observable.delay(5000);
|
4113
|
+
* 4 - res = Rx.Observable.delay(5000, 1000, Rx.Scheduler.timeout);
|
4114
|
+
* @memberOf Observable#
|
4115
|
+
* @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) by which to shift the observable sequence.
|
4116
|
+
* @param {Scheduler} [scheduler] Scheduler to run the delay timers on. If not specified, the timeout scheduler is used.
|
4117
|
+
* @returns {Observable} Time-shifted sequence.
|
4118
|
+
*/
|
4119
|
+
observableProto.delay = function (dueTime, scheduler) {
|
4120
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
4121
|
+
return dueTime instanceof Date ?
|
4122
|
+
observableDelayDate(this, dueTime.getTime(), scheduler) :
|
4123
|
+
observableDelayTimeSpan(this, dueTime, scheduler);
|
4212
4124
|
};
|
4213
4125
|
|
4214
4126
|
/**
|
@@ -4227,29 +4139,6 @@
|
|
4227
4139
|
return this.throttleWithSelector(function () { return observableTimer(dueTime, scheduler); })
|
4228
4140
|
};
|
4229
4141
|
|
4230
|
-
/**
|
4231
|
-
* Records the time interval between consecutive values in an observable sequence.
|
4232
|
-
*
|
4233
|
-
* @example
|
4234
|
-
* 1 - res = source.timeInterval();
|
4235
|
-
* 2 - res = source.timeInterval(Rx.Scheduler.timeout);
|
4236
|
-
*
|
4237
|
-
* @param [scheduler] Scheduler used to compute time intervals. If not specified, the timeout scheduler is used.
|
4238
|
-
* @returns {Observable} An observable sequence with time interval information on values.
|
4239
|
-
*/
|
4240
|
-
observableProto.timeInterval = function (scheduler) {
|
4241
|
-
var source = this;
|
4242
|
-
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
4243
|
-
return observableDefer(function () {
|
4244
|
-
var last = scheduler.now();
|
4245
|
-
return source.map(function (x) {
|
4246
|
-
var now = scheduler.now(), span = now - last;
|
4247
|
-
last = now;
|
4248
|
-
return { value: x, interval: span };
|
4249
|
-
});
|
4250
|
-
});
|
4251
|
-
};
|
4252
|
-
|
4253
4142
|
/**
|
4254
4143
|
* Records the timestamp for each value in an observable sequence.
|
4255
4144
|
*
|
@@ -4377,60 +4266,6 @@
|
|
4377
4266
|
});
|
4378
4267
|
};
|
4379
4268
|
|
4380
|
-
/**
|
4381
|
-
* Generates an observable sequence by iterating a state from an initial state until the condition fails.
|
4382
|
-
*
|
4383
|
-
* @example
|
4384
|
-
* res = source.generateWithRelativeTime(0,
|
4385
|
-
* function (x) { return return true; },
|
4386
|
-
* function (x) { return x + 1; },
|
4387
|
-
* function (x) { return x; },
|
4388
|
-
* function (x) { return 500; }
|
4389
|
-
* );
|
4390
|
-
*
|
4391
|
-
* @param {Mixed} initialState Initial state.
|
4392
|
-
* @param {Function} condition Condition to terminate generation (upon returning false).
|
4393
|
-
* @param {Function} iterate Iteration step function.
|
4394
|
-
* @param {Function} resultSelector Selector function for results produced in the sequence.
|
4395
|
-
* @param {Function} timeSelector Time selector function to control the speed of values being produced each iteration, returning integer values denoting milliseconds.
|
4396
|
-
* @param {Scheduler} [scheduler] Scheduler on which to run the generator loop. If not specified, the timeout scheduler is used.
|
4397
|
-
* @returns {Observable} The generated sequence.
|
4398
|
-
*/
|
4399
|
-
Observable.generateWithRelativeTime = function (initialState, condition, iterate, resultSelector, timeSelector, scheduler) {
|
4400
|
-
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
4401
|
-
return new AnonymousObservable(function (observer) {
|
4402
|
-
var first = true,
|
4403
|
-
hasResult = false,
|
4404
|
-
result,
|
4405
|
-
state = initialState,
|
4406
|
-
time;
|
4407
|
-
return scheduler.scheduleRecursiveWithRelative(0, function (self) {
|
4408
|
-
hasResult && observer.onNext(result);
|
4409
|
-
|
4410
|
-
try {
|
4411
|
-
if (first) {
|
4412
|
-
first = false;
|
4413
|
-
} else {
|
4414
|
-
state = iterate(state);
|
4415
|
-
}
|
4416
|
-
hasResult = condition(state);
|
4417
|
-
if (hasResult) {
|
4418
|
-
result = resultSelector(state);
|
4419
|
-
time = timeSelector(state);
|
4420
|
-
}
|
4421
|
-
} catch (e) {
|
4422
|
-
observer.onError(e);
|
4423
|
-
return;
|
4424
|
-
}
|
4425
|
-
if (hasResult) {
|
4426
|
-
self(time);
|
4427
|
-
} else {
|
4428
|
-
observer.onCompleted();
|
4429
|
-
}
|
4430
|
-
});
|
4431
|
-
});
|
4432
|
-
};
|
4433
|
-
|
4434
4269
|
/**
|
4435
4270
|
* Time shifts the observable sequence by delaying the subscription.
|
4436
4271
|
*
|
@@ -4681,38 +4516,20 @@
|
|
4681
4516
|
});
|
4682
4517
|
};
|
4683
4518
|
|
4684
|
-
/**
|
4685
|
-
* Returns elements within the specified duration from the end of the observable source sequence, using the specified schedulers to run timers and to drain the collected elements.
|
4686
|
-
*
|
4687
|
-
* @example
|
4688
|
-
* 1 - res = source.takeLastWithTime(5000, [optional timer scheduler], [optional loop scheduler]);
|
4689
|
-
* @description
|
4690
|
-
* This operator accumulates a queue with a length enough to store elements received during the initial duration window.
|
4691
|
-
* As more elements are received, elements older than the specified duration are taken from the queue and produced on the
|
4692
|
-
* result sequence. This causes elements to be delayed with duration.
|
4693
|
-
* @param {Number} duration Duration for taking elements from the end of the sequence.
|
4694
|
-
* @param {Scheduler} [timerScheduler] Scheduler to run the timer on. If not specified, defaults to Rx.Scheduler.timeout.
|
4695
|
-
* @param {Scheduler} [loopScheduler] Scheduler to drain the collected elements. If not specified, defaults to Rx.Scheduler.immediate.
|
4696
|
-
* @returns {Observable} An observable sequence with the elements taken during the specified duration from the end of the source sequence.
|
4697
|
-
*/
|
4698
|
-
observableProto.takeLastWithTime = function (duration, timerScheduler, loopScheduler) {
|
4699
|
-
return this.takeLastBufferWithTime(duration, timerScheduler).selectMany(function (xs) { return observableFromArray(xs, loopScheduler); });
|
4700
|
-
};
|
4701
|
-
|
4702
4519
|
/**
|
4703
|
-
* Returns
|
4520
|
+
* Returns elements within the specified duration from the end of the observable source sequence, using the specified schedulers to run timers and to drain the collected elements.
|
4704
4521
|
*
|
4705
4522
|
* @example
|
4706
|
-
* 1 - res = source.
|
4523
|
+
* 1 - res = source.takeLastWithTime(5000, [optional timer scheduler], [optional loop scheduler]);
|
4707
4524
|
* @description
|
4708
4525
|
* This operator accumulates a queue with a length enough to store elements received during the initial duration window.
|
4709
4526
|
* As more elements are received, elements older than the specified duration are taken from the queue and produced on the
|
4710
|
-
* result sequence. This causes elements to be delayed with duration.
|
4527
|
+
* result sequence. This causes elements to be delayed with duration.
|
4711
4528
|
* @param {Number} duration Duration for taking elements from the end of the sequence.
|
4712
|
-
* @param {Scheduler} scheduler
|
4713
|
-
* @returns {Observable} An observable sequence
|
4529
|
+
* @param {Scheduler} [scheduler] Scheduler to run the timer on. If not specified, defaults to Rx.Scheduler.timeout.
|
4530
|
+
* @returns {Observable} An observable sequence with the elements taken during the specified duration from the end of the source sequence.
|
4714
4531
|
*/
|
4715
|
-
observableProto.
|
4532
|
+
observableProto.takeLastWithTime = function (duration, scheduler) {
|
4716
4533
|
var source = this;
|
4717
4534
|
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
4718
4535
|
return new AnonymousObservable(function (observer) {
|
@@ -4725,18 +4542,17 @@
|
|
4725
4542
|
q.shift();
|
4726
4543
|
}
|
4727
4544
|
}, observer.onError.bind(observer), function () {
|
4728
|
-
var now = scheduler.now()
|
4545
|
+
var now = scheduler.now();
|
4729
4546
|
while (q.length > 0) {
|
4730
4547
|
var next = q.shift();
|
4731
4548
|
if (now - next.interval <= duration) {
|
4732
|
-
|
4549
|
+
observer.onNext(next.value);
|
4733
4550
|
}
|
4734
4551
|
}
|
4735
4552
|
|
4736
|
-
observer.onNext(res);
|
4737
4553
|
observer.onCompleted();
|
4738
4554
|
});
|
4739
|
-
});
|
4555
|
+
});
|
4740
4556
|
};
|
4741
4557
|
|
4742
4558
|
/**
|
@@ -4787,56 +4603,6 @@
|
|
4787
4603
|
});
|
4788
4604
|
};
|
4789
4605
|
|
4790
|
-
/**
|
4791
|
-
* Skips elements from the observable source sequence until the specified start time, using the specified scheduler to run timers.
|
4792
|
-
* Errors produced by the source sequence are always forwarded to the result sequence, even if the error occurs before the start time.
|
4793
|
-
*
|
4794
|
-
* @examples
|
4795
|
-
* 1 - res = source.skipUntilWithTime(new Date(), [optional scheduler]);
|
4796
|
-
* 2 - res = source.skipUntilWithTime(5000, [optional scheduler]);
|
4797
|
-
* @param startTime Time to start taking elements from the source sequence. If this value is less than or equal to Date(), no elements will be skipped.
|
4798
|
-
* @param scheduler Scheduler to run the timer on. If not specified, defaults to Rx.Scheduler.timeout.
|
4799
|
-
* @returns {Observable} An observable sequence with the elements skipped until the specified start time.
|
4800
|
-
*/
|
4801
|
-
observableProto.skipUntilWithTime = function (startTime, scheduler) {
|
4802
|
-
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
4803
|
-
var source = this, schedulerMethod = startTime instanceof Date ?
|
4804
|
-
'scheduleWithAbsolute' :
|
4805
|
-
'scheduleWithRelative';
|
4806
|
-
return new AnonymousObservable(function (observer) {
|
4807
|
-
var open = false;
|
4808
|
-
|
4809
|
-
return new CompositeDisposable(
|
4810
|
-
scheduler[schedulerMethod](startTime, function () { open = true; }),
|
4811
|
-
source.subscribe(
|
4812
|
-
function (x) { open && observer.onNext(x); },
|
4813
|
-
observer.onError.bind(observer),
|
4814
|
-
observer.onCompleted.bind(observer)));
|
4815
|
-
});
|
4816
|
-
};
|
4817
|
-
|
4818
|
-
/**
|
4819
|
-
* Takes elements for the specified duration until the specified end time, using the specified scheduler to run timers.
|
4820
|
-
*
|
4821
|
-
* @example
|
4822
|
-
* 1 - res = source.takeUntilWithTime(new Date(), [optional scheduler]);
|
4823
|
-
* 2 - res = source.takeUntilWithTime(5000, [optional scheduler]);
|
4824
|
-
* @param {Number | Date} endTime Time to stop taking elements from the source sequence. If this value is less than or equal to new Date(), the result stream will complete immediately.
|
4825
|
-
* @param {Scheduler} scheduler Scheduler to run the timer on.
|
4826
|
-
* @returns {Observable} An observable sequence with the elements taken until the specified end time.
|
4827
|
-
*/
|
4828
|
-
observableProto.takeUntilWithTime = function (endTime, scheduler) {
|
4829
|
-
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
4830
|
-
var source = this, schedulerMethod = endTime instanceof Date ?
|
4831
|
-
'scheduleWithAbsolute' :
|
4832
|
-
'scheduleWithRelative';
|
4833
|
-
return new AnonymousObservable(function (observer) {
|
4834
|
-
return new CompositeDisposable(scheduler[schedulerMethod](endTime, function () {
|
4835
|
-
observer.onCompleted();
|
4836
|
-
}), source.subscribe(observer));
|
4837
|
-
});
|
4838
|
-
};
|
4839
|
-
|
4840
4606
|
var PausableObservable = (function (_super) {
|
4841
4607
|
|
4842
4608
|
inherits(PausableObservable, _super);
|
@@ -4846,7 +4612,7 @@
|
|
4846
4612
|
subscription = conn.subscribe(observer),
|
4847
4613
|
connection = disposableEmpty;
|
4848
4614
|
|
4849
|
-
var pausable = this.
|
4615
|
+
var pausable = this.pauser.distinctUntilChanged().subscribe(function (b) {
|
4850
4616
|
if (b) {
|
4851
4617
|
connection = conn.connect();
|
4852
4618
|
} else {
|
@@ -4858,27 +4624,25 @@
|
|
4858
4624
|
return new CompositeDisposable(subscription, connection, pausable);
|
4859
4625
|
}
|
4860
4626
|
|
4861
|
-
function PausableObservable(source,
|
4627
|
+
function PausableObservable(source, pauser) {
|
4862
4628
|
this.source = source;
|
4863
|
-
this.
|
4864
|
-
|
4629
|
+
this.controller = new Subject();
|
4630
|
+
|
4631
|
+
if (pauser && pauser.subscribe) {
|
4632
|
+
this.pauser = this.controller.merge(pauser);
|
4633
|
+
} else {
|
4634
|
+
this.pauser = this.controller;
|
4635
|
+
}
|
4636
|
+
|
4865
4637
|
_super.call(this, subscribe);
|
4866
4638
|
}
|
4867
4639
|
|
4868
4640
|
PausableObservable.prototype.pause = function () {
|
4869
|
-
|
4870
|
-
return;
|
4871
|
-
}
|
4872
|
-
this.isPaused = true;
|
4873
|
-
this.subject.onNext(false);
|
4641
|
+
this.controller.onNext(false);
|
4874
4642
|
};
|
4875
4643
|
|
4876
4644
|
PausableObservable.prototype.resume = function () {
|
4877
|
-
|
4878
|
-
return;
|
4879
|
-
}
|
4880
|
-
this.isPaused = false;
|
4881
|
-
this.subject.onNext(true);
|
4645
|
+
this.controller.onNext(true);
|
4882
4646
|
};
|
4883
4647
|
|
4884
4648
|
return PausableObservable;
|
@@ -4945,30 +4709,33 @@
|
|
4945
4709
|
inherits(PausableBufferedObservable, _super);
|
4946
4710
|
|
4947
4711
|
function subscribe(observer) {
|
4948
|
-
var q = [],
|
4712
|
+
var q = [], previousShouldFire;
|
4949
4713
|
|
4950
4714
|
var subscription =
|
4951
4715
|
combineLatestSource(
|
4952
4716
|
this.source,
|
4953
|
-
this.
|
4717
|
+
this.pauser.distinctUntilChanged().startWith(false),
|
4954
4718
|
function (data, shouldFire) {
|
4955
4719
|
return { data: data, shouldFire: shouldFire };
|
4956
4720
|
})
|
4957
4721
|
.subscribe(
|
4958
4722
|
function (results) {
|
4959
|
-
if (results.shouldFire
|
4960
|
-
|
4961
|
-
|
4962
|
-
|
4963
|
-
|
4964
|
-
|
4723
|
+
if (previousShouldFire !== undefined && results.shouldFire != previousShouldFire) {
|
4724
|
+
// change in shouldFire
|
4725
|
+
if (results.shouldFire) {
|
4726
|
+
while (q.length > 0) {
|
4727
|
+
observer.onNext(q.shift());
|
4728
|
+
}
|
4729
|
+
}
|
4730
|
+
} else {
|
4731
|
+
// new data
|
4732
|
+
if (results.shouldFire) {
|
4733
|
+
observer.onNext(results.data);
|
4734
|
+
} else {
|
4735
|
+
q.push(results.data);
|
4965
4736
|
}
|
4966
|
-
previous = true;
|
4967
|
-
} else if (!results.shouldFire && !previous) {
|
4968
|
-
q.push(results.data);
|
4969
|
-
} else if (!results.shouldFire && previous) {
|
4970
|
-
previous = false;
|
4971
4737
|
}
|
4738
|
+
previousShouldFire = results.shouldFire;
|
4972
4739
|
|
4973
4740
|
},
|
4974
4741
|
function (err) {
|
@@ -4986,33 +4753,28 @@
|
|
4986
4753
|
observer.onCompleted();
|
4987
4754
|
}
|
4988
4755
|
);
|
4989
|
-
|
4990
|
-
this.subject.onNext(false);
|
4991
|
-
|
4992
4756
|
return subscription;
|
4993
4757
|
}
|
4994
4758
|
|
4995
|
-
function PausableBufferedObservable(source,
|
4759
|
+
function PausableBufferedObservable(source, pauser) {
|
4996
4760
|
this.source = source;
|
4997
|
-
this.
|
4998
|
-
|
4761
|
+
this.controller = new Subject();
|
4762
|
+
|
4763
|
+
if (pauser && pauser.subscribe) {
|
4764
|
+
this.pauser = this.controller.merge(pauser);
|
4765
|
+
} else {
|
4766
|
+
this.pauser = this.controller;
|
4767
|
+
}
|
4768
|
+
|
4999
4769
|
_super.call(this, subscribe);
|
5000
4770
|
}
|
5001
4771
|
|
5002
4772
|
PausableBufferedObservable.prototype.pause = function () {
|
5003
|
-
|
5004
|
-
return;
|
5005
|
-
}
|
5006
|
-
this.isPaused = true;
|
5007
|
-
this.subject.onNext(false);
|
4773
|
+
this.controller.onNext(false);
|
5008
4774
|
};
|
5009
4775
|
|
5010
4776
|
PausableBufferedObservable.prototype.resume = function () {
|
5011
|
-
|
5012
|
-
return;
|
5013
|
-
}
|
5014
|
-
this.isPaused = false;
|
5015
|
-
this.subject.onNext(true);
|
4777
|
+
this.controller.onNext(true);
|
5016
4778
|
};
|
5017
4779
|
|
5018
4780
|
return PausableBufferedObservable;
|
@@ -5193,50 +4955,6 @@
|
|
5193
4955
|
|
5194
4956
|
return ControlledSubject;
|
5195
4957
|
}(Observable));
|
5196
|
-
/**
|
5197
|
-
* Returns a new observable that triggers on the second and subsequent triggerings of the input observable.
|
5198
|
-
* The Nth triggering of the input observable passes the arguments from the N-1th and Nth triggering as a pair.
|
5199
|
-
* The argument passed to the N-1th triggering is held in hidden internal state until the Nth triggering occurs.
|
5200
|
-
* @returns {Observable} An observable that triggers on successive pairs of observations from the input observable as an array.
|
5201
|
-
*/
|
5202
|
-
observableProto.pairwise = function () {
|
5203
|
-
var source = this;
|
5204
|
-
return new AnonymousObservable(function (observer) {
|
5205
|
-
var previous, hasPrevious = false;
|
5206
|
-
return source.subscribe(
|
5207
|
-
function (x) {
|
5208
|
-
if (hasPrevious) {
|
5209
|
-
observer.onNext([previous, x]);
|
5210
|
-
} else {
|
5211
|
-
hasPrevious = true;
|
5212
|
-
}
|
5213
|
-
previous = x;
|
5214
|
-
},
|
5215
|
-
observer.onError.bind(observer),
|
5216
|
-
observer.onCompleted.bind(observer));
|
5217
|
-
});
|
5218
|
-
};
|
5219
|
-
/**
|
5220
|
-
* Returns two observables which partition the observations of the source by the given function.
|
5221
|
-
* The first will trigger observations for those values for which the predicate returns true.
|
5222
|
-
* The second will trigger observations for those values where the predicate returns false.
|
5223
|
-
* The predicate is executed once for each subscribed observer.
|
5224
|
-
* Both also propagate all error observations arising from the source and each completes
|
5225
|
-
* when the source completes.
|
5226
|
-
* @param {Function} predicate
|
5227
|
-
* The function to determine which output Observable will trigger a particular observation.
|
5228
|
-
* @returns {Array}
|
5229
|
-
* An array of observables. The first triggers when the predicate returns true,
|
5230
|
-
* and the second triggers when the predicate returns false.
|
5231
|
-
*/
|
5232
|
-
observableProto.partition = function(predicate, thisArg) {
|
5233
|
-
var published = this.publish().refCount();
|
5234
|
-
return [
|
5235
|
-
published.filter(predicate, thisArg),
|
5236
|
-
published.filter(function (x, i, o) { return !predicate.call(thisArg, x, i, o); })
|
5237
|
-
];
|
5238
|
-
};
|
5239
|
-
|
5240
4958
|
/*
|
5241
4959
|
* Performs a exclusive waiting for the first to finish before subscribing to another observable.
|
5242
4960
|
* Observables that come in between subscriptions will be dropped on the floor.
|
@@ -5352,13 +5070,11 @@
|
|
5352
5070
|
|
5353
5071
|
// Fix subscriber to check for undefined or function returned to decorate as Disposable
|
5354
5072
|
function fixSubscriber(subscriber) {
|
5355
|
-
if (typeof subscriber === '
|
5356
|
-
subscriber = disposableEmpty;
|
5357
|
-
} else if (typeof subscriber === 'function') {
|
5358
|
-
subscriber = disposableCreate(subscriber);
|
5359
|
-
}
|
5073
|
+
if (subscriber && typeof subscriber.dispose === 'function') { return subscriber; }
|
5360
5074
|
|
5361
|
-
return subscriber
|
5075
|
+
return typeof subscriber === 'function' ?
|
5076
|
+
disposableCreate(subscriber) :
|
5077
|
+
disposableEmpty;
|
5362
5078
|
}
|
5363
5079
|
|
5364
5080
|
function AnonymousObservable(subscribe) {
|
@@ -5455,23 +5171,23 @@
|
|
5455
5171
|
return AutoDetachObserver;
|
5456
5172
|
}(AbstractObserver));
|
5457
5173
|
|
5458
|
-
/** @private */
|
5459
|
-
var InnerSubscription = function (subject, observer) {
|
5460
|
-
this.subject = subject;
|
5461
|
-
this.observer = observer;
|
5462
|
-
};
|
5463
|
-
|
5464
|
-
/**
|
5465
|
-
* @private
|
5466
|
-
* @memberOf InnerSubscription
|
5467
|
-
*/
|
5468
|
-
InnerSubscription.prototype.dispose = function () {
|
5469
|
-
if (!this.subject.isDisposed && this.observer !== null) {
|
5470
|
-
var idx = this.subject.observers.indexOf(this.observer);
|
5471
|
-
this.subject.observers.splice(idx, 1);
|
5472
|
-
this.observer = null;
|
5473
|
-
}
|
5474
|
-
};
|
5174
|
+
/** @private */
|
5175
|
+
var InnerSubscription = function (subject, observer) {
|
5176
|
+
this.subject = subject;
|
5177
|
+
this.observer = observer;
|
5178
|
+
};
|
5179
|
+
|
5180
|
+
/**
|
5181
|
+
* @private
|
5182
|
+
* @memberOf InnerSubscription
|
5183
|
+
*/
|
5184
|
+
InnerSubscription.prototype.dispose = function () {
|
5185
|
+
if (!this.subject.isDisposed && this.observer !== null) {
|
5186
|
+
var idx = this.subject.observers.indexOf(this.observer);
|
5187
|
+
this.subject.observers.splice(idx, 1);
|
5188
|
+
this.observer = null;
|
5189
|
+
}
|
5190
|
+
};
|
5475
5191
|
|
5476
5192
|
/**
|
5477
5193
|
* Represents an object that is both an observable sequence as well as an observer.
|
@@ -5580,176 +5296,154 @@
|
|
5580
5296
|
return Subject;
|
5581
5297
|
}(Observable));
|
5582
5298
|
|
5583
|
-
|
5584
|
-
|
5585
|
-
|
5586
|
-
|
5587
|
-
|
5588
|
-
|
5589
|
-
function subscribe(observer) {
|
5590
|
-
checkDisposed.call(this);
|
5591
|
-
|
5592
|
-
if (!this.isStopped) {
|
5593
|
-
this.observers.push(observer);
|
5594
|
-
return new InnerSubscription(this, observer);
|
5595
|
-
}
|
5596
|
-
|
5597
|
-
var ex = this.exception,
|
5598
|
-
hv = this.hasValue,
|
5599
|
-
v = this.value;
|
5600
|
-
|
5601
|
-
if (ex) {
|
5602
|
-
observer.onError(ex);
|
5603
|
-
} else if (hv) {
|
5604
|
-
observer.onNext(v);
|
5605
|
-
observer.onCompleted();
|
5606
|
-
} else {
|
5607
|
-
observer.onCompleted();
|
5608
|
-
}
|
5609
|
-
|
5610
|
-
return disposableEmpty;
|
5611
|
-
}
|
5299
|
+
/**
|
5300
|
+
* Represents the result of an asynchronous operation.
|
5301
|
+
* The last value before the OnCompleted notification, or the error received through OnError, is sent to all subscribed observers.
|
5302
|
+
*/
|
5303
|
+
var AsyncSubject = Rx.AsyncSubject = (function (__super__) {
|
5612
5304
|
|
5613
|
-
|
5305
|
+
function subscribe(observer) {
|
5306
|
+
checkDisposed.call(this);
|
5307
|
+
|
5308
|
+
if (!this.isStopped) {
|
5309
|
+
this.observers.push(observer);
|
5310
|
+
return new InnerSubscription(this, observer);
|
5311
|
+
}
|
5614
5312
|
|
5615
|
-
|
5616
|
-
|
5617
|
-
|
5618
|
-
*/
|
5619
|
-
function AsyncSubject() {
|
5620
|
-
_super.call(this, subscribe);
|
5313
|
+
var ex = this.exception,
|
5314
|
+
hv = this.hasValue,
|
5315
|
+
v = this.value;
|
5621
5316
|
|
5622
|
-
|
5623
|
-
|
5624
|
-
|
5625
|
-
|
5626
|
-
|
5627
|
-
|
5628
|
-
|
5317
|
+
if (ex) {
|
5318
|
+
observer.onError(ex);
|
5319
|
+
} else if (hv) {
|
5320
|
+
observer.onNext(v);
|
5321
|
+
observer.onCompleted();
|
5322
|
+
} else {
|
5323
|
+
observer.onCompleted();
|
5324
|
+
}
|
5629
5325
|
|
5630
|
-
|
5631
|
-
|
5632
|
-
* Indicates whether the subject has observers subscribed to it.
|
5633
|
-
* @returns {Boolean} Indicates whether the subject has observers subscribed to it.
|
5634
|
-
*/
|
5635
|
-
hasObservers: function () {
|
5636
|
-
checkDisposed.call(this);
|
5637
|
-
return this.observers.length > 0;
|
5638
|
-
},
|
5639
|
-
/**
|
5640
|
-
* Notifies all subscribed observers about the end of the sequence, also causing the last received value to be sent out (if any).
|
5641
|
-
*/
|
5642
|
-
onCompleted: function () {
|
5643
|
-
var o, i, len;
|
5644
|
-
checkDisposed.call(this);
|
5645
|
-
if (!this.isStopped) {
|
5646
|
-
this.isStopped = true;
|
5647
|
-
var os = this.observers.slice(0),
|
5648
|
-
v = this.value,
|
5649
|
-
hv = this.hasValue;
|
5650
|
-
|
5651
|
-
if (hv) {
|
5652
|
-
for (i = 0, len = os.length; i < len; i++) {
|
5653
|
-
o = os[i];
|
5654
|
-
o.onNext(v);
|
5655
|
-
o.onCompleted();
|
5656
|
-
}
|
5657
|
-
} else {
|
5658
|
-
for (i = 0, len = os.length; i < len; i++) {
|
5659
|
-
os[i].onCompleted();
|
5660
|
-
}
|
5661
|
-
}
|
5326
|
+
return disposableEmpty;
|
5327
|
+
}
|
5662
5328
|
|
5663
|
-
|
5664
|
-
}
|
5665
|
-
},
|
5666
|
-
/**
|
5667
|
-
* Notifies all subscribed observers about the exception.
|
5668
|
-
* @param {Mixed} error The exception to send to all observers.
|
5669
|
-
*/
|
5670
|
-
onError: function (exception) {
|
5671
|
-
checkDisposed.call(this);
|
5672
|
-
if (!this.isStopped) {
|
5673
|
-
var os = this.observers.slice(0);
|
5674
|
-
this.isStopped = true;
|
5675
|
-
this.exception = exception;
|
5329
|
+
inherits(AsyncSubject, __super__);
|
5676
5330
|
|
5677
|
-
|
5678
|
-
|
5679
|
-
|
5331
|
+
/**
|
5332
|
+
* Creates a subject that can only receive one value and that value is cached for all future observations.
|
5333
|
+
* @constructor
|
5334
|
+
*/
|
5335
|
+
function AsyncSubject() {
|
5336
|
+
__super__.call(this, subscribe);
|
5337
|
+
|
5338
|
+
this.isDisposed = false;
|
5339
|
+
this.isStopped = false;
|
5340
|
+
this.value = null;
|
5341
|
+
this.hasValue = false;
|
5342
|
+
this.observers = [];
|
5343
|
+
this.exception = null;
|
5344
|
+
}
|
5680
5345
|
|
5681
|
-
|
5682
|
-
|
5683
|
-
|
5684
|
-
|
5685
|
-
|
5686
|
-
|
5687
|
-
|
5688
|
-
|
5689
|
-
|
5690
|
-
|
5691
|
-
|
5692
|
-
|
5693
|
-
|
5694
|
-
|
5695
|
-
|
5696
|
-
|
5697
|
-
|
5698
|
-
|
5699
|
-
|
5700
|
-
|
5701
|
-
|
5702
|
-
|
5346
|
+
addProperties(AsyncSubject.prototype, Observer, {
|
5347
|
+
/**
|
5348
|
+
* Indicates whether the subject has observers subscribed to it.
|
5349
|
+
* @returns {Boolean} Indicates whether the subject has observers subscribed to it.
|
5350
|
+
*/
|
5351
|
+
hasObservers: function () {
|
5352
|
+
checkDisposed.call(this);
|
5353
|
+
return this.observers.length > 0;
|
5354
|
+
},
|
5355
|
+
/**
|
5356
|
+
* Notifies all subscribed observers about the end of the sequence, also causing the last received value to be sent out (if any).
|
5357
|
+
*/
|
5358
|
+
onCompleted: function () {
|
5359
|
+
var o, i, len;
|
5360
|
+
checkDisposed.call(this);
|
5361
|
+
if (!this.isStopped) {
|
5362
|
+
this.isStopped = true;
|
5363
|
+
var os = this.observers.slice(0),
|
5364
|
+
v = this.value,
|
5365
|
+
hv = this.hasValue;
|
5366
|
+
|
5367
|
+
if (hv) {
|
5368
|
+
for (i = 0, len = os.length; i < len; i++) {
|
5369
|
+
o = os[i];
|
5370
|
+
o.onNext(v);
|
5371
|
+
o.onCompleted();
|
5703
5372
|
}
|
5704
|
-
|
5705
|
-
|
5706
|
-
|
5707
|
-
|
5708
|
-
|
5709
|
-
/** @private */
|
5710
|
-
var AnonymousSubject = (function (_super) {
|
5711
|
-
inherits(AnonymousSubject, _super);
|
5373
|
+
} else {
|
5374
|
+
for (i = 0, len = os.length; i < len; i++) {
|
5375
|
+
os[i].onCompleted();
|
5376
|
+
}
|
5377
|
+
}
|
5712
5378
|
|
5713
|
-
|
5714
|
-
return this.observable.subscribe(observer);
|
5379
|
+
this.observers = [];
|
5715
5380
|
}
|
5381
|
+
},
|
5382
|
+
/**
|
5383
|
+
* Notifies all subscribed observers about the error.
|
5384
|
+
* @param {Mixed} error The Error to send to all observers.
|
5385
|
+
*/
|
5386
|
+
onError: function (error) {
|
5387
|
+
checkDisposed.call(this);
|
5388
|
+
if (!this.isStopped) {
|
5389
|
+
var os = this.observers.slice(0);
|
5390
|
+
this.isStopped = true;
|
5391
|
+
this.exception = error;
|
5392
|
+
|
5393
|
+
for (var i = 0, len = os.length; i < len; i++) {
|
5394
|
+
os[i].onError(error);
|
5395
|
+
}
|
5716
5396
|
|
5717
|
-
|
5718
|
-
* @private
|
5719
|
-
* @constructor
|
5720
|
-
*/
|
5721
|
-
function AnonymousSubject(observer, observable) {
|
5722
|
-
_super.call(this, subscribe);
|
5723
|
-
this.observer = observer;
|
5724
|
-
this.observable = observable;
|
5397
|
+
this.observers = [];
|
5725
5398
|
}
|
5399
|
+
},
|
5400
|
+
/**
|
5401
|
+
* Sends a value to the subject. The last value received before successful termination will be sent to all subscribed and future observers.
|
5402
|
+
* @param {Mixed} value The value to store in the subject.
|
5403
|
+
*/
|
5404
|
+
onNext: function (value) {
|
5405
|
+
checkDisposed.call(this);
|
5406
|
+
if (this.isStopped) { return; }
|
5407
|
+
this.value = value;
|
5408
|
+
this.hasValue = true;
|
5409
|
+
},
|
5410
|
+
/**
|
5411
|
+
* Unsubscribe all observers and release resources.
|
5412
|
+
*/
|
5413
|
+
dispose: function () {
|
5414
|
+
this.isDisposed = true;
|
5415
|
+
this.observers = null;
|
5416
|
+
this.exception = null;
|
5417
|
+
this.value = null;
|
5418
|
+
}
|
5419
|
+
});
|
5726
5420
|
|
5727
|
-
|
5728
|
-
|
5729
|
-
* @private
|
5730
|
-
* @memberOf AnonymousSubject#
|
5731
|
-
*/
|
5732
|
-
onCompleted: function () {
|
5733
|
-
this.observer.onCompleted();
|
5734
|
-
},
|
5735
|
-
/**
|
5736
|
-
* @private
|
5737
|
-
* @memberOf AnonymousSubject#
|
5738
|
-
*/
|
5739
|
-
onError: function (exception) {
|
5740
|
-
this.observer.onError(exception);
|
5741
|
-
},
|
5742
|
-
/**
|
5743
|
-
* @private
|
5744
|
-
* @memberOf AnonymousSubject#
|
5745
|
-
*/
|
5746
|
-
onNext: function (value) {
|
5747
|
-
this.observer.onNext(value);
|
5748
|
-
}
|
5749
|
-
});
|
5421
|
+
return AsyncSubject;
|
5422
|
+
}(Observable));
|
5750
5423
|
|
5751
|
-
|
5752
|
-
|
5424
|
+
var AnonymousSubject = Rx.AnonymousSubject = (function (__super__) {
|
5425
|
+
inherits(AnonymousSubject, __super__);
|
5426
|
+
|
5427
|
+
function AnonymousSubject(observer, observable) {
|
5428
|
+
this.observer = observer;
|
5429
|
+
this.observable = observable;
|
5430
|
+
__super__.call(this, this.observable.subscribe.bind(this.observable));
|
5431
|
+
}
|
5432
|
+
|
5433
|
+
addProperties(AnonymousSubject.prototype, Observer, {
|
5434
|
+
onCompleted: function () {
|
5435
|
+
this.observer.onCompleted();
|
5436
|
+
},
|
5437
|
+
onError: function (exception) {
|
5438
|
+
this.observer.onError(exception);
|
5439
|
+
},
|
5440
|
+
onNext: function (value) {
|
5441
|
+
this.observer.onNext(value);
|
5442
|
+
}
|
5443
|
+
});
|
5444
|
+
|
5445
|
+
return AnonymousSubject;
|
5446
|
+
}(Observable));
|
5753
5447
|
|
5754
5448
|
/**
|
5755
5449
|
* Represents a value that changes over time.
|
@@ -6013,21 +5707,21 @@
|
|
6013
5707
|
return ReplaySubject;
|
6014
5708
|
}(Observable));
|
6015
5709
|
|
6016
|
-
if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
|
6017
|
-
root.Rx = Rx;
|
6018
|
-
|
6019
|
-
define(function() {
|
6020
|
-
return Rx;
|
6021
|
-
});
|
6022
|
-
} else if (freeExports && freeModule) {
|
6023
|
-
// in Node.js or RingoJS
|
6024
|
-
if (moduleExports) {
|
6025
|
-
(freeModule.exports = Rx).Rx = Rx;
|
6026
|
-
} else {
|
6027
|
-
freeExports.Rx = Rx;
|
6028
|
-
}
|
6029
|
-
} else {
|
6030
|
-
// in a browser or Rhino
|
6031
|
-
root.Rx = Rx;
|
5710
|
+
if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
|
5711
|
+
root.Rx = Rx;
|
5712
|
+
|
5713
|
+
define(function() {
|
5714
|
+
return Rx;
|
5715
|
+
});
|
5716
|
+
} else if (freeExports && freeModule) {
|
5717
|
+
// in Node.js or RingoJS
|
5718
|
+
if (moduleExports) {
|
5719
|
+
(freeModule.exports = Rx).Rx = Rx;
|
5720
|
+
} else {
|
5721
|
+
freeExports.Rx = Rx;
|
5722
|
+
}
|
5723
|
+
} else {
|
5724
|
+
// in a browser or Rhino
|
5725
|
+
root.Rx = Rx;
|
6032
5726
|
}
|
6033
5727
|
}.call(this));
|