rxjs-rails 2.2.20 → 2.2.26

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rxjs/rails/version.rb +1 -1
  3. data/vendor/assets/javascripts/rx.aggregates.js +38 -20
  4. data/vendor/assets/javascripts/rx.aggregates.min.js +1 -1
  5. data/vendor/assets/javascripts/rx.all.compat.js +9288 -0
  6. data/vendor/assets/javascripts/rx.all.compat.min.js +3 -0
  7. data/vendor/assets/javascripts/rx.all.js +9102 -0
  8. data/vendor/assets/javascripts/rx.all.min.js +3 -0
  9. data/vendor/assets/javascripts/rx.async.compat.js +5 -4
  10. data/vendor/assets/javascripts/rx.async.compat.min.js +1 -1
  11. data/vendor/assets/javascripts/rx.async.js +5 -4
  12. data/vendor/assets/javascripts/rx.async.min.js +1 -1
  13. data/vendor/assets/javascripts/rx.backpressure.js +24 -12
  14. data/vendor/assets/javascripts/rx.backpressure.min.js +1 -1
  15. data/vendor/assets/javascripts/rx.binding.js +85 -85
  16. data/vendor/assets/javascripts/rx.coincidence.js +59 -15
  17. data/vendor/assets/javascripts/rx.coincidence.min.js +1 -1
  18. data/vendor/assets/javascripts/rx.compat.js +809 -742
  19. data/vendor/assets/javascripts/rx.compat.min.js +2 -2
  20. data/vendor/assets/javascripts/rx.core.compat.js +2629 -0
  21. data/vendor/assets/javascripts/rx.core.compat.min.js +1 -0
  22. data/vendor/assets/javascripts/rx.core.js +2511 -0
  23. data/vendor/assets/javascripts/rx.core.min.js +1 -0
  24. data/vendor/assets/javascripts/rx.experimental.js +43 -43
  25. data/vendor/assets/javascripts/rx.joinpatterns.js +281 -281
  26. data/vendor/assets/javascripts/rx.js +792 -725
  27. data/vendor/assets/javascripts/rx.lite.compat.js +890 -758
  28. data/vendor/assets/javascripts/rx.lite.compat.min.js +2 -2
  29. data/vendor/assets/javascripts/rx.lite.extras.js +664 -0
  30. data/vendor/assets/javascripts/rx.lite.extras.min.js +1 -0
  31. data/vendor/assets/javascripts/rx.lite.js +890 -758
  32. data/vendor/assets/javascripts/rx.lite.min.js +2 -2
  33. data/vendor/assets/javascripts/rx.min.js +2 -2
  34. data/vendor/assets/javascripts/rx.testing.js +166 -166
  35. data/vendor/assets/javascripts/rx.testing.min.js +1 -1
  36. data/vendor/assets/javascripts/rx.time.js +132 -131
  37. data/vendor/assets/javascripts/rx.time.min.js +1 -1
  38. data/vendor/assets/javascripts/rx.virtualtime.js +2 -2
  39. metadata +13 -4
  40. data/vendor/assets/javascripts/rx.node.js +0 -142
@@ -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
 
@@ -198,7 +198,7 @@
198
198
  }
199
199
 
200
200
  function isFunction(value) {
201
- return typeof value == 'function';
201
+ return typeof value == 'function' || false;
202
202
  }
203
203
 
204
204
  // fallback for older versions of Chrome and Safari
@@ -392,100 +392,100 @@
392
392
  return a;
393
393
  }
394
394
 
395
- // Collections
396
- var IndexedItem = function (id, value) {
397
- this.id = id;
398
- this.value = value;
399
- };
400
-
401
- IndexedItem.prototype.compareTo = function (other) {
402
- var c = this.value.compareTo(other.value);
403
- if (c === 0) {
404
- c = this.id - other.id;
405
- }
406
- return c;
407
- };
408
-
409
- // Priority Queue for Scheduling
410
- var PriorityQueue = Rx.internals.PriorityQueue = function (capacity) {
411
- this.items = new Array(capacity);
412
- this.length = 0;
413
- };
414
-
415
- var priorityProto = PriorityQueue.prototype;
416
- priorityProto.isHigherPriority = function (left, right) {
417
- return this.items[left].compareTo(this.items[right]) < 0;
418
- };
419
-
420
- priorityProto.percolate = function (index) {
421
- if (index >= this.length || index < 0) {
422
- return;
423
- }
424
- var parent = index - 1 >> 1;
425
- if (parent < 0 || parent === index) {
426
- return;
427
- }
428
- if (this.isHigherPriority(index, parent)) {
429
- var temp = this.items[index];
430
- this.items[index] = this.items[parent];
431
- this.items[parent] = temp;
432
- this.percolate(parent);
433
- }
434
- };
435
-
436
- priorityProto.heapify = function (index) {
437
- if (index === undefined) {
438
- index = 0;
439
- }
440
- if (index >= this.length || index < 0) {
441
- return;
442
- }
443
- var left = 2 * index + 1,
444
- right = 2 * index + 2,
445
- first = index;
446
- if (left < this.length && this.isHigherPriority(left, first)) {
447
- first = left;
448
- }
449
- if (right < this.length && this.isHigherPriority(right, first)) {
450
- first = right;
451
- }
452
- if (first !== index) {
453
- var temp = this.items[index];
454
- this.items[index] = this.items[first];
455
- this.items[first] = temp;
456
- this.heapify(first);
457
- }
458
- };
459
-
460
- priorityProto.peek = function () { return this.items[0].value; };
461
-
462
- priorityProto.removeAt = function (index) {
463
- this.items[index] = this.items[--this.length];
464
- delete this.items[this.length];
465
- this.heapify();
466
- };
467
-
468
- priorityProto.dequeue = function () {
469
- var result = this.peek();
470
- this.removeAt(0);
471
- return result;
472
- };
473
-
474
- priorityProto.enqueue = function (item) {
475
- var index = this.length++;
476
- this.items[index] = new IndexedItem(PriorityQueue.count++, item);
477
- this.percolate(index);
478
- };
479
-
480
- priorityProto.remove = function (item) {
481
- for (var i = 0; i < this.length; i++) {
482
- if (this.items[i].value === item) {
483
- this.removeAt(i);
484
- return true;
485
- }
486
- }
487
- return false;
488
- };
395
+ // Collections
396
+ var IndexedItem = function (id, value) {
397
+ this.id = id;
398
+ this.value = value;
399
+ };
400
+
401
+ IndexedItem.prototype.compareTo = function (other) {
402
+ var c = this.value.compareTo(other.value);
403
+ if (c === 0) {
404
+ c = this.id - other.id;
405
+ }
406
+ return c;
407
+ };
408
+
409
+ // Priority Queue for Scheduling
410
+ var PriorityQueue = Rx.internals.PriorityQueue = function (capacity) {
411
+ this.items = new Array(capacity);
412
+ this.length = 0;
413
+ };
414
+
415
+ var priorityProto = PriorityQueue.prototype;
416
+ priorityProto.isHigherPriority = function (left, right) {
417
+ return this.items[left].compareTo(this.items[right]) < 0;
418
+ };
419
+
420
+ priorityProto.percolate = function (index) {
421
+ if (index >= this.length || index < 0) {
422
+ return;
423
+ }
424
+ var parent = index - 1 >> 1;
425
+ if (parent < 0 || parent === index) {
426
+ return;
427
+ }
428
+ if (this.isHigherPriority(index, parent)) {
429
+ var temp = this.items[index];
430
+ this.items[index] = this.items[parent];
431
+ this.items[parent] = temp;
432
+ this.percolate(parent);
433
+ }
434
+ };
435
+
436
+ priorityProto.heapify = function (index) {
437
+ if (index === undefined) {
438
+ index = 0;
439
+ }
440
+ if (index >= this.length || index < 0) {
441
+ return;
442
+ }
443
+ var left = 2 * index + 1,
444
+ right = 2 * index + 2,
445
+ first = index;
446
+ if (left < this.length && this.isHigherPriority(left, first)) {
447
+ first = left;
448
+ }
449
+ if (right < this.length && this.isHigherPriority(right, first)) {
450
+ first = right;
451
+ }
452
+ if (first !== index) {
453
+ var temp = this.items[index];
454
+ this.items[index] = this.items[first];
455
+ this.items[first] = temp;
456
+ this.heapify(first);
457
+ }
458
+ };
459
+
460
+ priorityProto.peek = function () { return this.items[0].value; };
461
+
462
+ priorityProto.removeAt = function (index) {
463
+ this.items[index] = this.items[--this.length];
464
+ delete this.items[this.length];
465
+ this.heapify();
466
+ };
467
+
468
+ priorityProto.dequeue = function () {
469
+ var result = this.peek();
470
+ this.removeAt(0);
471
+ return result;
472
+ };
473
+
474
+ priorityProto.enqueue = function (item) {
475
+ var index = this.length++;
476
+ this.items[index] = new IndexedItem(PriorityQueue.count++, item);
477
+ this.percolate(index);
478
+ };
479
+
480
+ priorityProto.remove = function (item) {
481
+ for (var i = 0; i < this.length; i++) {
482
+ if (this.items[i].value === item) {
483
+ this.removeAt(i);
484
+ return true;
485
+ }
486
+ }
487
+ return false;
488
+ };
489
489
  PriorityQueue.count = 0;
