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
@@ -510,100 +510,100 @@
510
510
  };
511
511
  }
512
512
 
513
- // Collections
514
- var IndexedItem = function (id, value) {
515
- this.id = id;
516
- this.value = value;
517
- };
518
-
519
- IndexedItem.prototype.compareTo = function (other) {
520
- var c = this.value.compareTo(other.value);
521
- if (c === 0) {
522
- c = this.id - other.id;
523
- }
524
- return c;
525
- };
526
-
527
- // Priority Queue for Scheduling
528
- var PriorityQueue = Rx.internals.PriorityQueue = function (capacity) {
529
- this.items = new Array(capacity);
530
- this.length = 0;
531
- };
532
-
533
- var priorityProto = PriorityQueue.prototype;
534
- priorityProto.isHigherPriority = function (left, right) {
535
- return this.items[left].compareTo(this.items[right]) < 0;
536
- };
537
-
538
- priorityProto.percolate = function (index) {
539
- if (index >= this.length || index < 0) {
540
- return;
541
- }
542
- var parent = index - 1 >> 1;
543
- if (parent < 0 || parent === index) {
544
- return;
545
- }
546
- if (this.isHigherPriority(index, parent)) {
547
- var temp = this.items[index];
548
- this.items[index] = this.items[parent];
549
- this.items[parent] = temp;
550
- this.percolate(parent);
551
- }
552
- };
553
-
554
- priorityProto.heapify = function (index) {
555
- if (index === undefined) {
556
- index = 0;
557
- }
558
- if (index >= this.length || index < 0) {
559
- return;
560
- }
561
- var left = 2 * index + 1,
562
- right = 2 * index + 2,
563
- first = index;
564
- if (left < this.length && this.isHigherPriority(left, first)) {
565
- first = left;
566
- }
567
- if (right < this.length && this.isHigherPriority(right, first)) {
568
- first = right;
569
- }
570
- if (first !== index) {
571
- var temp = this.items[index];
572
- this.items[index] = this.items[first];
573
- this.items[first] = temp;
574
- this.heapify(first);
575
- }
576
- };
577
-
578
- priorityProto.peek = function () { return this.items[0].value; };
579
-
580
- priorityProto.removeAt = function (index) {
581
- this.items[index] = this.items[--this.length];
582
- delete this.items[this.length];
583
- this.heapify();
584
- };
585
-
586
- priorityProto.dequeue = function () {
587
- var result = this.peek();
588
- this.removeAt(0);
589
- return result;
590
- };
591
-
592
- priorityProto.enqueue = function (item) {
593
- var index = this.length++;
594
- this.items[index] = new IndexedItem(PriorityQueue.count++, item);
595
- this.percolate(index);
596
- };
597
-
598
- priorityProto.remove = function (item) {
599
- for (var i = 0; i < this.length; i++) {
600
- if (this.items[i].value === item) {
601
- this.removeAt(i);
602
- return true;
603
- }
604
- }
605
- return false;
606
- };
513
+ // Collections
514
+ var IndexedItem = function (id, value) {
515
+ this.id = id;
516
+ this.value = value;
517
+ };
518
+
519
+ IndexedItem.prototype.compareTo = function (other) {
520
+ var c = this.value.compareTo(other.value);
521
+ if (c === 0) {
522
+ c = this.id - other.id;
523
+ }
524
+ return c;
525
+ };
526
+
527
+ // Priority Queue for Scheduling
528
+ var PriorityQueue = Rx.internals.PriorityQueue = function (capacity) {
529
+ this.items = new Array(capacity);
530
+ this.length = 0;
531
+ };
532
+
533
+ var priorityProto = PriorityQueue.prototype;
534
+ priorityProto.isHigherPriority = function (left, right) {
535
+ return this.items[left].compareTo(this.items[right]) < 0;
536
+ };
537
+
538
+ priorityProto.percolate = function (index) {
539
+ if (index >= this.length || index < 0) {
540
+ return;
541
+ }
542
+ var parent = index - 1 >> 1;
543
+ if (parent < 0 || parent === index) {
544
+ return;
545
+ }
546
+ if (this.isHigherPriority(index, parent)) {
547
+ var temp = this.items[index];
548
+ this.items[index] = this.items[parent];
549
+ this.items[parent] = temp;
550
+ this.percolate(parent);
551
+ }
552
+ };
553
+
554
+ priorityProto.heapify = function (index) {
555
+ if (index === undefined) {
556
+ index = 0;
557
+ }
558
+ if (index >= this.length || index < 0) {
559
+ return;
560
+ }
561
+ var left = 2 * index + 1,
562
+ right = 2 * index + 2,
563
+ first = index;
564
+ if (left < this.length && this.isHigherPriority(left, first)) {
565
+ first = left;
566
+ }
567
+ if (right < this.length && this.isHigherPriority(right, first)) {
568
+ first = right;
569
+ }
570
+ if (first !== index) {
571
+ var temp = this.items[index];
572
+ this.items[index] = this.items[first];
573
+ this.items[first] = temp;
574
+ this.heapify(first);
575
+ }
576
+ };
577
+
578
+ priorityProto.peek = function () { return this.items[0].value; };
579
+
580
+ priorityProto.removeAt = function (index) {
581
+ this.items[index] = this.items[--this.length];
582
+ delete this.items[this.length];
583
+ this.heapify();
584
+ };
585
+
586
+ priorityProto.dequeue = function () {
587
+ var result = this.peek();
588
+ this.removeAt(0);
589
+ return result;
590
+ };
591
+
592
+ priorityProto.enqueue = function (item) {
593
+ var index = this.length++;
594
+ this.items[index] = new IndexedItem(PriorityQueue.count++, item);
595
+ this.percolate(index);
596
+ };
597
+
598
+ priorityProto.remove = function (item) {
599
+ for (var i = 0; i < this.length; i++) {
600
+ if (this.items[i].value === item) {
601
+ this.removeAt(i);
602
+ return true;
603
+ }
604
+ }
605
+ return false;
606
+ };
607
607
  PriorityQueue.count = 0;
608
608
  /**
609
609
  * Represents a group of disposable resources that are disposed together.
@@ -872,30 +872,30 @@
872
872
  return RefCountDisposable;
873
873
  })();
874
874
 
875
- var ScheduledItem = Rx.internals.ScheduledItem = function (scheduler, state, action, dueTime, comparer) {
876
- this.scheduler = scheduler;
877
- this.state = state;
878
- this.action = action;
879
- this.dueTime = dueTime;
880
- this.comparer = comparer || defaultSubComparer;
881
- this.disposable = new SingleAssignmentDisposable();
882
- }
883
-
884
- ScheduledItem.prototype.invoke = function () {
885
- this.disposable.setDisposable(this.invokeCore());
886
- };
887
-
888
- ScheduledItem.prototype.compareTo = function (other) {
889
- return this.comparer(this.dueTime, other.dueTime);
890
- };
891
-
892
- ScheduledItem.prototype.isCancelled = function () {
893
- return this.disposable.isDisposed;
894
- };
895
-
896
- ScheduledItem.prototype.invokeCore = function () {
897
- return this.action(this.scheduler, this.state);
898
- };
875
+ var ScheduledItem = Rx.internals.ScheduledItem = function (scheduler, state, action, dueTime, comparer) {
876
+ this.scheduler = scheduler;
877
+ this.state = state;
878
+ this.action = action;
879
+ this.dueTime = dueTime;
880
+ this.comparer = comparer || defaultSubComparer;
881
+ this.disposable = new SingleAssignmentDisposable();
882
+ }
883
+
884
+ ScheduledItem.prototype.invoke = function () {
885
+ this.disposable.setDisposable(this.invokeCore());
886
+ };
887
+
888
+ ScheduledItem.prototype.compareTo = function (other) {
889
+ return this.comparer(this.dueTime, other.dueTime);
890
+ };
891
+
892
+ ScheduledItem.prototype.isCancelled = function () {
893
+ return this.disposable.isDisposed;
894
+ };
895
+
896
+ ScheduledItem.prototype.invokeCore = function () {
897
+ return this.action(this.scheduler, this.state);
898
+ };
899
899
 
900
900
  /** Provides a set of static properties to access commonly used schedulers. */
