rxjs-rails 2.3.9 → 2.3.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rxjs/rails/version.rb +1 -1
  3. data/vendor/assets/javascripts/rx.aggregates.js +174 -204
  4. data/vendor/assets/javascripts/rx.aggregates.min.js +1 -1
  5. data/vendor/assets/javascripts/rx.all.compat.js +1626 -1528
  6. data/vendor/assets/javascripts/rx.all.compat.min.js +3 -3
  7. data/vendor/assets/javascripts/rx.all.js +1624 -1526
  8. data/vendor/assets/javascripts/rx.all.min.js +3 -3
  9. data/vendor/assets/javascripts/rx.async.compat.js +241 -0
  10. data/vendor/assets/javascripts/rx.async.compat.min.js +1 -1
  11. data/vendor/assets/javascripts/rx.async.js +241 -0
  12. data/vendor/assets/javascripts/rx.async.min.js +1 -1
  13. data/vendor/assets/javascripts/rx.backpressure.js +3 -3
  14. data/vendor/assets/javascripts/rx.backpressure.min.js +1 -1
  15. data/vendor/assets/javascripts/rx.binding.js +350 -378
  16. data/vendor/assets/javascripts/rx.binding.min.js +1 -1
  17. data/vendor/assets/javascripts/rx.coincidence.js +16 -21
  18. data/vendor/assets/javascripts/rx.compat.js +633 -683
  19. data/vendor/assets/javascripts/rx.compat.min.js +2 -2
  20. data/vendor/assets/javascripts/rx.js +633 -683
  21. data/vendor/assets/javascripts/rx.lite.compat.js +941 -1137
  22. data/vendor/assets/javascripts/rx.lite.compat.min.js +2 -2
  23. data/vendor/assets/javascripts/rx.lite.extras.js +58 -74
  24. data/vendor/assets/javascripts/rx.lite.extras.min.js +1 -1
  25. data/vendor/assets/javascripts/rx.lite.js +941 -1137
  26. data/vendor/assets/javascripts/rx.lite.min.js +2 -2
  27. data/vendor/assets/javascripts/rx.min.js +2 -2
  28. data/vendor/assets/javascripts/rx.time.js +182 -212
  29. data/vendor/assets/javascripts/rx.time.min.js +1 -1
  30. metadata +10 -10
@@ -43,7 +43,22 @@
43
43
  defaultError = Rx.helpers.defaultError = function (err) { throw err; },
44
44
  isPromise = Rx.helpers.isPromise = function (p) { return !!p && typeof p.then === 'function'; },
45
45
  asArray = Rx.helpers.asArray = function () { return Array.prototype.slice.call(arguments); },
46
- not = Rx.helpers.not = function (a) { return !a; };
46
+ not = Rx.helpers.not = function (a) { return !a; },
47
+ isFunction = Rx.helpers.isFunction = (function () {
48
+
49
+ var isFn = function (value) {
50
+ return typeof value == 'function' || false;
51
+ }
52
+
53
+ // fallback for older versions of Chrome and Safari
54
+ if (isFn(/x/)) {
55
+ isFn = function(value) {
56
+ return typeof value == 'function' && toString.call(value) == '[object Function]';
57
+ };
58
+ }
59
+
60
+ return isFn;
61
+ }());
47
62
 
48
63
  // Errors
49
64
  var sequenceContainsNoElements = 'Sequence contains no elements.';
@@ -198,18 +213,7 @@
198
213
  isArguments = function(value) {
199
214
  return (value && typeof value == 'object') ? hasOwnProperty.call(value, 'callee') : false;
200
215
  };
201
- }
202
-
203
- function isFunction(value) {
204
- return typeof value == 'function' || false;
205
- }
206
-
207
- // fallback for older versions of Chrome and Safari
208
- if (isFunction(/x/)) {
209
- isFunction = function(value) {
210
- return typeof value == 'function' && toString.call(value) == funcClass;
211
- };
212
- }
216
+ }
213
217
 
214
218
  var isEqual = Rx.internals.isEqual = function (x, y) {
215
219
  return deepEquals(x, y, [], []);
@@ -546,101 +550,91 @@ if (!Array.prototype.forEach) {
546
550
  };
547
551
  }
548
552
 
549
- // Collections
550
- var IndexedItem = function (id, value) {
551
- this.id = id;
552
- this.value = value;
553
- };
553
+ // Collections
554
+ function IndexedItem(id, value) {
555
+ this.id = id;
556
+ this.value = value;
557
+ }
554
558
 
555
- IndexedItem.prototype.compareTo = function (other) {
556
- var c = this.value.compareTo(other.value);
557
- if (c === 0) {
558
- c = this.id - other.id;
559
- }
560
- return c;
561
- };
559
+ IndexedItem.prototype.compareTo = function (other) {
560
+ var c = this.value.compareTo(other.value);
561
+ c === 0 && (c = this.id - other.id);
562
+ return c;
563
+ };
562
564
 
563
- // Priority Queue for Scheduling
564
- var PriorityQueue = Rx.internals.PriorityQueue = function (capacity) {
565
- this.items = new Array(capacity);
566
- this.length = 0;
567
- };
565
+ // Priority Queue for Scheduling
566
+ var PriorityQueue = Rx.internals.PriorityQueue = function (capacity) {
567
+ this.items = new Array(capacity);
568
+ this.length = 0;
569
+ };
568
570
 
569
- var priorityProto = PriorityQueue.prototype;
570
- priorityProto.isHigherPriority = function (left, right) {
571
- return this.items[left].compareTo(this.items[right]) < 0;
572
- };
571
+ var priorityProto = PriorityQueue.prototype;
572
+ priorityProto.isHigherPriority = function (left, right) {
573
+ return this.items[left].compareTo(this.items[right]) < 0;
574
+ };
573
575
 
574
- priorityProto.percolate = function (index) {
575
- if (index >= this.length || index < 0) {
576
- return;
577
- }
578
- var parent = index - 1 >> 1;
579
- if (parent < 0 || parent === index) {
580
- return;
581
- }
582
- if (this.isHigherPriority(index, parent)) {
583
- var temp = this.items[index];
584
- this.items[index] = this.items[parent];
585
- this.items[parent] = temp;
586
- this.percolate(parent);
587
- }
588
- };
576
+ priorityProto.percolate = function (index) {
577
+ if (index >= this.length || index < 0) { return; }
578
+ var parent = index - 1 >> 1;
579
+ if (parent < 0 || parent === index) { return; }
580
+ if (this.isHigherPriority(index, parent)) {
581
+ var temp = this.items[index];
582
+ this.items[index] = this.items[parent];
583
+ this.items[parent] = temp;
584
+ this.percolate(parent);
585
+ }
586
+ };
589
587
 
590
- priorityProto.heapify = function (index) {
591
- if (index === undefined) {
592
- index = 0;
593
- }
594
- if (index >= this.length || index < 0) {
595
- return;
596
- }
597
- var left = 2 * index + 1,
598
- right = 2 * index + 2,
599
- first = index;
600
- if (left < this.length && this.isHigherPriority(left, first)) {
601
- first = left;
602
- }
603
- if (right < this.length && this.isHigherPriority(right, first)) {
604
- first = right;
605
- }
606
- if (first !== index) {
607
- var temp = this.items[index];
608
- this.items[index] = this.items[first];
609
- this.items[first] = temp;
610
- this.heapify(first);
611
- }
612
- };
613
-
614
- priorityProto.peek = function () { return this.items[0].value; };
588
+ priorityProto.heapify = function (index) {
589
+ +index || (index = 0);
590
+ if (index >= this.length || index < 0) { return; }
591
+ var left = 2 * index + 1,
592
+ right = 2 * index + 2,
593
+ first = index;
594
+ if (left < this.length && this.isHigherPriority(left, first)) {
595
+ first = left;
596
+ }
597
+ if (right < this.length && this.isHigherPriority(right, first)) {
598
+ first = right;
599
+ }
600
+ if (first !== index) {
601
+ var temp = this.items[index];
602
+ this.items[index] = this.items[first];
603
+ this.items[first] = temp;
604
+ this.heapify(first);
605
+ }
606
+ };
607
+
608
+ priorityProto.peek = function () { return this.items[0].value; };
615
609
 
616
- priorityProto.removeAt = function (index) {
617
- this.items[index] = this.items[--this.length];
618
- delete this.items[this.length];
619
- this.heapify();
620
- };
610
+ priorityProto.removeAt = function (index) {
611
+ this.items[index] = this.items[--this.length];
612
+ delete this.items[this.length];
613
+ this.heapify();
614
+ };
621
615
 
622
- priorityProto.dequeue = function () {
623
- var result = this.peek();
624
- this.removeAt(0);
625
- return result;
626
- };
616
+ priorityProto.dequeue = function () {
617
+ var result = this.peek();
618
+ this.removeAt(0);
619
+ return result;
620
+ };
627
621
 
628
- priorityProto.enqueue = function (item) {
629
- var index = this.length++;
630
- this.items[index] = new IndexedItem(PriorityQueue.count++, item);
631
- this.percolate(index);
632
- };
622
+ priorityProto.enqueue = function (item) {
623
+ var index = this.length++;
624
+ this.items[index] = new IndexedItem(PriorityQueue.count++, item);
625
+ this.percolate(index);
626
+ };
633
627
 
634
- priorityProto.remove = function (item) {
635
- for (var i = 0; i < this.length; i++) {
636
- if (this.items[i].value === item) {
637
- this.removeAt(i);
638
- return true;
639
- }
640
- }
641
- return false;
642
- };
643
- PriorityQueue.count = 0;
628
+ priorityProto.remove = function (item) {
629
+ for (var i = 0; i < this.length; i++) {
630
+ if (this.items[i].value === item) {
631
+ this.removeAt(i);
632
+ return true;
633
+ }
634
+ }
635
+ return false;
636
+ };
637
+ PriorityQueue.count = 0;
644
638
  /**
645
639
  * Represents a group of disposable resources that are disposed together.
646
640
  * @constructor
@@ -709,39 +703,38 @@ if (!Array.prototype.forEach) {
709
703
  return this.disposables.slice(0);
710
704
  };
711
705
 
712
- /**
713
- * Provides a set of static methods for creating Disposables.
714
- *
715
- * @constructor
716
- * @param {Function} dispose Action to run during the first call to dispose. The action is guaranteed to be run at most once.
717
- */
718
- var Disposable = Rx.Disposable = function (action) {
719
- this.isDisposed = false;
720
- this.action = action || noop;
721
- };
706
+ /**
707
+ * Provides a set of static methods for creating Disposables.
708
+ *
709
+ * @constructor
710
+ * @param {Function} dispose Action to run during the first call to dispose. The action is guaranteed to be run at most once.
711
+ */
712
+ var Disposable = Rx.Disposable = function (action) {
713
+ this.isDisposed = false;
714
+ this.action = action || noop;
715
+ };
722
716
 
723
- /** Performs the task of cleaning up resources. */
724
- Disposable.prototype.dispose = function () {
725
- if (!this.isDisposed) {
726
- this.action();
727
- this.isDisposed = true;
728
- }
729
- };
717
+ /** Performs the task of cleaning up resources. */
718
+ Disposable.prototype.dispose = function () {
719
+ if (!this.isDisposed) {
720
+ this.action();
721
+ this.isDisposed = true;
722
+ }
723
+ };
730
724
 
731
- /**
732
- * Creates a disposable object that invokes the specified action when disposed.
733
- * @param {Function} dispose Action to run during the first call to dispose. The action is guaranteed to be run at most once.
734
- * @return {Disposable} The disposable object that runs the given action upon disposal.
735
- */
736
- var disposableCreate = Disposable.create = function (action) { return new Disposable(action); };
725
+ /**
726
+ * Creates a disposable object that invokes the specified action when disposed.
727
+ * @param {Function} dispose Action to run during the first call to dispose. The action is guaranteed to be run at most once.
728
+ * @return {Disposable} The disposable object that runs the given action upon disposal.
729
+ */
730
+ var disposableCreate = Disposable.create = function (action) { return new Disposable(action); };
737
731
 
738
- /**
739
- * Gets the disposable that does nothing when disposed.
740
- */
741
- var disposableEmpty = Disposable.empty = { dispose: noop };
732
+ /**
733
+ * Gets the disposable that does nothing when disposed.
734
+ */
735
+ var disposableEmpty = Disposable.empty = { dispose: noop };
742
736
 