490
490
  /**
491
491
  * Represents a group of disposable resources that are disposed together.
@@ -754,30 +754,30 @@
754
754
  return RefCountDisposable;
755
755
  })();
756
756
 
757
- var ScheduledItem = Rx.internals.ScheduledItem = function (scheduler, state, action, dueTime, comparer) {
758
- this.scheduler = scheduler;
759
- this.state = state;
760
- this.action = action;
761
- this.dueTime = dueTime;
762
- this.comparer = comparer || defaultSubComparer;
763
- this.disposable = new SingleAssignmentDisposable();
764
- }
765
-
766
- ScheduledItem.prototype.invoke = function () {
767
- this.disposable.setDisposable(this.invokeCore());
768
- };
769
-
770
- ScheduledItem.prototype.compareTo = function (other) {
771
- return this.comparer(this.dueTime, other.dueTime);
772
- };
773
-
774
- ScheduledItem.prototype.isCancelled = function () {
775
- return this.disposable.isDisposed;
776
- };
777
-
778
- ScheduledItem.prototype.invokeCore = function () {
779
- return this.action(this.scheduler, this.state);
780
- };
757
+ var ScheduledItem = Rx.internals.ScheduledItem = function (scheduler, state, action, dueTime, comparer) {
758
+ this.scheduler = scheduler;
759
+ this.state = state;
760
+ this.action = action;
761
+ this.dueTime = dueTime;
762
+ this.comparer = comparer || defaultSubComparer;
763
+ this.disposable = new SingleAssignmentDisposable();
764
+ }
765
+
766
+ ScheduledItem.prototype.invoke = function () {
767
+ this.disposable.setDisposable(this.invokeCore());
768
+ };
769
+
770
+ ScheduledItem.prototype.compareTo = function (other) {
771
+ return this.comparer(this.dueTime, other.dueTime);
772
+ };
773
+
774
+ ScheduledItem.prototype.isCancelled = function () {
775
+ return this.disposable.isDisposed;
776
+ };
777
+
778
+ ScheduledItem.prototype.invokeCore = function () {
779
+ return this.action(this.scheduler, this.state);
780
+ };
781
781
 
782
782
  /** Provides a set of static properties to access commonly used schedulers. */