901
901
  var Scheduler = Rx.Scheduler = (function () {
@@ -1150,25 +1150,25 @@
1150
1150
 
1151
1151
  var normalizeTime = Scheduler.normalize;
1152
1152
 
1153
- /**
1154
- * Gets a scheduler that schedules work immediately on the current thread.
1155
- */
1156
- var immediateScheduler = Scheduler.immediate = (function () {
1157
-
1158
- function scheduleNow(state, action) { return action(this, state); }
1159
-
1160
- function scheduleRelative(state, dueTime, action) {
1161
- var dt = normalizeTime(dt);
1162
- while (dt - this.now() > 0) { }
1163
- return action(this, state);
1164
- }
1165
-
1166
- function scheduleAbsolute(state, dueTime, action) {
1167
- return this.scheduleWithRelativeAndState(state, dueTime - this.now(), action);
1168
- }
1169
-
1170
- return new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
1171
- }());
1153
+ /**
1154
+ * Gets a scheduler that schedules work immediately on the current thread.
1155
+ */
1156
+ var immediateScheduler = Scheduler.immediate = (function () {
1157
+
1158
+ function scheduleNow(state, action) { return action(this, state); }
1159
+
1160
+ function scheduleRelative(state, dueTime, action) {
1161
+ var dt = normalizeTime(dt);
1162
+ while (dt - this.now() > 0) { }
1163
+ return action(this, state);
1164
+ }
1165
+
1166
+ function scheduleAbsolute(state, dueTime, action) {
1167
+ return this.scheduleWithRelativeAndState(state, dueTime - this.now(), action);
1168
+ }
1169
+
1170
+ return new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
1171
+ }());
1172
1172
 
1173
1173
  /**
1174
1174
  * Gets a scheduler that schedules work as soon as possible on the current thread.
@@ -1232,34 +1232,34 @@
1232
1232
  return currentScheduler;
1233
1233
  }());
1234
1234
 
1235
- var SchedulePeriodicRecursive = Rx.internals.SchedulePeriodicRecursive = (function () {
1236
- function tick(command, recurse) {
1237
- recurse(0, this._period);
1238
- try {
1239
- this._state = this._action(this._state);
1240
- } catch (e) {
1241
- this._cancel.dispose();
1242
- throw e;
1243
- }
1244
- }
1245
-
1246
- function SchedulePeriodicRecursive(scheduler, state, period, action) {
1247
- this._scheduler = scheduler;
1248
- this._state = state;
1249
- this._period = period;
1250
- this._action = action;
1251
- }
1252
-
1253
- SchedulePeriodicRecursive.prototype.start = function () {
1254
- var d = new SingleAssignmentDisposable();
1255
- this._cancel = d;
1256
- d.setDisposable(this._scheduler.scheduleRecursiveWithRelativeAndState(0, this._period, tick.bind(this)));
1257
-
1258
- return d;
1259
- };
1260
-
1261
- return SchedulePeriodicRecursive;
1262
- }());
1235
+ var SchedulePeriodicRecursive = Rx.internals.SchedulePeriodicRecursive = (function () {
1236
+ function tick(command, recurse) {
1237
+ recurse(0, this._period);
1238
+ try {
1239
+ this._state = this._action(this._state);
1240
+ } catch (e) {
1241
+ this._cancel.dispose();
1242
+ throw e;
1243
+ }
1244
+ }
1245
+
1246
+ function SchedulePeriodicRecursive(scheduler, state, period, action) {
1247
+ this._scheduler = scheduler;
1248
+ this._state = state;
1249
+ this._period = period;
1250
+ this._action = action;
1251
+ }
1252
+
1253
+ SchedulePeriodicRecursive.prototype.start = function () {
1254
+ var d = new SingleAssignmentDisposable();
1255
+ this._cancel = d;
1256
+ d.setDisposable(this._scheduler.scheduleRecursiveWithRelativeAndState(0, this._period, tick.bind(this)));
1257
+
1258
+ return d;
1259
+ };
1260
+
1261
+ return SchedulePeriodicRecursive;
1262
+ }());
1263
1263
 
1264
1264
 
1265
1265
  var scheduleMethod, clearMethod = noop;
@@ -1534,151 +1534,150 @@
1534
1534
  };
1535
1535
  }());
1536
1536
 
1537
- var Enumerator = Rx.internals.Enumerator = function (next) {
1538
- this._next = next;
1539
- };
1540
-
1541
- Enumerator.prototype.next = function () {
1542
- return this._next();
1543
- };
1544
-
1545
- Enumerator.prototype[$iterator$] = function () { return this; }
1546
-
1547
- var Enumerable = Rx.internals.Enumerable = function (iterator) {
1548
- this._iterator = iterator;
1549
- };
1550
-
1551
- Enumerable.prototype[$iterator$] = function () {
1552
- return this._iterator();
1553
- };
1554
-
1555
- Enumerable.prototype.concat = function () {
1556
- var sources = this;
1557
- return new AnonymousObservable(function (observer) {
1558
- var e;
1559
- try {
1560
- e = sources[$iterator$]();
1561
- } catch(err) {
1562
- observer.onError();
1563
- return;
1564
- }
1565
-
1566
- var isDisposed,
1567
- subscription = new SerialDisposable();
1568
- var cancelable = immediateScheduler.scheduleRecursive(function (self) {
1569
- var currentItem;
1570
- if (isDisposed) { return; }
1571
-
1572
- try {
1573
- currentItem = e.next();
1574
- } catch (ex) {
1575
- observer.onError(ex);
1576
- return;
1577
- }
1578
-
1579
- if (currentItem.done) {
1580
- observer.onCompleted();
1581
- return;
1582
- }
1583
-
1584
- // Check if promise
1585
- var currentValue = currentItem.value;
1586
- isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
1587
-
1588
- var d = new SingleAssignmentDisposable();
1589
- subscription.setDisposable(d);
1590
- d.setDisposable(currentValue.subscribe(
1591
- observer.onNext.bind(observer),
1592
- observer.onError.bind(observer),
1593
- function () { self(); })
1594
- );
1595
- });
1596
-
1597
- return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
1598
- isDisposed = true;
1599
- }));
1600
- });
1601
- };
1602
-
1603
- Enumerable.prototype.catchException = function () {
1604
- var sources = this;
1605
- return new AnonymousObservable(function (observer) {
1606
- var e;
1607
- try {
1608
- e = sources[$iterator$]();
1609
- } catch(err) {
1610
- observer.onError();
1611
- return;
1612
- }
1613
-
1614
- var isDisposed,
1615
- lastException,
1616
- subscription = new SerialDisposable();
1617
- var cancelable = immediateScheduler.scheduleRecursive(function (self) {
1618
- if (isDisposed) { return; }
1619
-
1620
- var currentItem;
1621
- try {
1622
- currentItem = e.next();
1623
- } catch (ex) {
1624
- observer.onError(ex);
1625
- return;
1626
- }
1627
-
1628
- if (currentItem.done) {
1629
- if (lastException) {
1630
- observer.onError(lastException);
1631
- } else {
1632
- observer.onCompleted();
1633
- }
1634
- return;
1635
- }
1636
-
1637
- // Check if promise
1638
- var currentValue = currentItem.value;
1639
- isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
1640
-
1641
- var d = new SingleAssignmentDisposable();
1642
- subscription.setDisposable(d);
1643
- d.setDisposable(currentValue.subscribe(
1644
- observer.onNext.bind(observer),
1645
- function (exn) {
1646
- lastException = exn;
1647
- self();
1648
- },
1649
- observer.onCompleted.bind(observer)));
1650
- });
1651
- return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
1652
- isDisposed = true;
1653
- }));
1654
- });
1655
- };
1656
-
1657
-
1658
- var enumerableRepeat = Enumerable.repeat = function (value, repeatCount) {
1659
- if (repeatCount == null) { repeatCount = -1; }
1660
- return new Enumerable(function () {
1661
- var left = repeatCount;
1662
- return new Enumerator(function () {
1663
- if (left === 0) { return doneEnumerator; }
1664
- if (left > 0) { left--; }
1665
- return { done: false, value: value };
1666
- });
1667
- });
1668
- };
1669
-
1670
- var enumerableFor = Enumerable.forEach = function (source, selector, thisArg) {
1671
- selector || (selector = identity);
1672
- return new Enumerable(function () {
1673
- var index = -1;
1674
- return new Enumerator(
1675
- function () {
1676
- return ++index < source.length ?
1677
- { done: false, value: selector.call(thisArg, source[index], index, source) } :
1678
- doneEnumerator;
1679
- });
1680
- });
1681
- };
1537
+ var Enumerator = Rx.internals.Enumerator = function (next) {
1538
+ this._next = next;
1539
+ };
1540
+
1541
+ Enumerator.prototype.next = function () {
1542
+ return this._next();
1543
+ };
1544
+
1545
+ Enumerator.prototype[$iterator$] = function () { return this; }
1546
+
1547
+ var Enumerable = Rx.internals.Enumerable = function (iterator) {
1548
+ this._iterator = iterator;
1549
+ };
1550
+
1551
+ Enumerable.prototype[$iterator$] = function () {
1552
+ return this._iterator();
1553
+ };
1554
+
1555
+ Enumerable.prototype.concat = function () {
1556
+ var sources = this;
1557
+ return new AnonymousObservable(function (observer) {
1558
+ var e;
1559
+ try {
1560
+ e = sources[$iterator$]();
1561
+ } catch(err) {
1562
+ observer.onError();
1563
+ return;
1564
+ }
1565
+
1566
+ var isDisposed,
1567
+ subscription = new SerialDisposable();
1568
+ var cancelable = immediateScheduler.scheduleRecursive(function (self) {
1569
+ var currentItem;
1570
+ if (isDisposed) { return; }
1571
+
1572
+ try {
1573
+ currentItem = e.next();
1574
+ } catch (ex) {
1575
+ observer.onError(ex);
1576
+ return;
1577
+ }
1578
+
1579
+ if (currentItem.done) {
1580
+ observer.onCompleted();
1581
+ return;
1582
+ }
1583
+
1584
+ // Check if promise
1585
+ var currentValue = currentItem.value;
1586
+ isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
1587
+
1588
+ var d = new SingleAssignmentDisposable();
1589
+ subscription.setDisposable(d);
1590
+ d.setDisposable(currentValue.subscribe(
1591
+ observer.onNext.bind(observer),
1592
+ observer.onError.bind(observer),
1593
+ function () { self(); })
1594
+ );
1595
+ });
1596
+
1597
+ return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
1598
+ isDisposed = true;
1599
+ }));
1600
+ });
1601
+ };
1602
+
1603
+ Enumerable.prototype.catchException = function () {
1604
+ var sources = this;
1605
+ return new AnonymousObservable(function (observer) {
1606
+ var e;
1607
+ try {
1608
+ e = sources[$iterator$]();
1609
+ } catch(err) {
1610
+ observer.onError();
1611
+ return;
1612
+ }
1613
+
1614
+ var isDisposed,
1615
+ lastException,
1616
+ subscription = new SerialDisposable();
1617
+ var cancelable = immediateScheduler.scheduleRecursive(function (self) {
1618
+ if (isDisposed) { return; }
1619
+
1620
+ var currentItem;
1621
+ try {
1622
+ currentItem = e.next();
1623
+ } catch (ex) {
1624
+ observer.onError(ex);
1625
+ return;
1626
+ }
1627
+
1628
+ if (currentItem.done) {
1629
+ if (lastException) {
1630
+ observer.onError(lastException);
1631
+ } else {
1632
+ observer.onCompleted();
1633
+ }
1634
+ return;
1635
+ }
1636
+
1637
+ // Check if promise
1638
+ var currentValue = currentItem.value;
1639
+ isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
1640
+
1641
+ var d = new SingleAssignmentDisposable();
1642
+ subscription.setDisposable(d);
1643
+ d.setDisposable(currentValue.subscribe(
1644
+ observer.onNext.bind(observer),
1645
+ function (exn) {
1646
+ lastException = exn;
1647
+ self();
1648
+ },
1649
+ observer.onCompleted.bind(observer)));
1650
+ });
1651
+ return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
1652
+ isDisposed = true;
1653
+ }));
1654
+ });
1655
+ };
1656
+
1657
+ var enumerableRepeat = Enumerable.repeat = function (value, repeatCount) {
1658
+ if (repeatCount == null) { repeatCount = -1; }
1659
+ return new Enumerable(function () {
1660
+ var left = repeatCount;
1661
+ return new Enumerator(function () {
1662
+ if (left === 0) { return doneEnumerator; }
1663
+ if (left > 0) { left--; }
1664
+ return { done: false, value: value };
1665
+ });
1666
+ });
1667
+ };
1668
+
1669
+ var enumerableFor = Enumerable.forEach = function (source, selector, thisArg) {
1670
+ selector || (selector = identity);
1671
+ return new Enumerable(function () {
1672
+ var index = -1;
1673
+ return new Enumerator(
1674
+ function () {
1675
+ return ++index < source.length ?
1676
+ { done: false, value: selector.call(thisArg, source[index], index, source) } :
1677
+ doneEnumerator;
1678
+ });
1679
+ });
1680
+ };
1682
1681
 
1683
1682
  /**
1684
1683
  * Supports push-style iteration over an observable sequence.
@@ -1859,83 +1858,43 @@
1859
1858
  return AnonymousObserver;
1860
1859
  }(AbstractObserver));
1861
1860
 
1862
- var observableProto;
1861
+ var observableProto;
1863
1862
 
1864
- /**
1865
- * Represents a push-style collection.
1866
- */
1867
- var Observable = Rx.Observable = (function () {
1868
-
1869
- /**
1870
- * @constructor
1871
- * @private
1872
- */
1873
- function Observable(subscribe) {
1874
- this._subscribe = subscribe;
1875
- }
1876
-
1877
- observableProto = Observable.prototype;
1863
+ /**
1864
+ * Represents a push-style collection.
1865
+ */
1866
+ var Observable = Rx.Observable = (function () {
1878
1867
 
1879
- observableProto.finalValue = function () {
1880
- var source = this;
1881
- return new AnonymousObservable(function (observer) {
1882
- var hasValue = false, value;
1883
- return source.subscribe(function (x) {
1884
- hasValue = true;
1885
- value = x;
1886
- }, observer.onError.bind(observer), function () {
1887
- if (!hasValue) {
1888
- observer.onError(new Error(sequenceContainsNoElements));
1889
- } else {
1890
- observer.onNext(value);
1891
- observer.onCompleted();
1892
- }
1893
- });
1894
- });
1895
- };
1868
+ function Observable(subscribe) {
1869
+ this._subscribe = subscribe;
1870
+ }
1896
1871
 
1897
- /**
1898
- * Subscribes an observer to the observable sequence.
1899
- *
1900
- * @example
1901
- * 1 - source.subscribe();
1902
- * 2 - source.subscribe(observer);
1903
- * 3 - source.subscribe(function (x) { console.log(x); });
1904
- * 4 - source.subscribe(function (x) { console.log(x); }, function (err) { console.log(err); });
1905
- * 5 - source.subscribe(function (x) { console.log(x); }, function (err) { console.log(err); }, function () { console.log('done'); });
1906
- * @param {Mixed} [observerOrOnNext] The object that is to receive notifications or an action to invoke for each element in the observable sequence.
1907
- * @param {Function} [onError] Action to invoke upon exceptional termination of the observable sequence.
1908
- * @param {Function} [onCompleted] Action to invoke upon graceful termination of the observable sequence.
1909
- * @returns {Diposable} The source sequence whose subscriptions and unsubscriptions happen on the specified scheduler.
1910
- */
1911
- observableProto.subscribe = observableProto.forEach = function (observerOrOnNext, onError, onCompleted) {
1912
- var subscriber;
1913
- if (typeof observerOrOnNext === 'object') {
1914
- subscriber = observerOrOnNext;
1915
- } else {
1916
- subscriber = observerCreate(observerOrOnNext, onError, onCompleted);
1917
- }
1872
+ observableProto = Observable.prototype;
1918
1873
 
1919
- return this._subscribe(subscriber);
1920
- };
1874
+ /**
1875
+ * Subscribes an observer to the observable sequence.
1876
+ *
1877
+ * @example
1878
+ * 1 - source.subscribe();
1879
+ * 2 - source.subscribe(observer);
1880
+ * 3 - source.subscribe(function (x) { console.log(x); });
1881
+ * 4 - source.subscribe(function (x) { console.log(x); }, function (err) { console.log(err); });
1882
+ * 5 - source.subscribe(function (x) { console.log(x); }, function (err) { console.log(err); }, function () { console.log('done'); });
1883
+ * @param {Mixed} [observerOrOnNext] The object that is to receive notifications or an action to invoke for each element in the observable sequence.
1884
+ * @param {Function} [onError] Action to invoke upon exceptional termination of the observable sequence.
1885
+ * @param {Function} [onCompleted] Action to invoke upon graceful termination of the observable sequence.
1886
+ * @returns {Diposable} The source sequence whose subscriptions and unsubscriptions happen on the specified scheduler.
1887
+ */
1888
+ observableProto.subscribe = observableProto.forEach = function (observerOrOnNext, onError, onCompleted) {
1889
+ var subscriber = typeof observerOrOnNext === 'object' ?
1890
+ observerOrOnNext :
1891
+ observerCreate(observerOrOnNext, onError, onCompleted);
1921
1892
 
1922
- /**
1923
- * Creates a list from an observable sequence.
1924
- *
1925
- * @memberOf Observable
1926
- * @returns An observable sequence containing a single element with a list containing all the elements of the source sequence.
1927
- */
1928
- observableProto.toArray = function () {
1929
- function accumulator(list, i) {
1930
- var newList = list.slice(0);
1931
- newList.push(i);
1932
- return newList;
1933
- }
1934
- return this.scan([], accumulator).startWith([]).finalValue();
1935
- };
1893
+ return this._subscribe(subscriber);
1894
+ };
1936
1895
 
1937
- return Observable;
1938
- })();
1896
+ return Observable;
1897
+ })();
1939
1898
 
1940
1899
  var ScheduledObserver = Rx.internals.ScheduledObserver = (function (_super) {
1941
1900
  inherits(ScheduledObserver, _super);
@@ -2006,6 +1965,24 @@
2006
1965
  return ScheduledObserver;
2007
1966
  }(AbstractObserver));
2008
1967
 
1968
+ /**
1969
+ * Creates a list from an observable sequence.
1970
+ * @returns An observable sequence containing a single element with a list containing all the elements of the source sequence.
1971
+ */
1972
+ observableProto.toArray = function () {
1973
+ var self = this;
1974
+ return new AnonymousObservable(function(observer) {
1975
+ var arr = [];
1976
+ return self.subscribe(
1977
+ arr.push.bind(arr),
1978
+ observer.onError.bind(observer),
1979
+ function () {
1980
+ observer.onNext(arr);
1981
+ observer.onCompleted();
1982
+ });
1983
+ });
1984
+ };
1985
+
2009
1986
  /**
2010
1987
  * Creates an observable sequence from a specified subscribe method implementation.
2011
1988
  *
@@ -2554,37 +2531,35 @@
2554
2531
  });
2555
2532
  };
2556
2533
 
2557
- /**
2558
- * Returns the values from the source observable sequence only after the other observable sequence produces a value.
2559
- * @param {Observable} other The observable sequence that triggers propagation of elements of the source sequence.
2560
- * @returns {Observable} An observable sequence containing the elements of the source sequence starting from the point the other sequence triggered propagation.
2561
- */
2562
- observableProto.skipUntil = function (other) {
2563
- var source = this;
2564
- return new AnonymousObservable(function (observer) {
2565
- var isOpen = false;
2566
- var disposables = new CompositeDisposable(source.subscribe(function (left) {
2567
- if (isOpen) {
2568
- observer.onNext(left);
2569
- }
2570
- }, observer.onError.bind(observer), function () {
2571
- if (isOpen) {
2572
- observer.onCompleted();
2573
- }
2574
- }));
2534
+ /**
2535
+ * Returns the values from the source observable sequence only after the other observable sequence produces a value.
2536
+ * @param {Observable | Promise} other The observable sequence or Promise that triggers propagation of elements of the source sequence.
2537
+ * @returns {Observable} An observable sequence containing the elements of the source sequence starting from the point the other sequence triggered propagation.
2538
+ */
2539
+ observableProto.skipUntil = function (other) {
2540
+ var source = this;
2541
+ return new AnonymousObservable(function (observer) {
2542
+ var isOpen = false;
2543
+ var disposables = new CompositeDisposable(source.subscribe(function (left) {
2544
+ isOpen && observer.onNext(left);
2545
+ }, observer.onError.bind(observer), function () {
2546
+ isOpen && observer.onCompleted();
2547
+ }));
2575
2548
 
2576
- var rightSubscription = new SingleAssignmentDisposable();
2577
- disposables.add(rightSubscription);
2578
- rightSubscription.setDisposable(other.subscribe(function () {
2579
- isOpen = true;
2580
- rightSubscription.dispose();
2581
- }, observer.onError.bind(observer), function () {
2582
- rightSubscription.dispose();
2583
- }));
2549
+ isPromise(other) && (other = observableFromPromise(other));
2584
2550
 
2585
- return disposables;
2586
- });
2587
- };
2551
+ var rightSubscription = new SingleAssignmentDisposable();
2552
+ disposables.add(rightSubscription);
2553
+ rightSubscription.setDisposable(other.subscribe(function () {
2554
+ isOpen = true;
2555
+ rightSubscription.dispose();
2556
+ }, observer.onError.bind(observer), function () {
2557
+ rightSubscription.dispose();
2558
+ }));
2559
+
2560
+ return disposables;
2561
+ });
2562
+ };
2588
2563
 
2589
2564
  /**
2590
2565
  * Transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.
@@ -2633,20 +2608,21 @@
2633
2608
  });
2634
2609
  };
2635
2610
 
2636
- /**
2637
- * Returns the values from the source observable sequence until the other observable sequence produces a value.
2638
- * @param {Observable} other Observable sequence that terminates propagation of elements of the source sequence.
2639
- * @returns {Observable} An observable sequence containing the elements of the source sequence up to the point the other sequence interrupted further propagation.
2640
- */
2641
- observableProto.takeUntil = function (other) {
2642
- var source = this;
2643
- return new AnonymousObservable(function (observer) {
2644
- return new CompositeDisposable(
2645
- source.subscribe(observer),
2646
- other.subscribe(observer.onCompleted.bind(observer), observer.onError.bind(observer), noop)
2647
- );
2648
- });
2649
- };
2611
+ /**
2612
+ * Returns the values from the source observable sequence until the other observable sequence produces a value.
2613
+ * @param {Observable | Promise} other Observable sequence or Promise that terminates propagation of elements of the source sequence.
2614
+ * @returns {Observable} An observable sequence containing the elements of the source sequence up to the point the other sequence interrupted further propagation.
2615
+ */
2616
+ observableProto.takeUntil = function (other) {
2617
+ var source = this;
2618
+ return new AnonymousObservable(function (observer) {
2619
+ isPromise(other) && (other = observableFromPromise(other));
2620
+ return new CompositeDisposable(
2621
+ source.subscribe(observer),
2622
+ other.subscribe(observer.onCompleted.bind(observer), observer.onError.bind(observer), noop)
2623
+ );
2624
+ });
2625
+ };
2650
2626
 
2651
2627
  function zipArray(second, resultSelector) {
2652
2628
  var first = this;
@@ -2918,29 +2894,35 @@
2918
2894
  });
2919
2895
  };
