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, [], []);
@@ -395,101 +399,91 @@
395
399
  return a;
396
400
  }
397
401
 
398
- // Collections
399
- var IndexedItem = function (id, value) {
400
- this.id = id;
401
- this.value = value;
402
- };
402
+ // Collections
403
+ function IndexedItem(id, value) {
404
+ this.id = id;
405
+ this.value = value;
406
+ }
403
407
 
404
- IndexedItem.prototype.compareTo = function (other) {
405
- var c = this.value.compareTo(other.value);
406
- if (c === 0) {
407
- c = this.id - other.id;
408
- }
409
- return c;
410
- };
408
+ IndexedItem.prototype.compareTo = function (other) {
409
+ var c = this.value.compareTo(other.value);
410
+ c === 0 && (c = this.id - other.id);
411
+ return c;
412
+ };
411
413
 
412
- // Priority Queue for Scheduling
413
- var PriorityQueue = Rx.internals.PriorityQueue = function (capacity) {
414
- this.items = new Array(capacity);
415
- this.length = 0;
416
- };
414
+ // Priority Queue for Scheduling
415
+ var PriorityQueue = Rx.internals.PriorityQueue = function (capacity) {
416
+ this.items = new Array(capacity);
417
+ this.length = 0;
418
+ };
417
419
 
418
- var priorityProto = PriorityQueue.prototype;
419
- priorityProto.isHigherPriority = function (left, right) {
420
- return this.items[left].compareTo(this.items[right]) < 0;
421
- };
420
+ var priorityProto = PriorityQueue.prototype;
421
+ priorityProto.isHigherPriority = function (left, right) {
422
+ return this.items[left].compareTo(this.items[right]) < 0;
423
+ };
422
424
 
423
- priorityProto.percolate = function (index) {
424
- if (index >= this.length || index < 0) {
425
- return;
426
- }
427
- var parent = index - 1 >> 1;
428
- if (parent < 0 || parent === index) {
429
- return;
430
- }
431
- if (this.isHigherPriority(index, parent)) {
432
- var temp = this.items[index];
433
- this.items[index] = this.items[parent];
434
- this.items[parent] = temp;
435
- this.percolate(parent);
436
- }
437
- };
425
+ priorityProto.percolate = function (index) {
426
+ if (index >= this.length || index < 0) { return; }
427
+ var parent = index - 1 >> 1;
428
+ if (parent < 0 || parent === index) { return; }
429
+ if (this.isHigherPriority(index, parent)) {
430
+ var temp = this.items[index];
431
+ this.items[index] = this.items[parent];
432
+ this.items[parent] = temp;
433
+ this.percolate(parent);
434
+ }
435
+ };
438
436
 
439
- priorityProto.heapify = function (index) {
440
- if (index === undefined) {
441
- index = 0;
442
- }
443
- if (index >= this.length || index < 0) {
444
- return;
445
- }
446
- var left = 2 * index + 1,
447
- right = 2 * index + 2,
448
- first = index;
449
- if (left < this.length && this.isHigherPriority(left, first)) {
450
- first = left;
451
- }
452
- if (right < this.length && this.isHigherPriority(right, first)) {
453
- first = right;
454
- }
455
- if (first !== index) {
456
- var temp = this.items[index];
457
- this.items[index] = this.items[first];
458
- this.items[first] = temp;
459
- this.heapify(first);
460
- }
461
- };
462
-
463
- priorityProto.peek = function () { return this.items[0].value; };
437
+ priorityProto.heapify = function (index) {
438
+ +index || (index = 0);
439
+ if (index >= this.length || index < 0) { return; }
440
+ var left = 2 * index + 1,
441
+ right = 2 * index + 2,
442
+ first = index;
443
+ if (left < this.length && this.isHigherPriority(left, first)) {
444
+ first = left;
445
+ }
446
+ if (right < this.length && this.isHigherPriority(right, first)) {
447
+ first = right;
448
+ }
449
+ if (first !== index) {
450
+ var temp = this.items[index];
451
+ this.items[index] = this.items[first];
452
+ this.items[first] = temp;
453
+ this.heapify(first);
454
+ }
455
+ };
456
+
457
+ priorityProto.peek = function () { return this.items[0].value; };
464
458
 
465
- priorityProto.removeAt = function (index) {
466
- this.items[index] = this.items[--this.length];
467
- delete this.items[this.length];
468
- this.heapify();
469
- };
459
+ priorityProto.removeAt = function (index) {
460
+ this.items[index] = this.items[--this.length];
461
+ delete this.items[this.length];
462
+ this.heapify();
463
+ };
470
464
 
471
- priorityProto.dequeue = function () {
472
- var result = this.peek();
473
- this.removeAt(0);
474
- return result;
475
- };
465
+ priorityProto.dequeue = function () {
466
+ var result = this.peek();
467
+ this.removeAt(0);
468
+ return result;
469
+ };
476
470
 
477
- priorityProto.enqueue = function (item) {
478
- var index = this.length++;
479
- this.items[index] = new IndexedItem(PriorityQueue.count++, item);
480
- this.percolate(index);
481
- };
471
+ priorityProto.enqueue = function (item) {
472
+ var index = this.length++;
473
+ this.items[index] = new IndexedItem(PriorityQueue.count++, item);
474
+ this.percolate(index);
475
+ };
482
476
 
483
- priorityProto.remove = function (item) {
484
- for (var i = 0; i < this.length; i++) {
485
- if (this.items[i].value === item) {
486
- this.removeAt(i);
487
- return true;
488
- }
489
- }
490
- return false;
491
- };
492
- PriorityQueue.count = 0;
477
+ priorityProto.remove = function (item) {
478
+ for (var i = 0; i < this.length; i++) {
479
+ if (this.items[i].value === item) {
480
+ this.removeAt(i);
481
+ return true;
482
+ }
483
+ }
484
+ return false;
485
+ };
486
+ PriorityQueue.count = 0;
493
487
  /**
494
488
  * Represents a group of disposable resources that are disposed together.
495
489
  * @constructor
@@ -558,39 +552,38 @@
558
552
  return this.disposables.slice(0);
559
553
  };
560
554
 
561
- /**
562
- * Provides a set of static methods for creating Disposables.
563
- *
564
- * @constructor
565
- * @param {Function} dispose Action to run during the first call to dispose. The action is guaranteed to be run at most once.
566
- */
567
- var Disposable = Rx.Disposable = function (action) {
568
- this.isDisposed = false;
569
- this.action = action || noop;
570
- };
555
+ /**
556
+ * Provides a set of static methods for creating Disposables.
557
+ *
558
+ * @constructor
559
+ * @param {Function} dispose Action to run during the first call to dispose. The action is guaranteed to be run at most once.
560
+ */
561
+ var Disposable = Rx.Disposable = function (action) {
562
+ this.isDisposed = false;
563
+ this.action = action || noop;
564
+ };
571
565
 
572
- /** Performs the task of cleaning up resources. */
573
- Disposable.prototype.dispose = function () {
574
- if (!this.isDisposed) {
575
- this.action();
576
- this.isDisposed = true;
577
- }
578
- };
566
+ /** Performs the task of cleaning up resources. */
567
+ Disposable.prototype.dispose = function () {
568
+ if (!this.isDisposed) {
569
+ this.action();
570
+ this.isDisposed = true;
571
+ }
572
+ };
579
573
 
580
- /**
581
- * Creates a disposable object that invokes the specified action when disposed.
582
- * @param {Function} dispose Action to run during the first call to dispose. The action is guaranteed to be run at most once.
583
- * @return {Disposable} The disposable object that runs the given action upon disposal.
584
- */
585
- var disposableCreate = Disposable.create = function (action) { return new Disposable(action); };
574
+ /**
575
+ * Creates a disposable object that invokes the specified action when disposed.
576
+ * @param {Function} dispose Action to run during the first call to dispose. The action is guaranteed to be run at most once.
577
+ * @return {Disposable} The disposable object that runs the given action upon disposal.
578
+ */
579
+ var disposableCreate = Disposable.create = function (action) { return new Disposable(action); };
586
580
 