783
783
  var Scheduler = Rx.Scheduler = (function () {
@@ -1032,25 +1032,25 @@
1032
1032
 
1033
1033
  var normalizeTime = Scheduler.normalize;
1034
1034
 
1035
- /**
1036
- * Gets a scheduler that schedules work immediately on the current thread.
1037
- */
1038
- var immediateScheduler = Scheduler.immediate = (function () {
1039
-
1040
- function scheduleNow(state, action) { return action(this, state); }
1041
-
1042
- function scheduleRelative(state, dueTime, action) {
1043
- var dt = normalizeTime(dt);
1044
- while (dt - this.now() > 0) { }
1045
- return action(this, state);
1046
- }
1047
-
1048
- function scheduleAbsolute(state, dueTime, action) {
1049
- return this.scheduleWithRelativeAndState(state, dueTime - this.now(), action);
1050
- }
1051
-
1052
- return new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
1053
- }());
1035
+ /**
1036
+ * Gets a scheduler that schedules work immediately on the current thread.
1037
+ */
1038
+ var immediateScheduler = Scheduler.immediate = (function () {
1039
+
1040
+ function scheduleNow(state, action) { return action(this, state); }
1041
+
1042
+ function scheduleRelative(state, dueTime, action) {
1043
+ var dt = normalizeTime(dt);
1044
+ while (dt - this.now() > 0) { }
1045
+ return action(this, state);
1046
+ }
1047
+
1048
+ function scheduleAbsolute(state, dueTime, action) {
1049
+ return this.scheduleWithRelativeAndState(state, dueTime - this.now(), action);
1050
+ }
1051
+
1052
+ return new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
1053
+ }());
1054
1054
 
1055
1055
  /**
1056
1056
  * Gets a scheduler that schedules work as soon as possible on the current thread.
@@ -1114,34 +1114,34 @@
1114
1114
  return currentScheduler;
1115
1115
  }());
1116
1116
 
1117
- var SchedulePeriodicRecursive = Rx.internals.SchedulePeriodicRecursive = (function () {
1118
- function tick(command, recurse) {
1119
- recurse(0, this._period);
1120
- try {
1121
- this._state = this._action(this._state);
1122
- } catch (e) {
1123
- this._cancel.dispose();
1124
- throw e;
1125
- }
1126
- }
1127
-
1128
- function SchedulePeriodicRecursive(scheduler, state, period, action) {
1129
- this._scheduler = scheduler;
1130
- this._state = state;
1131
- this._period = period;
1132
- this._action = action;
1133
- }
1134
-
1135
- SchedulePeriodicRecursive.prototype.start = function () {
1136
- var d = new SingleAssignmentDisposable();
1137
- this._cancel = d;
1138
- d.setDisposable(this._scheduler.scheduleRecursiveWithRelativeAndState(0, this._period, tick.bind(this)));
1139
-
1140
- return d;
1141
- };
1142
-
1143
- return SchedulePeriodicRecursive;
1144
- }());
1117
+ var SchedulePeriodicRecursive = Rx.internals.SchedulePeriodicRecursive = (function () {
1118
+ function tick(command, recurse) {
1119
+ recurse(0, this._period);
1120
+ try {
1121
+ this._state = this._action(this._state);
1122
+ } catch (e) {
1123
+ this._cancel.dispose();
1124
+ throw e;
1125
+ }
1126
+ }
1127
+
1128
+ function SchedulePeriodicRecursive(scheduler, state, period, action) {
1129
+ this._scheduler = scheduler;
1130
+ this._state = state;
1131
+ this._period = period;
1132
+ this._action = action;
1133
+ }
1134
+
1135
+ SchedulePeriodicRecursive.prototype.start = function () {
1136
+ var d = new SingleAssignmentDisposable();
1137
+ this._cancel = d;
1138
+ d.setDisposable(this._scheduler.scheduleRecursiveWithRelativeAndState(0, this._period, tick.bind(this)));
1139
+
1140
+ return d;
1141
+ };
1142
+
1143
+ return SchedulePeriodicRecursive;
1144
+ }());
1145
1145
 
1146
1146
 
1147
1147
  var scheduleMethod, clearMethod = noop;
@@ -1416,151 +1416,150 @@
1416
1416
  };
1417
1417
  }());
1418
1418
 
1419
- var Enumerator = Rx.internals.Enumerator = function (next) {
1420
- this._next = next;
1421
- };
1422
-
1423
- Enumerator.prototype.next = function () {
1424
- return this._next();
1425
- };
1426
-
1427
- Enumerator.prototype[$iterator$] = function () { return this; }
1428
-
1429
- var Enumerable = Rx.internals.Enumerable = function (iterator) {
1430
- this._iterator = iterator;
1431
- };
1432
-
1433
- Enumerable.prototype[$iterator$] = function () {
1434
- return this._iterator();
1435
- };
1436
-
1437
- Enumerable.prototype.concat = function () {
1438
- var sources = this;
1439
- return new AnonymousObservable(function (observer) {
1440
- var e;
1441
- try {
1442
- e = sources[$iterator$]();
1443
- } catch(err) {
1444
- observer.onError();
1445
- return;
1446
- }
1447
-
1448
- var isDisposed,
1449
- subscription = new SerialDisposable();
1450
- var cancelable = immediateScheduler.scheduleRecursive(function (self) {
1451
- var currentItem;
1452
- if (isDisposed) { return; }
1453
-
1454
- try {
1455
- currentItem = e.next();
1456
- } catch (ex) {
1457
- observer.onError(ex);
1458
- return;
1459
- }
1460
-
1461
- if (currentItem.done) {
1462
- observer.onCompleted();
1463
- return;
1464
- }
1465
-
1466
- // Check if promise
1467
- var currentValue = currentItem.value;
1468
- isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
1469
-
1470
- var d = new SingleAssignmentDisposable();
1471
- subscription.setDisposable(d);
1472
- d.setDisposable(currentValue.subscribe(
1473
- observer.onNext.bind(observer),
1474
- observer.onError.bind(observer),
1475
- function () { self(); })
1476
- );
1477
- });
1478
-
1479
- return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
1480
- isDisposed = true;
1481
- }));
1482
- });
1483
- };
1484
-
1485
- Enumerable.prototype.catchException = function () {
1486
- var sources = this;
1487
- return new AnonymousObservable(function (observer) {
1488
- var e;
1489
- try {
1490
- e = sources[$iterator$]();
1491
- } catch(err) {
1492
- observer.onError();
1493
- return;
1494
- }
1495
-
1496
- var isDisposed,
1497
- lastException,
1498
- subscription = new SerialDisposable();
1499
- var cancelable = immediateScheduler.scheduleRecursive(function (self) {
1500
- if (isDisposed) { return; }
1501
-
1502
- var currentItem;
1503
- try {
1504
- currentItem = e.next();
1505
- } catch (ex) {
1506
- observer.onError(ex);
1507
- return;
1508
- }
1509
-
1510
- if (currentItem.done) {
1511
- if (lastException) {
1512
- observer.onError(lastException);
1513
- } else {
1514
- observer.onCompleted();
1515
- }
1516
- return;
1517
- }
1518
-
1519
- // Check if promise
1520
- var currentValue = currentItem.value;
1521
- isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
1522
-
1523
- var d = new SingleAssignmentDisposable();
1524
- subscription.setDisposable(d);
1525
- d.setDisposable(currentValue.subscribe(
1526
- observer.onNext.bind(observer),
1527
- function (exn) {
1528
- lastException = exn;
1529
- self();
1530
- },
1531
- observer.onCompleted.bind(observer)));
1532
- });
1533
- return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
1534
- isDisposed = true;
1535
- }));
1536
- });
1537
- };
1538
-
1539
-
1540
- var enumerableRepeat = Enumerable.repeat = function (value, repeatCount) {
1541
- if (repeatCount == null) { repeatCount = -1; }
1542
- return new Enumerable(function () {
1543
- var left = repeatCount;
1544
- return new Enumerator(function () {
1545
- if (left === 0) { return doneEnumerator; }
1546
- if (left > 0) { left--; }
1547
- return { done: false, value: value };
1548
- });
1549
- });
1550
- };
1551
-
1552
- var enumerableFor = Enumerable.forEach = function (source, selector, thisArg) {
1553
- selector || (selector = identity);
1554
- return new Enumerable(function () {
1555
- var index = -1;
1556
- return new Enumerator(
1557
- function () {
1558
- return ++index < source.length ?
1559
- { done: false, value: selector.call(thisArg, source[index], index, source) } :
1560
- doneEnumerator;
1561
- });
1562
- });
1563
- };
1419
+ var Enumerator = Rx.internals.Enumerator = function (next) {
1420
+ this._next = next;
1421
+ };
1422
+
1423
+ Enumerator.prototype.next = function () {
1424
+ return this._next();
1425
+ };
1426
+
1427
+ Enumerator.prototype[$iterator$] = function () { return this; }
1428
+
1429
+ var Enumerable = Rx.internals.Enumerable = function (iterator) {
1430
+ this._iterator = iterator;
1431
+ };
1432
+
1433
+ Enumerable.prototype[$iterator$] = function () {
1434
+ return this._iterator();
1435
+ };
1436
+
1437
+ Enumerable.prototype.concat = function () {
1438
+ var sources = this;
1439
+ return new AnonymousObservable(function (observer) {
1440
+ var e;
1441
+ try {
1442
+ e = sources[$iterator$]();
1443
+ } catch(err) {
1444
+ observer.onError();
1445
+ return;
1446
+ }
1447
+
1448
+ var isDisposed,
1449
+ subscription = new SerialDisposable();
1450
+ var cancelable = immediateScheduler.scheduleRecursive(function (self) {
1451
+ var currentItem;
1452
+ if (isDisposed) { return; }
1453
+
1454
+ try {
1455
+ currentItem = e.next();
1456
+ } catch (ex) {
1457
+ observer.onError(ex);
1458
+ return;
1459
+ }
1460
+
1461
+ if (currentItem.done) {
1462
+ observer.onCompleted();
1463
+ return;
1464
+ }
1465
+
1466
+ // Check if promise
1467
+ var currentValue = currentItem.value;
1468
+ isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
1469
+
1470
+ var d = new SingleAssignmentDisposable();
1471
+ subscription.setDisposable(d);
1472
+ d.setDisposable(currentValue.subscribe(
1473
+ observer.onNext.bind(observer),
1474
+ observer.onError.bind(observer),
1475
+ function () { self(); })
1476
+ );
1477
+ });
1478
+
1479
+ return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
1480
+ isDisposed = true;
1481
+ }));
1482
+ });
1483
+ };
1484
+
1485
+ Enumerable.prototype.catchException = function () {
1486
+ var sources = this;
1487
+ return new AnonymousObservable(function (observer) {
1488
+ var e;
1489
+ try {
1490
+ e = sources[$iterator$]();
1491
+ } catch(err) {
1492
+ observer.onError();
1493
+ return;
1494
+ }
1495
+
1496
+ var isDisposed,
1497
+ lastException,
1498
+ subscription = new SerialDisposable();
1499
+ var cancelable = immediateScheduler.scheduleRecursive(function (self) {
1500
+ if (isDisposed) { return; }
1501
+
1502
+ var currentItem;
1503
+ try {
1504
+ currentItem = e.next();
1505
+ } catch (ex) {
1506
+ observer.onError(ex);
1507
+ return;
1508
+ }
1509
+
1510
+ if (currentItem.done) {
1511
+ if (lastException) {
1512
+ observer.onError(lastException);
1513
+ } else {
1514
+ observer.onCompleted();
1515
+ }
1516
+ return;
1517
+ }
1518
+
1519
+ // Check if promise
1520
+ var currentValue = currentItem.value;
1521
+ isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
1522
+
1523
+ var d = new SingleAssignmentDisposable();
1524
+ subscription.setDisposable(d);
1525
+ d.setDisposable(currentValue.subscribe(
1526
+ observer.onNext.bind(observer),
1527
+ function (exn) {
1528
+ lastException = exn;
1529
+ self();
1530
+ },
1531
+ observer.onCompleted.bind(observer)));
1532
+ });
1533
+ return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
1534
+ isDisposed = true;
1535
+ }));
1536
+ });
1537
+ };
1538
+
1539
+ var enumerableRepeat = Enumerable.repeat = function (value, repeatCount) {
1540
+ if (repeatCount == null) { repeatCount = -1; }
1541
+ return new Enumerable(function () {
1542
+ var left = repeatCount;
1543
+ return new Enumerator(function () {
1544
+ if (left === 0) { return doneEnumerator; }
1545
+ if (left > 0) { left--; }
1546
+ return { done: false, value: value };
1547
+ });
1548
+ });
1549
+ };
1550
+
1551
+ var enumerableFor = Enumerable.forEach = function (source, selector, thisArg) {
1552
+ selector || (selector = identity);
1553
+ return new Enumerable(function () {
1554
+ var index = -1;
1555
+ return new Enumerator(
1556
+ function () {
1557
+ return ++index < source.length ?
1558
+ { done: false, value: selector.call(thisArg, source[index], index, source) } :
1559
+ doneEnumerator;
1560
+ });
1561
+ });
1562
+ };
1564
1563
 
1565
1564
  /**
1566
1565
  * Supports push-style iteration over an observable sequence.
@@ -1741,83 +1740,43 @@
1741
1740
  return AnonymousObserver;
1742
1741
  }(AbstractObserver));
1743
1742
 
1744
- var observableProto;
1743
+ var observableProto;
1745
1744
 
1746
- /**
1747
- * Represents a push-style collection.
1748
- */
1749
- var Observable = Rx.Observable = (function () {
1750
-
1751
- /**
1752
- * @constructor
1753
- * @private
1754
- */
1755
- function Observable(subscribe) {
1756
- this._subscribe = subscribe;
1757
- }
1758
-
1759
- observableProto = Observable.prototype;
1745
+ /**
1746
+ * Represents a push-style collection.
1747
+ */
1748
+ var Observable = Rx.Observable = (function () {
1760
1749
 
1761
- observableProto.finalValue = function () {
1762
- var source = this;
1763
- return new AnonymousObservable(function (observer) {
1764
- var hasValue = false, value;
1765
- return source.subscribe(function (x) {
1766
- hasValue = true;
1767
- value = x;
1768
- }, observer.onError.bind(observer), function () {
1769
- if (!hasValue) {
1770
- observer.onError(new Error(sequenceContainsNoElements));
1771
- } else {
1772
- observer.onNext(value);
1773
- observer.onCompleted();
1774
- }
1775
- });
1776
- });
1777
- };
1750
+ function Observable(subscribe) {
1751
+ this._subscribe = subscribe;
1752
+ }
1778
1753
 
1779
- /**
1780
- * Subscribes an observer to the observable sequence.
1781
- *
1782
- * @example
1783
- * 1 - source.subscribe();
1784
- * 2 - source.subscribe(observer);
1785
- * 3 - source.subscribe(function (x) { console.log(x); });
1786
- * 4 - source.subscribe(function (x) { console.log(x); }, function (err) { console.log(err); });
1787
- * 5 - source.subscribe(function (x) { console.log(x); }, function (err) { console.log(err); }, function () { console.log('done'); });
1788
- * @param {Mixed} [observerOrOnNext] The object that is to receive notifications or an action to invoke for each element in the observable sequence.
1789
- * @param {Function} [onError] Action to invoke upon exceptional termination of the observable sequence.
1790
- * @param {Function} [onCompleted] Action to invoke upon graceful termination of the observable sequence.
1791
- * @returns {Diposable} The source sequence whose subscriptions and unsubscriptions happen on the specified scheduler.
1792
- */
1793
- observableProto.subscribe = observableProto.forEach = function (observerOrOnNext, onError, onCompleted) {
1794
- var subscriber;
1795
- if (typeof observerOrOnNext === 'object') {
1796
- subscriber = observerOrOnNext;
1797
- } else {
1798
- subscriber = observerCreate(observerOrOnNext, onError, onCompleted);
1799
- }
1754
+ observableProto = Observable.prototype;
1800
1755
 
1801
- return this._subscribe(subscriber);
1802
- };
1756
+ /**
1757
+ * Subscribes an observer to the observable sequence.
1758
+ *
1759
+ * @example
1760
+ * 1 - source.subscribe();
1761
+ * 2 - source.subscribe(observer);
1762
+ * 3 - source.subscribe(function (x) { console.log(x); });
1763
+ * 4 - source.subscribe(function (x) { console.log(x); }, function (err) { console.log(err); });
1764
+ * 5 - source.subscribe(function (x) { console.log(x); }, function (err) { console.log(err); }, function () { console.log('done'); });
1765
+ * @param {Mixed} [observerOrOnNext] The object that is to receive notifications or an action to invoke for each element in the observable sequence.
1766
+ * @param {Function} [onError] Action to invoke upon exceptional termination of the observable sequence.
1767
+ * @param {Function} [onCompleted] Action to invoke upon graceful termination of the observable sequence.
1768
+ * @returns {Diposable} The source sequence whose subscriptions and unsubscriptions happen on the specified scheduler.
1769
+ */
1770
+ observableProto.subscribe = observableProto.forEach = function (observerOrOnNext, onError, onCompleted) {
1771
+ var subscriber = typeof observerOrOnNext === 'object' ?
1772
+ observerOrOnNext :
1773
+ observerCreate(observerOrOnNext, onError, onCompleted);
1803
1774
 
1804
- /**
1805
- * Creates a list from an observable sequence.
1806
- *
1807
- * @memberOf Observable
1808
- * @returns An observable sequence containing a single element with a list containing all the elements of the source sequence.
1809
- */
1810
- observableProto.toArray = function () {
1811
- function accumulator(list, i) {
1812
- var newList = list.slice(0);
1813
- newList.push(i);
1814
- return newList;
1815
- }
1816
- return this.scan([], accumulator).startWith([]).finalValue();
1817
- };
1775
+ return this._subscribe(subscriber);
1776
+ };
1818
1777
 
1819
- return Observable;
1820
- })();
1778
+ return Observable;
1779
+ })();
1821
1780
 
1822
1781
  var ScheduledObserver = Rx.internals.ScheduledObserver = (function (_super) {
1823
1782
  inherits(ScheduledObserver, _super);
@@ -1888,6 +1847,24 @@
1888
1847
  return ScheduledObserver;
1889
1848
  }(AbstractObserver));
1890
1849
 
1850
+ /**
1851
+ * Creates a list from an observable sequence.
1852
+ * @returns An observable sequence containing a single element with a list containing all the elements of the source sequence.
1853
+ */
1854
+ observableProto.toArray = function () {
1855
+ var self = this;
1856
+ return new AnonymousObservable(function(observer) {
1857
+ var arr = [];
1858
+ return self.subscribe(
1859
+ arr.push.bind(arr),
1860
+ observer.onError.bind(observer),
1861
+ function () {
1862
+ observer.onNext(arr);
1863
+ observer.onCompleted();
1864
+ });
1865
+ });
1866
+ };
1867
+
1891
1868
  /**
1892
1869
  * Creates an observable sequence from a specified subscribe method implementation.
1893
1870
  *
@@ -2436,37 +2413,35 @@
2436
2413
  });
2437
2414
  };
2438
2415
 
2439
- /**
2440
- * Returns the values from the source observable sequence only after the other observable sequence produces a value.
2441
- * @param {Observable} other The observable sequence that triggers propagation of elements of the source sequence.
2442
- * @returns {Observable} An observable sequence containing the elements of the source sequence starting from the point the other sequence triggered propagation.
2443
- */
2444
- observableProto.skipUntil = function (other) {
2445
- var source = this;
2446
- return new AnonymousObservable(function (observer) {
2447
- var isOpen = false;
2448
- var disposables = new CompositeDisposable(source.subscribe(function (left) {
2449
- if (isOpen) {
2450
- observer.onNext(left);
2451
- }
2452
- }, observer.onError.bind(observer), function () {
2453
- if (isOpen) {
2454
- observer.onCompleted();
2455
- }
2456
- }));
2416
+ /**
2417
+ * Returns the values from the source observable sequence only after the other observable sequence produces a value.
2418
+ * @param {Observable | Promise} other The observable sequence or Promise that triggers propagation of elements of the source sequence.
2419
+ * @returns {Observable} An observable sequence containing the elements of the source sequence starting from the point the other sequence triggered propagation.
2420
+ */
2421
+ observableProto.skipUntil = function (other) {
2422
+ var source = this;
2423
+ return new AnonymousObservable(function (observer) {
2424
+ var isOpen = false;
2425
+ var disposables = new CompositeDisposable(source.subscribe(function (left) {
2426
+ isOpen && observer.onNext(left);
2427
+ }, observer.onError.bind(observer), function () {
2428
+ isOpen && observer.onCompleted();
2429
+ }));
2457
2430
 
2458
- var rightSubscription = new SingleAssignmentDisposable();
2459
- disposables.add(rightSubscription);
2460
- rightSubscription.setDisposable(other.subscribe(function () {
2461
- isOpen = true;
2462
- rightSubscription.dispose();
2463
- }, observer.onError.bind(observer), function () {
2464
- rightSubscription.dispose();
2465
- }));
2431
+ isPromise(other) && (other = observableFromPromise(other));
2466
2432
 
2467
- return disposables;
2468
- });
2469
- };
2433
+ var rightSubscription = new SingleAssignmentDisposable();
2434
+ disposables.add(rightSubscription);
2435
+ rightSubscription.setDisposable(other.subscribe(function () {
2436
+ isOpen = true;
2437
+ rightSubscription.dispose();
2438
+ }, observer.onError.bind(observer), function () {
2439
+ rightSubscription.dispose();
2440
+ }));
2441
+
2442
+ return disposables;
2443
+ });
2444
+ };
2470
2445
 
2471
2446
  /**
2472
2447
  * Transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.
@@ -2515,20 +2490,21 @@
2515
2490
  });
2516
2491
  };
2517
2492
 
2518
- /**
2519
- * Returns the values from the source observable sequence until the other observable sequence produces a value.
2520
- * @param {Observable} other Observable sequence that terminates propagation of elements of the source sequence.
2521
- * @returns {Observable} An observable sequence containing the elements of the source sequence up to the point the other sequence interrupted further propagation.
2522
- */
2523
- observableProto.takeUntil = function (other) {
2524
- var source = this;
2525
- return new AnonymousObservable(function (observer) {
2526
- return new CompositeDisposable(
2527
- source.subscribe(observer),
2528
- other.subscribe(observer.onCompleted.bind(observer), observer.onError.bind(observer), noop)
2529
- );
2530
- });
2531
- };
2493
+ /**
2494
+ * Returns the values from the source observable sequence until the other observable sequence produces a value.
2495
+ * @param {Observable | Promise} other Observable sequence or Promise that terminates propagation of elements of the source sequence.
2496
+ * @returns {Observable} An observable sequence containing the elements of the source sequence up to the point the other sequence interrupted further propagation.
2497
+ */
2498
+ observableProto.takeUntil = function (other) {
2499
+ var source = this;
2500
+ return new AnonymousObservable(function (observer) {
2501
+ isPromise(other) && (other = observableFromPromise(other));
2502
+ return new CompositeDisposable(
2503
+ source.subscribe(observer),
2504
+ other.subscribe(observer.onCompleted.bind(observer), observer.onError.bind(observer), noop)
2505
+ );
2506
+ });
2507
+ };
2532
2508
 
2533
2509
  function zipArray(second, resultSelector) {
2534
2510
  var first = this;
@@ -2800,29 +2776,35 @@
2800
2776
  });
2801
2777
  };