2920
2896
 
2921
- /**
2922
- * Invokes a specified action after the source observable sequence terminates gracefully or exceptionally.
2923
- *
2924
- * @example
2925
- * var res = observable.finallyAction(function () { console.log('sequence ended'; });
2926
- * @param {Function} finallyAction Action to invoke after the source observable sequence terminates.
2927
- * @returns {Observable} Source sequence with the action-invoking termination behavior applied.
2928
- */
2929
- observableProto['finally'] = observableProto.finallyAction = function (action) {
2930
- var source = this;
2931
- return new AnonymousObservable(function (observer) {
2932
- var subscription = source.subscribe(observer);
2933
- return disposableCreate(function () {
2934
- try {
2935
- subscription.dispose();
2936
- } catch (e) {
2937
- throw e;
2938
- } finally {
2939
- action();
2940
- }
2941
- });
2942
- });
2943
- };
2897
+ /**
2898
+ * Invokes a specified action after the source observable sequence terminates gracefully or exceptionally.
2899
+ *
2900
+ * @example
2901
+ * var res = observable.finallyAction(function () { console.log('sequence ended'; });
2902
+ * @param {Function} finallyAction Action to invoke after the source observable sequence terminates.
2903
+ * @returns {Observable} Source sequence with the action-invoking termination behavior applied.
2904
+ */
2905
+ observableProto['finally'] = observableProto.finallyAction = function (action) {
2906
+ var source = this;
2907
+ return new AnonymousObservable(function (observer) {
2908
+ var subscription;
2909
+ try {
2910
+ subscription = source.subscribe(observer);
2911
+ } catch (e) {
2912
+ action();
2913
+ throw e;
2914
+ }
2915
+ return disposableCreate(function () {
2916
+ try {
2917
+ subscription.dispose();
2918
+ } catch (e) {
2919
+ throw e;
2920
+ } finally {
2921
+ action();
2922
+ }
2923
+ });
2924
+ });
2925
+ };
2944
2926
 