743
- var SingleAssignmentDisposable = Rx.SingleAssignmentDisposable =
744
- SerialDisposable = Rx.SerialDisposable = (function () {
737
+ var SingleAssignmentDisposable = Rx.SingleAssignmentDisposable = (function () {
745
738
  function BooleanDisposable () {
746
739
  this.isDisposed = false;
747
740
  this.current = null;
@@ -786,6 +779,7 @@ if (!Array.prototype.forEach) {
786
779
 
787
780
  return BooleanDisposable;
788
781
  }());
782
+ var SerialDisposable = Rx.SerialDisposable = SingleAssignmentDisposable;
789
783
  /**
790
784
  * Represents a disposable resource that only disposes its underlying disposable resource when all dependent disposable objects have been disposed.
791
785
  */
@@ -1154,6 +1148,7 @@ if (!Array.prototype.forEach) {
1154
1148
  }(Scheduler.prototype));
1155
1149
 
1156
1150
  (function (schedulerProto) {
1151
+
1157
1152
  /**
1158
1153
  * Schedules a periodic piece of work by dynamically discovering the scheduler's capabilities. The periodic task will be scheduled using window.setInterval for the base implementation.
1159
1154
  * @param {Number} period Period for running the work periodically.
@@ -1171,17 +1166,19 @@ if (!Array.prototype.forEach) {
1171
1166
  * @param {Function} action Action to be executed, potentially updating the state.
1172
1167
  * @returns {Disposable} The disposable object used to cancel the scheduled recurring action (best effort).
1173
1168
  */
1174
- Scheduler.prototype.schedulePeriodicWithState = function (state, period, action) {
1169
+ Scheduler.prototype.schedulePeriodicWithState = function(state, period, action) {
1170
+ if (typeof root.setInterval === 'undefined') { throw new Error('Periodic scheduling not supported.'); }
1175
1171
  var s = state;
1176
-
1177
- var id = setInterval(function () {
1172
+
1173
+ var id = root.setInterval(function () {
1178
1174
  s = action(s);
1179
1175
  }, period);
1180
1176
 
1181
1177
  return disposableCreate(function () {
1182
- clearInterval(id);
1178
+ root.clearInterval(id);
1183
1179
  });
1184
1180
  };
1181
+
1185
1182
  }(Scheduler.prototype));
1186
1183
 
1187
1184
  (function (schedulerProto) {
@@ -1303,100 +1300,121 @@ if (!Array.prototype.forEach) {
1303
1300
  return currentScheduler;
1304
1301
  }());
1305
1302
 
1306
-
1307
1303
  var scheduleMethod, clearMethod = noop;
1308
- (function () {
1304
+ var localTimer = (function () {
1305
+ var localSetTimeout, localClearTimeout = noop;
1306
+ if ('WScript' in this) {
1307
+ localSetTimeout = function (fn, time) {
1308
+ WScript.Sleep(time);
1309
+ fn();
1310
+ };
1311
+ } else if (!!root.setTimeout) {
1312
+ localSetTimeout = root.setTimeout;
1313
+ localClearTimeout = root.clearTimeout;
1314
+ } else {
1315
+ throw new Error('No concurrency detected!');
1316
+ }
1309
1317
 
1310
- var reNative = RegExp('^' +
1311
- String(toString)
1312
- .replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
1313
- .replace(/toString| for [^\]]+/g, '.*?') + '$'
1314
- );
1318
+ return {
1319
+ setTimeout: localSetTimeout,
1320
+ clearTimeout: localClearTimeout
1321
+ };
1322
+ }());
1323
+ var localSetTimeout = localTimer.setTimeout,
1324
+ localClearTimeout = localTimer.clearTimeout;
1325
+
1326
+ (function () {
1327
+
1328
+ var reNative = RegExp('^' +
1329
+ String(toString)
1330
+ .replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
1331
+ .replace(/toString| for [^\]]+/g, '.*?') + '$'
1332
+ );
1333
+
1334
+ var setImmediate = typeof (setImmediate = freeGlobal && moduleExports && freeGlobal.setImmediate) == 'function' &&
1335
+ !reNative.test(setImmediate) && setImmediate,
1336
+ clearImmediate = typeof (clearImmediate = freeGlobal && moduleExports && freeGlobal.clearImmediate) == 'function' &&
1337
+ !reNative.test(clearImmediate) && clearImmediate;
1338
+
1339
+ function postMessageSupported () {
1340
+ // Ensure not in a worker
1341
+ if (!root.postMessage || root.importScripts) { return false; }
1342
+ var isAsync = false,
1343
+ oldHandler = root.onmessage;
1344
+ // Test for async
1345
+ root.onmessage = function () { isAsync = true; };
1346
+ root.postMessage('','*');
1347
+ root.onmessage = oldHandler;
1348
+
1349
+ return isAsync;
1350
+ }
1315
1351
 
1316
- var setImmediate = typeof (setImmediate = freeGlobal && moduleExports && freeGlobal.setImmediate) == 'function' &&
1317
- !reNative.test(setImmediate) && setImmediate,
1318
- clearImmediate = typeof (clearImmediate = freeGlobal && moduleExports && freeGlobal.clearImmediate) == 'function' &&
1319
- !reNative.test(clearImmediate) && clearImmediate;
1320
-
1321
- function postMessageSupported () {
1322
- // Ensure not in a worker
1323
- if (!root.postMessage || root.importScripts) { return false; }
1324
- var isAsync = false,
1325
- oldHandler = root.onmessage;
1326
- // Test for async
1327
- root.onmessage = function () { isAsync = true; };
1328
- root.postMessage('','*');
1329
- root.onmessage = oldHandler;
1330
-
1331
- return isAsync;
1352
+ // Use in order, nextTick, setImmediate, postMessage, MessageChannel, script readystatechanged, setTimeout
1353
+ if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
1354
+ scheduleMethod = process.nextTick;
1355
+ } else if (typeof setImmediate === 'function') {
1356
+ scheduleMethod = setImmediate;
1357
+ clearMethod = clearImmediate;
1358
+ } else if (postMessageSupported()) {
1359
+ var MSG_PREFIX = 'ms.rx.schedule' + Math.random(),
1360
+ tasks = {},
1361
+ taskId = 0;
1362
+
1363
+ function onGlobalPostMessage(event) {
1364
+ // Only if we're a match to avoid any other global events
1365
+ if (typeof event.data === 'string' && event.data.substring(0, MSG_PREFIX.length) === MSG_PREFIX) {
1366
+ var handleId = event.data.substring(MSG_PREFIX.length),
1367
+ action = tasks[handleId];
1368
+ action();
1369
+ delete tasks[handleId];
1370
+ }
1332
1371
  }
1333
1372
 
1334
- // Use in order, nextTick, setImmediate, postMessage, MessageChannel, script readystatechanged, setTimeout
1335
- if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
1336
- scheduleMethod = process.nextTick;
1337
- } else if (typeof setImmediate === 'function') {
1338
- scheduleMethod = setImmediate;
1339
- clearMethod = clearImmediate;
1340
- } else if (postMessageSupported()) {
1341
- var MSG_PREFIX = 'ms.rx.schedule' + Math.random(),
1342
- tasks = {},
1343
- taskId = 0;
1344
-
1345
- function onGlobalPostMessage(event) {
1346
- // Only if we're a match to avoid any other global events
1347
- if (typeof event.data === 'string' && event.data.substring(0, MSG_PREFIX.length) === MSG_PREFIX) {
1348
- var handleId = event.data.substring(MSG_PREFIX.length),
1349
- action = tasks[handleId];
1350
- action();
1351
- delete tasks[handleId];
1352
- }
1353
- }
1354
-
1355
- if (root.addEventListener) {
1356
- root.addEventListener('message', onGlobalPostMessage, false);
1357
- } else {
1358
- root.attachEvent('onmessage', onGlobalPostMessage, false);
1359
- }
1373
+ if (root.addEventListener) {
1374
+ root.addEventListener('message', onGlobalPostMessage, false);
1375
+ } else {
1376
+ root.attachEvent('onmessage', onGlobalPostMessage, false);
1377
+ }
1360
1378
 
1361
- scheduleMethod = function (action) {
1362
- var currentId = taskId++;
1363
- tasks[currentId] = action;
1364
- root.postMessage(MSG_PREFIX + currentId, '*');
1365
- };
1366
- } else if (!!root.MessageChannel) {
1367
- var channel = new root.MessageChannel(),
1368
- channelTasks = {},
1369
- channelTaskId = 0;
1370
-
1371
- channel.port1.onmessage = function (event) {
1372
- var id = event.data,
1373
- action = channelTasks[id];
1374
- action();
1375
- delete channelTasks[id];
1376
- };
1379
+ scheduleMethod = function (action) {
1380
+ var currentId = taskId++;
1381
+ tasks[currentId] = action;
1382
+ root.postMessage(MSG_PREFIX + currentId, '*');
1383
+ };
1384
+ } else if (!!root.MessageChannel) {
1385
+ var channel = new root.MessageChannel(),
1386
+ channelTasks = {},
1387
+ channelTaskId = 0;
1388
+
1389
+ channel.port1.onmessage = function (event) {
1390
+ var id = event.data,
1391
+ action = channelTasks[id];
1392
+ action();
1393
+ delete channelTasks[id];
1394
+ };
1377
1395
 
1378
- scheduleMethod = function (action) {
1379
- var id = channelTaskId++;
1380
- channelTasks[id] = action;
1381
- channel.port2.postMessage(id);
1382
- };
1383
- } else if ('document' in root && 'onreadystatechange' in root.document.createElement('script')) {
1384
-
1385
- scheduleMethod = function (action) {
1386
- var scriptElement = root.document.createElement('script');
1387
- scriptElement.onreadystatechange = function () {
1388
- action();
1389
- scriptElement.onreadystatechange = null;
1390
- scriptElement.parentNode.removeChild(scriptElement);
1391
- scriptElement = null;
1392
- };
1393
- root.document.documentElement.appendChild(scriptElement);
1396
+ scheduleMethod = function (action) {
1397
+ var id = channelTaskId++;
1398
+ channelTasks[id] = action;
1399
+ channel.port2.postMessage(id);
1400
+ };
1401
+ } else if ('document' in root && 'onreadystatechange' in root.document.createElement('script')) {
1402
+
1403
+ scheduleMethod = function (action) {
1404
+ var scriptElement = root.document.createElement('script');
1405
+ scriptElement.onreadystatechange = function () {
1406
+ action();
1407
+ scriptElement.onreadystatechange = null;
1408
+ scriptElement.parentNode.removeChild(scriptElement);
1409
+ scriptElement = null;
1394
1410
  };
1411
+ root.document.documentElement.appendChild(scriptElement);
1412
+ };
1395
1413
 
1396
- } else {
1397
- scheduleMethod = function (action) { return setTimeout(action, 0); };
1398
- clearMethod = clearTimeout;
1399
- }
1414
+ } else {
1415
+ scheduleMethod = function (action) { return localSetTimeout(action, 0); };
1416
+ clearMethod = localClearTimeout;
1417
+ }
1400
1418
  }());
1401
1419
 
1402
1420
  /**
@@ -1405,33 +1423,33 @@ if (!Array.prototype.forEach) {
1405
1423
  var timeoutScheduler = Scheduler.timeout = (function () {
1406
1424
 
1407
1425
  function scheduleNow(state, action) {
1408
- var scheduler = this,
1409
- disposable = new SingleAssignmentDisposable();
1410
- var id = scheduleMethod(function () {
1411
- if (!disposable.isDisposed) {
1412
- disposable.setDisposable(action(scheduler, state));
1413
- }
1414
- });
1415
- return new CompositeDisposable(disposable, disposableCreate(function () {
1416
- clearMethod(id);
1417
- }));
1426
+ var scheduler = this,
1427
+ disposable = new SingleAssignmentDisposable();
1428
+ var id = scheduleMethod(function () {
1429
+ if (!disposable.isDisposed) {
1430
+ disposable.setDisposable(action(scheduler, state));
1431
+ }
1432
+ });
1433
+ return new CompositeDisposable(disposable, disposableCreate(function () {
1434
+ clearMethod(id);
1435
+ }));
1418
1436
  }
1419
1437
 
1420
1438
  function scheduleRelative(state, dueTime, action) {
1421
- var scheduler = this,
1422
- dt = Scheduler.normalize(dueTime);
1423
- if (dt === 0) {
1424
- return scheduler.scheduleWithState(state, action);
1425
- }
1426
- var disposable = new SingleAssignmentDisposable();
1427
- var id = setTimeout(function () {
1428
- if (!disposable.isDisposed) {
1429
- disposable.setDisposable(action(scheduler, state));
1430
- }
1431
- }, dt);
1432
- return new CompositeDisposable(disposable, disposableCreate(function () {
1433
- clearTimeout(id);
1434
- }));
1439
+ var scheduler = this,
1440
+ dt = Scheduler.normalize(dueTime);
1441
+ if (dt === 0) {
1442
+ return scheduler.scheduleWithState(state, action);
1443
+ }
1444
+ var disposable = new SingleAssignmentDisposable();
1445
+ var id = localSetTimeout(function () {
1446
+ if (!disposable.isDisposed) {
1447
+ disposable.setDisposable(action(scheduler, state));
1448
+ }
1449
+ }, dt);
1450
+ return new CompositeDisposable(disposable, disposableCreate(function () {
1451
+ localClearTimeout(id);
1452
+ }));
1435
1453
  }
1436
1454
 
1437
1455
  function scheduleAbsolute(state, dueTime, action) {
@@ -2023,11 +2041,11 @@ if (!Array.prototype.forEach) {
2023
2041
  return CheckedObserver;
2024
2042
  }(Observer));
2025
2043
 
2026
- var ScheduledObserver = Rx.internals.ScheduledObserver = (function (_super) {
2027
- inherits(ScheduledObserver, _super);
2044
+ var ScheduledObserver = Rx.internals.ScheduledObserver = (function (__super__) {
2045
+ inherits(ScheduledObserver, __super__);
2028
2046
 
2029
2047
  function ScheduledObserver(scheduler, observer) {
2030
- _super.call(this);
2048
+ __super__.call(this);
2031
2049
  this.scheduler = scheduler;
2032
2050
  this.observer = observer;
2033
2051
  this.isAcquired = false;
@@ -2043,10 +2061,10 @@ if (!Array.prototype.forEach) {
2043
2061
  });
2044
2062
  };
2045
2063
 
2046
- ScheduledObserver.prototype.error = function (exception) {
2064
+ ScheduledObserver.prototype.error = function (err) {
2047
2065
  var self = this;
2048
2066
  this.queue.push(function () {
2049
- self.observer.onError(exception);
2067
+ self.observer.onError(err);
2050
2068
  });
2051
2069
  };
2052
2070
 
@@ -2085,42 +2103,37 @@ if (!Array.prototype.forEach) {
2085
2103
  };
2086
2104
 
2087
2105
  ScheduledObserver.prototype.dispose = function () {
2088
- _super.prototype.dispose.call(this);
2106
+ __super__.prototype.dispose.call(this);
2089
2107
  this.disposable.dispose();
2090
2108
  };
2091
2109
 
2092
2110
  return ScheduledObserver;
2093
2111
  }(AbstractObserver));
2094
2112
 
2095
- /** @private */
2096
- var ObserveOnObserver = (function (_super) {
2097
- inherits(ObserveOnObserver, _super);
2113
+ var ObserveOnObserver = (function (__super__) {
2114
+ inherits(ObserveOnObserver, __super__);
2098
2115
 
2099
- /** @private */
2100
- function ObserveOnObserver() {
2101
- _super.apply(this, arguments);
2102
- }
2116
+ function ObserveOnObserver() {
2117
+ __super__.apply(this, arguments);
2118
+ }
2103
2119
 
2104
- /** @private */
2105
- ObserveOnObserver.prototype.next = function (value) {
2106
- _super.prototype.next.call(this, value);
2107
- this.ensureActive();
2108
- };
2120
+ ObserveOnObserver.prototype.next = function (value) {
2121
+ __super__.prototype.next.call(this, value);
2122
+ this.ensureActive();
2123
+ };
2109
2124
 
2110
- /** @private */
2111
- ObserveOnObserver.prototype.error = function (e) {
2112
- _super.prototype.error.call(this, e);
2113
- this.ensureActive();
2114
- };
2125
+ ObserveOnObserver.prototype.error = function (e) {
2126
+ __super__.prototype.error.call(this, e);
2127
+ this.ensureActive();
2128
+ };
2115
2129
 
2116
- /** @private */
2117
- ObserveOnObserver.prototype.completed = function () {
2118
- _super.prototype.completed.call(this);
2119
- this.ensureActive();
2120
- };
2130
+ ObserveOnObserver.prototype.completed = function () {
2131
+ __super__.prototype.completed.call(this);
2132
+ this.ensureActive();
2133
+ };
2121
2134
 
2122
- return ObserveOnObserver;
2123
- })(ScheduledObserver);
2135
+ return ObserveOnObserver;
2136
+ })(ScheduledObserver);
2124
2137
 
2125
2138
  var observableProto;
2126
2139
 
@@ -2160,43 +2173,43 @@ if (!Array.prototype.forEach) {
2160
2173
  return Observable;
2161
2174
  })();
2162
2175
 
2163
- /**
2164
- * Wraps the source sequence in order to run its observer callbacks on the specified scheduler.
2165
- *
2166
- * This only invokes observer callbacks on a scheduler. In case the subscription and/or unsubscription actions have side-effects
2167
- * that require to be run on a scheduler, use subscribeOn.
2168
- *
2169
- * @param {Scheduler} scheduler Scheduler to notify observers on.
2170
- * @returns {Observable} The source sequence whose observations happen on the specified scheduler.
2171
- */
2172
- observableProto.observeOn = function (scheduler) {
2173
- var source = this;
2174
- return new AnonymousObservable(function (observer) {
2175
- return source.subscribe(new ObserveOnObserver(scheduler, observer));
2176
- });
2177
- };
2176
+ /**
2177
+ * Wraps the source sequence in order to run its observer callbacks on the specified scheduler.
2178
+ *
2179
+ * This only invokes observer callbacks on a scheduler. In case the subscription and/or unsubscription actions have side-effects
2180
+ * that require to be run on a scheduler, use subscribeOn.
2181
+ *
2182
+ * @param {Scheduler} scheduler Scheduler to notify observers on.
2183
+ * @returns {Observable} The source sequence whose observations happen on the specified scheduler.
2184
+ */
2185
+ observableProto.observeOn = function (scheduler) {
2186
+ var source = this;
2187
+ return new AnonymousObservable(function (observer) {
2188
+ return source.subscribe(new ObserveOnObserver(scheduler, observer));
2189
+ });
2190
+ };
2178
2191
 
2179
- /**
2180
- * Wraps the source sequence in order to run its subscription and unsubscription logic on the specified scheduler. This operation is not commonly used;
2181
- * see the remarks section for more information on the distinction between subscribeOn and observeOn.
2192
+ /**
2193
+ * Wraps the source sequence in order to run its subscription and unsubscription logic on the specified scheduler. This operation is not commonly used;
2194
+ * see the remarks section for more information on the distinction between subscribeOn and observeOn.
2182
2195
 
2183
- * This only performs the side-effects of subscription and unsubscription on the specified scheduler. In order to invoke observer
2184
- * callbacks on a scheduler, use observeOn.
2196
+ * This only performs the side-effects of subscription and unsubscription on the specified scheduler. In order to invoke observer
2197
+ * callbacks on a scheduler, use observeOn.
2185
2198
 
2186
- * @param {Scheduler} scheduler Scheduler to perform subscription and unsubscription actions on.
2187
- * @returns {Observable} The source sequence whose subscriptions and unsubscriptions happen on the specified scheduler.
2188
- */
2189
- observableProto.subscribeOn = function (scheduler) {
2190
- var source = this;
2191
- return new AnonymousObservable(function (observer) {
2192
- var m = new SingleAssignmentDisposable(), d = new SerialDisposable();
2193
- d.setDisposable(m);
2194
- m.setDisposable(scheduler.schedule(function () {
2195
- d.setDisposable(new ScheduledDisposable(scheduler, source.subscribe(observer)));
2196
- }));
2197
- return d;
2198
- });
2199
- };
2199
+ * @param {Scheduler} scheduler Scheduler to perform subscription and unsubscription actions on.
2200
+ * @returns {Observable} The source sequence whose subscriptions and unsubscriptions happen on the specified scheduler.
2201
+ */
2202
+ observableProto.subscribeOn = function (scheduler) {
2203
+ var source = this;
2204
+ return new AnonymousObservable(function (observer) {
2205
+ var m = new SingleAssignmentDisposable(), d = new SerialDisposable();
2206
+ d.setDisposable(m);
2207
+ m.setDisposable(scheduler.schedule(function () {
2208
+ d.setDisposable(new ScheduledDisposable(scheduler, source.subscribe(observer)));
2209
+ }));
2210
+ return d;
2211
+ });
2212
+ };
2200
2213
 
2201
2214
  /**
2202
2215
  * Converts a Promise to an Observable sequence
@@ -2219,38 +2232,32 @@ if (!Array.prototype.forEach) {
2219
2232
  return subject;
2220
2233
  });
2221
2234
  };
2222
- /*
2223
- * Converts an existing observable sequence to an ES6 Compatible Promise
2224
- * @example
2225
- * var promise = Rx.Observable.return(42).toPromise(RSVP.Promise);
2226
- *
2227
- * // With config
2228
- * Rx.config.Promise = RSVP.Promise;
2229
- * var promise = Rx.Observable.return(42).toPromise();
2230
- * @param {Function} [promiseCtor] The constructor of the promise. If not provided, it looks for it in Rx.config.Promise.
2231
- * @returns {Promise} An ES6 compatible promise with the last value from the observable sequence.
2232
- */
2233
- observableProto.toPromise = function (promiseCtor) {
2234
- promiseCtor || (promiseCtor = Rx.config.Promise);
2235
- if (!promiseCtor) {
2236
- throw new Error('Promise type not provided nor in Rx.config.Promise');
2237
- }
2238
- var source = this;
2239
- return new promiseCtor(function (resolve, reject) {
2240
- // No cancellation can be done
2241
- var value, hasValue = false;
2242
- source.subscribe(function (v) {
2243
- value = v;
2244
- hasValue = true;
2245
- }, function (err) {
2246
- reject(err);
2247
- }, function () {
2248
- if (hasValue) {
2249
- resolve(value);
2250
- }
2251
- });
2252
- });
2253
- };
2235
+ /*
2236
+ * Converts an existing observable sequence to an ES6 Compatible Promise
2237
+ * @example
2238
+ * var promise = Rx.Observable.return(42).toPromise(RSVP.Promise);
2239
+ *
2240
+ * // With config
2241
+ * Rx.config.Promise = RSVP.Promise;
2242
+ * var promise = Rx.Observable.return(42).toPromise();
2243
+ * @param {Function} [promiseCtor] The constructor of the promise. If not provided, it looks for it in Rx.config.Promise.
2244
+ * @returns {Promise} An ES6 compatible promise with the last value from the observable sequence.
2245
+ */
2246
+ observableProto.toPromise = function (promiseCtor) {
2247
+ promiseCtor || (promiseCtor = Rx.config.Promise);
2248
+ if (!promiseCtor) { throw new TypeError('Promise type not provided nor in Rx.config.Promise'); }
2249
+ var source = this;
2250
+ return new promiseCtor(function (resolve, reject) {
2251
+ // No cancellation can be done
2252
+ var value, hasValue = false;
2253
+ source.subscribe(function (v) {
2254
+ value = v;
2255
+ hasValue = true;
2256
+ }, reject, function () {
2257
+ hasValue && resolve(value);
2258
+ });
2259
+ });
2260
+ };
2254
2261
  /**
2255
2262
  * Creates a list from an observable sequence.
2256
2263
  * @returns An observable sequence containing a single element with a list containing all the elements of the source sequence.
@@ -2504,15 +2511,15 @@ if (!Array.prototype.forEach) {
2504
2511
  return observableFromArray(args, scheduler);
2505
2512
  };
2506
2513
 
2507
- /**
2508
- * Returns a non-terminating observable sequence, which can be used to denote an infinite duration (e.g. when using reactive joins).
2509
- * @returns {Observable} An observable sequence whose observers will never get called.
2510
- */
2511
- var observableNever = Observable.never = function () {
2512
- return new AnonymousObservable(function () {
2513
- return disposableEmpty;
2514
- });
2515
- };
2514
+ /**
2515
+ * Returns a non-terminating observable sequence, which can be used to denote an infinite duration (e.g. when using reactive joins).
2516
+ * @returns {Observable} An observable sequence whose observers will never get called.
2517
+ */
2518
+ var observableNever = Observable.never = function () {
2519
+ return new AnonymousObservable(function () {
2520
+ return disposableEmpty;
2521
+ });
2522
+ };
2516
2523
 
2517
2524
  /**
2518
2525
  * Generates an observable sequence of integral numbers within a specified range, using the specified scheduler to send out observer messages.
@@ -2580,16 +2587,12 @@ if (!Array.prototype.forEach) {
2580
2587
 
2581
2588
  /**
2582
2589
  * Returns an observable sequence that terminates with an exception, using the specified scheduler to send out the single onError message.
2583
- * There is an alias to this method called 'throwException' for browsers <IE9.
2584
- *
2585
- * @example
2586
- * var res = Rx.Observable.throw(new Error('Error'));
2587
- * var res = Rx.Observable.throw(new Error('Error'), Rx.Scheduler.timeout);
2590
+ * There is an alias to this method called 'throwError' for browsers <IE9.
2588
2591
  * @param {Mixed} exception An object used for the sequence's termination.
2589
2592
  * @param {Scheduler} scheduler Scheduler to send the exceptional termination call on. If not specified, defaults to Scheduler.immediate.
2590
2593
  * @returns {Observable} The observable sequence that terminates exceptionally with the specified exception object.
2591
2594
  */
2592
- var observableThrow = Observable['throw'] = Observable.throwException = function (exception, scheduler) {
2595
+ var observableThrow = Observable['throw'] = Observable.throwException = Observable.throwError = function (exception, scheduler) {
2593
2596
  isScheduler(scheduler) || (scheduler = immediateScheduler);
2594
2597
  return new AnonymousObservable(function (observer) {
2595
2598
  return scheduler.schedule(function () {
@@ -2599,10 +2602,7 @@ if (!Array.prototype.forEach) {
2599
2602
  };
2600
2603
 
2601
2604
  /**
2602
- * Constructs an observable sequence that depends on a resource object, whose lifetime is tied to the resulting observable sequence's lifetime.
2603
- *
2604
- * @example
2605
- * var res = Rx.Observable.using(function () { return new AsyncSubject(); }, function (s) { return s; });
2605
+ * Constructs an observable sequence that depends on a resource object, whose lifetime is tied to the resulting observable sequence's lifetime.
2606
2606
  * @param {Function} resourceFactory Factory function to obtain a resource object.
2607
2607
  * @param {Function} observableFactory Factory function to obtain an observable sequence that depends on the obtained resource.
2608
2608
  * @returns {Observable} An observable sequence whose lifetime controls the lifetime of the dependent resource object.
@@ -2612,9 +2612,7 @@ if (!Array.prototype.forEach) {
2612
2612
  var disposable = disposableEmpty, resource, source;
2613
2613
  try {
2614
2614
  resource = resourceFactory();
2615
- if (resource) {
2616
- disposable = resource;
2617
- }
2615
+ resource && (disposable = resource);
2618
2616
  source = observableFactory(resource);
2619
2617
  } catch (exception) {
2620
2618
  return new CompositeDisposable(observableThrow(exception).subscribe(observer), disposable);
@@ -2971,20 +2969,16 @@ if (!Array.prototype.forEach) {
2971
2969
  var innerSubscription = new SingleAssignmentDisposable();
2972
2970
  group.add(innerSubscription);
2973
2971
 
2974
- // Check if Promise or Observable
2975
- if (isPromise(innerSource)) {
2976
- innerSource = observableFromPromise(innerSource);
2977
- }
2972
+ // Check for promises support
2973
+ isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
2978
2974
 
2979
- innerSubscription.setDisposable(innerSource.subscribe(function (x) {
2980
- observer.onNext(x);
2981
- }, observer.onError.bind(observer), function () {
2982
- group.remove(innerSubscription);
2983
- if (isStopped && group.length === 1) { observer.onCompleted(); }
2975
+ innerSubscription.setDisposable(innerSource.subscribe(observer.onNext.bind(observer), observer.onError.bind(observer), function () {
2976
+ group.remove(innerSubscription);
2977
+ isStopped && group.length === 1 && observer.onCompleted();
2984
2978
  }));
2985
2979
  }, observer.onError.bind(observer), function () {
2986
2980
  isStopped = true;
2987
- if (group.length === 1) { observer.onCompleted(); }
2981
+ group.length === 1 && observer.onCompleted();
2988
2982
  }));
2989
2983
  return group;
2990
2984
  });
@@ -2996,9 +2990,7 @@ if (!Array.prototype.forEach) {
2996
2990
  * @returns {Observable} An observable sequence that concatenates the first and second sequence, even if the first sequence terminates exceptionally.
2997
2991
  */
2998
2992
  observableProto.onErrorResumeNext = function (second) {
2999
- if (!second) {
3000
- throw new Error('Second observable is required');
3001
- }
2993
+ if (!second) { throw new Error('Second observable is required'); }
3002
2994
  return onErrorResumeNext([this, second]);
3003
2995
  };
3004
2996
 
@@ -3021,11 +3013,7 @@ if (!Array.prototype.forEach) {
3021
3013
  isPromise(current) && (current = observableFromPromise(current));
3022
3014
  d = new SingleAssignmentDisposable();
3023
3015
  subscription.setDisposable(d);
3024
- d.setDisposable(current.subscribe(observer.onNext.bind(observer), function () {
3025
- self();
3026
- }, function () {
3027
- self();
3028
- }));
3016
+ d.setDisposable(current.subscribe(observer.onNext.bind(observer), self, self));
3029
3017
  } else {
3030
3018
  observer.onCompleted();
3031
3019
  }
@@ -3064,52 +3052,44 @@ if (!Array.prototype.forEach) {
3064
3052
  });
3065
3053
  };
3066
3054
 
3067
- /**
3068
- * Transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.
3069
- * @returns {Observable} The observable sequence that at any point in time produces the elements of the most recent inner observable sequence that has been received.
3070
- */
3071
- observableProto['switch'] = observableProto.switchLatest = function () {
3072
- var sources = this;
3073
- return new AnonymousObservable(function (observer) {
3074
- var hasLatest = false,
3075
- innerSubscription = new SerialDisposable(),
3076
- isStopped = false,
3077
- latest = 0,
3078
- subscription = sources.subscribe(function (innerSource) {
3079
- var d = new SingleAssignmentDisposable(), id = ++latest;
3080
- hasLatest = true;
3081
- innerSubscription.setDisposable(d);
3082
-
3083
- // Check if Promise or Observable
3084
- if (isPromise(innerSource)) {
3085
- innerSource = observableFromPromise(innerSource);
3086
- }
3055
+ /**
3056
+ * Transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.
3057
+ * @returns {Observable} The observable sequence that at any point in time produces the elements of the most recent inner observable sequence that has been received.
3058
+ */
3059
+ observableProto['switch'] = observableProto.switchLatest = function () {
3060
+ var sources = this;
3061
+ return new AnonymousObservable(function (observer) {
3062
+ var hasLatest = false,
3063
+ innerSubscription = new SerialDisposable(),
3064
+ isStopped = false,
3065
+ latest = 0,
3066
+ subscription = sources.subscribe(
3067
+ function (innerSource) {
3068
+ var d = new SingleAssignmentDisposable(), id = ++latest;
3069
+ hasLatest = true;
3070
+ innerSubscription.setDisposable(d);
3071
+
3072
+ // Check if Promise or Observable
3073
+ isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
3087
3074
 
3088
- d.setDisposable(innerSource.subscribe(function (x) {
3089
- if (latest === id) {
3090
- observer.onNext(x);
3091
- }
3092
- }, function (e) {
3093
- if (latest === id) {
3094
- observer.onError(e);
3095
- }
3096
- }, function () {
3097
- if (latest === id) {
3098
- hasLatest = false;
3099
- if (isStopped) {
3100
- observer.onCompleted();
3101
- }
3102
- }
3103
- }));
3104
- }, observer.onError.bind(observer), function () {
3105
- isStopped = true;
3106
- if (!hasLatest) {
3107
- observer.onCompleted();
3108
- }
3109
- });
3110
- return new CompositeDisposable(subscription, innerSubscription);
3111
- });
3112
- };
3075
+ d.setDisposable(innerSource.subscribe(
3076
+ function (x) { latest === id && observer.onNext(x); },
3077
+ function (e) { latest === id && observer.onError(e); },
3078
+ function () {
3079
+ if (latest === id) {
3080
+ hasLatest = false;
3081
+ isStopped && observer.onCompleted();
3082
+ }
3083
+ }));
3084
+ },
3085
+ observer.onError.bind(observer),
3086
+ function () {
3087
+ isStopped = true;
3088
+ !hasLatest && observer.onCompleted();
3089
+ });
3090
+ return new CompositeDisposable(subscription, innerSubscription);
3091
+ });
3092
+ };
3113
3093
 
3114
3094
  /**
3115
3095
  * Returns the values from the source observable sequence until the other observable sequence produces a value.
@@ -3274,16 +3254,13 @@ if (!Array.prototype.forEach) {
3274
3254
  });
3275
3255
  };
3276
3256
 
3277
- /**
3278
- * Hides the identity of an observable sequence.
3279
- * @returns {Observable} An observable sequence that hides the identity of the source sequence.
3280
- */
3281
- observableProto.asObservable = function () {
3282
- var source = this;
3283
- return new AnonymousObservable(function (observer) {
3284
- return source.subscribe(observer);
3285
- });
3286
- };
3257
+ /**
3258
+ * Hides the identity of an observable sequence.
3259
+ * @returns {Observable} An observable sequence that hides the identity of the source sequence.
3260
+ */
3261
+ observableProto.asObservable = function () {
3262
+ return new AnonymousObservable(this.subscribe.bind(this));
3263
+ };
3287
3264
 
3288
3265
  /**
3289
3266
  * Projects each element of an observable sequence into zero or more buffers which are produced based on element count information.
@@ -3448,35 +3425,35 @@ if (!Array.prototype.forEach) {
3448
3425
  });
3449
3426
  };
3450
3427
 
3451
- /**
3452
- * Ignores all elements in an observable sequence leaving only the termination messages.
3453
- * @returns {Observable} An empty observable sequence that signals termination, successful or exceptional, of the source sequence.
3454
- */
3455
- observableProto.ignoreElements = function () {
3456
- var source = this;
3457
- return new AnonymousObservable(function (observer) {
3458
- return source.subscribe(noop, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3459
- });
3460
- };
3428
+ /**
3429
+ * Ignores all elements in an observable sequence leaving only the termination messages.
3430
+ * @returns {Observable} An empty observable sequence that signals termination, successful or exceptional, of the source sequence.
3431
+ */
3432
+ observableProto.ignoreElements = function () {
3433
+ var source = this;
3434
+ return new AnonymousObservable(function (observer) {
3435
+ return source.subscribe(noop, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3436
+ });
3437
+ };
3461
3438
 
3462
- /**
3463
- * Materializes the implicit notifications of an observable sequence as explicit notification values.
3464
- * @returns {Observable} An observable sequence containing the materialized notification values from the source sequence.
3465
- */
3466
- observableProto.materialize = function () {
3467
- var source = this;
3468
- return new AnonymousObservable(function (observer) {
3469
- return source.subscribe(function (value) {
3470
- observer.onNext(notificationCreateOnNext(value));
3471
- }, function (e) {
3472
- observer.onNext(notificationCreateOnError(e));
3473
- observer.onCompleted();
3474
- }, function () {
3475
- observer.onNext(notificationCreateOnCompleted());
3476
- observer.onCompleted();
3477
- });
3478
- });
3479
- };
3439
+ /**
3440
+ * Materializes the implicit notifications of an observable sequence as explicit notification values.
3441
+ * @returns {Observable} An observable sequence containing the materialized notification values from the source sequence.
3442
+ */
3443
+ observableProto.materialize = function () {
3444
+ var source = this;
3445
+ return new AnonymousObservable(function (observer) {
3446
+ return source.subscribe(function (value) {
3447
+ observer.onNext(notificationCreateOnNext(value));
3448
+ }, function (e) {
3449
+ observer.onNext(notificationCreateOnError(e));
3450
+ observer.onCompleted();
3451
+ }, function () {
3452
+ observer.onNext(notificationCreateOnCompleted());
3453
+ observer.onCompleted();
3454
+ });
3455
+ });
3456
+ };
3480
3457
 
3481
3458
  /**
3482
3459
  * Repeats the observable sequence a specified number of times. If the repeat count is not specified, the sequence repeats indefinitely.
@@ -3505,106 +3482,94 @@ if (!Array.prototype.forEach) {
3505
3482
  return enumerableRepeat(this, retryCount).catchException();
3506
3483
  };
3507
3484
 
3508
- /**
3509
- * Applies an accumulator function over an observable sequence and returns each intermediate result. The optional seed value is used as the initial accumulator value.
3510
- * For aggregation behavior with no intermediate results, see Observable.aggregate.
3511
- * @example
3512
- * var res = source.scan(function (acc, x) { return acc + x; });
3513
- * var res = source.scan(0, function (acc, x) { return acc + x; });
3514
- * @param {Mixed} [seed] The initial accumulator value.
3515
- * @param {Function} accumulator An accumulator function to be invoked on each element.
3516
- * @returns {Observable} An observable sequence containing the accumulated values.
3517
- */
3518
- observableProto.scan = function () {
3519
- var hasSeed = false, seed, accumulator, source = this;
3520
- if (arguments.length === 2) {
3521
- hasSeed = true;
3522
- seed = arguments[0];
3523
- accumulator = arguments[1];
3524
- } else {
3525
- accumulator = arguments[0];
3485
+ /**
3486
+ * Applies an accumulator function over an observable sequence and returns each intermediate result. The optional seed value is used as the initial accumulator value.
3487
+ * For aggregation behavior with no intermediate results, see Observable.aggregate.
3488
+ * @example
3489
+ * var res = source.scan(function (acc, x) { return acc + x; });
3490
+ * var res = source.scan(0, function (acc, x) { return acc + x; });
3491
+ * @param {Mixed} [seed] The initial accumulator value.
3492
+ * @param {Function} accumulator An accumulator function to be invoked on each element.
3493
+ * @returns {Observable} An observable sequence containing the accumulated values.
3494
+ */
3495
+ observableProto.scan = function () {
3496
+ var hasSeed = false, seed, accumulator, source = this;
3497
+ if (arguments.length === 2) {
3498
+ hasSeed = true;
3499
+ seed = arguments[0];
3500
+ accumulator = arguments[1];
3501
+ } else {
3502
+ accumulator = arguments[0];
3503
+ }
3504
+ return new AnonymousObservable(function (observer) {
3505
+ var hasAccumulation, accumulation, hasValue;
3506
+ return source.subscribe (
3507
+ function (x) {
3508
+ !hasValue && (hasValue = true);
3509
+ try {
3510
+ if (hasAccumulation) {
3511
+ accumulation = accumulator(accumulation, x);
3512
+ } else {
3513
+ accumulation = hasSeed ? accumulator(seed, x) : x;
3514
+ hasAccumulation = true;
3515
+ }
3516
+ } catch (e) {
3517
+ observer.onError(e);
3518
+ return;
3519
+ }
3520
+
3521
+ observer.onNext(accumulation);
3522
+ },
3523
+ observer.onError.bind(observer),
3524
+ function () {
3525
+ !hasValue && hasSeed && observer.onNext(seed);
3526
+ observer.onCompleted();
3526
3527
  }
3527
- return new AnonymousObservable(function (observer) {
3528
- var hasAccumulation, accumulation, hasValue;
3529
- return source.subscribe (
3530
- function (x) {
3531
- try {
3532
- if (!hasValue) {
3533
- hasValue = true;
3534
- }
3535
-
3536
- if (hasAccumulation) {
3537
- accumulation = accumulator(accumulation, x);
3538
- } else {
3539
- accumulation = hasSeed ? accumulator(seed, x) : x;
3540
- hasAccumulation = true;
3541
- }
3542
- } catch (e) {
3543
- observer.onError(e);
3544
- return;
3545
- }
3546
-
3547
- observer.onNext(accumulation);
3548
- },
3549
- observer.onError.bind(observer),
3550
- function () {
3551
- if (!hasValue && hasSeed) {
3552
- observer.onNext(seed);
3553
- }
3554
- observer.onCompleted();
3555
- }
3556
- );
3557
- });
3558
- };
3528
+ );
3529
+ });
3530
+ };
3559
3531
 
3560
- /**
3561
- * Bypasses a specified number of elements at the end of an observable sequence.
3562
- * @description
3563
- * This operator accumulates a queue with a length enough to store the first `count` elements. As more elements are
3564
- * received, elements are taken from the front of the queue and produced on the result sequence. This causes elements to be delayed.
3565
- * @param count Number of elements to bypass at the end of the source sequence.
3566
- * @returns {Observable} An observable sequence containing the source sequence elements except for the bypassed ones at the end.
3567
- */
3568
- observableProto.skipLast = function (count) {
3569
- var source = this;
3570
- return new AnonymousObservable(function (observer) {
3571
- var q = [];
3572
- return source.subscribe(function (x) {
3573
- q.push(x);
3574
- if (q.length > count) {
3575
- observer.onNext(q.shift());
3576
- }
3577
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3578
- });
3579
- };
3532
+ /**
3533
+ * Bypasses a specified number of elements at the end of an observable sequence.
3534
+ * @description
3535
+ * This operator accumulates a queue with a length enough to store the first `count` elements. As more elements are
3536
+ * received, elements are taken from the front of the queue and produced on the result sequence. This causes elements to be delayed.
3537
+ * @param count Number of elements to bypass at the end of the source sequence.
3538
+ * @returns {Observable} An observable sequence containing the source sequence elements except for the bypassed ones at the end.
3539
+ */
3540
+ observableProto.skipLast = function (count) {
3541
+ var source = this;
3542
+ return new AnonymousObservable(function (observer) {
3543
+ var q = [];
3544
+ return source.subscribe(function (x) {
3545
+ q.push(x);
3546
+ q.length > count && observer.onNext(q.shift());
3547
+ }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3548
+ });
3549
+ };
3580
3550
 
3581
- /**
3582
- * Prepends a sequence of values to an observable sequence with an optional scheduler and an argument list of values to prepend.
3583
- *
3584
- * var res = source.startWith(1, 2, 3);
3585
- * var res = source.startWith(Rx.Scheduler.timeout, 1, 2, 3);
3586
- *
3587
- * @memberOf Observable#
3588
- * @returns {Observable} The source sequence prepended with the specified values.
3589
- */
3590
- observableProto.startWith = function () {
3591
- var values, scheduler, start = 0;
3592
- if (!!arguments.length && 'now' in Object(arguments[0])) {
3593
- scheduler = arguments[0];
3594
- start = 1;
3595
- } else {
3596
- scheduler = immediateScheduler;
3597
- }
3598
- values = slice.call(arguments, start);
3599
- return enumerableFor([observableFromArray(values, scheduler), this]).concat();
3600
- };
3551
+ /**
3552
+ * Prepends a sequence of values to an observable sequence with an optional scheduler and an argument list of values to prepend.
3553
+ * @example
3554
+ * var res = source.startWith(1, 2, 3);
3555
+ * var res = source.startWith(Rx.Scheduler.timeout, 1, 2, 3);
3556
+ * @param {Arguments} args The specified values to prepend to the observable sequence
3557
+ * @returns {Observable} The source sequence prepended with the specified values.
3558
+ */
3559
+ observableProto.startWith = function () {
3560
+ var values, scheduler, start = 0;
3561
+ if (!!arguments.length && isScheduler(arguments[0])) {
3562
+ scheduler = arguments[0];
3563
+ start = 1;
3564
+ } else {
3565
+ scheduler = immediateScheduler;
3566
+ }
3567
+ values = slice.call(arguments, start);
3568
+ return enumerableFor([observableFromArray(values, scheduler), this]).concat();
3569
+ };
3601
3570
 
3602
3571
  /**
3603
3572
  * Returns a specified number of contiguous elements from the end of an observable sequence.
3604
- *
3605
- * @example
3606
- * var res = source.takeLast(5);
3607
- *
3608
3573
  * @description
3609
3574
  * This operator accumulates a buffer with a length enough to store elements count elements. Upon completion of
3610
3575
  * the source sequence, this buffer is drained on the result sequence. This causes the elements to be delayed.
@@ -4020,14 +3985,14 @@ if (!Array.prototype.forEach) {
4020
3985
  });
4021
3986
  };
4022
3987
 
4023
- /**
4024
- * Retrieves the value of a specified property from all elements in the Observable sequence.
4025
- * @param {String} property The property to pluck.
4026
- * @returns {Observable} Returns a new Observable sequence of property values.
4027
- */
4028
- observableProto.pluck = function (property) {
4029
- return this.select(function (x) { return x[property]; });
4030
- };
3988
+ /**
3989
+ * Retrieves the value of a specified property from all elements in the Observable sequence.
3990
+ * @param {String} prop The property to pluck.
3991
+ * @returns {Observable} Returns a new Observable sequence of property values.
3992
+ */
3993
+ observableProto.pluck = function (prop) {
3994
+ return this.map(function (x) { return x[prop]; });
3995
+ };
4031
3996
 
4032
3997
  function flatMap(source, selector, thisArg) {
4033
3998
  return source.map(function (x, i) {
@@ -4123,133 +4088,118 @@ if (!Array.prototype.forEach) {
4123
4088
  });
4124
4089
  }).mergeAll();
4125
4090
  };
4126
- /**
4127
- * Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then
4128
- * transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.
4129
- * @param {Function} selector A transform function to apply to each source element; the second parameter of the function represents the index of the source element.
4130
- * @param {Any} [thisArg] Object to use as this when executing callback.
4131
- * @returns {Observable} An observable sequence whose elements are the result of invoking the transform function on each element of source producing an Observable of Observable sequences
4132
- * and that at any point in time produces the elements of the most recent inner observable sequence that has been received.
4133
- */
4134
- observableProto.selectSwitch = observableProto.flatMapLatest = observableProto.switchMap = function (selector, thisArg) {
4135
- return this.select(selector, thisArg).switchLatest();
4136
- };
4091
+ /**
4092
+ * Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then
4093
+ * transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.
4094
+ * @param {Function} selector A transform function to apply to each source element; the second parameter of the function represents the index of the source element.
4095
+ * @param {Any} [thisArg] Object to use as this when executing callback.
4096
+ * @returns {Observable} An observable sequence whose elements are the result of invoking the transform function on each element of source producing an Observable of Observable sequences
4097
+ * and that at any point in time produces the elements of the most recent inner observable sequence that has been received.
4098
+ */
4099
+ observableProto.selectSwitch = observableProto.flatMapLatest = observableProto.switchMap = function (selector, thisArg) {
4100
+ return this.select(selector, thisArg).switchLatest();
4101
+ };
4137
4102
 
4138
- /**
4139
- * Bypasses a specified number of elements in an observable sequence and then returns the remaining elements.
4140
- * @param {Number} count The number of elements to skip before returning the remaining elements.
4141
- * @returns {Observable} An observable sequence that contains the elements that occur after the specified index in the input sequence.
4142
- */
4143
- observableProto.skip = function (count) {
4144
- if (count < 0) {
4145
- throw new Error(argumentOutOfRange);
4103
+ /**
4104
+ * Bypasses a specified number of elements in an observable sequence and then returns the remaining elements.
4105
+ * @param {Number} count The number of elements to skip before returning the remaining elements.
4106
+ * @returns {Observable} An observable sequence that contains the elements that occur after the specified index in the input sequence.
4107
+ */
4108
+ observableProto.skip = function (count) {
4109
+ if (count < 0) { throw new Error(argumentOutOfRange); }
4110
+ var source = this;
4111
+ return new AnonymousObservable(function (observer) {
4112
+ var remaining = count;
4113
+ return source.subscribe(function (x) {
4114
+ if (remaining <= 0) {
4115
+ observer.onNext(x);
4116
+ } else {
4117
+ remaining--;
4118
+ }
4119
+ }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4120
+ });
4121
+ };
4122
+
4123
+ /**
4124
+ * Bypasses elements in an observable sequence as long as a specified condition is true and then returns the remaining elements.
4125
+ * The element's index is used in the logic of the predicate function.
4126
+ *
4127
+ * var res = source.skipWhile(function (value) { return value < 10; });
4128
+ * var res = source.skipWhile(function (value, index) { return value < 10 || index < 10; });
4129
+ * @param {Function} predicate A function to test each element for a condition; the second parameter of the function represents the index of the source element.
4130
+ * @param {Any} [thisArg] Object to use as this when executing callback.
4131
+ * @returns {Observable} An observable sequence that contains the elements from the input sequence starting at the first element in the linear series that does not pass the test specified by predicate.
4132
+ */
4133
+ observableProto.skipWhile = function (predicate, thisArg) {
4134
+ var source = this;
4135
+ return new AnonymousObservable(function (observer) {
4136
+ var i = 0, running = false;
4137
+ return source.subscribe(function (x) {
4138
+ if (!running) {
4139
+ try {
4140
+ running = !predicate.call(thisArg, x, i++, source);
4141
+ } catch (e) {
4142
+ observer.onError(e);
4143
+ return;
4144
+ }
4146
4145
  }
4147
- var observable = this;
4148
- return new AnonymousObservable(function (observer) {
4149
- var remaining = count;
4150
- return observable.subscribe(function (x) {
4151
- if (remaining <= 0) {
4152
- observer.onNext(x);
4153
- } else {
4154
- remaining--;
4155
- }
4156
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4157
- });
4158
- };
4146
+ running && observer.onNext(x);
4147
+ }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4148
+ });
4149
+ };
4159
4150
 
4160
- /**
4161
- * Bypasses elements in an observable sequence as long as a specified condition is true and then returns the remaining elements.
4162
- * The element's index is used in the logic of the predicate function.
4163
- *
4164
- * var res = source.skipWhile(function (value) { return value < 10; });
4165
- * var res = source.skipWhile(function (value, index) { return value < 10 || index < 10; });
4166
- * @param {Function} predicate A function to test each element for a condition; the second parameter of the function represents the index of the source element.
4167
- * @param {Any} [thisArg] Object to use as this when executing callback.
4168
- * @returns {Observable} An observable sequence that contains the elements from the input sequence starting at the first element in the linear series that does not pass the test specified by predicate.
4169
- */
4170
- observableProto.skipWhile = function (predicate, thisArg) {
4171
- var source = this;
4172
- return new AnonymousObservable(function (observer) {
4173
- var i = 0, running = false;
4174
- return source.subscribe(function (x) {
4175
- if (!running) {
4176
- try {
4177
- running = !predicate.call(thisArg, x, i++, source);
4178
- } catch (e) {
4179
- observer.onError(e);
4180
- return;
4181
- }
4182
- }
4183
- if (running) {
4184
- observer.onNext(x);
4185
- }
4186
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4187
- });
4188
- };
4151
+ /**
4152
+ * Returns a specified number of contiguous elements from the start of an observable sequence, using the specified scheduler for the edge case of take(0).
4153
+ *
4154
+ * var res = source.take(5);
4155
+ * var res = source.take(0, Rx.Scheduler.timeout);
4156
+ * @param {Number} count The number of elements to return.
4157
+ * @param {Scheduler} [scheduler] Scheduler used to produce an OnCompleted message in case <paramref name="count count</paramref> is set to 0.
4158
+ * @returns {Observable} An observable sequence that contains the specified number of elements from the start of the input sequence.
4159
+ */
4160
+ observableProto.take = function (count, scheduler) {
4161
+ if (count < 0) { throw new RangeError(argumentOutOfRange); }
4162
+ if (count === 0) { return observableEmpty(scheduler); }
4163
+ var observable = this;
4164
+ return new AnonymousObservable(function (observer) {
4165
+ var remaining = count;
4166
+ return observable.subscribe(function (x) {
4167
+ if (remaining-- > 0) {
4168
+ observer.onNext(x);
4169
+ remaining === 0 && observer.onCompleted();
4170
+ }
4171
+ }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4172
+ });
4173
+ };
4189
4174
 
4190
- /**
4191
- * Returns a specified number of contiguous elements from the start of an observable sequence, using the specified scheduler for the edge case of take(0).
4192
- *
4193
- * var res = source.take(5);
4194
- * var res = source.take(0, Rx.Scheduler.timeout);
4195
- * @param {Number} count The number of elements to return.
4196
- * @param {Scheduler} [scheduler] Scheduler used to produce an OnCompleted message in case <paramref name="count count</paramref> is set to 0.
4197
- * @returns {Observable} An observable sequence that contains the specified number of elements from the start of the input sequence.
4198
- */
4199
- observableProto.take = function (count, scheduler) {
4200
- if (count < 0) {
4201
- throw new Error(argumentOutOfRange);
4202
- }
4203
- if (count === 0) {
4204
- return observableEmpty(scheduler);
4175
+ /**
4176
+ * Returns elements from an observable sequence as long as a specified condition is true.
4177
+ * The element's index is used in the logic of the predicate function.
4178
+ * @param {Function} predicate A function to test each element for a condition; the second parameter of the function represents the index of the source element.
4179
+ * @param {Any} [thisArg] Object to use as this when executing callback.
4180
+ * @returns {Observable} An observable sequence that contains the elements from the input sequence that occur before the element at which the test no longer passes.
4181
+ */
4182
+ observableProto.takeWhile = function (predicate, thisArg) {
4183
+ var observable = this;
4184
+ return new AnonymousObservable(function (observer) {
4185
+ var i = 0, running = true;
4186
+ return observable.subscribe(function (x) {
4187
+ if (running) {
4188
+ try {
4189
+ running = predicate.call(thisArg, x, i++, observable);
4190
+ } catch (e) {
4191
+ observer.onError(e);
4192
+ return;
4193
+ }
4194
+ if (running) {
4195
+ observer.onNext(x);
4196
+ } else {
4197
+ observer.onCompleted();
4198
+ }
4205
4199
  }
4206
- var observable = this;
4207
- return new AnonymousObservable(function (observer) {
4208
- var remaining = count;
4209
- return observable.subscribe(function (x) {
4210
- if (remaining > 0) {
4211
- remaining--;
4212
- observer.onNext(x);
4213
- if (remaining === 0) {
4214
- observer.onCompleted();
4215
- }
4216
- }
4217
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4218
- });
4219
- };
4220
-
4221
- /**
4222
- * Returns elements from an observable sequence as long as a specified condition is true.
4223
- * The element's index is used in the logic of the predicate function.
4224
- *
4225
- * @example
4226
- * var res = source.takeWhile(function (value) { return value < 10; });
4227
- * var res = source.takeWhile(function (value, index) { return value < 10 || index < 10; });
4228
- * @param {Function} predicate A function to test each element for a condition; the second parameter of the function represents the index of the source element.
4229
- * @param {Any} [thisArg] Object to use as this when executing callback.
4230
- * @returns {Observable} An observable sequence that contains the elements from the input sequence that occur before the element at which the test no longer passes.
4231
- */
4232
- observableProto.takeWhile = function (predicate, thisArg) {
4233
- var observable = this;
4234
- return new AnonymousObservable(function (observer) {
4235
- var i = 0, running = true;
4236
- return observable.subscribe(function (x) {
4237
- if (running) {
4238
- try {
4239
- running = predicate.call(thisArg, x, i++, observable);
4240
- } catch (e) {
4241
- observer.onError(e);
4242
- return;
4243
- }
4244
- if (running) {
4245
- observer.onNext(x);
4246
- } else {
4247
- observer.onCompleted();
4248
- }
4249
- }
4250
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4251
- });
4252
- };
4200
+ }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4201
+ });
4202
+ };
4253
4203
 
4254
4204
  /**
4255
4205
  * Filters the elements of an observable sequence based on a predicate by incorporating the element's index.
@@ -4298,42 +4248,40 @@ if (!Array.prototype.forEach) {
4298
4248
  });
4299
4249
  };
4300
4250
 
4301
- function extremaBy(source, keySelector, comparer) {
4302
- return new AnonymousObservable(function (observer) {
4303
- var hasValue = false, lastKey = null, list = [];
4304
- return source.subscribe(function (x) {
4305
- var comparison, key;
4306
- try {
4307
- key = keySelector(x);
4308
- } catch (ex) {
4309
- observer.onError(ex);
4310
- return;
4311
- }
4312
- comparison = 0;
4313
- if (!hasValue) {
4314
- hasValue = true;
4315
- lastKey = key;
4316
- } else {
4317
- try {
4318
- comparison = comparer(key, lastKey);
4319
- } catch (ex1) {
4320
- observer.onError(ex1);
4321
- return;
4322
- }
4323
- }
4324
- if (comparison > 0) {
4325
- lastKey = key;
4326
- list = [];
4327
- }
4328
- if (comparison >= 0) {
4329
- list.push(x);
4330
- }
4331
- }, observer.onError.bind(observer), function () {
4332
- observer.onNext(list);
4333
- observer.onCompleted();
4334
- });
4335
- });
4336
- }
4251
+ function extremaBy(source, keySelector, comparer) {
4252
+ return new AnonymousObservable(function (observer) {
4253
+ var hasValue = false, lastKey = null, list = [];
4254
+ return source.subscribe(function (x) {
4255
+ var comparison, key;
4256
+ try {
4257
+ key = keySelector(x);
4258
+ } catch (ex) {
4259
+ observer.onError(ex);
4260
+ return;
4261
+ }
4262
+ comparison = 0;
4263
+ if (!hasValue) {
4264
+ hasValue = true;
4265
+ lastKey = key;
4266
+ } else {
4267
+ try {
4268
+ comparison = comparer(key, lastKey);
4269
+ } catch (ex1) {
4270
+ observer.onError(ex1);
4271
+ return;
4272
+ }
4273
+ }
4274
+ if (comparison > 0) {
4275
+ lastKey = key;
4276
+ list = [];
4277
+ }
4278
+ if (comparison >= 0) { list.push(x); }
4279
+ }, observer.onError.bind(observer), function () {
4280
+ observer.onNext(list);
4281
+ observer.onCompleted();
4282
+ });
4283
+ });
4284
+ }
4337
4285
 
4338
4286
  function firstOnly(x) {
4339
4287
  if (x.length === 0) {
@@ -4464,25 +4412,25 @@ if (!Array.prototype.forEach) {
4464
4412
  });
4465
4413
  };
4466
4414
 
4415
+ /**
4416
+ * Computes the sum of a sequence of values that are obtained by invoking an optional transform function on each element of the input sequence, else if not specified computes the sum on each item in the sequence.
4417
+ * @example
4418
+ * var res = source.sum();
4419
+ * var res = source.sum(function (x) { return x.value; });
4420
+ * @param {Function} [selector] A transform function to apply to each element.
4421
+ * @param {Any} [thisArg] Object to use as this when executing callback.
4422
+ * @returns {Observable} An observable sequence containing a single element with the sum of the values in the source sequence.
4423
+ */
4424
+ observableProto.sum = function (keySelector, thisArg) {
4425
+ return keySelector && isFunction(keySelector) ?
4426
+ this.map(keySelector, thisArg).sum() :
4427
+ this.aggregate(0, function (prev, curr) {
4428
+ return prev + curr;
4429
+ });
4430
+ };
4431
+
4467
4432
  /**
4468
- * Computes the sum of a sequence of values that are obtained by invoking an optional transform function on each element of the input sequence, else if not specified computes the sum on each item in the sequence.
4469
- * @example
4470
- * var res = source.sum();
4471
- * var res = source.sum(function (x) { return x.value; });
4472
- * @param {Function} [selector] A transform function to apply to each element.
4473
- * @param {Any} [thisArg] Object to use as this when executing callback.
4474
- * @returns {Observable} An observable sequence containing a single element with the sum of the values in the source sequence.
4475
- */
4476
- observableProto.sum = function (keySelector, thisArg) {
4477
- return keySelector ?
4478
- this.select(keySelector, thisArg).sum() :
4479
- this.aggregate(0, function (prev, curr) {
4480
- return prev + curr;
4481
- });
4482
- };
4483
-
4484
- /**
4485
- * Returns the elements in an observable sequence with the minimum key value according to the specified comparer.
4433
+ * Returns the elements in an observable sequence with the minimum key value according to the specified comparer.
4486
4434
  * @example
4487
4435
  * var res = source.minBy(function (x) { return x.value; });
4488
4436
  * var res = source.minBy(function (x) { return x.value; }, function (x, y) { return x - y; });
@@ -4568,27 +4516,25 @@ if (!Array.prototype.forEach) {
4568
4516
  };
4569
4517
 
4570
4518
  function sequenceEqualArray(first, second, comparer) {
4571
- return new AnonymousObservable(function (observer) {
4572
- var count = 0, len = second.length;
4573
- return first.subscribe(function (value) {
4574
- var equal = false;
4575
- try {
4576
- if (count < len) {
4577
- equal = comparer(value, second[count++]);
4578
- }
4579
- } catch (e) {
4580
- observer.onError(e);
4581
- return;
4582
- }
4583
- if (!equal) {
4584
- observer.onNext(false);
4585
- observer.onCompleted();
4586
- }
4587
- }, observer.onError.bind(observer), function () {
4588
- observer.onNext(count === len);
4519
+ return new AnonymousObservable(function (observer) {
4520
+ var count = 0, len = second.length;
4521
+ return first.subscribe(function (value) {
4522
+ var equal = false;
4523
+ try {
4524
+ count < len && (equal = comparer(value, second[count++]));
4525
+ } catch (e) {
4526
+ observer.onError(e);
4527
+ return;
4528
+ }
4529
+ if (!equal) {
4530
+ observer.onNext(false);
4589
4531
  observer.onCompleted();
4590
- });
4532
+ }
4533
+ }, observer.onError.bind(observer), function () {
4534
+ observer.onNext(count === len);
4535
+ observer.onCompleted();
4591
4536
  });
4537
+ });
4592
4538
  }
4593
4539
 
4594
4540
  /**
@@ -4614,17 +4560,17 @@ if (!Array.prototype.forEach) {
4614
4560
  var subscription1 = first.subscribe(function (x) {
4615
4561
  var equal, v;
4616
4562
  if (qr.length > 0) {
4617
- v = qr.shift();
4618
- try {
4619
- equal = comparer(v, x);
4620
- } catch (e) {
4621
- observer.onError(e);
4622
- return;
4623
- }
4624
- if (!equal) {
4625
- observer.onNext(false);
4626
- observer.onCompleted();
4627
- }
4563
+ v = qr.shift();
4564
+ try {
4565
+ equal = comparer(v, x);
4566
+ } catch (e) {
4567
+ observer.onError(e);
4568
+ return;
4569
+ }
4570
+ if (!equal) {
4571
+ observer.onNext(false);
4572
+ observer.onCompleted();
4573
+ }
4628
4574
  } else if (doner) {
4629
4575
  observer.onNext(false);
4630
4576
  observer.onCompleted();
@@ -4646,9 +4592,9 @@ if (!Array.prototype.forEach) {
4646
4592
 
4647
4593
  isPromise(second) && (second = observableFromPromise(second));
4648
4594
  var subscription2 = second.subscribe(function (x) {
4649
- var equal, v;
4595
+ var equal;
4650
4596
  if (ql.length > 0) {
4651
- v = ql.shift();
4597
+ var v = ql.shift();
4652
4598
  try {
4653
4599
  equal = comparer(v, x);
4654
4600
  } catch (exception) {
@@ -4728,60 +4674,60 @@ if (!Array.prototype.forEach) {
4728
4674
  return elementAtOrDefault(this, index, true, defaultValue);
4729
4675
  };
4730
4676
 
4731
- function singleOrDefaultAsync(source, hasDefault, defaultValue) {
4732
- return new AnonymousObservable(function (observer) {
4733
- var value = defaultValue, seenValue = false;
4734
- return source.subscribe(function (x) {
4735
- if (seenValue) {
4736
- observer.onError(new Error('Sequence contains more than one element'));
4737
- } else {
4738
- value = x;
4739
- seenValue = true;
4740
- }
4741
- }, observer.onError.bind(observer), function () {
4742
- if (!seenValue && !hasDefault) {
4743
- observer.onError(new Error(sequenceContainsNoElements));
4744
- } else {
4745
- observer.onNext(value);
4746
- observer.onCompleted();
4747
- }
4748
- });
4749
- });
4750
- }
4677
+ function singleOrDefaultAsync(source, hasDefault, defaultValue) {
4678
+ return new AnonymousObservable(function (observer) {
4679
+ var value = defaultValue, seenValue = false;
4680
+ return source.subscribe(function (x) {
4681
+ if (seenValue) {
4682
+ observer.onError(new Error('Sequence contains more than one element'));
4683
+ } else {
4684
+ value = x;
4685
+ seenValue = true;
4686
+ }
4687
+ }, observer.onError.bind(observer), function () {
4688
+ if (!seenValue && !hasDefault) {
4689
+ observer.onError(new Error(sequenceContainsNoElements));
4690
+ } else {
4691
+ observer.onNext(value);
4692
+ observer.onCompleted();
4693
+ }
4694
+ });
4695
+ });
4696
+ }
4751
4697
 
4752
- /**
4753
- * Returns the only element of an observable sequence that satisfies the condition in the optional predicate, and reports an exception if there is not exactly one element in the observable sequence.
4754
- * @example
4755
- * var res = res = source.single();
4756
- * var res = res = source.single(function (x) { return x === 42; });
4757
- * @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
4758
- * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
4759
- * @returns {Observable} Sequence containing the single element in the observable sequence that satisfies the condition in the predicate.
4760
- */
4761
- observableProto.single = function (predicate, thisArg) {
4762
- return predicate ?
4763
- this.where(predicate, thisArg).single() :
4764
- singleOrDefaultAsync(this, false);
4765
- };
4698
+ /**
4699
+ * Returns the only element of an observable sequence that satisfies the condition in the optional predicate, and reports an exception if there is not exactly one element in the observable sequence.
4700
+ * @example
4701
+ * var res = res = source.single();
4702
+ * var res = res = source.single(function (x) { return x === 42; });
4703
+ * @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
4704
+ * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
4705
+ * @returns {Observable} Sequence containing the single element in the observable sequence that satisfies the condition in the predicate.
4706
+ */
4707
+ observableProto.single = function (predicate, thisArg) {
4708
+ return predicate && isFunction(predicate) ?
4709
+ this.where(predicate, thisArg).single() :
4710
+ singleOrDefaultAsync(this, false);
4711
+ };
4766
4712
 
4767
- /**
4768
- * Returns the only element of an observable sequence that matches the predicate, or a default value if no such element exists; this method reports an exception if there is more than one element in the observable sequence.
4769
- * @example
4770
- * var res = res = source.singleOrDefault();
4771
- * var res = res = source.singleOrDefault(function (x) { return x === 42; });
4772
- * res = source.singleOrDefault(function (x) { return x === 42; }, 0);
4773
- * res = source.singleOrDefault(null, 0);
4774
- * @memberOf Observable#
4775
- * @param {Function} predicate A predicate function to evaluate for elements in the source sequence.
4776
- * @param [defaultValue] The default value if the index is outside the bounds of the source sequence.
4777
- * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
4778
- * @returns {Observable} Sequence containing the single element in the observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.
4779
- */
4780
- observableProto.singleOrDefault = function (predicate, defaultValue, thisArg) {
4781
- return predicate?
4782
- this.where(predicate, thisArg).singleOrDefault(null, defaultValue) :
4783
- singleOrDefaultAsync(this, true, defaultValue)
4784
- };
4713
+ /**
4714
+ * Returns the only element of an observable sequence that matches the predicate, or a default value if no such element exists; this method reports an exception if there is more than one element in the observable sequence.
4715
+ * @example
4716
+ * var res = res = source.singleOrDefault();
4717
+ * var res = res = source.singleOrDefault(function (x) { return x === 42; });
4718
+ * res = source.singleOrDefault(function (x) { return x === 42; }, 0);
4719
+ * res = source.singleOrDefault(null, 0);
4720
+ * @memberOf Observable#
4721
+ * @param {Function} predicate A predicate function to evaluate for elements in the source sequence.
4722
+ * @param [defaultValue] The default value if the index is outside the bounds of the source sequence.
4723
+ * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
4724
+ * @returns {Observable} Sequence containing the single element in the observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.
4725
+ */
4726
+ observableProto.singleOrDefault = function (predicate, defaultValue, thisArg) {
4727
+ return predicate && isFunction(predicate) ?
4728
+ this.where(predicate, thisArg).singleOrDefault(null, defaultValue) :
4729
+ singleOrDefaultAsync(this, true, defaultValue);
4730
+ };
4785
4731
  function firstOrDefaultAsync(source, hasDefault, defaultValue) {
4786
4732
  return new AnonymousObservable(function (observer) {
4787
4733
  return source.subscribe(function (x) {
@@ -4926,71 +4872,26 @@ if (!Array.prototype.forEach) {
4926
4872
  return findValue(this, predicate, thisArg, true);
4927
4873
  };
4928
4874
 
4929
- function toSet(source, type) {
4930
- return new AnonymousObservable(function (observer) {
4931
- var s = new type();
4932
- return source.subscribe(
4933
- s.add.bind(s),
4934
- observer.onError.bind(observer),
4935
- function () {
4936
- observer.onNext(s);
4937
- observer.onCompleted();
4938
- });
4939
- });
4940
- }
4941
4875
  if (!!root.Set) {
4942
4876
  /**
4943
4877
  * Converts the observable sequence to a Set if it exists.
4944
4878
  * @returns {Observable} An observable sequence with a single value of a Set containing the values from the observable sequence.
4945
4879
  */
4946
4880
  observableProto.toSet = function () {
4947
- return toSet(this, root.Set);
4948
- };
4949
- }
4950
-
4951
- if (!!root.WeakSet) {
4952
- /**
4953
- * Converts the observable sequence to a WeakSet if it exists.
4954
- * @returns {Observable} An observable sequence with a single value of a WeakSet containing the values from the observable sequence.
4955
- */
4956
- observableProto.toWeakSet = function () {
4957
- return toSet(this, root.WeakSet);
4881
+ var source = this;
4882
+ return new AnonymousObservable(function (observer) {
4883
+ var s = new root.Set();
4884
+ return source.subscribe(
4885
+ s.add.bind(s),
4886
+ observer.onError.bind(observer),
4887
+ function () {
4888
+ observer.onNext(s);
4889
+ observer.onCompleted();
4890
+ });
4891
+ });
4958
4892
  };
4959
4893
  }
4960
4894
 
4961
- function toMap(source, type, keySelector, elementSelector) {
4962
- return new AnonymousObservable(function (observer) {
4963
- var m = new type();
4964
- return source.subscribe(
4965
- function (x) {
4966
- var key;
4967
- try {
4968
- key = keySelector(x);
4969
- } catch (e) {
4970
- observer.onError(e);
4971
- return;
4972
- }
4973
-
4974
- var element = x;
4975
- if (elementSelector) {
4976
- try {
4977
- element = elementSelector(x);
4978
- } catch (e) {
4979
- observer.onError(e);
4980
- return;
4981
- }
4982
- }
4983
-
4984
- m.set(key, element);
4985
- },
4986
- observer.onError.bind(observer),
4987
- function () {
4988
- observer.onNext(m);
4989
- observer.onCompleted();
4990
- });
4991
- });
4992
- }
4993
-
4994
4895
  if (!!root.Map) {
4995
4896
  /**
4996
4897
  * Converts the observable sequence to a Map if it exists.
@@ -4999,86 +4900,345 @@ if (!Array.prototype.forEach) {
4999
4900
  * @returns {Observable} An observable sequence with a single value of a Map containing the values from the observable sequence.
5000
4901
  */
5001
4902
  observableProto.toMap = function (keySelector, elementSelector) {
5002
- return toMap(this, root.Map, keySelector, elementSelector);
4903
+ var source = this;
4904
+ return new AnonymousObservable(function (observer) {
4905
+ var m = new root.Map();
4906
+ return source.subscribe(
4907
+ function (x) {
4908
+ var key;
4909
+ try {
4910
+ key = keySelector(x);
4911
+ } catch (e) {
4912
+ observer.onError(e);
4913
+ return;
4914
+ }
4915
+
4916
+ var element = x;
4917
+ if (elementSelector) {
4918
+ try {
4919
+ element = elementSelector(x);
4920
+ } catch (e) {
4921
+ observer.onError(e);
4922
+ return;
4923
+ }
4924
+ }
4925
+
4926
+ m.set(key, element);
4927
+ },
4928
+ observer.onError.bind(observer),
4929
+ function () {
4930
+ observer.onNext(m);
4931
+ observer.onCompleted();
4932
+ });
4933
+ });
5003
4934
  };
5004
4935
  }
5005
4936
 
5006
- if (!!root.WeakMap) {
5007
- /**
5008
- * Converts the observable sequence to a WeakMap if it exists.
5009
- * @param {Function} keySelector A function which produces the key for the WeakMap
5010
- * @param {Function} [elementSelector] An optional function which produces the element for the WeakMap. If not present, defaults to the value from the observable sequence.
5011
- * @returns {Observable} An observable sequence with a single value of a WeakMap containing the values from the observable sequence.
5012
- */
5013
- observableProto.toWeakMap = function (keySelector, elementSelector) {
5014
- return toMap(this, root.WeakMap, keySelector, elementSelector);
5015
- };
4937
+ var fnString = 'function';
4938
+
4939
+ function toThunk(obj, ctx) {
4940
+ if (Array.isArray(obj)) {
4941
+ return objectToThunk.call(ctx, obj);
4942
+ }
4943
+
4944
+ if (isGeneratorFunction(obj)) {
4945
+ return observableSpawn(obj.call(ctx));
4946
+ }
4947
+
4948
+ if (isGenerator(obj)) {
4949
+ return observableSpawn(obj);
4950
+ }
4951
+
4952
+ if (isObservable(obj)) {
4953
+ return observableToThunk(obj);
4954
+ }
4955
+
4956
+ if (isPromise(obj)) {
4957
+ return promiseToThunk(obj);
4958
+ }
4959
+
4960
+ if (typeof obj === fnString) {
4961
+ return obj;
4962
+ }
4963
+
4964
+ if (isObject(obj) || Array.isArray(obj)) {
4965
+ return objectToThunk.call(ctx, obj);
4966
+ }
4967
+
4968
+ return obj;
5016
4969
  }
5017
4970
 
5018
- /**
5019
- * Invokes the specified function asynchronously on the specified scheduler, surfacing the result through an observable sequence.
5020
- *
5021
- * @example
5022
- * var res = Rx.Observable.start(function () { console.log('hello'); });
5023
- * var res = Rx.Observable.start(function () { console.log('hello'); }, Rx.Scheduler.timeout);
5024
- * var res = Rx.Observable.start(function () { this.log('hello'); }, Rx.Scheduler.timeout, console);
5025
- *
5026
- * @param {Function} func Function to run asynchronously.
5027
- * @param {Scheduler} [scheduler] Scheduler to run the function on. If not specified, defaults to Scheduler.timeout.
5028
- * @param [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
5029
- * @returns {Observable} An observable sequence exposing the function's result value, or an exception.
5030
- *
5031
- * Remarks
5032
- * * The function is called immediately, not during the subscription of the resulting sequence.
5033
- * * Multiple subscriptions to the resulting sequence can observe the function's result.
5034
- */
5035
- Observable.start = function (func, context, scheduler) {
5036
- return observableToAsync(func, context, scheduler)();
5037
- };
4971
+ function objectToThunk(obj) {
4972
+ var ctx = this;
5038
4973
 
5039
- /**
5040
- * Converts the function into an asynchronous function. Each invocation of the resulting asynchronous function causes an invocation of the original synchronous function on the specified scheduler.
5041
- *
5042
- * @example
5043
- * var res = Rx.Observable.toAsync(function (x, y) { return x + y; })(4, 3);
5044
- * var res = Rx.Observable.toAsync(function (x, y) { return x + y; }, Rx.Scheduler.timeout)(4, 3);
5045
- * var res = Rx.Observable.toAsync(function (x) { this.log(x); }, Rx.Scheduler.timeout, console)('hello');
5046
- *
5047
- * @param {Function} function Function to convert to an asynchronous function.
5048
- * @param {Scheduler} [scheduler] Scheduler to run the function on. If not specified, defaults to Scheduler.timeout.
5049
- * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
5050
- * @returns {Function} Asynchronous function.
5051
- */
5052
- var observableToAsync = Observable.toAsync = function (func, context, scheduler) {
5053
- isScheduler(scheduler) || (scheduler = timeoutScheduler);
5054
- return function () {
5055
- var args = arguments,
5056
- subject = new AsyncSubject();
4974
+ return function (done) {
4975
+ var keys = Object.keys(obj),
4976
+ pending = keys.length,
4977
+ results = new obj.constructor(),
4978
+ finished;
5057
4979
 
5058
- scheduler.schedule(function () {
5059
- var result;
4980
+ if (!pending) {
4981
+ timeoutScheduler.schedule(function () { done(null, results); });
4982
+ return;
4983
+ }
4984
+
4985
+ for (var i = 0, len = keys.length; i < len; i++) {
4986
+ run(obj[keys[i]], keys[i]);
4987
+ }
4988
+
4989
+ function run(fn, key) {
4990
+ if (finished) { return; }
5060
4991
  try {
5061
- result = func.apply(context, args);
4992
+ fn = toThunk(fn, ctx);
4993
+
4994
+ if (typeof fn !== fnString) {
4995
+ results[key] = fn;
4996
+ return --pending || done(null, results);
4997
+ }
4998
+
4999
+ fn.call(ctx, function(err, res){
5000
+ if (finished) { return; }
5001
+
5002
+ if (err) {
5003
+ finished = true;
5004
+ return done(err);
5005
+ }
5006
+
5007
+ results[key] = res;
5008
+ --pending || done(null, results);
5009
+ });
5062
5010
  } catch (e) {
5063
- subject.onError(e);
5064
- return;
5011
+ finished = true;
5012
+ done(e);
5065
5013
  }
5066
- subject.onNext(result);
5067
- subject.onCompleted();
5068
- });
5069
- return subject.asObservable();
5070
- };
5071
- };
5014
+ }
5015
+ }
5016
+ }
5072
5017
 
5073
- /**
5074
- * Converts a callback function to an observable sequence.
5075
- *
5076
- * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence.
5077
- * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
5078
- * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next.
5079
- * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array.
5080
- */
5081
- Observable.fromCallback = function (func, context, selector) {
5018
+ function observableToThink(observable) {
5019
+ return function (fn) {
5020
+ var value, hasValue = false;
5021
+ observable.subscribe(
5022
+ function (v) {
5023
+ value = v;
5024
+ hasValue = true;
5025
+ },
5026
+ fn,
5027
+ function () {
5028
+ hasValue && fn(null, value);
5029
+ });
5030
+ }
5031
+ }
5032
+
5033
+ function promiseToThunk(promise) {
5034
+ return function(fn){
5035
+ promise.then(function(res) {
5036
+ fn(null, res);
5037
+ }, fn);
5038
+ }
5039
+ }
5040
+
5041
+ function isObservable(obj) {
5042
+ return obj && obj.prototype.subscribe === fnString;
5043
+ }
5044
+
5045
+ function isGeneratorFunction(obj) {
5046
+ return obj && obj.constructor && obj.constructor.name === 'GeneratorFunction';
5047
+ }
5048
+
5049
+ function isGenerator(obj) {
5050
+ return obj && typeof obj.next === fnString && typeof obj.throw === fnString;
5051
+ }
5052
+
5053
+ function isObject(val) {
5054
+ return val && val.constructor === Object;
5055
+ }
5056
+
5057
+ /*
5058
+ * Spawns a generator function which allows for Promises, Observable sequences, Arrays, Objects, Generators and functions.
5059
+ * @param {Function} The spawning function.
5060
+ * @returns {Function} a function which has a done continuation.
5061
+ */
5062
+ var observableSpawn = Rx.spawn = function (fn) {
5063
+ var isGenFun = isGeneratorFunction(fn);
5064
+
5065
+ return function (done) {
5066
+ var ctx = this,
5067
+ gen = fan;
5068
+
5069
+ if (isGenFun) {
5070
+ var args = slice.call(arguments),
5071
+ len = args.length,
5072
+ hasCallback = len && typeof args[len - 1] === fnString;
5073
+
5074
+ done = hasCallback ? args.pop() : error;
5075
+ gen = fn.apply(this, args);
5076
+ } else {
5077
+ done = done || error;
5078
+ }
5079
+
5080
+ next();
5081
+
5082
+ function exit(err, res) {
5083
+ timeoutScheduler.schedule(done.bind(ctx, err, res));
5084
+ }
5085
+
5086
+ function next(err, res) {
5087
+ var ret;
5088
+
5089
+ // multiple args
5090
+ if (arguments.length > 2) res = slice.call(arguments, 1);
5091
+
5092
+ if (err) {
5093
+ try {
5094
+ ret = gen.throw(err);
5095
+ } catch (e) {
5096
+ return exit(e);
5097
+ }
5098
+ }
5099
+
5100
+ if (!err) {
5101
+ try {
5102
+ ret = gen.next(res);
5103
+ } catch (e) {
5104
+ return exit(e);
5105
+ }
5106
+ }
5107
+
5108
+ if (ret.done) {
5109
+ return exit(null, ret.value);
5110
+ }
5111
+
5112
+ ret.value = toThunk(ret.value, ctx);
5113
+
5114
+ if (typeof ret.value === fnString) {
5115
+ var called = false;
5116
+ try {
5117
+ ret.value.call(ctx, function(){
5118
+ if (called) {
5119
+ return;
5120
+ }
5121
+
5122
+ called = true;
5123
+ next.apply(ctx, arguments);
5124
+ });
5125
+ } catch (e) {
5126
+ timeoutScheduler.schedule(function () {
5127
+ if (called) {
5128
+ return;
5129
+ }
5130
+
5131
+ called = true;
5132
+ next.call(ctx, e);
5133
+ });
5134
+ }
5135
+ return;
5136
+ }
5137
+
5138
+ // Not supported
5139
+ next(new TypeError('Rx.spawn only supports a function, Promise, Observable, Object or Array.'));
5140
+ }
5141
+ }
5142
+ };
5143
+
5144
+ /**
5145
+ * Takes a function with a callback and turns it into a thunk.
5146
+ * @param {Function} A function with a callback such as fs.readFile
5147
+ * @returns {Function} A function, when executed will continue the state machine.
5148
+ */
5149
+ Rx.denodify = function (fn) {
5150
+ return function (){
5151
+ var args = slice.call(arguments),
5152
+ results,
5153
+ called,
5154
+ callback;
5155
+
5156
+ args.push(function(){
5157
+ results = arguments;
5158
+
5159
+ if (callback && !called) {
5160
+ called = true;
5161
+ cb.apply(this, results);
5162
+ }
5163
+ });
5164
+
5165
+ fn.apply(this, args);
5166
+
5167
+ return function (fn){
5168
+ callback = fn;
5169
+
5170
+ if (results && !called) {
5171
+ called = true;
5172
+ fn.apply(this, results);
5173
+ }
5174
+ }
5175
+ }
5176
+ };
5177
+
5178
+ /**
5179
+ * Invokes the specified function asynchronously on the specified scheduler, surfacing the result through an observable sequence.
5180
+ *
5181
+ * @example
5182
+ * var res = Rx.Observable.start(function () { console.log('hello'); });
5183
+ * var res = Rx.Observable.start(function () { console.log('hello'); }, Rx.Scheduler.timeout);
5184
+ * var res = Rx.Observable.start(function () { this.log('hello'); }, Rx.Scheduler.timeout, console);
5185
+ *
5186
+ * @param {Function} func Function to run asynchronously.
5187
+ * @param {Scheduler} [scheduler] Scheduler to run the function on. If not specified, defaults to Scheduler.timeout.
5188
+ * @param [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
5189
+ * @returns {Observable} An observable sequence exposing the function's result value, or an exception.
5190
+ *
5191
+ * Remarks
5192
+ * * The function is called immediately, not during the subscription of the resulting sequence.
5193
+ * * Multiple subscriptions to the resulting sequence can observe the function's result.
5194
+ */
5195
+ Observable.start = function (func, context, scheduler) {
5196
+ return observableToAsync(func, context, scheduler)();
5197
+ };
5198
+
5199
+ /**
5200
+ * Converts the function into an asynchronous function. Each invocation of the resulting asynchronous function causes an invocation of the original synchronous function on the specified scheduler.
5201
+ *
5202
+ * @example
5203
+ * var res = Rx.Observable.toAsync(function (x, y) { return x + y; })(4, 3);
5204
+ * var res = Rx.Observable.toAsync(function (x, y) { return x + y; }, Rx.Scheduler.timeout)(4, 3);
5205
+ * var res = Rx.Observable.toAsync(function (x) { this.log(x); }, Rx.Scheduler.timeout, console)('hello');
5206
+ *
5207
+ * @param {Function} function Function to convert to an asynchronous function.
5208
+ * @param {Scheduler} [scheduler] Scheduler to run the function on. If not specified, defaults to Scheduler.timeout.
5209
+ * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
5210
+ * @returns {Function} Asynchronous function.
5211
+ */
5212
+ var observableToAsync = Observable.toAsync = function (func, context, scheduler) {
5213
+ isScheduler(scheduler) || (scheduler = timeoutScheduler);
5214
+ return function () {
5215
+ var args = arguments,
5216
+ subject = new AsyncSubject();
5217
+
5218
+ scheduler.schedule(function () {
5219
+ var result;
5220
+ try {
5221
+ result = func.apply(context, args);
5222
+ } catch (e) {
5223
+ subject.onError(e);
5224
+ return;
5225
+ }
5226
+ subject.onNext(result);
5227
+ subject.onCompleted();
5228
+ });
5229
+ return subject.asObservable();
5230
+ };
5231
+ };
5232
+
5233
+ /**
5234
+ * Converts a callback function to an observable sequence.
5235
+ *
5236
+ * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence.
5237
+ * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
5238
+ * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next.
5239
+ * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array.
5240
+ */
5241
+ Observable.fromCallback = function (func, context, selector) {
5082
5242
  return function () {
5083
5243
  var args = slice.call(arguments, 0);
5084
5244
 
@@ -5495,6 +5655,7 @@ if (!Array.prototype.forEach) {
5495
5655
  .subscribe(
5496
5656
  function (results) {
5497
5657
  if (previousShouldFire !== undefined && results.shouldFire != previousShouldFire) {
5658
+ previousShouldFire = results.shouldFire;
5498
5659
  // change in shouldFire
5499
5660
  if (results.shouldFire) {
5500
5661
  while (q.length > 0) {
@@ -5502,6 +5663,7 @@ if (!Array.prototype.forEach) {
5502
5663
  }
5503
5664
  }
5504
5665
  } else {
5666
+ previousShouldFire = results.shouldFire;
5505
5667
  // new data
5506
5668
  if (results.shouldFire) {
5507
5669
  observer.onNext(results.data);
@@ -5509,9 +5671,7 @@ if (!Array.prototype.forEach) {
5509
5671
  q.push(results.data);
5510
5672
  }
5511
5673
  }
5512
- previousShouldFire = results.shouldFire;
5513
-
5514
- },
5674
+ },
5515
5675
  function (err) {
5516
5676
  // Empty buffer before sending error
5517
5677
  while (q.length > 0) {
@@ -5750,121 +5910,114 @@ if (!Array.prototype.forEach) {
5750
5910
  var source = this;
5751
5911
  return typeof subjectOrSubjectSelector === 'function' ?
5752
5912
  new AnonymousObservable(function (observer) {
5753
- var connectable = source.multicast(subjectOrSubjectSelector());
5754
- return new CompositeDisposable(selector(connectable).subscribe(observer), connectable.connect());
5913
+ var connectable = source.multicast(subjectOrSubjectSelector());
5914
+ return new CompositeDisposable(selector(connectable).subscribe(observer), connectable.connect());
5755
5915
  }) :
5756
5916
  new ConnectableObservable(source, subjectOrSubjectSelector);
5757
5917
  };
5758
5918
 
5759
- /**
5760
- * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence.
5761
- * This operator is a specialization of Multicast using a regular Subject.
5762
- *
5763
- * @example
5764
- * var resres = source.publish();
5765
- * var res = source.publish(function (x) { return x; });
5766
- *
5767
- * @param {Function} [selector] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all notifications of the source from the time of the subscription on.
5768
- * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
5769
- */
5770
- observableProto.publish = function (selector) {
5771
- return !selector ?
5772
- this.multicast(new Subject()) :
5773
- this.multicast(function () {
5774
- return new Subject();
5775
- }, selector);
5776
- };
5919
+ /**
5920
+ * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence.
5921
+ * This operator is a specialization of Multicast using a regular Subject.
5922
+ *
5923
+ * @example
5924
+ * var resres = source.publish();
5925
+ * var res = source.publish(function (x) { return x; });
5926
+ *
5927
+ * @param {Function} [selector] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all notifications of the source from the time of the subscription on.
5928
+ * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
5929
+ */
5930
+ observableProto.publish = function (selector) {
5931
+ return selector && isFunction(selector) ?
5932
+ this.multicast(function () { return new Subject(); }, selector) :
5933
+ this.multicast(new Subject());
5934
+ };
5777
5935
 
5778
- /**
5779
- * Returns an observable sequence that shares a single subscription to the underlying sequence.
5780
- * This operator is a specialization of publish which creates a subscription when the number of observers goes from zero to one, then shares that subscription with all subsequent observers until the number of observers returns to zero, at which point the subscription is disposed.
5781
- *
5782
- * @example
5783
- * var res = source.share();
5784
- *
5785
- * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence.
5786
- */
5787
- observableProto.share = function () {
5788
- return this.publish(null).refCount();
5789
- };
5936
+ /**
5937
+ * Returns an observable sequence that shares a single subscription to the underlying sequence.
5938
+ * This operator is a specialization of publish which creates a subscription when the number of observers goes from zero to one, then shares that subscription with all subsequent observers until the number of observers returns to zero, at which point the subscription is disposed.
5939
+ *
5940
+ * @example
5941
+ * var res = source.share();
5942
+ *
5943
+ * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence.
5944
+ */
5945
+ observableProto.share = function () {
5946
+ return this.publish().refCount();
5947
+ };
5790
5948
 
5791
- /**
5792
- * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence containing only the last notification.
5793
- * This operator is a specialization of Multicast using a AsyncSubject.
5794
- *
5795
- * @example
5796
- * var res = source.publishLast();
5797
- * var res = source.publishLast(function (x) { return x; });
5798
- *
5799
- * @param selector [Optional] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will only receive the last notification of the source.
5800
- * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
5801
- */
5802
- observableProto.publishLast = function (selector) {
5803
- return !selector ?
5804
- this.multicast(new AsyncSubject()) :
5805
- this.multicast(function () {
5806
- return new AsyncSubject();
5807
- }, selector);
5808
- };
5949
+ /**
5950
+ * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence containing only the last notification.
5951
+ * This operator is a specialization of Multicast using a AsyncSubject.
5952
+ *
5953
+ * @example
5954
+ * var res = source.publishLast();
5955
+ * var res = source.publishLast(function (x) { return x; });
5956
+ *
5957
+ * @param selector [Optional] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will only receive the last notification of the source.
5958
+ * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
5959
+ */
5960
+ observableProto.publishLast = function (selector) {
5961
+ return selector && isFunction(selector) ?
5962
+ this.multicast(function () { return new AsyncSubject(); }, selector) :
5963
+ this.multicast(new AsyncSubject());
5964
+ };
5809
5965
 
5810
- /**
5811
- * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence and starts with initialValue.
5812
- * This operator is a specialization of Multicast using a BehaviorSubject.
5813
- *
5814
- * @example
5815
- * var res = source.publishValue(42);
5816
- * var res = source.publishValue(function (x) { return x.select(function (y) { return y * y; }) }, 42);
5817
- *
5818
- * @param {Function} [selector] Optional selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive immediately receive the initial value, followed by all notifications of the source from the time of the subscription on.
5819
- * @param {Mixed} initialValue Initial value received by observers upon subscription.
5820
- * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
5821
- */
5822
- observableProto.publishValue = function (initialValueOrSelector, initialValue) {
5823
- return arguments.length === 2 ?
5824
- this.multicast(function () {
5825
- return new BehaviorSubject(initialValue);
5826
- }, initialValueOrSelector) :
5827
- this.multicast(new BehaviorSubject(initialValueOrSelector));
5828
- };
5966
+ /**
5967
+ * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence and starts with initialValue.
5968
+ * This operator is a specialization of Multicast using a BehaviorSubject.
5969
+ *
5970
+ * @example
5971
+ * var res = source.publishValue(42);
5972
+ * var res = source.publishValue(function (x) { return x.select(function (y) { return y * y; }) }, 42);
5973
+ *
5974
+ * @param {Function} [selector] Optional selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive immediately receive the initial value, followed by all notifications of the source from the time of the subscription on.
5975
+ * @param {Mixed} initialValue Initial value received by observers upon subscription.
5976
+ * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
5977
+ */
5978
+ observableProto.publishValue = function (initialValueOrSelector, initialValue) {
5979
+ return arguments.length === 2 ?
5980
+ this.multicast(function () {
5981
+ return new BehaviorSubject(initialValue);
5982
+ }, initialValueOrSelector) :
5983
+ this.multicast(new BehaviorSubject(initialValueOrSelector));
5984
+ };
5829
5985
 
5830
- /**
5831
- * Returns an observable sequence that shares a single subscription to the underlying sequence and starts with an initialValue.
5832
- * This operator is a specialization of publishValue which creates a subscription when the number of observers goes from zero to one, then shares that subscription with all subsequent observers until the number of observers returns to zero, at which point the subscription is disposed.
5833
- *
5834
- * @example
5835
- * var res = source.shareValue(42);
5836
- *
5837
- * @param {Mixed} initialValue Initial value received by observers upon subscription.
5838
- * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence.
5839
- */
5840
- observableProto.shareValue = function (initialValue) {
5841
- return this.publishValue(initialValue).
5842
- refCount();
5843
- };
5986
+ /**
5987
+ * Returns an observable sequence that shares a single subscription to the underlying sequence and starts with an initialValue.
5988
+ * This operator is a specialization of publishValue which creates a subscription when the number of observers goes from zero to one, then shares that subscription with all subsequent observers until the number of observers returns to zero, at which point the subscription is disposed.
5989
+ *
5990
+ * @example
5991
+ * var res = source.shareValue(42);
5992
+ *
5993
+ * @param {Mixed} initialValue Initial value received by observers upon subscription.
5994
+ * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence.
5995
+ */
5996
+ observableProto.shareValue = function (initialValue) {
5997
+ return this.publishValue(initialValue).refCount();
5998
+ };
5844
5999
 
5845
- /**
5846
- * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length for the replay buffer.
5847
- * This operator is a specialization of Multicast using a ReplaySubject.
5848
- *
5849
- * @example
5850
- * var res = source.replay(null, 3);
5851
- * var res = source.replay(null, 3, 500);
5852
- * var res = source.replay(null, 3, 500, scheduler);
5853
- * var res = source.replay(function (x) { return x.take(6).repeat(); }, 3, 500, scheduler);
5854
- *
5855
- * @param selector [Optional] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source subject to the specified replay buffer trimming policy.
5856
- * @param bufferSize [Optional] Maximum element count of the replay buffer.
5857
- * @param window [Optional] Maximum time length of the replay buffer.
5858
- * @param scheduler [Optional] Scheduler where connected observers within the selector function will be invoked on.
5859
- * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
5860
- */
5861
- observableProto.replay = function (selector, bufferSize, window, scheduler) {
5862
- return !selector ?
5863
- this.multicast(new ReplaySubject(bufferSize, window, scheduler)) :
5864
- this.multicast(function () {
5865
- return new ReplaySubject(bufferSize, window, scheduler);
5866
- }, selector);
5867
- };
6000
+ /**
6001
+ * Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length for the replay buffer.
6002
+ * This operator is a specialization of Multicast using a ReplaySubject.
6003
+ *
6004
+ * @example
6005
+ * var res = source.replay(null, 3);
6006
+ * var res = source.replay(null, 3, 500);
6007
+ * var res = source.replay(null, 3, 500, scheduler);
6008
+ * var res = source.replay(function (x) { return x.take(6).repeat(); }, 3, 500, scheduler);
6009
+ *
6010
+ * @param selector [Optional] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source subject to the specified replay buffer trimming policy.
6011
+ * @param bufferSize [Optional] Maximum element count of the replay buffer.
6012
+ * @param window [Optional] Maximum time length of the replay buffer.
6013
+ * @param scheduler [Optional] Scheduler where connected observers within the selector function will be invoked on.
6014
+ * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
6015
+ */
6016
+ observableProto.replay = function (selector, bufferSize, window, scheduler) {
6017
+ return selector && isFunction(selector) ?
6018
+ this.multicast(function () { return new ReplaySubject(bufferSize, window, scheduler); }, selector) :
6019
+ this.multicast(new ReplaySubject(bufferSize, window, scheduler));
6020
+ };
5868
6021
 
5869
6022
  /**
5870
6023
  * Returns an observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length for the replay buffer.
@@ -5903,267 +6056,247 @@ if (!Array.prototype.forEach) {
5903
6056
  }
5904
6057
  };
5905
6058
 
5906
- /**
5907
- * Represents a value that changes over time.
5908
- * Observers can subscribe to the subject to receive the last (or initial) value and all subsequent notifications.
5909
- */
5910
- var BehaviorSubject = Rx.BehaviorSubject = (function (_super) {
5911
- function subscribe(observer) {
5912
- checkDisposed.call(this);
5913
- if (!this.isStopped) {
5914
- this.observers.push(observer);
5915
- observer.onNext(this.value);
5916
- return new InnerSubscription(this, observer);
5917
- }
5918
- var ex = this.exception;
5919
- if (ex) {
5920
- observer.onError(ex);
5921
- } else {
5922
- observer.onCompleted();
5923
- }
5924
- return disposableEmpty;
5925
- }
6059
+ /**
6060
+ * Represents a value that changes over time.
6061
+ * Observers can subscribe to the subject to receive the last (or initial) value and all subsequent notifications.
6062
+ */
6063
+ var BehaviorSubject = Rx.BehaviorSubject = (function (__super__) {
6064
+ function subscribe(observer) {
6065
+ checkDisposed.call(this);
6066
+ if (!this.isStopped) {
6067
+ this.observers.push(observer);
6068
+ observer.onNext(this.value);
6069
+ return new InnerSubscription(this, observer);
6070
+ }
6071
+ var ex = this.exception;
6072
+ if (ex) {
6073
+ observer.onError(ex);
6074
+ } else {
6075
+ observer.onCompleted();
6076
+ }
6077
+ return disposableEmpty;
6078
+ }
5926
6079
 
5927
- inherits(BehaviorSubject, _super);
6080
+ inherits(BehaviorSubject, __super__);
5928
6081
 
5929
- /**
5930
- * @constructor
5931
- * Initializes a new instance of the BehaviorSubject class which creates a subject that caches its last value and starts with the specified value.
5932
- * @param {Mixed} value Initial value sent to observers when no other value has been received by the subject yet.
5933
- */
5934
- function BehaviorSubject(value) {
5935
- _super.call(this, subscribe);
6082
+ /**
6083
+ * @constructor
6084
+ * Initializes a new instance of the BehaviorSubject class which creates a subject that caches its last value and starts with the specified value.
6085
+ * @param {Mixed} value Initial value sent to observers when no other value has been received by the subject yet.
6086
+ */
6087
+ function BehaviorSubject(value) {
6088
+ __super__.call(this, subscribe);
6089
+ this.value = value,
6090
+ this.observers = [],
6091
+ this.isDisposed = false,
6092
+ this.isStopped = false,
6093
+ this.exception = null;
6094
+ }
5936
6095
 
5937
- this.value = value,
5938
- this.observers = [],
5939
- this.isDisposed = false,
5940
- this.isStopped = false,
5941
- this.exception = null;
6096
+ addProperties(BehaviorSubject.prototype, Observer, {
6097
+ /**
6098
+ * Indicates whether the subject has observers subscribed to it.
6099
+ * @returns {Boolean} Indicates whether the subject has observers subscribed to it.
6100
+ */
6101
+ hasObservers: function () {
6102
+ return this.observers.length > 0;
6103
+ },
6104
+ /**
6105
+ * Notifies all subscribed observers about the end of the sequence.
6106
+ */
6107
+ onCompleted: function () {
6108
+ checkDisposed.call(this);
6109
+ if (this.isStopped) { return; }
6110
+ this.isStopped = true;
6111
+ for (var i = 0, os = this.observers.slice(0), len = os.length; i < len; i++) {
6112
+ os[i].onCompleted();
5942
6113
  }
5943
6114
 
5944
- addProperties(BehaviorSubject.prototype, Observer, {
5945
- /**
5946
- * Indicates whether the subject has observers subscribed to it.
5947
- * @returns {Boolean} Indicates whether the subject has observers subscribed to it.
5948
- */
5949
- hasObservers: function () {
5950
- return this.observers.length > 0;
5951
- },
5952
- /**
5953
- * Notifies all subscribed observers about the end of the sequence.
5954
- */
5955
- onCompleted: function () {
5956
- checkDisposed.call(this);
5957
- if (!this.isStopped) {
5958
- var os = this.observers.slice(0);
5959
- this.isStopped = true;
5960
- for (var i = 0, len = os.length; i < len; i++) {
5961
- os[i].onCompleted();
5962
- }
6115
+ this.observers = [];
6116
+ },
6117
+ /**
6118
+ * Notifies all subscribed observers about the exception.
6119
+ * @param {Mixed} error The exception to send to all observers.
6120
+ */
6121
+ onError: function (error) {
6122
+ checkDisposed.call(this);
6123
+ if (this.isStopped) { return; }
6124
+ this.isStopped = true;
6125
+ this.exception = error;
5963
6126
 
5964
- this.observers = [];
5965
- }
5966
- },
5967
- /**
5968
- * Notifies all subscribed observers about the exception.
5969
- * @param {Mixed} error The exception to send to all observers.
5970
- */
5971
- onError: function (error) {
5972
- checkDisposed.call(this);
5973
- if (!this.isStopped) {
5974
- var os = this.observers.slice(0);
5975
- this.isStopped = true;
5976
- this.exception = error;
6127
+ for (var i = 0, os = this.observers.slice(0), len = os.length; i < len; i++) {
6128
+ os[i].onError(error);
6129
+ }
5977
6130
 
5978
- for (var i = 0, len = os.length; i < len; i++) {
5979
- os[i].onError(error);
5980
- }
6131
+ this.observers = [];
6132
+ },
6133
+ /**
6134
+ * Notifies all subscribed observers about the arrival of the specified element in the sequence.
6135
+ * @param {Mixed} value The value to send to all observers.
6136
+ */
6137
+ onNext: function (value) {
6138
+ checkDisposed.call(this);
6139
+ if (this.isStopped) { return; }
6140
+ this.value = value;
6141
+ for (var i = 0, os = this.observers.slice(0), len = os.length; i < len; i++) {
6142
+ os[i].onNext(value);
6143
+ }
6144
+ },
6145
+ /**
6146
+ * Unsubscribe all observers and release resources.
6147
+ */
6148
+ dispose: function () {
6149
+ this.isDisposed = true;
6150
+ this.observers = null;
6151
+ this.value = null;
6152
+ this.exception = null;
6153
+ }
6154
+ });
5981
6155
 
5982
- this.observers = [];
5983
- }
5984
- },
5985
- /**
5986
- * Notifies all subscribed observers about the arrival of the specified element in the sequence.
5987
- * @param {Mixed} value The value to send to all observers.
5988
- */
5989
- onNext: function (value) {
5990
- checkDisposed.call(this);
5991
- if (!this.isStopped) {
5992
- this.value = value;
5993
- var os = this.observers.slice(0);
5994
- for (var i = 0, len = os.length; i < len; i++) {
5995
- os[i].onNext(value);
5996
- }
5997
- }
5998
- },
5999
- /**
6000
- * Unsubscribe all observers and release resources.
6001
- */
6002
- dispose: function () {
6003
- this.isDisposed = true;
6004
- this.observers = null;
6005
- this.value = null;
6006
- this.exception = null;
6007
- }
6008
- });
6156
+ return BehaviorSubject;
6157
+ }(Observable));
6009
6158
 
6010
- return BehaviorSubject;
6011
- }(Observable));
6159
+ /**
6160
+ * Represents an object that is both an observable sequence as well as an observer.
6161
+ * Each notification is broadcasted to all subscribed and future observers, subject to buffer trimming policies.
6162
+ */
6163
+ var ReplaySubject = Rx.ReplaySubject = (function (__super__) {
6012
6164
 
6013
- /**
6014
- * Represents an object that is both an observable sequence as well as an observer.
6015
- * Each notification is broadcasted to all subscribed and future observers, subject to buffer trimming policies.
6016
- */
6017
- var ReplaySubject = Rx.ReplaySubject = (function (_super) {
6165
+ function createRemovableDisposable(subject, observer) {
6166
+ return disposableCreate(function () {
6167
+ observer.dispose();
6168
+ !subject.isDisposed && subject.observers.splice(subject.observers.indexOf(observer), 1);
6169
+ });
6170
+ }
6018
6171
 
6019
- function RemovableDisposable (subject, observer) {
6020
- this.subject = subject;
6021
- this.observer = observer;
6022
- };
6172
+ function subscribe(observer) {
6173
+ var so = new ScheduledObserver(this.scheduler, observer),
6174
+ subscription = createRemovableDisposable(this, so);
6175
+ checkDisposed.call(this);
6176
+ this._trim(this.scheduler.now());
6177
+ this.observers.push(so);
6023
6178
 
6024
- RemovableDisposable.prototype.dispose = function () {
6025
- this.observer.dispose();
6026
- if (!this.subject.isDisposed) {
6027
- var idx = this.subject.observers.indexOf(this.observer);
6028
- this.subject.observers.splice(idx, 1);
6029
- }
6030
- };
6179
+ var n = this.q.length;
6031
6180
 
6032
- function subscribe(observer) {
6033
- var so = new ScheduledObserver(this.scheduler, observer),
6034
- subscription = new RemovableDisposable(this, so);
6035
- checkDisposed.call(this);
6036
- this._trim(this.scheduler.now());
6037
- this.observers.push(so);
6181
+ for (var i = 0, len = this.q.length; i < len; i++) {
6182
+ so.onNext(this.q[i].value);
6183
+ }
6038
6184
 
6039
- var n = this.q.length;
6185
+ if (this.hasError) {
6186
+ n++;
6187
+ so.onError(this.error);
6188
+ } else if (this.isStopped) {
6189
+ n++;
6190
+ so.onCompleted();
6191
+ }
6040
6192
 
6041
- for (var i = 0, len = this.q.length; i < len; i++) {
6042
- so.onNext(this.q[i].value);
6043
- }
6193
+ so.ensureActive(n);
6194
+ return subscription;
6195
+ }
6044
6196
 
6045
- if (this.hasError) {
6046
- n++;
6047
- so.onError(this.error);
6048
- } else if (this.isStopped) {
6049
- n++;
6050
- so.onCompleted();
6051
- }
6197
+ inherits(ReplaySubject, __super__);
6052
6198
 
6053
- so.ensureActive(n);
6054
- return subscription;
6055
- }
6199
+ /**
6200
+ * Initializes a new instance of the ReplaySubject class with the specified buffer size, window size and scheduler.
6201
+ * @param {Number} [bufferSize] Maximum element count of the replay buffer.
6202
+ * @param {Number} [windowSize] Maximum time length of the replay buffer.
6203
+ * @param {Scheduler} [scheduler] Scheduler the observers are invoked on.
6204
+ */
6205
+ function ReplaySubject(bufferSize, windowSize, scheduler) {
6206
+ this.bufferSize = bufferSize == null ? Number.MAX_VALUE : bufferSize;
6207
+ this.windowSize = windowSize == null ? Number.MAX_VALUE : windowSize;
6208
+ this.scheduler = scheduler || currentThreadScheduler;
6209
+ this.q = [];
6210
+ this.observers = [];
6211
+ this.isStopped = false;
6212
+ this.isDisposed = false;
6213
+ this.hasError = false;
6214
+ this.error = null;
6215
+ __super__.call(this, subscribe);
6216
+ }
6056
6217
 
6057
- inherits(ReplaySubject, _super);
6218
+ addProperties(ReplaySubject.prototype, Observer, {
6219
+ /**
6220
+ * Indicates whether the subject has observers subscribed to it.
6221
+ * @returns {Boolean} Indicates whether the subject has observers subscribed to it.
6222
+ */
6223
+ hasObservers: function () {
6224
+ return this.observers.length > 0;
6225
+ },
6226
+ _trim: function (now) {
6227
+ while (this.q.length > this.bufferSize) {
6228
+ this.q.shift();
6229
+ }
6230
+ while (this.q.length > 0 && (now - this.q[0].interval) > this.windowSize) {
6231
+ this.q.shift();
6232
+ }
6233
+ },
6234
+ /**
6235
+ * Notifies all subscribed observers about the arrival of the specified element in the sequence.
6236
+ * @param {Mixed} value The value to send to all observers.
6237
+ */
6238
+ onNext: function (value) {
6239
+ checkDisposed.call(this);
6240
+ if (this.isStopped) { return; }
6241
+ var now = this.scheduler.now();
6242
+ this.q.push({ interval: now, value: value });
6243
+ this._trim(now);
6058
6244
 
6059
- /**
6060
- * Initializes a new instance of the ReplaySubject class with the specified buffer size, window size and scheduler.
6061
- * @param {Number} [bufferSize] Maximum element count of the replay buffer.
6062
- * @param {Number} [windowSize] Maximum time length of the replay buffer.
6063
- * @param {Scheduler} [scheduler] Scheduler the observers are invoked on.
6064
- */
6065
- function ReplaySubject(bufferSize, windowSize, scheduler) {
6066
- this.bufferSize = bufferSize == null ? Number.MAX_VALUE : bufferSize;
6067
- this.windowSize = windowSize == null ? Number.MAX_VALUE : windowSize;
6068
- this.scheduler = scheduler || currentThreadScheduler;
6069
- this.q = [];
6070
- this.observers = [];
6071
- this.isStopped = false;
6072
- this.isDisposed = false;
6073
- this.hasError = false;
6074
- this.error = null;
6075
- _super.call(this, subscribe);
6245
+ var o = this.observers.slice(0);
6246
+ for (var i = 0, len = o.length; i < len; i++) {
6247
+ var observer = o[i];
6248
+ observer.onNext(value);
6249
+ observer.ensureActive();
6250
+ }
6251
+ },
6252
+ /**
6253
+ * Notifies all subscribed observers about the exception.
6254
+ * @param {Mixed} error The exception to send to all observers.
6255
+ */
6256
+ onError: function (error) {
6257
+ checkDisposed.call(this);
6258
+ if (this.isStopped) { return; }
6259
+ this.isStopped = true;
6260
+ this.error = error;
6261
+ this.hasError = true;
6262
+ var now = this.scheduler.now();
6263
+ this._trim(now);
6264
+ var o = this.observers.slice(0);
6265
+ for (var i = 0, len = o.length; i < len; i++) {
6266
+ var observer = o[i];
6267
+ observer.onError(error);
6268
+ observer.ensureActive();
6269
+ }
6270
+ this.observers = [];
6271
+ },
6272
+ /**
6273
+ * Notifies all subscribed observers about the end of the sequence.
6274
+ */
6275
+ onCompleted: function () {
6276
+ checkDisposed.call(this);
6277
+ if (this.isStopped) { return; }
6278
+ this.isStopped = true;
6279
+ var now = this.scheduler.now();
6280
+ this._trim(now);
6281
+ var o = this.observers.slice(0);
6282
+ for (var i = 0, len = o.length; i < len; i++) {
6283
+ var observer = o[i];
6284
+ observer.onCompleted();
6285
+ observer.ensureActive();
6076
6286
  }
6287
+ this.observers = [];
6288
+ },
6289
+ /**
6290
+ * Unsubscribe all observers and release resources.
6291
+ */
6292
+ dispose: function () {
6293
+ this.isDisposed = true;
6294
+ this.observers = null;
6295
+ }
6296
+ });
6077
6297
 
6078
- addProperties(ReplaySubject.prototype, Observer, {
6079
- /**
6080
- * Indicates whether the subject has observers subscribed to it.
6081
- * @returns {Boolean} Indicates whether the subject has observers subscribed to it.
6082
- */
6083
- hasObservers: function () {
6084
- return this.observers.length > 0;
6085
- },
6086
- /* @private */
6087
- _trim: function (now) {
6088
- while (this.q.length > this.bufferSize) {
6089
- this.q.shift();
6090
- }
6091
- while (this.q.length > 0 && (now - this.q[0].interval) > this.windowSize) {
6092
- this.q.shift();
6093
- }
6094
- },
6095
- /**
6096
- * Notifies all subscribed observers about the arrival of the specified element in the sequence.
6097
- * @param {Mixed} value The value to send to all observers.
6098
- */
6099
- onNext: function (value) {
6100
- var observer;
6101
- checkDisposed.call(this);
6102
- if (!this.isStopped) {
6103
- var now = this.scheduler.now();
6104
- this.q.push({ interval: now, value: value });
6105
- this._trim(now);
6106
-
6107
- var o = this.observers.slice(0);
6108
- for (var i = 0, len = o.length; i < len; i++) {
6109
- observer = o[i];
6110
- observer.onNext(value);
6111
- observer.ensureActive();
6112
- }
6113
- }
6114
- },
6115
- /**
6116
- * Notifies all subscribed observers about the exception.
6117
- * @param {Mixed} error The exception to send to all observers.
6118
- */
6119
- onError: function (error) {
6120
- var observer;
6121
- checkDisposed.call(this);
6122
- if (!this.isStopped) {
6123
- this.isStopped = true;
6124
- this.error = error;
6125
- this.hasError = true;
6126
- var now = this.scheduler.now();
6127
- this._trim(now);
6128
- var o = this.observers.slice(0);
6129
- for (var i = 0, len = o.length; i < len; i++) {
6130
- observer = o[i];
6131
- observer.onError(error);
6132
- observer.ensureActive();
6133
- }
6134
- this.observers = [];
6135
- }
6136
- },
6137
- /**
6138
- * Notifies all subscribed observers about the end of the sequence.
6139
- */
6140
- onCompleted: function () {
6141
- var observer;
6142
- checkDisposed.call(this);
6143
- if (!this.isStopped) {
6144
- this.isStopped = true;
6145
- var now = this.scheduler.now();
6146
- this._trim(now);
6147
- var o = this.observers.slice(0);
6148
- for (var i = 0, len = o.length; i < len; i++) {
6149
- observer = o[i];
6150
- observer.onCompleted();
6151
- observer.ensureActive();
6152
- }
6153
- this.observers = [];
6154
- }
6155
- },
6156
- /**
6157
- * Unsubscribe all observers and release resources.
6158
- */
6159
- dispose: function () {
6160
- this.isDisposed = true;
6161
- this.observers = null;
6162
- }
6163
- });
6164
-
6165
- return ReplaySubject;
6166
- }(Observable));
6298
+ return ReplaySubject;
6299
+ }(Observable));
6167
6300
 
6168
6301
  var ConnectableObservable = Rx.ConnectableObservable = (function (__super__) {
6169
6302
  inherits(ConnectableObservable, __super__);
@@ -7626,18 +7759,6 @@ if (!Array.prototype.forEach) {
7626
7759
 
7627
7760
  /**
7628
7761
  * Returns an observable sequence that produces a value after dueTime has elapsed and then after each period.
7629
- *
7630
- * @example
7631
- * 1 - res = Rx.Observable.timer(new Date());
7632
- * 2 - res = Rx.Observable.timer(new Date(), 1000);
7633
- * 3 - res = Rx.Observable.timer(new Date(), Rx.Scheduler.timeout);
7634
- * 4 - res = Rx.Observable.timer(new Date(), 1000, Rx.Scheduler.timeout);
7635
- *
7636
- * 5 - res = Rx.Observable.timer(5000);
7637
- * 6 - res = Rx.Observable.timer(5000, 1000);
7638
- * 7 - res = Rx.Observable.timer(5000, Rx.Scheduler.timeout);
7639
- * 8 - res = Rx.Observable.timer(5000, 1000, Rx.Scheduler.timeout);
7640
- *
7641
7762
  * @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) at which to produce the first value.
7642
7763
  * @param {Mixed} [periodOrScheduler] Period to produce subsequent values (specified as an integer denoting milliseconds), or the scheduler to run the timer on. If not specified, the resulting timer is not recurring.
7643
7764
  * @param {Scheduler} [scheduler] Scheduler to run the timer on. If not specified, the timeout scheduler is used.
@@ -7648,7 +7769,7 @@ if (!Array.prototype.forEach) {
7648
7769
  isScheduler(scheduler) || (scheduler = timeoutScheduler);
7649
7770
  if (periodOrScheduler !== undefined && typeof periodOrScheduler === 'number') {
7650
7771
  period = periodOrScheduler;
7651
- } else if (periodOrScheduler !== undefined && typeof periodOrScheduler === 'object') {
7772
+ } else if (isScheduler(periodOrScheduler)) {
7652
7773
  scheduler = periodOrScheduler;
7653
7774
  }
7654
7775
  if (dueTime instanceof Date && period === undefined) {
@@ -7767,7 +7888,37 @@ if (!Array.prototype.forEach) {
7767
7888
  */
7768
7889
  observableProto.throttle = function (dueTime, scheduler) {
7769
7890
  isScheduler(scheduler) || (scheduler = timeoutScheduler);
7770
- return this.throttleWithSelector(function () { return observableTimer(dueTime, scheduler); })
7891
+ var source = this;
7892
+ return new AnonymousObservable(function (observer) {
7893
+ var cancelable = new SerialDisposable(), hasvalue = false, value, id = 0;
7894
+ var subscription = source.subscribe(
7895
+ function (x) {
7896
+ hasvalue = true;
7897
+ value = x;
7898
+ id++;
7899
+ var currentId = id,
7900
+ d = new SingleAssignmentDisposable();
7901
+ cancelable.setDisposable(d);
7902
+ d.setDisposable(scheduler.scheduleWithRelative(dueTime, function () {
7903
+ hasValue && id === currentId && observer.onNext(value);
7904
+ hasvalue = false;
7905
+ }));
7906
+ },
7907
+ function (e) {
7908
+ cancelable.dispose();
7909
+ observer.onError(e);
7910
+ hasvalue = false;
7911
+ id++;
7912
+ },
7913
+ function () {
7914
+ cancelable.dispose();
7915
+ hasvalue && observer.onNext(value);
7916
+ observer.onCompleted();
7917
+ hasvalue = false;
7918
+ id++;
7919
+ });
7920
+ return new CompositeDisposable(subscription, cancelable);
7921
+ });
7771
7922
  };
7772
7923
 
7773
7924
  /**
@@ -7784,70 +7935,49 @@ if (!Array.prototype.forEach) {
7784
7935
  */
7785
7936
  observableProto.windowWithTime = function (timeSpan, timeShiftOrScheduler, scheduler) {
7786
7937
  var source = this, timeShift;
7787
-
7788
- timeShiftOrScheduler == null && (timeShift = timeSpan);
7938
+ if (timeShiftOrScheduler === undefined) {
7939
+ timeShift = timeSpan;
7940
+ }
7789
7941
  isScheduler(scheduler) || (scheduler = timeoutScheduler);
7790
7942
  if (typeof timeShiftOrScheduler === 'number') {
7791
7943
  timeShift = timeShiftOrScheduler;
7792
- } else if (typeof timeShiftOrScheduler === 'object') {
7944
+ } else if (isScheduler(timeShiftOrScheduler)) {
7793
7945
  timeShift = timeSpan;
7794
7946
  scheduler = timeShiftOrScheduler;
7795
7947
  }
7796
7948
  return new AnonymousObservable(function (observer) {
7797
7949
  var groupDisposable,
7798
- nextShift = timeShift,
7799
- nextSpan = timeSpan,
7800
- q = [],
7801
- refCountDisposable,
7802
- timerD = new SerialDisposable(),
7803
- totalTime = 0;
7804
- groupDisposable = new CompositeDisposable(timerD),
7805
- refCountDisposable = new RefCountDisposable(groupDisposable);
7806
-
7807
-
7808
- q.push(new Subject());
7809
- observer.onNext(addRef(q[0], refCountDisposable));
7810
- createTimer();
7811
- groupDisposable.add(source.subscribe(function (x) {
7812
- var i, len;
7813
- for (i = 0, len = q.length; i < len; i++) {
7814
- q[i].onNext(x);
7815
- }
7816
- }, function (e) {
7817
- var i, len;
7818
- for (i = 0, len = q.length; i < len; i++) {
7819
- q[i].onError(e);
7820
- }
7821
- observer.onError(e);
7822
- }, function () {
7823
- var i, len;
7824
- for (i = 0, len = q.length; i < len; i++) {
7825
- q[i].onCompleted();
7826
- }
7827
- observer.onCompleted();
7828
- }));
7829
-
7830
- return refCountDisposable;
7950
+ nextShift = timeShift,
7951
+ nextSpan = timeSpan,
7952
+ q = [],
7953
+ refCountDisposable,
7954
+ timerD = new SerialDisposable(),
7955
+ totalTime = 0;
7956
+ groupDisposable = new CompositeDisposable(timerD),
7957
+ refCountDisposable = new RefCountDisposable(groupDisposable);
7831
7958
 
7832
- function createTimer () {
7833
- var m = new SingleAssignmentDisposable(), isSpan = false, isShift = false;
7959
+ function createTimer () {
7960
+ var m = new SingleAssignmentDisposable(),
7961
+ isSpan = false,
7962
+ isShift = false;
7834
7963
  timerD.setDisposable(m);
7835
-
7836
7964
  if (nextSpan === nextShift) {
7837
7965
  isSpan = true;
7838
7966
  isShift = true;
7839
7967
  } else if (nextSpan < nextShift) {
7840
- isSpan = true;
7968
+ isSpan = true;
7841
7969
  } else {
7842
7970
  isShift = true;
7843
7971
  }
7844
-
7845
7972
  var newTotalTime = isSpan ? nextSpan : nextShift,
7846
- ts = newTotalTime - totalTime;
7973
+ ts = newTotalTime - totalTime;
7847
7974
  totalTime = newTotalTime;
7848
- isSpan && (nextSpan += timeShift);
7849
- isShift && (nextShift += timeShift);
7850
-
7975
+ if (isSpan) {
7976
+ nextSpan += timeShift;
7977
+ }
7978
+ if (isShift) {
7979
+ nextShift += timeShift;
7980
+ }
7851
7981
  m.setDisposable(scheduler.scheduleWithRelative(ts, function () {
7852
7982
  var s;
7853
7983
  if (isShift) {
@@ -7861,17 +7991,30 @@ if (!Array.prototype.forEach) {
7861
7991
  }
7862
7992
  createTimer();
7863
7993
  }));
7864
- }
7994
+ };
7995
+ q.push(new Subject());
7996
+ observer.onNext(addRef(q[0], refCountDisposable));
7997
+ createTimer();
7998
+ groupDisposable.add(source.subscribe(function (x) {
7999
+ for (var i = 0, len = q.length; i < len; i++) {
8000
+ q[i].onNext(x);
8001
+ }
8002
+ }, function (e) {
8003
+ for (var i = 0, len = q.length; i < len; i++) {
8004
+ q[i].onError(e);
8005
+ }
8006
+ observer.onError(e);
8007
+ }, function () {
8008
+ for (var i = 0, len = q.length; i < len; i++) {
8009
+ q[i].onCompleted();
8010
+ }
8011
+ observer.onCompleted();
8012
+ }));
8013
+ return refCountDisposable;
7865
8014
  });
7866
8015
  };
7867
-
7868
8016
  /**
7869
8017
  * Projects each element of an observable sequence into a window that is completed when either it's full or a given amount of time has elapsed.
7870
- * @example
7871
- * 1 - res = source.windowWithTimeOrCount(5000, 50); // 5s or 50 items
7872
- * 2 - res = source.windowWithTimeOrCount(5000, 50, scheduler); //5s or 50 items
7873
- *
7874
- * @memberOf Observable#
7875
8018
  * @param {Number} timeSpan Maximum time length of a window.
7876
8019
  * @param {Number} count Maximum element count of a window.
7877
8020
  * @param {Scheduler} [scheduler] Scheduler to run windowing timers on. If not specified, the timeout scheduler is used.
@@ -7882,15 +8025,31 @@ if (!Array.prototype.forEach) {
7882
8025
  isScheduler(scheduler) || (scheduler = timeoutScheduler);
7883
8026
  return new AnonymousObservable(function (observer) {
7884
8027
  var createTimer,
7885
- groupDisposable,
7886
- n = 0,
7887
- refCountDisposable,
7888
- s = new Subject()
7889
- timerD = new SerialDisposable(),
7890
- windowId = 0;
8028
+ groupDisposable,
8029
+ n = 0,
8030
+ refCountDisposable,
8031
+ s,
8032
+ timerD = new SerialDisposable(),
8033
+ windowId = 0;
7891
8034
  groupDisposable = new CompositeDisposable(timerD);
7892
8035
  refCountDisposable = new RefCountDisposable(groupDisposable);
7893
-
8036
+ createTimer = function (id) {
8037
+ var m = new SingleAssignmentDisposable();
8038
+ timerD.setDisposable(m);
8039
+ m.setDisposable(scheduler.scheduleWithRelative(timeSpan, function () {
8040
+ var newId;
8041
+ if (id !== windowId) {
8042
+ return;
8043
+ }
8044
+ n = 0;
8045
+ newId = ++windowId;
8046
+ s.onCompleted();
8047
+ s = new Subject();
8048
+ observer.onNext(addRef(s, refCountDisposable));
8049
+ createTimer(newId);
8050
+ }));
8051
+ };
8052
+ s = new Subject();
7894
8053
  observer.onNext(addRef(s, refCountDisposable));
7895
8054
  createTimer(0);
7896
8055
  groupDisposable.add(source.subscribe(function (x) {
@@ -7905,34 +8064,19 @@ if (!Array.prototype.forEach) {
7905
8064
  s = new Subject();
7906
8065
  observer.onNext(addRef(s, refCountDisposable));
7907
8066
  }
7908
- newWindow && createTimer(newId);
8067
+ if (newWindow) {
8068
+ createTimer(newId);
8069
+ }
7909
8070
  }, function (e) {
7910
8071
  s.onError(e);
7911
8072
  observer.onError(e);
7912
8073
  }, function () {
7913
8074
  s.onCompleted();
7914
8075
  observer.onCompleted();
7915
- }));
7916
-
7917
- return refCountDisposable;
7918
-
7919
- function createTimer(id) {
7920
- var m = new SingleAssignmentDisposable();
7921
- timerD.setDisposable(m);
7922
- m.setDisposable(scheduler.scheduleWithRelative(timeSpan, function () {
7923
- var newId;
7924
- if (id !== windowId) { return; }
7925
- n = 0;
7926
- newId = ++windowId;
7927
- s.onCompleted();
7928
- s = new Subject();
7929
- observer.onNext(addRef(s, refCountDisposable));
7930
- createTimer(newId);
7931
- }));
7932
- }
8076
+ }));
8077
+ return refCountDisposable;
7933
8078
  });
7934
8079
  };
7935
-
7936
8080
  /**
7937
8081
  * Projects each element of an observable sequence into zero or more buffers which are produced based on timing information.
7938
8082
  *
@@ -8052,16 +8196,7 @@ if (!Array.prototype.forEach) {
8052
8196
  };
8053
8197
 
8054
8198
  /**
8055
- * Returns the source observable sequence or the other observable sequence if dueTime elapses.
8056
- *
8057
- * @example
8058
- * 1 - res = source.timeout(new Date()); // As a date
8059
- * 2 - res = source.timeout(5000); // 5 seconds
8060
- * 3 - res = source.timeout(new Date(), Rx.Observable.returnValue(42)); // As a date and timeout observable
8061
- * 4 - res = source.timeout(5000, Rx.Observable.returnValue(42)); // 5 seconds and timeout observable
8062
- * 5 - res = source.timeout(new Date(), Rx.Observable.returnValue(42), Rx.Scheduler.timeout); // As a date and timeout observable
8063
- * 6 - res = source.timeout(5000, Rx.Observable.returnValue(42), Rx.Scheduler.timeout); // 5 seconds and timeout observable
8064
- *
8199
+ * Returns the source observable sequence or the other observable sequence if dueTime elapses.
8065
8200
  * @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) when a timeout occurs.
8066
8201
  * @param {Observable} [other] Sequence to return in case of a timeout. If not specified, a timeout error throwing sequence will be used.
8067
8202
  * @param {Scheduler} [scheduler] Scheduler to run the timeout timers on. If not specified, the timeout scheduler is used.
@@ -8084,7 +8219,7 @@ if (!Array.prototype.forEach) {
8084
8219
 
8085
8220
  subscription.setDisposable(original);
8086
8221
 
8087
- var createTimer = function () {
8222
+ function createTimer() {
8088
8223
  var myId = id;
8089
8224
  timer.setDisposable(scheduler[schedulerMethod](dueTime, function () {
8090
8225
  if (id === myId) {
@@ -8092,7 +8227,7 @@ if (!Array.prototype.forEach) {
8092
8227
  subscription.setDisposable(other.subscribe(observer));
8093
8228
  }
8094
8229
  }));
8095
- };
8230
+ }
8096
8231
 
8097
8232
  createTimer();
8098
8233
 
@@ -8305,83 +8440,71 @@ if (!Array.prototype.forEach) {
8305
8440
 
8306
8441
  /**
8307
8442
  * Returns the source observable sequence, switching to the other observable sequence if a timeout is signaled.
8308
- *
8309
- * @example
8310
- * 1 - res = source.timeoutWithSelector(Rx.Observable.timer(500));
8311
- * 2 - res = source.timeoutWithSelector(Rx.Observable.timer(500), function (x) { return Rx.Observable.timer(200); });
8312
- * 3 - res = source.timeoutWithSelector(Rx.Observable.timer(500), function (x) { return Rx.Observable.timer(200); }, Rx.Observable.returnValue(42));
8313
- *
8314
8443
  * @param {Observable} [firstTimeout] Observable sequence that represents the timeout for the first element. If not provided, this defaults to Observable.never().
8315
8444
  * @param {Function} [timeoutDurationSelector] Selector to retrieve an observable sequence that represents the timeout between the current element and the next element.
8316
8445
  * @param {Observable} [other] Sequence to return in case of a timeout. If not provided, this is set to Observable.throwException().
8317
8446
  * @returns {Observable} The source sequence switching to the other sequence in case of a timeout.
8318
8447
  */
8319
8448
  observableProto.timeoutWithSelector = function (firstTimeout, timeoutdurationSelector, other) {
8320
- if (arguments.length === 1) {
8321
- timeoutdurationSelector = firstTimeout;
8322
- var firstTimeout = observableNever();
8323
- }
8324
- other || (other = observableThrow(new Error('Timeout')));
8325
- var source = this;
8326
- return new AnonymousObservable(function (observer) {
8327
- var subscription = new SerialDisposable(), timer = new SerialDisposable(), original = new SingleAssignmentDisposable();
8449
+ if (arguments.length === 1) {
8450
+ timeoutdurationSelector = firstTimeout;
8451
+ firstTimeout = observableNever();
8452
+ }
8453
+ other || (other = observableThrow(new Error('Timeout')));
8454
+ var source = this;
8455
+ return new AnonymousObservable(function (observer) {
8456
+ var subscription = new SerialDisposable(), timer = new SerialDisposable(), original = new SingleAssignmentDisposable();
8328
8457
 
8329
- subscription.setDisposable(original);
8458
+ subscription.setDisposable(original);
8330
8459
 
8331
- var id = 0, switched = false, setTimer = function (timeout) {
8332
- var myId = id, timerWins = function () {
8333
- return id === myId;
8334
- };
8335
- var d = new SingleAssignmentDisposable();
8336
- timer.setDisposable(d);
8337
- d.setDisposable(timeout.subscribe(function () {
8338
- if (timerWins()) {
8339
- subscription.setDisposable(other.subscribe(observer));
8340
- }
8341
- d.dispose();
8342
- }, function (e) {
8343
- if (timerWins()) {
8344
- observer.onError(e);
8345
- }
8346
- }, function () {
8347
- if (timerWins()) {
8348
- subscription.setDisposable(other.subscribe(observer));
8349
- }
8350
- }));
8351
- };
8460
+ var id = 0, switched = false;
8352
8461
 
8353
- setTimer(firstTimeout);
8354
- var observerWins = function () {
8355
- var res = !switched;
8356
- if (res) {
8357
- id++;
8358
- }
8359
- return res;
8360
- };
8462
+ function setTimer(timeout) {
8463
+ var myId = id;
8361
8464
 
8362
- original.setDisposable(source.subscribe(function (x) {
8363
- if (observerWins()) {
8364
- observer.onNext(x);
8365
- var timeout;
8366
- try {
8367
- timeout = timeoutdurationSelector(x);
8368
- } catch (e) {
8369
- observer.onError(e);
8370
- return;
8371
- }
8372
- setTimer(timeout);
8373
- }
8374
- }, function (e) {
8375
- if (observerWins()) {
8376
- observer.onError(e);
8377
- }
8378
- }, function () {
8379
- if (observerWins()) {
8380
- observer.onCompleted();
8381
- }
8382
- }));
8383
- return new CompositeDisposable(subscription, timer);
8384
- });
8465
+ function timerWins () {
8466
+ return id === myId;
8467
+ }
8468
+
8469
+ var d = new SingleAssignmentDisposable();
8470
+ timer.setDisposable(d);
8471
+ d.setDisposable(timeout.subscribe(function () {
8472
+ timerWins() && subscription.setDisposable(other.subscribe(observer));
8473
+ d.dispose();
8474
+ }, function (e) {
8475
+ timerWins() && observer.onError(e);
8476
+ }, function () {
8477
+ timerWins() && subscription.setDisposable(other.subscribe(observer));
8478
+ }));
8479
+ };
8480
+
8481
+ setTimer(firstTimeout);
8482
+
8483
+ function observerWins() {
8484
+ var res = !switched;
8485
+ if (res) { id++; }
8486
+ return res;
8487
+ }
8488
+
8489
+ original.setDisposable(source.subscribe(function (x) {
8490
+ if (observerWins()) {
8491
+ observer.onNext(x);
8492
+ var timeout;
8493
+ try {
8494
+ timeout = timeoutdurationSelector(x);
8495
+ } catch (e) {
8496
+ observer.onError(e);
8497
+ return;
8498
+ }
8499
+ setTimer(isPromise(timeout) ? observableFromPromise(timeout) : timeout);
8500
+ }
8501
+ }, function (e) {
8502
+ observerWins() && observer.onError(e);
8503
+ }, function () {
8504
+ observerWins() && observer.onCompleted();
8505
+ }));
8506
+ return new CompositeDisposable(subscription, timer);
8507
+ });
8385
8508
  };
8386
8509
 
8387
8510
  /**
@@ -8396,7 +8519,8 @@ if (!Array.prototype.forEach) {
8396
8519
  observableProto.throttleWithSelector = function (throttleDurationSelector) {
8397
8520
  var source = this;
8398
8521
  return new AnonymousObservable(function (observer) {
8399
- var value, hasValue = false, cancelable = new SerialDisposable(), id = 0, subscription = source.subscribe(function (x) {
8522
+ var value, hasValue = false, cancelable = new SerialDisposable(), id = 0;
8523
+ var subscription = source.subscribe(function (x) {
8400
8524
  var throttle;
8401
8525
  try {
8402
8526
  throttle = throttleDurationSelector(x);
@@ -8404,21 +8528,20 @@ if (!Array.prototype.forEach) {
8404
8528
  observer.onError(e);
8405
8529
  return;
8406
8530
  }
8531
+
8532
+ isPromise(throttle) && (throttle = observableFromPromise(throttle));
8533
+
8407
8534
  hasValue = true;
8408
8535
  value = x;
8409
8536
  id++;
8410
8537
  var currentid = id, d = new SingleAssignmentDisposable();
8411
8538
  cancelable.setDisposable(d);
8412
8539
  d.setDisposable(throttle.subscribe(function () {
8413
- if (hasValue && id === currentid) {
8414
- observer.onNext(value);
8415
- }
8540
+ hasValue && id === currentid && observer.onNext(value);
8416
8541
  hasValue = false;
8417
8542
  d.dispose();
8418
8543
  }, observer.onError.bind(observer), function () {
8419
- if (hasValue && id === currentid) {
8420
- observer.onNext(value);
8421
- }
8544
+ hasValue && id === currentid && observer.onNext(value);
8422
8545
  hasValue = false;
8423
8546
  d.dispose();
8424
8547
  }));
@@ -8429,9 +8552,7 @@ if (!Array.prototype.forEach) {
8429
8552
  id++;
8430
8553
  }, function () {
8431
8554
  cancelable.dispose();
8432
- if (hasValue) {
8433
- observer.onNext(value);
8434
- }
8555
+ hasValue && observer.onNext(value);
8435
8556
  observer.onCompleted();
8436
8557
  hasValue = false;
8437
8558
  id++;
@@ -8477,9 +8598,6 @@ if (!Array.prototype.forEach) {
8477
8598
 
8478
8599
  /**
8479
8600
  * Returns elements within the specified duration from the end of the observable source sequence, using the specified schedulers to run timers and to drain the collected elements.
8480
- *
8481
- * @example
8482
- * 1 - res = source.takeLastWithTime(5000, [optional timer scheduler], [optional loop scheduler]);
8483
8601
  * @description
8484
8602
  * This operator accumulates a queue with a length enough to store elements received during the initial duration window.
8485
8603
  * As more elements are received, elements older than the specified duration are taken from the queue and produced on the
@@ -8493,7 +8611,6 @@ if (!Array.prototype.forEach) {
8493
8611
  isScheduler(scheduler) || (scheduler = timeoutScheduler);
8494
8612
  return new AnonymousObservable(function (observer) {
8495
8613
  var q = [];
8496
-
8497
8614
  return source.subscribe(function (x) {
8498
8615
  var now = scheduler.now();
8499
8616
  q.push({ interval: now, value: x });
@@ -8504,11 +8621,8 @@ if (!Array.prototype.forEach) {
8504
8621
  var now = scheduler.now();
8505
8622
  while (q.length > 0) {
8506
8623
  var next = q.shift();
8507
- if (now - next.interval <= duration) {
8508
- observer.onNext(next.value);
8509
- }
8624
+ if (now - next.interval <= duration) { observer.onNext(next.value); }
8510
8625
  }
8511
-
8512
8626
  observer.onCompleted();
8513
8627
  });
8514
8628
  });
@@ -8516,9 +8630,6 @@ if (!Array.prototype.forEach) {
8516
8630
 
8517
8631
  /**
8518
8632
  * Returns an array with the elements within the specified duration from the end of the observable source sequence, using the specified scheduler to run timers.
8519
- *
8520
- * @example
8521
- * 1 - res = source.takeLastBufferWithTime(5000, [optional scheduler]);
8522
8633
  * @description
8523
8634
  * This operator accumulates a queue with a length enough to store elements received during the initial duration window.
8524
8635
  * As more elements are received, elements older than the specified duration are taken from the queue and produced on the
@@ -8532,7 +8643,6 @@ if (!Array.prototype.forEach) {
8532
8643
  isScheduler(scheduler) || (scheduler = timeoutScheduler);
8533
8644
  return new AnonymousObservable(function (observer) {
8534
8645
  var q = [];
8535
-
8536
8646
  return source.subscribe(function (x) {
8537
8647
  var now = scheduler.now();
8538
8648
  q.push({ interval: now, value: x });
@@ -8543,11 +8653,8 @@ if (!Array.prototype.forEach) {
8543
8653
  var now = scheduler.now(), res = [];
8544
8654
  while (q.length > 0) {
8545
8655
  var next = q.shift();
8546
- if (now - next.interval <= duration) {
8547
- res.push(next.value);
8548
- }
8656
+ if (now - next.interval <= duration) { res.push(next.value); }
8549
8657
  }
8550
-
8551
8658
  observer.onNext(res);
8552
8659
  observer.onCompleted();
8553
8660
  });
@@ -8607,10 +8714,10 @@ if (!Array.prototype.forEach) {
8607
8714
  * Errors produced by the source sequence are always forwarded to the result sequence, even if the error occurs before the start time.
8608
8715
  *
8609
8716
  * @examples
8610
- * 1 - res = source.skipUntilWithTime(new Date(), [optional scheduler]);
8611
- * 2 - res = source.skipUntilWithTime(5000, [optional scheduler]);
8612
- * @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.
8613
- * @param scheduler Scheduler to run the timer on. If not specified, defaults to Rx.Scheduler.timeout.
8717
+ * 1 - res = source.skipUntilWithTime(new Date(), [scheduler]);
8718
+ * 2 - res = source.skipUntilWithTime(5000, [scheduler]);
8719
+ * @param {Date|Number} 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.
8720
+ * @param {Scheduler} [scheduler] Scheduler to run the timer on. If not specified, defaults to Rx.Scheduler.timeout.
8614
8721
  * @returns {Observable} An observable sequence with the elements skipped until the specified start time.
8615
8722
  */
8616
8723
  observableProto.skipUntilWithTime = function (startTime, scheduler) {
@@ -8631,13 +8738,9 @@ if (!Array.prototype.forEach) {
8631
8738
  };
8632
8739
 
8633
8740
  /**
8634
- * Takes elements for the specified duration until the specified end time, using the specified scheduler to run timers.
8635
- *
8636
- * @example
8637
- * 1 - res = source.takeUntilWithTime(new Date(), [optional scheduler]);
8638
- * 2 - res = source.takeUntilWithTime(5000, [optional scheduler]);
8741
+ * Takes elements for the specified duration until the specified end time, using the specified scheduler to run timers.
8639
8742
  * @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.
8640
- * @param {Scheduler} scheduler Scheduler to run the timer on.
8743
+ * @param {Scheduler} [scheduler] Scheduler to run the timer on.
8641
8744
  * @returns {Observable} An observable sequence with the elements taken until the specified end time.
8642
8745
  */
8643
8746
  observableProto.takeUntilWithTime = function (endTime, scheduler) {
@@ -8646,9 +8749,9 @@ if (!Array.prototype.forEach) {
8646
8749
  'scheduleWithAbsolute' :
8647
8750
  'scheduleWithRelative';
8648
8751
  return new AnonymousObservable(function (observer) {
8649
- return new CompositeDisposable(scheduler[schedulerMethod](endTime, function () {
8650
- observer.onCompleted();
8651
- }), source.subscribe(observer));
8752
+ return new CompositeDisposable(
8753
+ scheduler[schedulerMethod](endTime, observer.onCompleted.bind(observer)),
8754
+ source.subscribe(observer));
8652
8755
  });
8653
8756
  };
8654
8757
 
@@ -9142,30 +9245,25 @@ if (!Array.prototype.forEach) {
9142
9245
  return AutoDetachObserver;
9143
9246
  }(AbstractObserver));
9144
9247
 
9145
- /** @private */
9146
- var GroupedObservable = (function (_super) {
9147
- inherits(GroupedObservable, _super);
9248
+ var GroupedObservable = (function (__super__) {
9249
+ inherits(GroupedObservable, __super__);
9148
9250
 
9149
- function subscribe(observer) {
9150
- return this.underlyingObservable.subscribe(observer);
9151
- }
9251
+ function subscribe(observer) {
9252
+ return this.underlyingObservable.subscribe(observer);
9253
+ }
9152
9254
 
9153
- /**
9154
- * @constructor
9155
- * @private
9156
- */
9157
- function GroupedObservable(key, underlyingObservable, mergedDisposable) {
9158
- _super.call(this, subscribe);
9159
- this.key = key;
9160
- this.underlyingObservable = !mergedDisposable ?
9161
- underlyingObservable :
9162
- new AnonymousObservable(function (observer) {
9163
- return new CompositeDisposable(mergedDisposable.getDisposable(), underlyingObservable.subscribe(observer));
9164
- });
9165
- }
9255
+ function GroupedObservable(key, underlyingObservable, mergedDisposable) {
9256
+ __super__.call(this, subscribe);
9257
+ this.key = key;
9258
+ this.underlyingObservable = !mergedDisposable ?
9259
+ underlyingObservable :
9260
+ new AnonymousObservable(function (observer) {
9261
+ return new CompositeDisposable(mergedDisposable.getDisposable(), underlyingObservable.subscribe(observer));
9262
+ });
9263
+ }
9166
9264
 
9167
- return GroupedObservable;
9168
- }(Observable));
9265
+ return GroupedObservable;
9266
+ }(Observable));
9169
9267
 
9170
9268
  /**
9171
9269
  * Represents an object that is both an observable sequence as well as an observer.