2802
2778
 
2803
- /**
2804
- * Invokes a specified action after the source observable sequence terminates gracefully or exceptionally.
2805
- *
2806
- * @example
2807
- * var res = observable.finallyAction(function () { console.log('sequence ended'; });
2808
- * @param {Function} finallyAction Action to invoke after the source observable sequence terminates.
2809
- * @returns {Observable} Source sequence with the action-invoking termination behavior applied.
2810
- */
2811
- observableProto['finally'] = observableProto.finallyAction = function (action) {
2812
- var source = this;
2813
- return new AnonymousObservable(function (observer) {
2814
- var subscription = source.subscribe(observer);
2815
- return disposableCreate(function () {
2816
- try {
2817
- subscription.dispose();
2818
- } catch (e) {
2819
- throw e;
2820
- } finally {
2821
- action();
2822
- }
2823
- });
2824
- });
2825
- };
2779
+ /**
2780
+ * Invokes a specified action after the source observable sequence terminates gracefully or exceptionally.
2781
+ *
2782
+ * @example
2783
+ * var res = observable.finallyAction(function () { console.log('sequence ended'; });
2784
+ * @param {Function} finallyAction Action to invoke after the source observable sequence terminates.
2785
+ * @returns {Observable} Source sequence with the action-invoking termination behavior applied.
2786
+ */
2787
+ observableProto['finally'] = observableProto.finallyAction = function (action) {
2788
+ var source = this;
2789
+ return new AnonymousObservable(function (observer) {
2790
+ var subscription;
2791
+ try {
2792
+ subscription = source.subscribe(observer);
2793
+ } catch (e) {
2794
+ action();
2795
+ throw e;
2796
+ }
2797
+ return disposableCreate(function () {
2798
+ try {
2799
+ subscription.dispose();
2800
+ } catch (e) {
2801
+ throw e;
2802
+ } finally {
2803
+ action();
2804
+ }
2805
+ });
2806
+ });
2807
+ };
2826
2808
 