2945
2927
  /**
2946
2928
  * Ignores all elements in an observable sequence leaving only the termination messages.
@@ -3132,7 +3114,72 @@
3132
3114
  observer.onNext(q);
3133
3115
  observer.onCompleted();
3134
3116
  });
3135
- });
3117
+ });
3118
+ };
3119
+
3120
+ function concatMap(selector) {
3121
+ return this.map(function (x, i) {
3122
+ var result = selector(x, i);
3123
+ return isPromise(result) ? observableFromPromise(result) : result;
3124
+ }).concatAll();
3125
+ }
3126
+
3127
+ function concatMapObserver(onNext, onError, onCompleted) {
3128
+ var source = this;
3129
+ return new AnonymousObservable(function (observer) {
3130
+ var index = 0;
3131
+
3132
+ return source.subscribe(
3133
+ function (x) {
3134
+ observer.onNext(onNext(x, index++));
3135
+ },
3136
+ function (err) {
3137
+ observer.onNext(onError(err));
3138
+ observer.completed();
3139
+ },
3140
+ function () {
3141
+ observer.onNext(onCompleted());
3142
+ observer.onCompleted();
3143
+ });
3144
+ }).concatAll();
3145
+ }
3146
+
3147
+ /**
3148
+ * One of the Following:
3149
+ * Projects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
3150
+ *
3151
+ * @example
3152
+ * var res = source.selectMany(function (x) { return Rx.Observable.range(0, x); });
3153
+ * Or:
3154
+ * 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.
3155
+ *
3156
+ * var res = source.selectMany(function (x) { return Rx.Observable.range(0, x); }, function (x, y) { return x + y; });
3157
+ * Or:
3158
+ * Projects each element of the source observable sequence to the other observable sequence and merges the resulting observable sequences into one observable sequence.
3159
+ *
3160
+ * var res = source.selectMany(Rx.Observable.fromArray([1,2,3]));
3161
+ * @param selector A transform function to apply to each element or an observable sequence to project each element from the
3162
+ * source sequence onto which could be either an observable or Promise.
3163
+ * @param {Function} [resultSelector] A transform function to apply to each element of the intermediate sequence.
3164
+ * @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.
3165
+ */
3166
+ observableProto.selectConcat = observableProto.concatMap = function (selector, resultSelector) {
3167
+ if (resultSelector) {
3168
+ return this.concatMap(function (x, i) {
3169
+ var selectorResult = selector(x, i),
3170
+ result = isPromise(selectorResult) ? observableFromPromise(selectorResult) : selectorResult;
3171
+
3172
+ return result.map(function (y) {
3173
+ return resultSelector(x, y, i);
3174
+ });
3175
+ });
3176
+ }
3177
+ if (typeof selector === 'function') {
3178
+ return concatMap.call(this, selector);
3179
+ }
3180
+ return concatMap.call(this, function () {
3181
+ return selector;
3182
+ });
3136
3183
  };