587
- /**
588
- * Gets the disposable that does nothing when disposed.
589
- */
590
- var disposableEmpty = Disposable.empty = { dispose: noop };
581
+ /**
582
+ * Gets the disposable that does nothing when disposed.
583
+ */
584
+ var disposableEmpty = Disposable.empty = { dispose: noop };
591
585
 
592
- var SingleAssignmentDisposable = Rx.SingleAssignmentDisposable =
593
- SerialDisposable = Rx.SerialDisposable = (function () {
586
+ var SingleAssignmentDisposable = Rx.SingleAssignmentDisposable = (function () {
594
587
  function BooleanDisposable () {
595
588
  this.isDisposed = false;
596
589
  this.current = null;
@@ -635,6 +628,7 @@
635
628
 
636
629
  return BooleanDisposable;
637
630
  }());
631
+ var SerialDisposable = Rx.SerialDisposable = SingleAssignmentDisposable;
638
632
  /**
639
633
  * Represents a disposable resource that only disposes its underlying disposable resource when all dependent disposable objects have been disposed.
640
634
  */
@@ -1003,6 +997,7 @@
1003
997
  }(Scheduler.prototype));
1004
998
 
1005
999
  (function (schedulerProto) {
1000
+
1006
1001
  /**
1007
1002
  * 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.
1008
1003
  * @param {Number} period Period for running the work periodically.
@@ -1020,17 +1015,19 @@
1020
1015
  * @param {Function} action Action to be executed, potentially updating the state.
1021
1016
  * @returns {Disposable} The disposable object used to cancel the scheduled recurring action (best effort).
1022
1017
  */
1023
- Scheduler.prototype.schedulePeriodicWithState = function (state, period, action) {
1018
+ Scheduler.prototype.schedulePeriodicWithState = function(state, period, action) {
1019
+ if (typeof root.setInterval === 'undefined') { throw new Error('Periodic scheduling not supported.'); }
1024
1020
  var s = state;
1025
-
1026
- var id = setInterval(function () {
1021
+
1022
+ var id = root.setInterval(function () {
1027
1023
  s = action(s);
1028
1024
  }, period);
1029
1025
 
1030
1026
  return disposableCreate(function () {
1031
- clearInterval(id);
1027
+ root.clearInterval(id);
1032
1028
  });
1033
1029
  };
1030
+
1034
1031
  }(Scheduler.prototype));
1035
1032
 
1036
1033
  (function (schedulerProto) {
@@ -1152,100 +1149,121 @@
1152
1149
  return currentScheduler;
1153
1150
  }());
1154
1151
 
1155
-
1156
1152
  var scheduleMethod, clearMethod = noop;
1157
- (function () {
1153
+ var localTimer = (function () {
1154
+ var localSetTimeout, localClearTimeout = noop;
1155
+ if ('WScript' in this) {
1156
+ localSetTimeout = function (fn, time) {
1157
+ WScript.Sleep(time);
1158
+ fn();
1159
+ };
1160
+ } else if (!!root.setTimeout) {
1161
+ localSetTimeout = root.setTimeout;
1162
+ localClearTimeout = root.clearTimeout;
1163
+ } else {
1164
+ throw new Error('No concurrency detected!');
1165
+ }
1158
1166
 
1159
- var reNative = RegExp('^' +
1160
- String(toString)
1161
- .replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
1162
- .replace(/toString| for [^\]]+/g, '.*?') + '$'
1163
- );
1167
+ return {
1168
+ setTimeout: localSetTimeout,
1169
+ clearTimeout: localClearTimeout
1170
+ };
1171
+ }());
1172
+ var localSetTimeout = localTimer.setTimeout,
1173
+ localClearTimeout = localTimer.clearTimeout;
1174
+
1175
+ (function () {
1176
+
1177
+ var reNative = RegExp('^' +
1178
+ String(toString)
1179
+ .replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
1180
+ .replace(/toString| for [^\]]+/g, '.*?') + '$'
1181
+ );
1182
+
1183
+ var setImmediate = typeof (setImmediate = freeGlobal && moduleExports && freeGlobal.setImmediate) == 'function' &&
1184
+ !reNative.test(setImmediate) && setImmediate,
1185
+ clearImmediate = typeof (clearImmediate = freeGlobal && moduleExports && freeGlobal.clearImmediate) == 'function' &&
1186
+ !reNative.test(clearImmediate) && clearImmediate;
1187
+
1188
+ function postMessageSupported () {
1189
+ // Ensure not in a worker
1190
+ if (!root.postMessage || root.importScripts) { return false; }
1191
+ var isAsync = false,
1192
+ oldHandler = root.onmessage;
1193
+ // Test for async
1194
+ root.onmessage = function () { isAsync = true; };
1195
+ root.postMessage('','*');
1196
+ root.onmessage = oldHandler;
1197
+
1198
+ return isAsync;
1199
+ }
1164
1200
 
1165
- var setImmediate = typeof (setImmediate = freeGlobal && moduleExports && freeGlobal.setImmediate) == 'function' &&
1166
- !reNative.test(setImmediate) && setImmediate,
1167
- clearImmediate = typeof (clearImmediate = freeGlobal && moduleExports && freeGlobal.clearImmediate) == 'function' &&
1168
- !reNative.test(clearImmediate) && clearImmediate;
1169
-
1170
- function postMessageSupported () {
1171
- // Ensure not in a worker
1172
- if (!root.postMessage || root.importScripts) { return false; }
1173
- var isAsync = false,
1174
- oldHandler = root.onmessage;
1175
- // Test for async
1176
- root.onmessage = function () { isAsync = true; };
1177
- root.postMessage('','*');
1178
- root.onmessage = oldHandler;
1179
-
1180
- return isAsync;
1201
+ // Use in order, nextTick, setImmediate, postMessage, MessageChannel, script readystatechanged, setTimeout
1202
+ if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
1203
+ scheduleMethod = process.nextTick;
1204
+ } else if (typeof setImmediate === 'function') {
1205
+ scheduleMethod = setImmediate;
1206
+ clearMethod = clearImmediate;
1207
+ } else if (postMessageSupported()) {
1208
+ var MSG_PREFIX = 'ms.rx.schedule' + Math.random(),
1209
+ tasks = {},
1210
+ taskId = 0;
1211
+
1212
+ function onGlobalPostMessage(event) {
1213
+ // Only if we're a match to avoid any other global events
1214
+ if (typeof event.data === 'string' && event.data.substring(0, MSG_PREFIX.length) === MSG_PREFIX) {
1215
+ var handleId = event.data.substring(MSG_PREFIX.length),
1216
+ action = tasks[handleId];
1217
+ action();
1218
+ delete tasks[handleId];
1219
+ }
1181
1220
  }
1182
1221
 
1183
- // Use in order, nextTick, setImmediate, postMessage, MessageChannel, script readystatechanged, setTimeout
1184
- if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
1185
- scheduleMethod = process.nextTick;
1186
- } else if (typeof setImmediate === 'function') {
1187
- scheduleMethod = setImmediate;
1188
- clearMethod = clearImmediate;
1189
- } else if (postMessageSupported()) {
1190
- var MSG_PREFIX = 'ms.rx.schedule' + Math.random(),
1191
- tasks = {},
1192
- taskId = 0;
1193
-
1194
- function onGlobalPostMessage(event) {
1195
- // Only if we're a match to avoid any other global events
1196
- if (typeof event.data === 'string' && event.data.substring(0, MSG_PREFIX.length) === MSG_PREFIX) {
1197
- var handleId = event.data.substring(MSG_PREFIX.length),
1198
- action = tasks[handleId];
1199
- action();
1200
- delete tasks[handleId];
1201
- }
1202
- }
1222
+ if (root.addEventListener) {
1223
+ root.addEventListener('message', onGlobalPostMessage, false);
1224
+ } else {
1225
+ root.attachEvent('onmessage', onGlobalPostMessage, false);
1226
+ }
1203
1227
 
1204
- if (root.addEventListener) {
1205
- root.addEventListener('message', onGlobalPostMessage, false);
1206
- } else {
1207
- root.attachEvent('onmessage', onGlobalPostMessage, false);
1208
- }
1228
+ scheduleMethod = function (action) {
1229
+ var currentId = taskId++;
1230
+ tasks[currentId] = action;
1231
+ root.postMessage(MSG_PREFIX + currentId, '*');
1232
+ };
1233
+ } else if (!!root.MessageChannel) {
1234
+ var channel = new root.MessageChannel(),
1235
+ channelTasks = {},
1236
+ channelTaskId = 0;
1237
+
1238
+ channel.port1.onmessage = function (event) {
1239
+ var id = event.data,
1240
+ action = channelTasks[id];
1241
+ action();
1242
+ delete channelTasks[id];
1243
+ };
1209
1244
 
1210
- scheduleMethod = function (action) {
1211
- var currentId = taskId++;
1212
- tasks[currentId] = action;
1213
- root.postMessage(MSG_PREFIX + currentId, '*');
1214
- };
1215
- } else if (!!root.MessageChannel) {
1216
- var channel = new root.MessageChannel(),
1217
- channelTasks = {},
1218
- channelTaskId = 0;
1219
-
1220
- channel.port1.onmessage = function (event) {
1221
- var id = event.data,
1222
- action = channelTasks[id];
1223
- action();
1224
- delete channelTasks[id];
1225
- };
1226
-
1227
- scheduleMethod = function (action) {
1228
- var id = channelTaskId++;
1229
- channelTasks[id] = action;
1230
- channel.port2.postMessage(id);
1231
- };
1232
- } else if ('document' in root && 'onreadystatechange' in root.document.createElement('script')) {
1233
-
1234
- scheduleMethod = function (action) {
1235
- var scriptElement = root.document.createElement('script');
1236
- scriptElement.onreadystatechange = function () {
1237
- action();
1238
- scriptElement.onreadystatechange = null;
1239
- scriptElement.parentNode.removeChild(scriptElement);
1240
- scriptElement = null;
1241
- };
1242
- root.document.documentElement.appendChild(scriptElement);
1245
+ scheduleMethod = function (action) {
1246
+ var id = channelTaskId++;
1247
+ channelTasks[id] = action;
1248
+ channel.port2.postMessage(id);
1249
+ };
1250
+ } else if ('document' in root && 'onreadystatechange' in root.document.createElement('script')) {
1251
+
1252
+ scheduleMethod = function (action) {
1253
+ var scriptElement = root.document.createElement('script');
1254
+ scriptElement.onreadystatechange = function () {
1255
+ action();
1256
+ scriptElement.onreadystatechange = null;
1257
+ scriptElement.parentNode.removeChild(scriptElement);
1258
+ scriptElement = null;
1243
1259
  };
1260
+ root.document.documentElement.appendChild(scriptElement);
1261
+ };
1244
1262
 
1245
- } else {
1246
- scheduleMethod = function (action) { return setTimeout(action, 0); };
1247
- clearMethod = clearTimeout;
1248
- }
1263
+ } else {
1264
+ scheduleMethod = function (action) { return localSetTimeout(action, 0); };
1265
+ clearMethod = localClearTimeout;
1266
+ }
1249
1267
  }());
1250
1268
 
1251
1269
  /**
@@ -1254,33 +1272,33 @@
1254
1272
  var timeoutScheduler = Scheduler.timeout = (function () {
1255
1273
 
1256
1274
  function scheduleNow(state, action) {
1257
- var scheduler = this,
1258
- disposable = new SingleAssignmentDisposable();
1259
- var id = scheduleMethod(function () {
1260
- if (!disposable.isDisposed) {
1261
- disposable.setDisposable(action(scheduler, state));
1262
- }
1263
- });
1264
- return new CompositeDisposable(disposable, disposableCreate(function () {
1265
- clearMethod(id);
1266
- }));
1275
+ var scheduler = this,
1276
+ disposable = new SingleAssignmentDisposable();
1277
+ var id = scheduleMethod(function () {
1278
+ if (!disposable.isDisposed) {
1279
+ disposable.setDisposable(action(scheduler, state));
1280
+ }
1281
+ });
1282
+ return new CompositeDisposable(disposable, disposableCreate(function () {
1283
+ clearMethod(id);
1284
+ }));
1267
1285
  }
1268
1286
 
1269
1287
  function scheduleRelative(state, dueTime, action) {
1270
- var scheduler = this,
1271
- dt = Scheduler.normalize(dueTime);
1272
- if (dt === 0) {
1273
- return scheduler.scheduleWithState(state, action);
1288
+ var scheduler = this,
1289
+ dt = Scheduler.normalize(dueTime);
1290
+ if (dt === 0) {
1291
+ return scheduler.scheduleWithState(state, action);
1292
+ }
1293
+ var disposable = new SingleAssignmentDisposable();
1294
+ var id = localSetTimeout(function () {
1295
+ if (!disposable.isDisposed) {
1296
+ disposable.setDisposable(action(scheduler, state));
1274
1297
  }
1275
- var disposable = new SingleAssignmentDisposable();
1276
- var id = setTimeout(function () {
1277
- if (!disposable.isDisposed) {
1278
- disposable.setDisposable(action(scheduler, state));
1279
- }
1280
- }, dt);
1281
- return new CompositeDisposable(disposable, disposableCreate(function () {
1282
- clearTimeout(id);
1283
- }));
1298
+ }, dt);
1299
+ return new CompositeDisposable(disposable, disposableCreate(function () {
1300
+ localClearTimeout(id);
1301
+ }));
1284
1302
  }
1285
1303
 
1286
1304
  function scheduleAbsolute(state, dueTime, action) {
@@ -1872,11 +1890,11 @@
1872
1890
  return CheckedObserver;
1873
1891
  }(Observer));
1874
1892
 
1875
- var ScheduledObserver = Rx.internals.ScheduledObserver = (function (_super) {
1876
- inherits(ScheduledObserver, _super);
1893
+ var ScheduledObserver = Rx.internals.ScheduledObserver = (function (__super__) {
1894
+ inherits(ScheduledObserver, __super__);
1877
1895
 
1878
1896
  function ScheduledObserver(scheduler, observer) {
1879
- _super.call(this);
1897
+ __super__.call(this);
1880
1898
  this.scheduler = scheduler;
1881
1899
  this.observer = observer;
1882
1900
  this.isAcquired = false;
@@ -1892,10 +1910,10 @@
1892
1910
  });
1893
1911
  };
1894
1912
 
1895
- ScheduledObserver.prototype.error = function (exception) {
1913
+ ScheduledObserver.prototype.error = function (err) {
1896
1914
  var self = this;
1897
1915
  this.queue.push(function () {
1898
- self.observer.onError(exception);
1916
+ self.observer.onError(err);
1899
1917
  });
1900
1918
  };
1901
1919
 
@@ -1934,42 +1952,37 @@
1934
1952
  };
1935
1953
 
1936
1954
  ScheduledObserver.prototype.dispose = function () {
1937
- _super.prototype.dispose.call(this);
1955
+ __super__.prototype.dispose.call(this);
1938
1956
  this.disposable.dispose();
1939
1957
  };
1940
1958
 
1941
1959
  return ScheduledObserver;
1942
1960
  }(AbstractObserver));
1943
1961
 
1944
- /** @private */
1945
- var ObserveOnObserver = (function (_super) {
1946
- inherits(ObserveOnObserver, _super);
1962
+ var ObserveOnObserver = (function (__super__) {
1963
+ inherits(ObserveOnObserver, __super__);
1947
1964
 
1948
- /** @private */
1949
- function ObserveOnObserver() {
1950
- _super.apply(this, arguments);
1951
- }
1965
+ function ObserveOnObserver() {
1966
+ __super__.apply(this, arguments);
1967
+ }
1952
1968
 
1953
- /** @private */
1954
- ObserveOnObserver.prototype.next = function (value) {
1955
- _super.prototype.next.call(this, value);
1956
- this.ensureActive();
1957
- };
1969
+ ObserveOnObserver.prototype.next = function (value) {
1970
+ __super__.prototype.next.call(this, value);
1971
+ this.ensureActive();
1972
+ };
1958
1973
 
1959
- /** @private */
1960
- ObserveOnObserver.prototype.error = function (e) {
1961
- _super.prototype.error.call(this, e);
1962
- this.ensureActive();
1963
- };
1974
+ ObserveOnObserver.prototype.error = function (e) {
1975
+ __super__.prototype.error.call(this, e);
1976
+ this.ensureActive();
1977
+ };
1964
1978
 
1965
- /** @private */
1966
- ObserveOnObserver.prototype.completed = function () {
1967
- _super.prototype.completed.call(this);
1968
- this.ensureActive();
1969
- };
1979
+ ObserveOnObserver.prototype.completed = function () {
1980
+ __super__.prototype.completed.call(this);
1981
+ this.ensureActive();
1982
+ };
1970
1983
 
1971
- return ObserveOnObserver;
1972
- })(ScheduledObserver);
1984
+ return ObserveOnObserver;
1985
+ })(ScheduledObserver);
1973
1986
 
1974
1987
  var observableProto;
1975
1988
 
@@ -2009,43 +2022,43 @@
2009
2022
  return Observable;
2010
2023
  })();
2011
2024
 
2012
- /**
2013
- * Wraps the source sequence in order to run its observer callbacks on the specified scheduler.
2014
- *
2015
- * This only invokes observer callbacks on a scheduler. In case the subscription and/or unsubscription actions have side-effects
2016
- * that require to be run on a scheduler, use subscribeOn.
2017
- *
2018
- * @param {Scheduler} scheduler Scheduler to notify observers on.
2019
- * @returns {Observable} The source sequence whose observations happen on the specified scheduler.
2020
- */
2021
- observableProto.observeOn = function (scheduler) {
2022
- var source = this;
2023
- return new AnonymousObservable(function (observer) {
2024
- return source.subscribe(new ObserveOnObserver(scheduler, observer));
2025
- });
2026
- };
2025
+ /**
2026
+ * Wraps the source sequence in order to run its observer callbacks on the specified scheduler.
2027
+ *
2028
+ * This only invokes observer callbacks on a scheduler. In case the subscription and/or unsubscription actions have side-effects
2029
+ * that require to be run on a scheduler, use subscribeOn.
2030
+ *
2031
+ * @param {Scheduler} scheduler Scheduler to notify observers on.
2032
+ * @returns {Observable} The source sequence whose observations happen on the specified scheduler.
2033
+ */
2034
+ observableProto.observeOn = function (scheduler) {
2035
+ var source = this;
2036
+ return new AnonymousObservable(function (observer) {
2037
+ return source.subscribe(new ObserveOnObserver(scheduler, observer));
2038
+ });
2039
+ };
2027
2040
 
2028
- /**
2029
- * Wraps the source sequence in order to run its subscription and unsubscription logic on the specified scheduler. This operation is not commonly used;
2030
- * see the remarks section for more information on the distinction between subscribeOn and observeOn.
2041
+ /**
2042
+ * Wraps the source sequence in order to run its subscription and unsubscription logic on the specified scheduler. This operation is not commonly used;
2043
+ * see the remarks section for more information on the distinction between subscribeOn and observeOn.
2031
2044
 
2032
- * This only performs the side-effects of subscription and unsubscription on the specified scheduler. In order to invoke observer
2033
- * callbacks on a scheduler, use observeOn.
2045
+ * This only performs the side-effects of subscription and unsubscription on the specified scheduler. In order to invoke observer
2046
+ * callbacks on a scheduler, use observeOn.
2034
2047
 
2035
- * @param {Scheduler} scheduler Scheduler to perform subscription and unsubscription actions on.
2036
- * @returns {Observable} The source sequence whose subscriptions and unsubscriptions happen on the specified scheduler.
2037
- */
2038
- observableProto.subscribeOn = function (scheduler) {
2039
- var source = this;
2040
- return new AnonymousObservable(function (observer) {
2041
- var m = new SingleAssignmentDisposable(), d = new SerialDisposable();
2042
- d.setDisposable(m);
2043
- m.setDisposable(scheduler.schedule(function () {
2044
- d.setDisposable(new ScheduledDisposable(scheduler, source.subscribe(observer)));
2045
- }));
2046
- return d;
2047
- });
2048
- };
2048
+ * @param {Scheduler} scheduler Scheduler to perform subscription and unsubscription actions on.
2049
+ * @returns {Observable} The source sequence whose subscriptions and unsubscriptions happen on the specified scheduler.
2050
+ */
2051
+ observableProto.subscribeOn = function (scheduler) {
2052
+ var source = this;
2053
+ return new AnonymousObservable(function (observer) {
2054
+ var m = new SingleAssignmentDisposable(), d = new SerialDisposable();
2055
+ d.setDisposable(m);
2056
+ m.setDisposable(scheduler.schedule(function () {
2057
+ d.setDisposable(new ScheduledDisposable(scheduler, source.subscribe(observer)));
2058
+ }));
2059
+ return d;
2060
+ });
2061
+ };
2049
2062
 
2050
2063
  /**
2051
2064
  * Converts a Promise to an Observable sequence
@@ -2068,38 +2081,32 @@
2068
2081
  return subject;
2069
2082
  });
2070
2083
  };
2071
- /*
2072
- * Converts an existing observable sequence to an ES6 Compatible Promise
2073
- * @example
2074
- * var promise = Rx.Observable.return(42).toPromise(RSVP.Promise);
2075
- *
2076
- * // With config
2077
- * Rx.config.Promise = RSVP.Promise;
2078
- * var promise = Rx.Observable.return(42).toPromise();
2079
- * @param {Function} [promiseCtor] The constructor of the promise. If not provided, it looks for it in Rx.config.Promise.
2080
- * @returns {Promise} An ES6 compatible promise with the last value from the observable sequence.
2081
- */
2082
- observableProto.toPromise = function (promiseCtor) {
2083
- promiseCtor || (promiseCtor = Rx.config.Promise);
2084
- if (!promiseCtor) {
2085
- throw new Error('Promise type not provided nor in Rx.config.Promise');
2086
- }
2087
- var source = this;
2088
- return new promiseCtor(function (resolve, reject) {
2089
- // No cancellation can be done
2090
- var value, hasValue = false;
2091
- source.subscribe(function (v) {
2092
- value = v;
2093
- hasValue = true;
2094
- }, function (err) {
2095
- reject(err);
2096
- }, function () {
2097
- if (hasValue) {
2098
- resolve(value);
2099
- }
2100
- });
2101
- });
2102
- };
2084
+ /*
2085
+ * Converts an existing observable sequence to an ES6 Compatible Promise
2086
+ * @example
2087
+ * var promise = Rx.Observable.return(42).toPromise(RSVP.Promise);
2088
+ *
2089
+ * // With config
2090
+ * Rx.config.Promise = RSVP.Promise;
2091
+ * var promise = Rx.Observable.return(42).toPromise();
2092
+ * @param {Function} [promiseCtor] The constructor of the promise. If not provided, it looks for it in Rx.config.Promise.
2093
+ * @returns {Promise} An ES6 compatible promise with the last value from the observable sequence.
2094
+ */
2095
+ observableProto.toPromise = function (promiseCtor) {
2096
+ promiseCtor || (promiseCtor = Rx.config.Promise);
2097
+ if (!promiseCtor) { throw new TypeError('Promise type not provided nor in Rx.config.Promise'); }
2098
+ var source = this;
2099
+ return new promiseCtor(function (resolve, reject) {
2100
+ // No cancellation can be done
2101
+ var value, hasValue = false;
2102
+ source.subscribe(function (v) {
2103
+ value = v;
2104
+ hasValue = true;
2105
+ }, reject, function () {
2106
+ hasValue && resolve(value);
2107
+ });
2108
+ });
2109
+ };
2103
2110
  /**
2104
2111
  * Creates a list from an observable sequence.
2105
2112
  * @returns An observable sequence containing a single element with a list containing all the elements of the source sequence.
@@ -2328,15 +2335,15 @@
2328
2335
  });
2329
2336
  };
2330
2337
 
2331
- /**
2332
- * Returns a non-terminating observable sequence, which can be used to denote an infinite duration (e.g. when using reactive joins).
2333
- * @returns {Observable} An observable sequence whose observers will never get called.
2334
- */
2335
- var observableNever = Observable.never = function () {
2336
- return new AnonymousObservable(function () {
2337
- return disposableEmpty;
2338
- });
2339
- };
2338
+ /**
2339
+ * Returns a non-terminating observable sequence, which can be used to denote an infinite duration (e.g. when using reactive joins).
2340
+ * @returns {Observable} An observable sequence whose observers will never get called.
2341
+ */
2342
+ var observableNever = Observable.never = function () {
2343
+ return new AnonymousObservable(function () {
2344
+ return disposableEmpty;
2345
+ });
2346
+ };
2340
2347
 
2341
2348
  /**
2342
2349
  * This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments.
@@ -2429,16 +2436,12 @@
2429
2436
 
2430
2437
  /**
2431
2438
  * Returns an observable sequence that terminates with an exception, using the specified scheduler to send out the single onError message.
2432
- * There is an alias to this method called 'throwException' for browsers <IE9.
2433
- *
2434
- * @example
2435
- * var res = Rx.Observable.throw(new Error('Error'));
2436
- * var res = Rx.Observable.throw(new Error('Error'), Rx.Scheduler.timeout);
2439
+ * There is an alias to this method called 'throwError' for browsers <IE9.
2437
2440
  * @param {Mixed} exception An object used for the sequence's termination.
2438
2441
  * @param {Scheduler} scheduler Scheduler to send the exceptional termination call on. If not specified, defaults to Scheduler.immediate.
2439
2442
  * @returns {Observable} The observable sequence that terminates exceptionally with the specified exception object.
2440
2443
  */
2441
- var observableThrow = Observable['throw'] = Observable.throwException = function (exception, scheduler) {
2444
+ var observableThrow = Observable['throw'] = Observable.throwException = Observable.throwError = function (exception, scheduler) {
2442
2445
  isScheduler(scheduler) || (scheduler = immediateScheduler);
2443
2446
  return new AnonymousObservable(function (observer) {
2444
2447
  return scheduler.schedule(function () {
@@ -2448,10 +2451,7 @@
2448
2451
  };
2449
2452
 
2450
2453
  /**
2451
- * Constructs an observable sequence that depends on a resource object, whose lifetime is tied to the resulting observable sequence's lifetime.
2452
- *
2453
- * @example
2454
- * var res = Rx.Observable.using(function () { return new AsyncSubject(); }, function (s) { return s; });
2454
+ * Constructs an observable sequence that depends on a resource object, whose lifetime is tied to the resulting observable sequence's lifetime.
2455
2455
  * @param {Function} resourceFactory Factory function to obtain a resource object.
2456
2456
  * @param {Function} observableFactory Factory function to obtain an observable sequence that depends on the obtained resource.
2457
2457
  * @returns {Observable} An observable sequence whose lifetime controls the lifetime of the dependent resource object.
@@ -2461,9 +2461,7 @@
2461
2461
  var disposable = disposableEmpty, resource, source;
2462
2462
  try {
2463
2463
  resource = resourceFactory();
2464
- if (resource) {
2465
- disposable = resource;
2466
- }
2464
+ resource && (disposable = resource);
2467
2465
  source = observableFactory(resource);
2468
2466
  } catch (exception) {
2469
2467
  return new CompositeDisposable(observableThrow(exception).subscribe(observer), disposable);
@@ -2820,20 +2818,16 @@
2820
2818
  var innerSubscription = new SingleAssignmentDisposable();
2821
2819
  group.add(innerSubscription);
2822
2820
 
2823
- // Check if Promise or Observable
2824
- if (isPromise(innerSource)) {
2825
- innerSource = observableFromPromise(innerSource);
2826
- }
2821
+ // Check for promises support
2822
+ isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
2827
2823
 
2828
- innerSubscription.setDisposable(innerSource.subscribe(function (x) {
2829
- observer.onNext(x);
2830
- }, observer.onError.bind(observer), function () {
2831
- group.remove(innerSubscription);
2832
- if (isStopped && group.length === 1) { observer.onCompleted(); }
2824
+ innerSubscription.setDisposable(innerSource.subscribe(observer.onNext.bind(observer), observer.onError.bind(observer), function () {
2825
+ group.remove(innerSubscription);
2826
+ isStopped && group.length === 1 && observer.onCompleted();
2833
2827
  }));
2834
2828
  }, observer.onError.bind(observer), function () {
2835
2829
  isStopped = true;
2836
- if (group.length === 1) { observer.onCompleted(); }
2830
+ group.length === 1 && observer.onCompleted();
2837
2831
  }));
2838
2832
  return group;
2839
2833
  });
@@ -2845,9 +2839,7 @@
2845
2839
  * @returns {Observable} An observable sequence that concatenates the first and second sequence, even if the first sequence terminates exceptionally.
2846
2840
  */
2847
2841
  observableProto.onErrorResumeNext = function (second) {
2848
- if (!second) {
2849
- throw new Error('Second observable is required');
2850
- }
2842
+ if (!second) { throw new Error('Second observable is required'); }
2851
2843
  return onErrorResumeNext([this, second]);
2852
2844
  };
2853
2845
 
@@ -2870,11 +2862,7 @@
2870
2862
  isPromise(current) && (current = observableFromPromise(current));
2871
2863
  d = new SingleAssignmentDisposable();
2872
2864
  subscription.setDisposable(d);
2873
- d.setDisposable(current.subscribe(observer.onNext.bind(observer), function () {
2874
- self();
2875
- }, function () {
2876
- self();
2877
- }));
2865
+ d.setDisposable(current.subscribe(observer.onNext.bind(observer), self, self));
2878
2866
  } else {
2879
2867
  observer.onCompleted();
2880
2868
  }
@@ -2913,52 +2901,44 @@
2913
2901
  });
2914
2902
  };
2915
2903
 
2916
- /**
2917
- * Transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.
2918
- * @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.
2919
- */
2920
- observableProto['switch'] = observableProto.switchLatest = function () {
2921
- var sources = this;
2922
- return new AnonymousObservable(function (observer) {
2923
- var hasLatest = false,
2924
- innerSubscription = new SerialDisposable(),
2925
- isStopped = false,
2926
- latest = 0,
2927
- subscription = sources.subscribe(function (innerSource) {
2928
- var d = new SingleAssignmentDisposable(), id = ++latest;
2929
- hasLatest = true;
2930
- innerSubscription.setDisposable(d);
2931
-
2932
- // Check if Promise or Observable
2933
- if (isPromise(innerSource)) {
2934
- innerSource = observableFromPromise(innerSource);
2935
- }
2904
+ /**
2905
+ * Transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.
2906
+ * @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.
2907
+ */
2908
+ observableProto['switch'] = observableProto.switchLatest = function () {
2909
+ var sources = this;
2910
+ return new AnonymousObservable(function (observer) {
2911
+ var hasLatest = false,
2912
+ innerSubscription = new SerialDisposable(),
2913
+ isStopped = false,
2914
+ latest = 0,
2915
+ subscription = sources.subscribe(
2916
+ function (innerSource) {
2917
+ var d = new SingleAssignmentDisposable(), id = ++latest;
2918
+ hasLatest = true;
2919
+ innerSubscription.setDisposable(d);
2920
+
2921
+ // Check if Promise or Observable
2922
+ isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
2936
2923
 
2937
- d.setDisposable(innerSource.subscribe(function (x) {
2938
- if (latest === id) {
2939
- observer.onNext(x);
2940
- }
2941
- }, function (e) {
2942
- if (latest === id) {
2943
- observer.onError(e);
2944
- }
2945
- }, function () {
2946
- if (latest === id) {
2947
- hasLatest = false;
2948
- if (isStopped) {
2949
- observer.onCompleted();
2950
- }
2951
- }
2952
- }));
2953
- }, observer.onError.bind(observer), function () {
2954
- isStopped = true;
2955
- if (!hasLatest) {
2956
- observer.onCompleted();
2957
- }
2958
- });
2959
- return new CompositeDisposable(subscription, innerSubscription);
2960
- });
2961
- };
2924
+ d.setDisposable(innerSource.subscribe(
2925
+ function (x) { latest === id && observer.onNext(x); },
2926
+ function (e) { latest === id && observer.onError(e); },
2927
+ function () {
2928
+ if (latest === id) {
2929
+ hasLatest = false;
2930
+ isStopped && observer.onCompleted();
2931
+ }
2932
+ }));
2933
+ },
2934
+ observer.onError.bind(observer),
2935
+ function () {
2936
+ isStopped = true;
2937
+ !hasLatest && observer.onCompleted();
2938
+ });
2939
+ return new CompositeDisposable(subscription, innerSubscription);
2940
+ });
2941
+ };
2962
2942
 
2963
2943
  /**
2964
2944
  * Returns the values from the source observable sequence until the other observable sequence produces a value.
@@ -3123,16 +3103,13 @@
3123
3103
  });
3124
3104
  };
3125
3105
 
3126
- /**
3127
- * Hides the identity of an observable sequence.
3128
- * @returns {Observable} An observable sequence that hides the identity of the source sequence.
3129
- */
3130
- observableProto.asObservable = function () {
3131
- var source = this;
3132
- return new AnonymousObservable(function (observer) {
3133
- return source.subscribe(observer);
3134
- });
3135
- };
3106
+ /**
3107
+ * Hides the identity of an observable sequence.
3108
+ * @returns {Observable} An observable sequence that hides the identity of the source sequence.
3109
+ */
3110
+ observableProto.asObservable = function () {
3111
+ return new AnonymousObservable(this.subscribe.bind(this));
3112
+ };
3136
3113
 
3137
3114
  /**
3138
3115
  * Projects each element of an observable sequence into zero or more buffers which are produced based on element count information.
@@ -3297,35 +3274,35 @@
3297
3274
  });
3298
3275
  };
3299
3276
 
3300
- /**
3301
- * Ignores all elements in an observable sequence leaving only the termination messages.
3302
- * @returns {Observable} An empty observable sequence that signals termination, successful or exceptional, of the source sequence.
3303
- */
3304
- observableProto.ignoreElements = function () {
3305
- var source = this;
3306
- return new AnonymousObservable(function (observer) {
3307
- return source.subscribe(noop, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3308
- });
3309
- };
3277
+ /**
3278
+ * Ignores all elements in an observable sequence leaving only the termination messages.
3279
+ * @returns {Observable} An empty observable sequence that signals termination, successful or exceptional, of the source sequence.
3280
+ */
3281
+ observableProto.ignoreElements = function () {
3282
+ var source = this;
3283
+ return new AnonymousObservable(function (observer) {
3284
+ return source.subscribe(noop, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3285
+ });
3286
+ };
3310
3287
 
3311
- /**
3312
- * Materializes the implicit notifications of an observable sequence as explicit notification values.
3313
- * @returns {Observable} An observable sequence containing the materialized notification values from the source sequence.
3314
- */
3315
- observableProto.materialize = function () {
3316
- var source = this;
3317
- return new AnonymousObservable(function (observer) {
3318
- return source.subscribe(function (value) {
3319
- observer.onNext(notificationCreateOnNext(value));
3320
- }, function (e) {
3321
- observer.onNext(notificationCreateOnError(e));
3322
- observer.onCompleted();
3323
- }, function () {
3324
- observer.onNext(notificationCreateOnCompleted());
3325
- observer.onCompleted();
3326
- });
3327
- });
3328
- };
3288
+ /**
3289
+ * Materializes the implicit notifications of an observable sequence as explicit notification values.
3290
+ * @returns {Observable} An observable sequence containing the materialized notification values from the source sequence.
3291
+ */
3292
+ observableProto.materialize = function () {
3293
+ var source = this;
3294
+ return new AnonymousObservable(function (observer) {
3295
+ return source.subscribe(function (value) {
3296
+ observer.onNext(notificationCreateOnNext(value));
3297
+ }, function (e) {
3298
+ observer.onNext(notificationCreateOnError(e));
3299
+ observer.onCompleted();
3300
+ }, function () {
3301
+ observer.onNext(notificationCreateOnCompleted());
3302
+ observer.onCompleted();
3303
+ });
3304
+ });
3305
+ };
3329
3306
 
3330
3307
  /**
3331
3308
  * Repeats the observable sequence a specified number of times. If the repeat count is not specified, the sequence repeats indefinitely.
@@ -3354,106 +3331,94 @@
3354
3331
  return enumerableRepeat(this, retryCount).catchException();
3355
3332
  };
3356
3333
 
3357
- /**
3358
- * Applies an accumulator function over an observable sequence and returns each intermediate result. The optional seed value is used as the initial accumulator value.
3359
- * For aggregation behavior with no intermediate results, see Observable.aggregate.
3360
- * @example
3361
- * var res = source.scan(function (acc, x) { return acc + x; });
3362
- * var res = source.scan(0, function (acc, x) { return acc + x; });
3363
- * @param {Mixed} [seed] The initial accumulator value.
3364
- * @param {Function} accumulator An accumulator function to be invoked on each element.
3365
- * @returns {Observable} An observable sequence containing the accumulated values.
3366
- */
3367
- observableProto.scan = function () {
3368
- var hasSeed = false, seed, accumulator, source = this;
3369
- if (arguments.length === 2) {
3370
- hasSeed = true;
3371
- seed = arguments[0];
3372
- accumulator = arguments[1];
3373
- } else {
3374
- accumulator = arguments[0];
3334
+ /**
3335
+ * Applies an accumulator function over an observable sequence and returns each intermediate result. The optional seed value is used as the initial accumulator value.
3336
+ * For aggregation behavior with no intermediate results, see Observable.aggregate.
3337
+ * @example
3338
+ * var res = source.scan(function (acc, x) { return acc + x; });
3339
+ * var res = source.scan(0, function (acc, x) { return acc + x; });
3340
+ * @param {Mixed} [seed] The initial accumulator value.
3341
+ * @param {Function} accumulator An accumulator function to be invoked on each element.
3342
+ * @returns {Observable} An observable sequence containing the accumulated values.
3343
+ */
3344
+ observableProto.scan = function () {
3345
+ var hasSeed = false, seed, accumulator, source = this;
3346
+ if (arguments.length === 2) {
3347
+ hasSeed = true;
3348
+ seed = arguments[0];
3349
+ accumulator = arguments[1];
3350
+ } else {
3351
+ accumulator = arguments[0];
3352
+ }
3353
+ return new AnonymousObservable(function (observer) {
3354
+ var hasAccumulation, accumulation, hasValue;
3355
+ return source.subscribe (
3356
+ function (x) {
3357
+ !hasValue && (hasValue = true);
3358
+ try {
3359
+ if (hasAccumulation) {
3360
+ accumulation = accumulator(accumulation, x);
3361
+ } else {
3362
+ accumulation = hasSeed ? accumulator(seed, x) : x;
3363
+ hasAccumulation = true;
3364
+ }
3365
+ } catch (e) {
3366
+ observer.onError(e);
3367
+ return;
3368
+ }
3369
+
3370
+ observer.onNext(accumulation);
3371
+ },
3372
+ observer.onError.bind(observer),
3373
+ function () {
3374
+ !hasValue && hasSeed && observer.onNext(seed);
3375
+ observer.onCompleted();
3375
3376
  }
3376
- return new AnonymousObservable(function (observer) {
3377
- var hasAccumulation, accumulation, hasValue;
3378
- return source.subscribe (
3379
- function (x) {
3380
- try {
3381
- if (!hasValue) {
3382
- hasValue = true;
3383
- }
3384
-
3385
- if (hasAccumulation) {
3386
- accumulation = accumulator(accumulation, x);
3387
- } else {
3388
- accumulation = hasSeed ? accumulator(seed, x) : x;
3389
- hasAccumulation = true;
3390
- }
3391
- } catch (e) {
3392
- observer.onError(e);
3393
- return;
3394
- }
3395
-
3396
- observer.onNext(accumulation);
3397
- },
3398
- observer.onError.bind(observer),
3399
- function () {
3400
- if (!hasValue && hasSeed) {
3401
- observer.onNext(seed);
3402
- }
3403
- observer.onCompleted();
3404
- }
3405
- );
3406
- });
3407
- };
3377
+ );
3378
+ });
3379
+ };
3408
3380
 
3409
- /**
3410
- * Bypasses a specified number of elements at the end of an observable sequence.
3411
- * @description
3412
- * This operator accumulates a queue with a length enough to store the first `count` elements. As more elements are
3413
- * received, elements are taken from the front of the queue and produced on the result sequence. This causes elements to be delayed.
3414
- * @param count Number of elements to bypass at the end of the source sequence.
3415
- * @returns {Observable} An observable sequence containing the source sequence elements except for the bypassed ones at the end.
3416
- */
3417
- observableProto.skipLast = function (count) {
3418
- var source = this;
3419
- return new AnonymousObservable(function (observer) {
3420
- var q = [];
3421
- return source.subscribe(function (x) {
3422
- q.push(x);
3423
- if (q.length > count) {
3424
- observer.onNext(q.shift());
3425
- }
3426
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3427
- });
3428
- };
3381
+ /**
3382
+ * Bypasses a specified number of elements at the end of an observable sequence.
3383
+ * @description
3384
+ * This operator accumulates a queue with a length enough to store the first `count` elements. As more elements are
3385
+ * received, elements are taken from the front of the queue and produced on the result sequence. This causes elements to be delayed.
3386
+ * @param count Number of elements to bypass at the end of the source sequence.
3387
+ * @returns {Observable} An observable sequence containing the source sequence elements except for the bypassed ones at the end.
3388
+ */
3389
+ observableProto.skipLast = function (count) {
3390
+ var source = this;
3391
+ return new AnonymousObservable(function (observer) {
3392
+ var q = [];
3393
+ return source.subscribe(function (x) {
3394
+ q.push(x);
3395
+ q.length > count && observer.onNext(q.shift());
3396
+ }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3397
+ });
3398
+ };
3429
3399
 
3430
- /**
3431
- * Prepends a sequence of values to an observable sequence with an optional scheduler and an argument list of values to prepend.
3432
- *
3433
- * var res = source.startWith(1, 2, 3);
3434
- * var res = source.startWith(Rx.Scheduler.timeout, 1, 2, 3);
3435
- *
3436
- * @memberOf Observable#
3437
- * @returns {Observable} The source sequence prepended with the specified values.
3438
- */
3439
- observableProto.startWith = function () {
3440
- var values, scheduler, start = 0;
3441
- if (!!arguments.length && 'now' in Object(arguments[0])) {
3442
- scheduler = arguments[0];
3443
- start = 1;
3444
- } else {
3445
- scheduler = immediateScheduler;
3446
- }
3447
- values = slice.call(arguments, start);
3448
- return enumerableFor([observableFromArray(values, scheduler), this]).concat();
3449
- };
3400
+ /**
3401
+ * Prepends a sequence of values to an observable sequence with an optional scheduler and an argument list of values to prepend.
3402
+ * @example
3403
+ * var res = source.startWith(1, 2, 3);
3404
+ * var res = source.startWith(Rx.Scheduler.timeout, 1, 2, 3);
3405
+ * @param {Arguments} args The specified values to prepend to the observable sequence
3406
+ * @returns {Observable} The source sequence prepended with the specified values.
3407
+ */
3408
+ observableProto.startWith = function () {
3409
+ var values, scheduler, start = 0;
3410
+ if (!!arguments.length && isScheduler(arguments[0])) {
3411
+ scheduler = arguments[0];
3412
+ start = 1;
3413
+ } else {
3414
+ scheduler = immediateScheduler;
3415
+ }
3416
+ values = slice.call(arguments, start);
3417
+ return enumerableFor([observableFromArray(values, scheduler), this]).concat();
3418
+ };
3450
3419
 
3451
3420
  /**
3452
3421
  * Returns a specified number of contiguous elements from the end of an observable sequence.
3453
- *
3454
- * @example
3455
- * var res = source.takeLast(5);
3456
- *
3457
3422
  * @description
3458
3423
  * This operator accumulates a buffer with a length enough to store elements count elements. Upon completion of
3459
3424
  * the source sequence, this buffer is drained on the result sequence. This causes the elements to be delayed.
@@ -3755,14 +3720,14 @@
3755
3720
  });
3756
3721
  };
3757
3722
 
3758
- /**
3759
- * Retrieves the value of a specified property from all elements in the Observable sequence.
3760
- * @param {String} property The property to pluck.
3761
- * @returns {Observable} Returns a new Observable sequence of property values.
3762
- */
3763
- observableProto.pluck = function (property) {
3764
- return this.select(function (x) { return x[property]; });
3765
- };
3723
+ /**
3724
+ * Retrieves the value of a specified property from all elements in the Observable sequence.
3725
+ * @param {String} prop The property to pluck.
3726
+ * @returns {Observable} Returns a new Observable sequence of property values.
3727
+ */
3728
+ observableProto.pluck = function (prop) {
3729
+ return this.map(function (x) { return x[prop]; });
3730
+ };
3766
3731
 
3767
3732
  /**
3768
3733
  * Projects each notification of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
@@ -3858,133 +3823,118 @@
3858
3823
  flatMap(this, function () { return selector; });
3859
3824
  };
3860
3825
 
3861
- /**
3862
- * Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then
3863
- * transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.
3864
- * @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.
3865
- * @param {Any} [thisArg] Object to use as this when executing callback.
3866
- * @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
3867
- * and that at any point in time produces the elements of the most recent inner observable sequence that has been received.
3868
- */
3869
- observableProto.selectSwitch = observableProto.flatMapLatest = observableProto.switchMap = function (selector, thisArg) {
3870
- return this.select(selector, thisArg).switchLatest();
3871
- };
3826
+ /**
3827
+ * Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then
3828
+ * transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.
3829
+ * @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.
3830
+ * @param {Any} [thisArg] Object to use as this when executing callback.
3831
+ * @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
3832
+ * and that at any point in time produces the elements of the most recent inner observable sequence that has been received.
3833
+ */
3834
+ observableProto.selectSwitch = observableProto.flatMapLatest = observableProto.switchMap = function (selector, thisArg) {
3835
+ return this.select(selector, thisArg).switchLatest();
3836
+ };
3872
3837
 
3873
- /**
3874
- * Bypasses a specified number of elements in an observable sequence and then returns the remaining elements.
3875
- * @param {Number} count The number of elements to skip before returning the remaining elements.
3876
- * @returns {Observable} An observable sequence that contains the elements that occur after the specified index in the input sequence.
3877
- */
3878
- observableProto.skip = function (count) {
3879
- if (count < 0) {
3880
- throw new Error(argumentOutOfRange);
3838
+ /**
3839
+ * Bypasses a specified number of elements in an observable sequence and then returns the remaining elements.
3840
+ * @param {Number} count The number of elements to skip before returning the remaining elements.
3841
+ * @returns {Observable} An observable sequence that contains the elements that occur after the specified index in the input sequence.
3842
+ */
3843
+ observableProto.skip = function (count) {
3844
+ if (count < 0) { throw new Error(argumentOutOfRange); }
3845
+ var source = this;
3846
+ return new AnonymousObservable(function (observer) {
3847
+ var remaining = count;
3848
+ return source.subscribe(function (x) {
3849
+ if (remaining <= 0) {
3850
+ observer.onNext(x);
3851
+ } else {
3852
+ remaining--;
3853
+ }
3854
+ }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3855
+ });
3856
+ };
3857
+
3858
+ /**
3859
+ * Bypasses elements in an observable sequence as long as a specified condition is true and then returns the remaining elements.
3860
+ * The element's index is used in the logic of the predicate function.
3861
+ *
3862
+ * var res = source.skipWhile(function (value) { return value < 10; });
3863
+ * var res = source.skipWhile(function (value, index) { return value < 10 || index < 10; });
3864
+ * @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.
3865
+ * @param {Any} [thisArg] Object to use as this when executing callback.
3866
+ * @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.
3867
+ */
3868
+ observableProto.skipWhile = function (predicate, thisArg) {
3869
+ var source = this;
3870
+ return new AnonymousObservable(function (observer) {
3871
+ var i = 0, running = false;
3872
+ return source.subscribe(function (x) {
3873
+ if (!running) {
3874
+ try {
3875
+ running = !predicate.call(thisArg, x, i++, source);
3876
+ } catch (e) {
3877
+ observer.onError(e);
3878
+ return;
3879
+ }
3881
3880
  }
3882
- var observable = this;
3883
- return new AnonymousObservable(function (observer) {
3884
- var remaining = count;
3885
- return observable.subscribe(function (x) {
3886
- if (remaining <= 0) {
3887
- observer.onNext(x);
3888
- } else {
3889
- remaining--;
3890
- }
3891
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3892
- });
3893
- };
3881
+ running && observer.onNext(x);
3882
+ }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3883
+ });
3884
+ };
3894
3885
 
3895
- /**
3896
- * Bypasses elements in an observable sequence as long as a specified condition is true and then returns the remaining elements.
3897
- * The element's index is used in the logic of the predicate function.
3898
- *
3899
- * var res = source.skipWhile(function (value) { return value < 10; });
3900
- * var res = source.skipWhile(function (value, index) { return value < 10 || index < 10; });
3901
- * @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.
3902
- * @param {Any} [thisArg] Object to use as this when executing callback.
3903
- * @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.
3904
- */
3905
- observableProto.skipWhile = function (predicate, thisArg) {
3906
- var source = this;
3907
- return new AnonymousObservable(function (observer) {
3908
- var i = 0, running = false;
3909
- return source.subscribe(function (x) {
3910
- if (!running) {
3911
- try {
3912
- running = !predicate.call(thisArg, x, i++, source);
3913
- } catch (e) {
3914
- observer.onError(e);
3915
- return;
3916
- }
3917
- }
3918
- if (running) {
3919
- observer.onNext(x);
3920
- }
3921
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3922
- });
3923
- };
3886
+ /**
3887
+ * 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).
3888
+ *
3889
+ * var res = source.take(5);
3890
+ * var res = source.take(0, Rx.Scheduler.timeout);
3891
+ * @param {Number} count The number of elements to return.
3892
+ * @param {Scheduler} [scheduler] Scheduler used to produce an OnCompleted message in case <paramref name="count count</paramref> is set to 0.
3893
+ * @returns {Observable} An observable sequence that contains the specified number of elements from the start of the input sequence.
3894
+ */
3895
+ observableProto.take = function (count, scheduler) {
3896
+ if (count < 0) { throw new RangeError(argumentOutOfRange); }
3897
+ if (count === 0) { return observableEmpty(scheduler); }
3898
+ var observable = this;
3899
+ return new AnonymousObservable(function (observer) {
3900
+ var remaining = count;
3901
+ return observable.subscribe(function (x) {
3902
+ if (remaining-- > 0) {
3903
+ observer.onNext(x);
3904
+ remaining === 0 && observer.onCompleted();
3905
+ }
3906
+ }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3907
+ });
3908
+ };
3924
3909
 
3925
- /**
3926
- * 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).
3927
- *
3928
- * var res = source.take(5);
3929
- * var res = source.take(0, Rx.Scheduler.timeout);
3930
- * @param {Number} count The number of elements to return.
3931
- * @param {Scheduler} [scheduler] Scheduler used to produce an OnCompleted message in case <paramref name="count count</paramref> is set to 0.
3932
- * @returns {Observable} An observable sequence that contains the specified number of elements from the start of the input sequence.
3933
- */
3934
- observableProto.take = function (count, scheduler) {
3935
- if (count < 0) {
3936
- throw new Error(argumentOutOfRange);
3937
- }
3938
- if (count === 0) {
3939
- return observableEmpty(scheduler);
3910
+ /**
3911
+ * Returns elements from an observable sequence as long as a specified condition is true.
3912
+ * The element's index is used in the logic of the predicate function.
3913
+ * @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.
3914
+ * @param {Any} [thisArg] Object to use as this when executing callback.
3915
+ * @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.
3916
+ */
3917
+ observableProto.takeWhile = function (predicate, thisArg) {
3918
+ var observable = this;
3919
+ return new AnonymousObservable(function (observer) {
3920
+ var i = 0, running = true;
3921
+ return observable.subscribe(function (x) {
3922
+ if (running) {
3923
+ try {
3924
+ running = predicate.call(thisArg, x, i++, observable);
3925
+ } catch (e) {
3926
+ observer.onError(e);
3927
+ return;
3928
+ }
3929
+ if (running) {
3930
+ observer.onNext(x);
3931
+ } else {
3932
+ observer.onCompleted();
3933
+ }
3940
3934
  }
3941
- var observable = this;
3942
- return new AnonymousObservable(function (observer) {
3943
- var remaining = count;
3944
- return observable.subscribe(function (x) {
3945
- if (remaining > 0) {
3946
- remaining--;
3947
- observer.onNext(x);
3948
- if (remaining === 0) {
3949
- observer.onCompleted();
3950
- }
3951
- }
3952
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3953
- });
3954
- };
3955
-
3956
- /**
3957
- * Returns elements from an observable sequence as long as a specified condition is true.
3958
- * The element's index is used in the logic of the predicate function.
3959
- *
3960
- * @example
3961
- * var res = source.takeWhile(function (value) { return value < 10; });
3962
- * var res = source.takeWhile(function (value, index) { return value < 10 || index < 10; });
3963
- * @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.
3964
- * @param {Any} [thisArg] Object to use as this when executing callback.
3965
- * @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.
3966
- */
3967
- observableProto.takeWhile = function (predicate, thisArg) {
3968
- var observable = this;
3969
- return new AnonymousObservable(function (observer) {
3970
- var i = 0, running = true;
3971
- return observable.subscribe(function (x) {
3972
- if (running) {
3973
- try {
3974
- running = predicate.call(thisArg, x, i++, observable);
3975
- } catch (e) {
3976
- observer.onError(e);
3977
- return;
3978
- }
3979
- if (running) {
3980
- observer.onNext(x);
3981
- } else {
3982
- observer.onCompleted();
3983
- }
3984
- }
3985
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3986
- });
3987
- };
3935
+ }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3936
+ });
3937
+ };
3988
3938
 
3989
3939
  /**
3990
3940
  * Filters the elements of an observable sequence based on a predicate by incorporating the element's index.