2827
2809
  /**
2828
2810
  * Ignores all elements in an observable sequence leaving only the termination messages.
@@ -3014,7 +2996,72 @@
3014
2996
  observer.onNext(q);
3015
2997
  observer.onCompleted();
3016
2998
  });
3017
- });
2999
+ });
3000
+ };
3001
+
3002
+ function concatMap(selector) {
3003
+ return this.map(function (x, i) {
3004
+ var result = selector(x, i);
3005
+ return isPromise(result) ? observableFromPromise(result) : result;
3006
+ }).concatAll();
3007
+ }
3008
+
3009
+ function concatMapObserver(onNext, onError, onCompleted) {
3010
+ var source = this;
3011
+ return new AnonymousObservable(function (observer) {
3012
+ var index = 0;
3013
+
3014
+ return source.subscribe(
3015
+ function (x) {
3016
+ observer.onNext(onNext(x, index++));
3017
+ },
3018
+ function (err) {
3019
+ observer.onNext(onError(err));
3020
+ observer.completed();
3021
+ },
3022
+ function () {
3023
+ observer.onNext(onCompleted());
3024
+ observer.onCompleted();
3025
+ });
3026
+ }).concatAll();
3027
+ }
3028
+
3029
+ /**
3030
+ * One of the Following:
3031
+ * Projects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
3032
+ *
3033
+ * @example
3034
+ * var res = source.selectMany(function (x) { return Rx.Observable.range(0, x); });
3035
+ * Or:
3036
+ * 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.
3037
+ *
3038
+ * var res = source.selectMany(function (x) { return Rx.Observable.range(0, x); }, function (x, y) { return x + y; });
3039
+ * Or:
3040
+ * Projects each element of the source observable sequence to the other observable sequence and merges the resulting observable sequences into one observable sequence.
3041
+ *
3042
+ * var res = source.selectMany(Rx.Observable.fromArray([1,2,3]));
3043
+ * @param selector A transform function to apply to each element or an observable sequence to project each element from the
3044
+ * source sequence onto which could be either an observable or Promise.
3045
+ * @param {Function} [resultSelector] A transform function to apply to each element of the intermediate sequence.
3046
+ * @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.
3047
+ */
3048
+ observableProto.selectConcat = observableProto.concatMap = function (selector, resultSelector) {
3049
+ if (resultSelector) {
3050
+ return this.concatMap(function (x, i) {
3051
+ var selectorResult = selector(x, i),
3052
+ result = isPromise(selectorResult) ? observableFromPromise(selectorResult) : selectorResult;
3053
+
3054
+ return result.map(function (y) {
3055
+ return resultSelector(x, y, i);
3056
+ });
3057
+ });
3058
+ }
3059
+ if (typeof selector === 'function') {
3060
+ return concatMap.call(this, selector);
3061
+ }
3062
+ return concatMap.call(this, function () {
3063
+ return selector;
3064
+ });
3018
3065
  };
3019
3066
 
3020
3067
  /**
@@ -3040,6 +3087,15 @@
3040
3087
  });
3041
3088
  };
3042
3089
 
3090
+ /**
3091
+ * Retrieves the value of a specified property from all elements in the Observable sequence.
3092
+ * @param {String} property The property to pluck.
3093
+ * @returns {Observable} Returns a new Observable sequence of property values.
3094
+ */
3095
+ observableProto.pluck = function (property) {
3096
+ return this.select(function (x) { return x[property]; });
3097
+ };
3098
+
3043
3099
  function selectMany(selector) {
3044
3100
  return this.select(function (x, i) {
3045
3101
  var result = selector(x, i);
@@ -3047,6 +3103,26 @@
3047
3103
  }).mergeObservable();
3048
3104
  }
3049
3105
 
3106
+ function selectManyObserver(onNext, onError, onCompleted) {
3107
+ var source = this;
3108
+ return new AnonymousObservable(function (observer) {
3109
+ var index = 0;
3110
+
3111
+ return source.subscribe(
3112
+ function (x) {
3113
+ observer.onNext(onNext(x, index++));
3114
+ },
3115
+ function (err) {
3116
+ observer.onNext(onError(err));
3117
+ observer.completed();
3118
+ },
3119
+ function () {
3120
+ observer.onNext(onCompleted());
3121
+ observer.onCompleted();
3122
+ });
3123
+ }).mergeAll();
3124
+ }
3125
+
3050
3126
  /**
3051
3127
  * One of the Following:
3052
3128
  * Projects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
@@ -3388,8 +3464,8 @@
3388
3464
  Observable.fromEvent = function (element, eventName, selector) {
3389
3465
  if (ember) {
3390
3466
  return fromEventPattern(
3391
- function (h) { Ember.addListener(element, eventName); },
3392
- function (h) { Ember.removeListener(element, eventName); },
3467
+ function (h) { Ember.addListener(element, eventName, h); },
3468
+ function (h) { Ember.removeListener(element, eventName, h); },
3393
3469
  selector);
3394
3470
  }
3395
3471
  if (jq) {
@@ -3419,6 +3495,7 @@
3419
3495
  });
3420
3496
  }).publish().refCount();
3421
3497
  };
3498
+
3422
3499
  /**
3423
3500
  * Creates an observable sequence from an event emitter via an addHandler/removeHandler pair.
3424
3501
  * @param {Function} addHandler The function to add a handler to the emitter.
@@ -3676,71 +3753,71 @@
3676
3753
  return this.replay(null, bufferSize, window, scheduler).refCount();
3677
3754
  };
3678
3755
 
3679
- /** @private */
3680
- var ConnectableObservable = Rx.ConnectableObservable = (function (_super) {
3681
- inherits(ConnectableObservable, _super);
3682
-
3683
- /**
3684
- * @constructor
3685
- * @private
3686
- */
3687
- function ConnectableObservable(source, subject) {
3688
- var state = {
3689
- subject: subject,
3690
- source: source.asObservable(),
3691
- hasSubscription: false,
3692
- subscription: null
3693
- };
3694
-
3695
- this.connect = function () {
3696
- if (!state.hasSubscription) {
3697
- state.hasSubscription = true;
3698
- state.subscription = new CompositeDisposable(state.source.subscribe(state.subject), disposableCreate(function () {
3699
- state.hasSubscription = false;
3700
- }));
3701
- }
3702
- return state.subscription;
3703
- };
3704
-
3705
- function subscribe(observer) {
3706
- return state.subject.subscribe(observer);
3707
- }
3708
-
3709
- _super.call(this, subscribe);
3710
- }
3711
-
3712
- /**
3713
- * @private
3714
- * @memberOf ConnectableObservable
3715
- */
3716
- ConnectableObservable.prototype.connect = function () { return this.connect(); };
3717
-
3718
- /**
3719
- * @private
3720
- * @memberOf ConnectableObservable
3721
- */
3722
- ConnectableObservable.prototype.refCount = function () {
3723
- var connectableSubscription = null, count = 0, source = this;
3724
- return new AnonymousObservable(function (observer) {
3725
- var shouldConnect, subscription;
3726
- count++;
3727
- shouldConnect = count === 1;
3728
- subscription = source.subscribe(observer);
3729
- if (shouldConnect) {
3730
- connectableSubscription = source.connect();
3731
- }
3732
- return disposableCreate(function () {
3733
- subscription.dispose();
3734
- count--;
3735
- if (count === 0) {
3736
- connectableSubscription.dispose();
3737
- }
3738
- });
3739
- });
3740
- };
3741
-
3742
- return ConnectableObservable;
3743
- }(Observable));
3756
+ /** @private */
3757
+ var ConnectableObservable = Rx.ConnectableObservable = (function (_super) {
3758
+ inherits(ConnectableObservable, _super);
3759
+
3760
+ /**
3761
+ * @constructor
3762
+ * @private
3763
+ */
3764
+ function ConnectableObservable(source, subject) {
3765
+ var state = {
3766
+ subject: subject,
3767
+ source: source.asObservable(),
3768
+ hasSubscription: false,
3769
+ subscription: null
3770
+ };
3771
+
3772
+ this.connect = function () {
3773
+ if (!state.hasSubscription) {
3774
+ state.hasSubscription = true;
3775
+ state.subscription = new CompositeDisposable(state.source.subscribe(state.subject), disposableCreate(function () {
3776
+ state.hasSubscription = false;
3777
+ }));
3778
+ }
3779
+ return state.subscription;
3780
+ };
3781
+
3782
+ function subscribe(observer) {
3783
+ return state.subject.subscribe(observer);
3784
+ }
3785
+
3786
+ _super.call(this, subscribe);
3787
+ }
3788
+
3789
+ /**
3790
+ * @private
3791
+ * @memberOf ConnectableObservable
3792
+ */
3793
+ ConnectableObservable.prototype.connect = function () { return this.connect(); };
3794
+
3795
+ /**
3796
+ * @private
3797
+ * @memberOf ConnectableObservable
3798
+ */
3799
+ ConnectableObservable.prototype.refCount = function () {
3800
+ var connectableSubscription = null, count = 0, source = this;
3801
+ return new AnonymousObservable(function (observer) {
3802
+ var shouldConnect, subscription;
3803
+ count++;
3804
+ shouldConnect = count === 1;
3805
+ subscription = source.subscribe(observer);
3806
+ if (shouldConnect) {
3807
+ connectableSubscription = source.connect();
3808
+ }
3809
+ return disposableCreate(function () {
3810
+ subscription.dispose();
3811
+ count--;
3812
+ if (count === 0) {
3813
+ connectableSubscription.dispose();
3814
+ }
3815
+ });
3816
+ });
3817
+ };
3818
+
3819
+ return ConnectableObservable;
3820
+ }(Observable));
3744
3821
 