3137
3184
 
3138
3185
  /**
@@ -3158,6 +3205,15 @@
3158
3205
  });
3159
3206
  };
3160
3207
 
3208
+ /**
3209
+ * Retrieves the value of a specified property from all elements in the Observable sequence.
3210
+ * @param {String} property The property to pluck.
3211
+ * @returns {Observable} Returns a new Observable sequence of property values.
3212
+ */
3213
+ observableProto.pluck = function (property) {
3214
+ return this.select(function (x) { return x[property]; });
3215
+ };
3216
+
3161
3217
  function selectMany(selector) {
3162
3218
  return this.select(function (x, i) {
3163
3219
  var result = selector(x, i);
@@ -3165,6 +3221,26 @@
3165
3221
  }).mergeObservable();
3166
3222
  }
3167
3223
 
3224
+ function selectManyObserver(onNext, onError, onCompleted) {
3225
+ var source = this;
3226
+ return new AnonymousObservable(function (observer) {
3227
+ var index = 0;
3228
+
3229
+ return source.subscribe(
3230
+ function (x) {
3231
+ observer.onNext(onNext(x, index++));
3232
+ },
3233
+ function (err) {
3234
+ observer.onNext(onError(err));
3235
+ observer.completed();
3236
+ },
3237
+ function () {
3238
+ observer.onNext(onCompleted());
3239
+ observer.onCompleted();
3240
+ });
3241
+ }).mergeAll();
3242
+ }
3243
+
3168
3244
  /**
3169
3245
  * One of the Following:
3170
3246
  * Projects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
@@ -3574,8 +3650,8 @@
3574
3650
  Observable.fromEvent = function (element, eventName, selector) {
3575
3651
  if (ember) {
3576
3652
  return fromEventPattern(
3577
- function (h) { Ember.addListener(element, eventName); },
3578
- function (h) { Ember.removeListener(element, eventName); },
3653
+ function (h) { Ember.addListener(element, eventName, h); },
3654
+ function (h) { Ember.removeListener(element, eventName, h); },
3579
3655
  selector);
3580
3656
  }
3581
3657
  if (jq) {
@@ -3605,6 +3681,7 @@
3605
3681
  });
3606
3682
  }).publish().refCount();
3607
3683
  };
3684
+
3608
3685
  /**
3609
3686
  * Creates an observable sequence from an event emitter via an addHandler/removeHandler pair.
3610
3687
  * @param {Function} addHandler The function to add a handler to the emitter.
@@ -3862,71 +3939,71 @@
3862
3939
  return this.replay(null, bufferSize, window, scheduler).refCount();
3863
3940
  };
3864
3941
 
3865
- /** @private */
3866
- var ConnectableObservable = Rx.ConnectableObservable = (function (_super) {
3867
- inherits(ConnectableObservable, _super);
3868
-
3869
- /**
3870
- * @constructor
3871
- * @private
3872
- */
3873
- function ConnectableObservable(source, subject) {
3874
- var state = {
3875
- subject: subject,
3876
- source: source.asObservable(),
3877
- hasSubscription: false,
3878
- subscription: null
3879
- };
3880
-
3881
- this.connect = function () {
3882
- if (!state.hasSubscription) {
3883
- state.hasSubscription = true;
3884
- state.subscription = new CompositeDisposable(state.source.subscribe(state.subject), disposableCreate(function () {
3885
- state.hasSubscription = false;
3886
- }));
3887
- }
3888
- return state.subscription;
3889
- };
3890
-
3891
- function subscribe(observer) {
3892
- return state.subject.subscribe(observer);
3893
- }
3894
-
3895
- _super.call(this, subscribe);
3896
- }
3897
-
3898
- /**
3899
- * @private
3900
- * @memberOf ConnectableObservable
3901
- */
3902
- ConnectableObservable.prototype.connect = function () { return this.connect(); };
3903
-
3904
- /**
3905
- * @private
3906
- * @memberOf ConnectableObservable
3907
- */
3908
- ConnectableObservable.prototype.refCount = function () {
3909
- var connectableSubscription = null, count = 0, source = this;
3910
- return new AnonymousObservable(function (observer) {
3911
- var shouldConnect, subscription;
3912
- count++;
3913
- shouldConnect = count === 1;
3914
- subscription = source.subscribe(observer);
3915
- if (shouldConnect) {
3916
- connectableSubscription = source.connect();
3917
- }
3918
- return disposableCreate(function () {
3919
- subscription.dispose();
3920
- count--;
3921
- if (count === 0) {
3922
- connectableSubscription.dispose();
3923
- }
3924
- });
3925
- });
3926
- };
3927
-
3928
- return ConnectableObservable;
3929
- }(Observable));
3942
+ /** @private */
3943
+ var ConnectableObservable = Rx.ConnectableObservable = (function (_super) {
3944
+ inherits(ConnectableObservable, _super);
3945
+
3946
+ /**
3947
+ * @constructor
3948
+ * @private
3949
+ */
3950
+ function ConnectableObservable(source, subject) {
3951
+ var state = {
3952
+ subject: subject,
3953
+ source: source.asObservable(),
3954
+ hasSubscription: false,
3955
+ subscription: null
3956
+ };
3957
+
3958
+ this.connect = function () {
3959
+ if (!state.hasSubscription) {
3960
+ state.hasSubscription = true;
3961
+ state.subscription = new CompositeDisposable(state.source.subscribe(state.subject), disposableCreate(function () {
3962
+ state.hasSubscription = false;
3963
+ }));
3964
+ }
3965
+ return state.subscription;
3966
+ };
3967
+
3968
+ function subscribe(observer) {
3969
+ return state.subject.subscribe(observer);
3970
+ }
3971
+
3972
+ _super.call(this, subscribe);
3973
+ }
3974
+
3975
+ /**
3976
+ * @private
3977
+ * @memberOf ConnectableObservable
3978
+ */
3979
+ ConnectableObservable.prototype.connect = function () { return this.connect(); };
3980
+
3981
+ /**
3982
+ * @private
3983
+ * @memberOf ConnectableObservable
3984
+ */
3985
+ ConnectableObservable.prototype.refCount = function () {
3986
+ var connectableSubscription = null, count = 0, source = this;
3987
+ return new AnonymousObservable(function (observer) {
3988
+ var shouldConnect, subscription;
3989
+ count++;
3990
+ shouldConnect = count === 1;
3991
+ subscription = source.subscribe(observer);
3992
+ if (shouldConnect) {
3993
+ connectableSubscription = source.connect();
3994
+ }
3995
+ return disposableCreate(function () {
3996
+ subscription.dispose();
3997
+ count--;
3998
+ if (count === 0) {
3999
+ connectableSubscription.dispose();
4000
+ }
4001
+ });
4002
+ });
4003
+ };
4004
+
4005
+ return ConnectableObservable;
4006
+ }(Observable));
3930
4007
 
3931
4008
  function observableTimerTimeSpan(dueTime, scheduler) {
3932
4009
  var d = normalizeTime(dueTime);
@@ -4182,77 +4259,71 @@
4182
4259
  return sampleObservable(this, intervalOrSampler);
4183
4260
  };
4184
4261
 
4185
- /**
4186
- * Returns the source observable sequence or the other observable sequence if dueTime elapses.
4187
- *
4188
- * @example
4189
- * 1 - res = source.timeout(new Date()); // As a date
4190
- * 2 - res = source.timeout(5000); // 5 seconds
4191
- * 3 - res = source.timeout(new Date(), Rx.Observable.returnValue(42)); // As a date and timeout observable
4192
- * 4 - res = source.timeout(5000, Rx.Observable.returnValue(42)); // 5 seconds and timeout observable
4193
- * 5 - res = source.timeout(new Date(), Rx.Observable.returnValue(42), Rx.Scheduler.timeout); // As a date and timeout observable
4194
- * 6 - res = source.timeout(5000, Rx.Observable.returnValue(42), Rx.Scheduler.timeout); // 5 seconds and timeout observable
4195
- *
4196
- * @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) when a timeout occurs.
4197
- * @param {Observable} [other] Sequence to return in case of a timeout. If not specified, a timeout error throwing sequence will be used.
4198
- * @param {Scheduler} [scheduler] Scheduler to run the timeout timers on. If not specified, the timeout scheduler is used.
4199
- * @returns {Observable} The source sequence switching to the other sequence in case of a timeout.
4200
- */
4201
- observableProto.timeout = function (dueTime, other, scheduler) {
4202
- var schedulerMethod, source = this;
4203
- other || (other = observableThrow(new Error('Timeout')));
4204
- scheduler || (scheduler = timeoutScheduler);
4205
- if (dueTime instanceof Date) {
4206
- schedulerMethod = function (dt, action) {
4207
- scheduler.scheduleWithAbsolute(dt, action);
4208
- };
4209
- } else {
4210
- schedulerMethod = function (dt, action) {
4211
- scheduler.scheduleWithRelative(dt, action);
4212
- };
4262
+ /**
4263
+ * Returns the source observable sequence or the other observable sequence if dueTime elapses.
4264
+ *
4265
+ * @example
4266
+ * 1 - res = source.timeout(new Date()); // As a date
4267
+ * 2 - res = source.timeout(5000); // 5 seconds
4268
+ * 3 - res = source.timeout(new Date(), Rx.Observable.returnValue(42)); // As a date and timeout observable
4269
+ * 4 - res = source.timeout(5000, Rx.Observable.returnValue(42)); // 5 seconds and timeout observable
4270
+ * 5 - res = source.timeout(new Date(), Rx.Observable.returnValue(42), Rx.Scheduler.timeout); // As a date and timeout observable
4271
+ * 6 - res = source.timeout(5000, Rx.Observable.returnValue(42), Rx.Scheduler.timeout); // 5 seconds and timeout observable
4272
+ *
4273
+ * @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) when a timeout occurs.
4274
+ * @param {Observable} [other] Sequence to return in case of a timeout. If not specified, a timeout error throwing sequence will be used.
4275
+ * @param {Scheduler} [scheduler] Scheduler to run the timeout timers on. If not specified, the timeout scheduler is used.
4276
+ * @returns {Observable} The source sequence switching to the other sequence in case of a timeout.
4277
+ */
4278
+ observableProto.timeout = function (dueTime, other, scheduler) {
4279
+ other || (other = observableThrow(new Error('Timeout')));
4280
+ scheduler || (scheduler = timeoutScheduler);
4281
+
4282
+ var source = this, schedulerMethod = dueTime instanceof Date ?
4283
+ 'scheduleWithAbsolute' :
4284
+ 'scheduleWithRelative';
4285
+
4286
+ return new AnonymousObservable(function (observer) {
4287
+ var id = 0,
4288
+ original = new SingleAssignmentDisposable(),
4289
+ subscription = new SerialDisposable(),
4290
+ switched = false,
4291
+ timer = new SerialDisposable();
4292
+
4293
+ subscription.setDisposable(original);
4294
+
4295
+ var createTimer = function () {
4296
+ var myId = id;
4297
+ timer.setDisposable(scheduler[schedulerMethod](dueTime, function () {
4298
+ if (id === myId) {
4299
+ isPromise(other) && (other = observableFromPromise(other));
4300
+ subscription.setDisposable(other.subscribe(observer));
4301
+ }
4302
+ }));
4303
+ };
4304
+
4305
+ createTimer();
4306
+
4307
+ original.setDisposable(source.subscribe(function (x) {
4308
+ if (!switched) {
4309
+ id++;
4310
+ observer.onNext(x);
4311
+ createTimer();
4213
4312
  }
4214
- return new AnonymousObservable(function (observer) {
4215
- var createTimer,
4216
- id = 0,
4217
- original = new SingleAssignmentDisposable(),
4218
- subscription = new SerialDisposable(),
4219
- switched = false,
4220
- timer = new SerialDisposable();
4221
- subscription.setDisposable(original);
4222
- createTimer = function () {
4223
- var myId = id;
4224
- timer.setDisposable(schedulerMethod(dueTime, function () {
4225
- switched = id === myId;
4226
- var timerWins = switched;
4227
- if (timerWins) {
4228
- subscription.setDisposable(other.subscribe(observer));
4229
- }
4230
- }));
4231
- };
4232
- createTimer();
4233
- original.setDisposable(source.subscribe(function (x) {
4234
- var onNextWins = !switched;
4235
- if (onNextWins) {
4236
- id++;
4237
- observer.onNext(x);
4238
- createTimer();
4239
- }
4240
- }, function (e) {
4241
- var onErrorWins = !switched;
4242
- if (onErrorWins) {
4243
- id++;
4244
- observer.onError(e);
4245
- }
4246
- }, function () {
4247
- var onCompletedWins = !switched;
4248
- if (onCompletedWins) {
4249
- id++;
4250
- observer.onCompleted();
4251
- }
4252
- }));
4253
- return new CompositeDisposable(subscription, timer);
4254
- });
4255
- };
4313
+ }, function (e) {
4314
+ if (!switched) {
4315
+ id++;
4316
+ observer.onError(e);
4317
+ }
4318
+ }, function () {
4319
+ if (!switched) {
4320
+ id++;
4321
+ observer.onCompleted();
4322
+ }
4323
+ }));
4324
+ return new CompositeDisposable(subscription, timer);
4325
+ });
4326
+ };
4256
4327
 
4257
4328
  /**
4258
4329
  * Generates an observable sequence by iterating a state from an initial state until the condition fails.
@@ -4675,50 +4746,55 @@
4675
4746
  });
4676
4747
  };
4677
4748
 
4678
- /**
4679
- * Skips elements from the observable source sequence until the specified start time, using the specified scheduler to run timers.
4680
- * Errors produced by the source sequence are always forwarded to the result sequence, even if the error occurs before the start time>.
4681
- *
4682
- * @examples
4683
- * 1 - res = source.skipUntilWithTime(new Date(), [optional scheduler]);
4684
- * @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.
4685
- * @param scheduler Scheduler to run the timer on. If not specified, defaults to Rx.Scheduler.timeout.
4686
- * @returns {Observable} An observable sequence with the elements skipped until the specified start time.
4687
- */
4688
- observableProto.skipUntilWithTime = function (startTime, scheduler) {
4689
- scheduler || (scheduler = timeoutScheduler);
4690
- var source = this;
4691
- return new AnonymousObservable(function (observer) {
4692
- var open = false,
4693
- t = scheduler.scheduleWithAbsolute(startTime, function () { open = true; }),
4694
- d = source.subscribe(function (x) {
4695
- if (open) {
4696
- observer.onNext(x);
4697
- }
4698
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4749
+ /**
4750
+ * Skips elements from the observable source sequence until the specified start time, using the specified scheduler to run timers.
4751
+ * Errors produced by the source sequence are always forwarded to the result sequence, even if the error occurs before the start time.
4752
+ *
4753
+ * @examples
4754
+ * 1 - res = source.skipUntilWithTime(new Date(), [optional scheduler]);
4755
+ * 2 - res = source.skipUntilWithTime(5000, [optional scheduler]);
4756
+ * @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.
4757
+ * @param scheduler Scheduler to run the timer on. If not specified, defaults to Rx.Scheduler.timeout.
4758
+ * @returns {Observable} An observable sequence with the elements skipped until the specified start time.
4759
+ */
4760
+ observableProto.skipUntilWithTime = function (startTime, scheduler) {
4761
+ scheduler || (scheduler = timeoutScheduler);
4762
+ var source = this, schedulerMethod = startTime instanceof Date ?
4763
+ 'scheduleWithAbsolute' :
4764
+ 'scheduleWithRelative';
4765
+ return new AnonymousObservable(function (observer) {
4766
+ var open = false;
4699
4767
 
4700
- return new CompositeDisposable(t, d);
4701
- });
4702
- };
4768
+ return new CompositeDisposable(
4769
+ scheduler[schedulerMethod](startTime, function () { open = true; }),
4770
+ source.subscribe(
4771
+ function (x) { open && observer.onNext(x); },
4772
+ observer.onError.bind(observer),
4773
+ observer.onCompleted.bind(observer)));
4774
+ });
4775
+ };
4703
4776
 
4704
- /**
4705
- * Takes elements for the specified duration until the specified end time, using the specified scheduler to run timers.
4706
- *
4707
- * @example
4708
- * 1 - res = source.takeUntilWithTime(new Date(), [optional scheduler]);
4709
- * @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.
4710
- * @param {Scheduler} scheduler Scheduler to run the timer on.
4711
- * @returns {Observable} An observable sequence with the elements taken until the specified end time.
4712
- */
4713
- observableProto.takeUntilWithTime = function (endTime, scheduler) {
4714
- scheduler || (scheduler = timeoutScheduler);
4715
- var source = this;
4716
- return new AnonymousObservable(function (observer) {
4717
- return new CompositeDisposable(scheduler.scheduleWithAbsolute(endTime, function () {
4718
- observer.onCompleted();
4719
- }), source.subscribe(observer));
4720
- });
4721
- };
4777
+ /**
4778
+ * Takes elements for the specified duration until the specified end time, using the specified scheduler to run timers.
4779
+ *
4780
+ * @example
4781
+ * 1 - res = source.takeUntilWithTime(new Date(), [optional scheduler]);
4782
+ * 2 - res = source.takeUntilWithTime(5000, [optional scheduler]);
4783
+ * @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.
4784
+ * @param {Scheduler} scheduler Scheduler to run the timer on.
4785
+ * @returns {Observable} An observable sequence with the elements taken until the specified end time.
4786
+ */
4787
+ observableProto.takeUntilWithTime = function (endTime, scheduler) {
4788
+ scheduler || (scheduler = timeoutScheduler);
4789
+ var source = this, schedulerMethod = endTime instanceof Date ?
4790
+ 'scheduleWithAbsolute' :
4791
+ 'scheduleWithRelative';
4792
+ return new AnonymousObservable(function (observer) {
4793
+ return new CompositeDisposable(scheduler[schedulerMethod](endTime, function () {
4794
+ observer.onCompleted();
4795
+ }), source.subscribe(observer));
4796
+ });
4797
+ };
4722
4798
 
4723
4799
  var PausableObservable = (function (_super) {
4724
4800
 
@@ -4792,15 +4868,15 @@
4792
4868
  var res;
4793
4869
  hasValue[i] = true;
4794
4870
  if (hasValueAll || (hasValueAll = hasValue.every(identity))) {
4795
- try {
4796
- res = resultSelector.apply(null, values);
4797
- } catch (ex) {
4798
- observer.onError(ex);
4799
- return;
4800
- }
4801
- observer.onNext(res);
4871
+ try {
4872
+ res = resultSelector.apply(null, values);
4873
+ } catch (ex) {
4874
+ observer.onError(ex);
4875
+ return;
4876
+ }
4877
+ observer.onNext(res);
4802
4878
  } else if (isDone) {
4803
- observer.onCompleted();
4879
+ observer.onCompleted();
4804
4880
  }
4805
4881
  }
4806
4882
 
@@ -4854,8 +4930,20 @@
4854
4930
  }
4855
4931
 
4856
4932
  },
4857
- observer.onError.bind(observer),
4858
- observer.onCompleted.bind(observer)
4933
+ function (err) {
4934
+ // Empty buffer before sending error
4935
+ while (q.length > 0) {
4936
+ observer.onNext(q.shift());
4937
+ }
4938
+ observer.onError(err);
4939
+ },
4940
+ function () {
4941
+ // Empty buffer before sending completion
4942
+ while (q.length > 0) {
4943
+ observer.onNext(q.shift());
4944
+ }
4945
+ observer.onCompleted();
4946
+ }
4859
4947
  );
4860
4948
 
4861
4949
  this.subject.onNext(false);
@@ -5064,56 +5152,100 @@
5064
5152
 
5065
5153
  return ControlledSubject;
5066
5154
  }(Observable));