3745
3822
  function observableTimerTimeSpan(dueTime, scheduler) {
3746
3823
  var d = normalizeTime(dueTime);
@@ -3996,77 +4073,71 @@
3996
4073
  return sampleObservable(this, intervalOrSampler);
3997
4074
  };
3998
4075
 
3999
- /**
4000
- * Returns the source observable sequence or the other observable sequence if dueTime elapses.
4001
- *
4002
- * @example
4003
- * 1 - res = source.timeout(new Date()); // As a date
4004
- * 2 - res = source.timeout(5000); // 5 seconds
4005
- * 3 - res = source.timeout(new Date(), Rx.Observable.returnValue(42)); // As a date and timeout observable
4006
- * 4 - res = source.timeout(5000, Rx.Observable.returnValue(42)); // 5 seconds and timeout observable
4007
- * 5 - res = source.timeout(new Date(), Rx.Observable.returnValue(42), Rx.Scheduler.timeout); // As a date and timeout observable
4008
- * 6 - res = source.timeout(5000, Rx.Observable.returnValue(42), Rx.Scheduler.timeout); // 5 seconds and timeout observable
4009
- *
4010
- * @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) when a timeout occurs.
4011
- * @param {Observable} [other] Sequence to return in case of a timeout. If not specified, a timeout error throwing sequence will be used.
4012
- * @param {Scheduler} [scheduler] Scheduler to run the timeout timers on. If not specified, the timeout scheduler is used.
4013
- * @returns {Observable} The source sequence switching to the other sequence in case of a timeout.
4014
- */
4015
- observableProto.timeout = function (dueTime, other, scheduler) {
4016
- var schedulerMethod, source = this;
4017
- other || (other = observableThrow(new Error('Timeout')));
4018
- scheduler || (scheduler = timeoutScheduler);
4019
- if (dueTime instanceof Date) {
4020
- schedulerMethod = function (dt, action) {
4021
- scheduler.scheduleWithAbsolute(dt, action);
4022
- };
4023
- } else {
4024
- schedulerMethod = function (dt, action) {
4025
- scheduler.scheduleWithRelative(dt, action);
4026
- };
4076
+ /**
4077
+ * Returns the source observable sequence or the other observable sequence if dueTime elapses.
4078
+ *
4079
+ * @example
4080
+ * 1 - res = source.timeout(new Date()); // As a date
4081
+ * 2 - res = source.timeout(5000); // 5 seconds
4082
+ * 3 - res = source.timeout(new Date(), Rx.Observable.returnValue(42)); // As a date and timeout observable
4083
+ * 4 - res = source.timeout(5000, Rx.Observable.returnValue(42)); // 5 seconds and timeout observable
4084
+ * 5 - res = source.timeout(new Date(), Rx.Observable.returnValue(42), Rx.Scheduler.timeout); // As a date and timeout observable
4085
+ * 6 - res = source.timeout(5000, Rx.Observable.returnValue(42), Rx.Scheduler.timeout); // 5 seconds and timeout observable
4086
+ *
4087
+ * @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) when a timeout occurs.
4088
+ * @param {Observable} [other] Sequence to return in case of a timeout. If not specified, a timeout error throwing sequence will be used.
4089
+ * @param {Scheduler} [scheduler] Scheduler to run the timeout timers on. If not specified, the timeout scheduler is used.
4090
+ * @returns {Observable} The source sequence switching to the other sequence in case of a timeout.
4091
+ */
4092
+ observableProto.timeout = function (dueTime, other, scheduler) {
4093
+ other || (other = observableThrow(new Error('Timeout')));
4094
+ scheduler || (scheduler = timeoutScheduler);
4095
+
4096
+ var source = this, schedulerMethod = dueTime instanceof Date ?
4097
+ 'scheduleWithAbsolute' :
4098
+ 'scheduleWithRelative';
4099
+
4100
+ return new AnonymousObservable(function (observer) {
4101
+ var id = 0,
4102
+ original = new SingleAssignmentDisposable(),
4103
+ subscription = new SerialDisposable(),
4104
+ switched = false,
4105
+ timer = new SerialDisposable();
4106
+
4107
+ subscription.setDisposable(original);
4108
+
4109
+ var createTimer = function () {
4110
+ var myId = id;
4111
+ timer.setDisposable(scheduler[schedulerMethod](dueTime, function () {
4112
+ if (id === myId) {
4113
+ isPromise(other) && (other = observableFromPromise(other));
4114
+ subscription.setDisposable(other.subscribe(observer));
4115
+ }
4116
+ }));
4117
+ };
4118
+
4119
+ createTimer();
4120
+
4121
+ original.setDisposable(source.subscribe(function (x) {
4122
+ if (!switched) {
4123
+ id++;
4124
+ observer.onNext(x);
4125
+ createTimer();
4027
4126
  }
4028
- return new AnonymousObservable(function (observer) {
4029
- var createTimer,
4030
- id = 0,
4031
- original = new SingleAssignmentDisposable(),
4032
- subscription = new SerialDisposable(),
4033
- switched = false,
4034
- timer = new SerialDisposable();
4035
- subscription.setDisposable(original);
4036
- createTimer = function () {
4037
- var myId = id;
4038
- timer.setDisposable(schedulerMethod(dueTime, function () {
4039
- switched = id === myId;
4040
- var timerWins = switched;
4041
- if (timerWins) {
4042
- subscription.setDisposable(other.subscribe(observer));
4043
- }
4044
- }));
4045
- };
4046
- createTimer();
4047
- original.setDisposable(source.subscribe(function (x) {
4048
- var onNextWins = !switched;
4049
- if (onNextWins) {
4050
- id++;
4051
- observer.onNext(x);
4052
- createTimer();
4053
- }
4054
- }, function (e) {
4055
- var onErrorWins = !switched;
4056
- if (onErrorWins) {
4057
- id++;
4058
- observer.onError(e);
4059
- }
4060
- }, function () {
4061
- var onCompletedWins = !switched;
4062
- if (onCompletedWins) {
4063
- id++;
4064
- observer.onCompleted();
4065
- }
4066
- }));
4067
- return new CompositeDisposable(subscription, timer);
4068
- });
4069
- };
4127
+ }, function (e) {
4128
+ if (!switched) {
4129
+ id++;
4130
+ observer.onError(e);
4131
+ }
4132
+ }, function () {
4133
+ if (!switched) {
4134
+ id++;
4135
+ observer.onCompleted();
4136
+ }
4137
+ }));
4138
+ return new CompositeDisposable(subscription, timer);
4139
+ });
4140
+ };
4070
4141
 
4071
4142
  /**
4072
4143
  * Generates an observable sequence by iterating a state from an initial state until the condition fails.
@@ -4489,50 +4560,55 @@
4489
4560
  });
4490
4561
  };
4491
4562
 
4492
- /**
4493
- * Skips elements from the observable source sequence until the specified start time, using the specified scheduler to run timers.
4494
- * Errors produced by the source sequence are always forwarded to the result sequence, even if the error occurs before the start time>.
4495
- *
4496
- * @examples
4497
- * 1 - res = source.skipUntilWithTime(new Date(), [optional scheduler]);
4498
- * @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.
4499
- * @param scheduler Scheduler to run the timer on. If not specified, defaults to Rx.Scheduler.timeout.
4500
- * @returns {Observable} An observable sequence with the elements skipped until the specified start time.
4501
- */
4502
- observableProto.skipUntilWithTime = function (startTime, scheduler) {
4503
- scheduler || (scheduler = timeoutScheduler);
4504
- var source = this;
4505
- return new AnonymousObservable(function (observer) {
4506
- var open = false,
4507
- t = scheduler.scheduleWithAbsolute(startTime, function () { open = true; }),
4508
- d = source.subscribe(function (x) {
4509
- if (open) {
4510
- observer.onNext(x);
4511
- }
4512
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4563
+ /**
4564
+ * Skips elements from the observable source sequence until the specified start time, using the specified scheduler to run timers.
4565
+ * Errors produced by the source sequence are always forwarded to the result sequence, even if the error occurs before the start time.
4566
+ *
4567
+ * @examples
4568
+ * 1 - res = source.skipUntilWithTime(new Date(), [optional scheduler]);
4569
+ * 2 - res = source.skipUntilWithTime(5000, [optional scheduler]);
4570
+ * @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.
4571
+ * @param scheduler Scheduler to run the timer on. If not specified, defaults to Rx.Scheduler.timeout.
4572
+ * @returns {Observable} An observable sequence with the elements skipped until the specified start time.
4573
+ */
4574
+ observableProto.skipUntilWithTime = function (startTime, scheduler) {
4575
+ scheduler || (scheduler = timeoutScheduler);
4576
+ var source = this, schedulerMethod = startTime instanceof Date ?
4577
+ 'scheduleWithAbsolute' :
4578
+ 'scheduleWithRelative';
4579
+ return new AnonymousObservable(function (observer) {
4580
+ var open = false;
4513
4581
 
4514
- return new CompositeDisposable(t, d);
4515
- });
4516
- };
4582
+ return new CompositeDisposable(
4583
+ scheduler[schedulerMethod](startTime, function () { open = true; }),
4584
+ source.subscribe(
4585
+ function (x) { open && observer.onNext(x); },
4586
+ observer.onError.bind(observer),
4587
+ observer.onCompleted.bind(observer)));
4588
+ });
4589
+ };
4517
4590
 
4518
- /**
4519
- * Takes elements for the specified duration until the specified end time, using the specified scheduler to run timers.
4520
- *
4521
- * @example
4522
- * 1 - res = source.takeUntilWithTime(new Date(), [optional scheduler]);
4523
- * @param {Number} 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.
4524
- * @param {Scheduler} scheduler Scheduler to run the timer on.
4525
- * @returns {Observable} An observable sequence with the elements taken until the specified end time.
4526
- */
4527
- observableProto.takeUntilWithTime = function (endTime, scheduler) {
4528
- scheduler || (scheduler = timeoutScheduler);
4529
- var source = this;
4530
- return new AnonymousObservable(function (observer) {
4531
- return new CompositeDisposable(scheduler.scheduleWithAbsolute(endTime, function () {
4532
- observer.onCompleted();
4533
- }), source.subscribe(observer));
4534
- });
4535
- };
4591
+ /**
4592
+ * Takes elements for the specified duration until the specified end time, using the specified scheduler to run timers.
4593
+ *
4594
+ * @example
4595
+ * 1 - res = source.takeUntilWithTime(new Date(), [optional scheduler]);
4596
+ * 2 - res = source.takeUntilWithTime(5000, [optional scheduler]);
4597
+ * @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.
4598
+ * @param {Scheduler} scheduler Scheduler to run the timer on.
4599
+ * @returns {Observable} An observable sequence with the elements taken until the specified end time.
4600
+ */
4601
+ observableProto.takeUntilWithTime = function (endTime, scheduler) {
4602
+ scheduler || (scheduler = timeoutScheduler);
4603
+ var source = this, schedulerMethod = endTime instanceof Date ?
4604
+ 'scheduleWithAbsolute' :
4605
+ 'scheduleWithRelative';
4606
+ return new AnonymousObservable(function (observer) {
4607
+ return new CompositeDisposable(scheduler[schedulerMethod](endTime, function () {
4608
+ observer.onCompleted();
4609
+ }), source.subscribe(observer));
4610
+ });
4611
+ };
4536
4612
 
4537
4613
  var PausableObservable = (function (_super) {
4538
4614
 
@@ -4606,15 +4682,15 @@
4606
4682
  var res;
4607
4683
  hasValue[i] = true;
4608
4684
  if (hasValueAll || (hasValueAll = hasValue.every(identity))) {
4609
- try {
4610
- res = resultSelector.apply(null, values);
4611
- } catch (ex) {
4612
- observer.onError(ex);
4613
- return;
4614
- }
4615
- observer.onNext(res);
4685
+ try {
4686
+ res = resultSelector.apply(null, values);
4687
+ } catch (ex) {
4688
+ observer.onError(ex);
4689
+ return;
4690
+ }
4691
+ observer.onNext(res);
4616
4692
  } else if (isDone) {
4617
- observer.onCompleted();
4693
+ observer.onCompleted();
4618
4694
  }
4619
4695
  }
4620
4696
 
@@ -4668,8 +4744,20 @@
4668
4744
  }
4669
4745
 
4670
4746
  },
4671
- observer.onError.bind(observer),
4672
- observer.onCompleted.bind(observer)
4747
+ function (err) {
4748
+ // Empty buffer before sending error
4749
+ while (q.length > 0) {
4750
+ observer.onNext(q.shift());
4751
+ }
4752
+ observer.onError(err);
4753
+ },
4754
+ function () {
4755
+ // Empty buffer before sending completion
4756
+ while (q.length > 0) {
4757
+ observer.onNext(q.shift());
4758
+ }
4759
+ observer.onCompleted();
4760
+ }
4673
4761
  );
4674
4762
 
4675
4763
  this.subject.onNext(false);
@@ -4878,56 +4966,100 @@
4878
4966
 
4879
4967
  return ControlledSubject;
4880
4968
  }(Observable));