5067
- var AnonymousObservable = Rx.AnonymousObservable = (function (_super) {
5068
- inherits(AnonymousObservable, _super);
5069
-
5070
- // Fix subscriber to check for undefined or function returned to decorate as Disposable
5071
- function fixSubscriber(subscriber) {
5072
- if (typeof subscriber === 'undefined') {
5073
- subscriber = disposableEmpty;
5074
- } else if (typeof subscriber === 'function') {
5075
- subscriber = disposableCreate(subscriber);
5076
- }
5155
+ /**
5156
+ * Returns a new observable that triggers on the second and subsequent triggerings of the input observable.
5157
+ * The Nth triggering of the input observable passes the arguments from the N-1th and Nth triggering as a pair.
5158
+ * The argument passed to the N-1th triggering is held in hidden internal state until the Nth triggering occurs.
5159
+ * @returns {Observable} An observable that triggers on successive pairs of observations from the input observable as an array.
5160
+ */
5161
+ observableProto.pairwise = function () {
5162
+ var source = this;
5163
+ return new AnonymousObservable(function (observer) {
5164
+ var previous, hasPrevious = false;
5165
+ return source.subscribe(
5166
+ function (x) {
5167
+ if (hasPrevious) {
5168
+ observer.onNext([previous, x]);
5169
+ } else {
5170
+ hasPrevious = true;
5171
+ }
5172
+ previous = x;
5173
+ },
5174
+ observer.onError.bind(observer),
5175
+ observer.onCompleted.bind(observer));
5176
+ });
5177
+ };
5178
+ /**
5179
+ * Returns two observables which partition the observations of the source by the given function.
5180
+ * The first will trigger observations for those values for which the predicate returns true.
5181
+ * The second will trigger observations for those values where the predicate returns false.
5182
+ * The predicate is executed once for each subscribed observer.
5183
+ * Both also propagate all error observations arising from the source and each completes
5184
+ * when the source completes.
5185
+ * @param {Function} predicate
5186
+ * The function to determine which output Observable will trigger a particular observation.
5187
+ * @returns {Array}
5188
+ * An array of observables. The first triggers when the predicate returns true,
5189
+ * and the second triggers when the predicate returns false.
5190
+ */
5191
+ observableProto.partition = function(predicate, thisArg) {
5192
+ var published = this.publish().refCount();
5193
+ return [
5194
+ published.filter(predicate, thisArg),
5195
+ published.filter(function (x, i, o) { return !predicate.call(thisArg, x, i, o); })
5196
+ ];
5197
+ };
5077
5198
 
5078
- return subscriber;
5079
- }
5199
+ var AnonymousObservable = Rx.AnonymousObservable = (function (__super__) {
5200
+ inherits(AnonymousObservable, __super__);
5080
5201
 
5081
- function AnonymousObservable(subscribe) {
5082
- if (!(this instanceof AnonymousObservable)) {
5083
- return new AnonymousObservable(subscribe);
5084
- }
5202
+ // Fix subscriber to check for undefined or function returned to decorate as Disposable
5203
+ function fixSubscriber(subscriber) {
5204
+ if (typeof subscriber === 'undefined') {
5205
+ subscriber = disposableEmpty;
5206
+ } else if (typeof subscriber === 'function') {
5207
+ subscriber = disposableCreate(subscriber);
5208
+ }
5085
5209
 
5086
- function s(observer) {
5087
- var autoDetachObserver = new AutoDetachObserver(observer);
5088
- if (currentThreadScheduler.scheduleRequired()) {
5089
- currentThreadScheduler.schedule(function () {
5090
- try {
5091
- autoDetachObserver.setDisposable(fixSubscriber(subscribe(autoDetachObserver)));
5092
- } catch (e) {
5093
- if (!autoDetachObserver.fail(e)) {
5094
- throw e;
5095
- }
5096
- }
5097
- });
5098
- } else {
5099
- try {
5100
- autoDetachObserver.setDisposable(fixSubscriber(subscribe(autoDetachObserver)));
5101
- } catch (e) {
5102
- if (!autoDetachObserver.fail(e)) {
5103
- throw e;
5104
- }
5105
- }
5106
- }
5210
+ return subscriber;
5211
+ }
5107
5212
 
5108
- return autoDetachObserver;
5109
- }
5213
+ function AnonymousObservable(subscribe) {
5214
+ if (!(this instanceof AnonymousObservable)) {
5215
+ return new AnonymousObservable(subscribe);
5216
+ }
5110
5217
 
5111
- _super.call(this, s);
5218
+ function s(observer) {
5219
+ var autoDetachObserver = new AutoDetachObserver(observer);
5220
+ if (currentThreadScheduler.scheduleRequired()) {
5221
+ currentThreadScheduler.schedule(function () {
5222
+ try {
5223
+ autoDetachObserver.setDisposable(fixSubscriber(subscribe(autoDetachObserver)));
5224
+ } catch (e) {
5225
+ if (!autoDetachObserver.fail(e)) {
5226
+ throw e;
5227
+ }
5228
+ }
5229
+ });
5230
+ } else {
5231
+ try {
5232
+ autoDetachObserver.setDisposable(fixSubscriber(subscribe(autoDetachObserver)));
5233
+ } catch (e) {
5234
+ if (!autoDetachObserver.fail(e)) {
5235
+ throw e;
5236
+ }
5237
+ }
5112
5238
  }
5113
5239
 
5114
- return AnonymousObservable;
5240
+ return autoDetachObserver;
5241
+ }
5242
+
5243
+ __super__.call(this, s);
5244
+ }
5245
+
5246
+ return AnonymousObservable;
5115
5247
 
5116
- }(Observable));
5248
+ }(Observable));
5117
5249
 
5118
5250
  /** @private */
5119
5251
  var AutoDetachObserver = (function (_super) {
@@ -5176,23 +5308,23 @@
5176
5308
  return AutoDetachObserver;
5177
5309
  }(AbstractObserver));
5178
5310
 
5179
- /** @private */
5180
- var InnerSubscription = function (subject, observer) {
5181
- this.subject = subject;
5182
- this.observer = observer;
5183
- };
5184
-
5185
- /**
5186
- * @private
5187
- * @memberOf InnerSubscription
5188
- */
5189
- InnerSubscription.prototype.dispose = function () {
5190
- if (!this.subject.isDisposed && this.observer !== null) {
5191
- var idx = this.subject.observers.indexOf(this.observer);
5192
- this.subject.observers.splice(idx, 1);
5193
- this.observer = null;
5194
- }
5195
- };
5311
+ /** @private */
5312
+ var InnerSubscription = function (subject, observer) {
5313
+ this.subject = subject;
5314
+ this.observer = observer;
5315
+ };
5316
+
5317
+ /**
5318
+ * @private
5319
+ * @memberOf InnerSubscription
5320
+ */
5321
+ InnerSubscription.prototype.dispose = function () {
5322
+ if (!this.subject.isDisposed && this.observer !== null) {
5323
+ var idx = this.subject.observers.indexOf(this.observer);
5324
+ this.subject.observers.splice(idx, 1);
5325
+ this.observer = null;
5326
+ }
5327
+ };
5196
5328
 
5197
5329
  /**
5198
5330
  * Represents an object that is both an observable sequence as well as an observer.
@@ -5427,50 +5559,50 @@
5427
5559
  return AsyncSubject;
5428
5560
  }(Observable));
5429
5561
 
5430
- /** @private */
5431
- var AnonymousSubject = (function (_super) {
5432
- inherits(AnonymousSubject, _super);
5433
-
5434
- function subscribe(observer) {
5435
- return this.observable.subscribe(observer);
5436
- }
5437
-
5438
- /**
5439
- * @private
5440
- * @constructor
5441
- */
5442
- function AnonymousSubject(observer, observable) {
5443
- _super.call(this, subscribe);
5444
- this.observer = observer;
5445
- this.observable = observable;
5446
- }
5447
-
5448
- addProperties(AnonymousSubject.prototype, Observer, {
5449
- /**
5450
- * @private
5451
- * @memberOf AnonymousSubject#
5452
- */
5453
- onCompleted: function () {
5454
- this.observer.onCompleted();
5455
- },
5456
- /**
5457
- * @private
5458
- * @memberOf AnonymousSubject#
5459
- */
5460
- onError: function (exception) {
5461
- this.observer.onError(exception);
5462
- },
5463
- /**
5464
- * @private
5465
- * @memberOf AnonymousSubject#
5466
- */
5467
- onNext: function (value) {
5468
- this.observer.onNext(value);
5469
- }
5470
- });
5471
-
5472
- return AnonymousSubject;
5473
- }(Observable));
5562
+ /** @private */
5563
+ var AnonymousSubject = (function (_super) {
5564
+ inherits(AnonymousSubject, _super);
5565
+
5566
+ function subscribe(observer) {
5567
+ return this.observable.subscribe(observer);
5568
+ }
5569
+
5570
+ /**
5571
+ * @private
5572
+ * @constructor
5573
+ */
5574
+ function AnonymousSubject(observer, observable) {
5575
+ _super.call(this, subscribe);
5576
+ this.observer = observer;
5577
+ this.observable = observable;
5578
+ }
5579
+
5580
+ addProperties(AnonymousSubject.prototype, Observer, {
5581
+ /**
5582
+ * @private
5583
+ * @memberOf AnonymousSubject#
5584
+ */
5585
+ onCompleted: function () {
5586
+ this.observer.onCompleted();
5587
+ },
5588
+ /**
5589
+ * @private
5590
+ * @memberOf AnonymousSubject#
5591
+ */
5592
+ onError: function (exception) {
5593
+ this.observer.onError(exception);
5594
+ },
5595
+ /**
5596
+ * @private
5597
+ * @memberOf AnonymousSubject#
5598
+ */
5599
+ onNext: function (value) {
5600
+ this.observer.onNext(value);
5601
+ }
5602
+ });
5603
+
5604
+ return AnonymousSubject;
5605
+ }(Observable));
5474
5606
 
5475
5607
  /**
5476
5608
  * Represents a value that changes over time.
@@ -5734,21 +5866,21 @@
5734
5866
  return ReplaySubject;
5735
5867
  }(Observable));
5736
5868
 
5737
- if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
5738
- root.Rx = Rx;
5739
-
5740
- define(function() {
5741
- return Rx;
5742
- });
5743
- } else if (freeExports && freeModule) {
5744
- // in Node.js or RingoJS
5745
- if (moduleExports) {
5746
- (freeModule.exports = Rx).Rx = Rx;
5747
- } else {
5748
- freeExports.Rx = Rx;
5749
- }
5750
- } else {
5751
- // in a browser or Rhino
5752
- root.Rx = Rx;
5869
+ if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
5870
+ root.Rx = Rx;
5871
+
5872
+ define(function() {
5873
+ return Rx;
5874
+ });
5875
+ } else if (freeExports && freeModule) {
5876
+ // in Node.js or RingoJS
5877
+ if (moduleExports) {
5878
+ (freeModule.exports = Rx).Rx = Rx;
5879
+ } else {
5880
+ freeExports.Rx = Rx;
5881
+ }
5882
+ } else {
5883
+ // in a browser or Rhino
5884
+ root.Rx = Rx;
5753
5885
  }
5754
5886
  }.call(this));