4881
- var AnonymousObservable = Rx.AnonymousObservable = (function (_super) {
4882
- inherits(AnonymousObservable, _super);
4883
-
4884
- // Fix subscriber to check for undefined or function returned to decorate as Disposable
4885
- function fixSubscriber(subscriber) {
4886
- if (typeof subscriber === 'undefined') {
4887
- subscriber = disposableEmpty;
4888
- } else if (typeof subscriber === 'function') {
4889
- subscriber = disposableCreate(subscriber);
4890
- }
4969
+ /**
4970
+ * Returns a new observable that triggers on the second and subsequent triggerings of the input observable.
4971
+ * The Nth triggering of the input observable passes the arguments from the N-1th and Nth triggering as a pair.
4972
+ * The argument passed to the N-1th triggering is held in hidden internal state until the Nth triggering occurs.
4973
+ * @returns {Observable} An observable that triggers on successive pairs of observations from the input observable as an array.
4974
+ */
4975
+ observableProto.pairwise = function () {
4976
+ var source = this;
4977
+ return new AnonymousObservable(function (observer) {
4978
+ var previous, hasPrevious = false;
4979
+ return source.subscribe(
4980
+ function (x) {
4981
+ if (hasPrevious) {
4982
+ observer.onNext([previous, x]);
4983
+ } else {
4984
+ hasPrevious = true;
4985
+ }
4986
+ previous = x;
4987
+ },
4988
+ observer.onError.bind(observer),
4989
+ observer.onCompleted.bind(observer));
4990
+ });
4991
+ };
4992
+ /**
4993
+ * Returns two observables which partition the observations of the source by the given function.
4994
+ * The first will trigger observations for those values for which the predicate returns true.
4995
+ * The second will trigger observations for those values where the predicate returns false.
4996
+ * The predicate is executed once for each subscribed observer.
4997
+ * Both also propagate all error observations arising from the source and each completes
4998
+ * when the source completes.
4999
+ * @param {Function} predicate
5000
+ * The function to determine which output Observable will trigger a particular observation.
5001
+ * @returns {Array}
5002
+ * An array of observables. The first triggers when the predicate returns true,
5003
+ * and the second triggers when the predicate returns false.
5004
+ */
5005
+ observableProto.partition = function(predicate, thisArg) {
5006
+ var published = this.publish().refCount();
5007
+ return [
5008
+ published.filter(predicate, thisArg),
5009
+ published.filter(function (x, i, o) { return !predicate.call(thisArg, x, i, o); })
5010
+ ];
5011
+ };
4891
5012
 
4892
- return subscriber;
4893
- }
5013
+ var AnonymousObservable = Rx.AnonymousObservable = (function (__super__) {
5014
+ inherits(AnonymousObservable, __super__);
4894
5015
 
4895
- function AnonymousObservable(subscribe) {
4896
- if (!(this instanceof AnonymousObservable)) {
4897
- return new AnonymousObservable(subscribe);
4898
- }
5016
+ // Fix subscriber to check for undefined or function returned to decorate as Disposable
5017
+ function fixSubscriber(subscriber) {
5018
+ if (typeof subscriber === 'undefined') {
5019
+ subscriber = disposableEmpty;
5020
+ } else if (typeof subscriber === 'function') {
5021
+ subscriber = disposableCreate(subscriber);
5022
+ }
4899
5023
 
4900
- function s(observer) {
4901
- var autoDetachObserver = new AutoDetachObserver(observer);
4902
- if (currentThreadScheduler.scheduleRequired()) {
4903
- currentThreadScheduler.schedule(function () {
4904
- try {
4905
- autoDetachObserver.setDisposable(fixSubscriber(subscribe(autoDetachObserver)));
4906
- } catch (e) {
4907
- if (!autoDetachObserver.fail(e)) {
4908
- throw e;
4909
- }
4910
- }
4911
- });
4912
- } else {
4913
- try {
4914
- autoDetachObserver.setDisposable(fixSubscriber(subscribe(autoDetachObserver)));
4915
- } catch (e) {
4916
- if (!autoDetachObserver.fail(e)) {
4917
- throw e;
4918
- }
4919
- }
4920
- }
5024
+ return subscriber;
5025
+ }
4921
5026
 
4922
- return autoDetachObserver;
4923
- }
5027
+ function AnonymousObservable(subscribe) {
5028
+ if (!(this instanceof AnonymousObservable)) {
5029
+ return new AnonymousObservable(subscribe);
5030
+ }
4924
5031
 
4925
- _super.call(this, s);
5032
+ function s(observer) {
5033
+ var autoDetachObserver = new AutoDetachObserver(observer);
5034
+ if (currentThreadScheduler.scheduleRequired()) {
5035
+ currentThreadScheduler.schedule(function () {
5036
+ try {
5037
+ autoDetachObserver.setDisposable(fixSubscriber(subscribe(autoDetachObserver)));
5038
+ } catch (e) {
5039
+ if (!autoDetachObserver.fail(e)) {
5040
+ throw e;
5041
+ }
5042
+ }
5043
+ });
5044
+ } else {
5045
+ try {
5046
+ autoDetachObserver.setDisposable(fixSubscriber(subscribe(autoDetachObserver)));
5047
+ } catch (e) {
5048
+ if (!autoDetachObserver.fail(e)) {
5049
+ throw e;
5050
+ }
5051
+ }
4926
5052
  }
4927
5053
 
4928
- return AnonymousObservable;
5054
+ return autoDetachObserver;
5055
+ }
5056
+
5057
+ __super__.call(this, s);
5058
+ }
5059
+
5060
+ return AnonymousObservable;
4929
5061
 
4930
- }(Observable));
5062
+ }(Observable));
4931
5063
 
4932
5064
  /** @private */
4933
5065
  var AutoDetachObserver = (function (_super) {
@@ -4990,23 +5122,23 @@
4990
5122
  return AutoDetachObserver;
4991
5123
  }(AbstractObserver));
4992
5124
 
4993
- /** @private */
4994
- var InnerSubscription = function (subject, observer) {
4995
- this.subject = subject;
4996
- this.observer = observer;
4997
- };
4998
-
4999
- /**
5000
- * @private
5001
- * @memberOf InnerSubscription
5002
- */
5003
- InnerSubscription.prototype.dispose = function () {
5004
- if (!this.subject.isDisposed && this.observer !== null) {
5005
- var idx = this.subject.observers.indexOf(this.observer);
5006
- this.subject.observers.splice(idx, 1);
5007
- this.observer = null;
5008
- }
5009
- };
5125
+ /** @private */
5126
+ var InnerSubscription = function (subject, observer) {
5127
+ this.subject = subject;
5128
+ this.observer = observer;
5129
+ };
5130
+
5131
+ /**
5132
+ * @private
5133
+ * @memberOf InnerSubscription
5134
+ */
5135
+ InnerSubscription.prototype.dispose = function () {
5136
+ if (!this.subject.isDisposed && this.observer !== null) {
5137
+ var idx = this.subject.observers.indexOf(this.observer);
5138
+ this.subject.observers.splice(idx, 1);
5139
+ this.observer = null;
5140
+ }
5141
+ };
5010
5142
 
5011
5143
  /**
5012
5144
  * Represents an object that is both an observable sequence as well as an observer.
@@ -5241,50 +5373,50 @@
5241
5373
  return AsyncSubject;
5242
5374
  }(Observable));
5243
5375
 
5244
- /** @private */
5245
- var AnonymousSubject = (function (_super) {
5246
- inherits(AnonymousSubject, _super);
5247
-
5248
- function subscribe(observer) {
5249
- return this.observable.subscribe(observer);
5250
- }
5251
-
5252
- /**
5253
- * @private
5254
- * @constructor
5255
- */
5256
- function AnonymousSubject(observer, observable) {
5257
- _super.call(this, subscribe);
5258
- this.observer = observer;
5259
- this.observable = observable;
5260
- }
5261
-
5262
- addProperties(AnonymousSubject.prototype, Observer, {
5263
- /**
5264
- * @private
5265
- * @memberOf AnonymousSubject#
5266
- */
5267
- onCompleted: function () {
5268
- this.observer.onCompleted();
5269
- },
5270
- /**
5271
- * @private
5272
- * @memberOf AnonymousSubject#
5273
- */
5274
- onError: function (exception) {
5275
- this.observer.onError(exception);
5276
- },
5277
- /**
5278
- * @private
5279
- * @memberOf AnonymousSubject#
5280
- */
5281
- onNext: function (value) {
5282
- this.observer.onNext(value);
5283
- }
5284
- });
5285
-
5286
- return AnonymousSubject;
5287
- }(Observable));
5376
+ /** @private */
5377
+ var AnonymousSubject = (function (_super) {
5378
+ inherits(AnonymousSubject, _super);
5379
+
5380
+ function subscribe(observer) {
5381
+ return this.observable.subscribe(observer);
5382
+ }
5383
+
5384
+ /**
5385
+ * @private
5386
+ * @constructor
5387
+ */
5388
+ function AnonymousSubject(observer, observable) {
5389
+ _super.call(this, subscribe);
5390
+ this.observer = observer;
5391
+ this.observable = observable;
5392
+ }
5393
+
5394
+ addProperties(AnonymousSubject.prototype, Observer, {
5395
+ /**
5396
+ * @private
5397
+ * @memberOf AnonymousSubject#
5398
+ */
5399
+ onCompleted: function () {
5400
+ this.observer.onCompleted();
5401
+ },
5402
+ /**
5403
+ * @private
5404
+ * @memberOf AnonymousSubject#
5405
+ */
5406
+ onError: function (exception) {
5407
+ this.observer.onError(exception);
5408
+ },
5409
+ /**
5410
+ * @private
5411
+ * @memberOf AnonymousSubject#
5412
+ */
5413
+ onNext: function (value) {
5414
+ this.observer.onNext(value);
5415
+ }
5416
+ });
5417
+
5418
+ return AnonymousSubject;
5419
+ }(Observable));
5288
5420
 
5289
5421
  /**
5290
5422
  * Represents a value that changes over time.
@@ -5548,21 +5680,21 @@
5548
5680
  return ReplaySubject;
5549
5681
  }(Observable));
5550
5682
 
5551
- if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
5552
- root.Rx = Rx;
5553
-
5554
- define(function() {
5555
- return Rx;
5556
- });
5557
- } else if (freeExports && freeModule) {
5558
- // in Node.js or RingoJS
5559
- if (moduleExports) {
5560
- (freeModule.exports = Rx).Rx = Rx;
5561
- } else {
5562
- freeExports.Rx = Rx;
5563
- }
5564
- } else {
5565
- // in a browser or Rhino
5566
- root.Rx = Rx;
5683
+ if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
5684
+ root.Rx = Rx;
5685
+
5686
+ define(function() {
5687
+ return Rx;
5688
+ });
5689
+ } else if (freeExports && freeModule) {
5690
+ // in Node.js or RingoJS
5691
+ if (moduleExports) {
5692
+ (freeModule.exports = Rx).Rx = Rx;
5693
+ } else {
5694
+ freeExports.Rx = Rx;
5695
+ }
5696
+ } else {
5697
+ // in a browser or Rhino
5698
+ root.Rx = Rx;
5567
5699
  }
5568
5700
  }.call(this));