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
  */
@@ -987,6 +981,7 @@
987
981
  }(Scheduler.prototype));
988
982
 
989
983
  (function (schedulerProto) {
984
+
990
985
  /**
991
986
  * 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.
992
987
  * @param {Number} period Period for running the work periodically.
@@ -1004,17 +999,19 @@
1004
999
  * @param {Function} action Action to be executed, potentially updating the state.
1005
1000
  * @returns {Disposable} The disposable object used to cancel the scheduled recurring action (best effort).
1006
1001
  */
1007
- Scheduler.prototype.schedulePeriodicWithState = function (state, period, action) {
1002
+ Scheduler.prototype.schedulePeriodicWithState = function(state, period, action) {
1003
+ if (typeof root.setInterval === 'undefined') { throw new Error('Periodic scheduling not supported.'); }
1008
1004
  var s = state;
1009
-
1010
- var id = setInterval(function () {
1005
+
1006
+ var id = root.setInterval(function () {
1011
1007
  s = action(s);
1012
1008
  }, period);
1013
1009
 
1014
1010
  return disposableCreate(function () {
1015
- clearInterval(id);
1011
+ root.clearInterval(id);
1016
1012
  });
1017
1013
  };
1014
+
1018
1015
  }(Scheduler.prototype));
1019
1016
 
1020
1017
  /**
@@ -1125,100 +1122,121 @@
1125
1122
  return SchedulePeriodicRecursive;
1126
1123
  }());
1127
1124
 
1128
-
1129
1125
  var scheduleMethod, clearMethod = noop;
1130
- (function () {
1126
+ var localTimer = (function () {
1127
+ var localSetTimeout, localClearTimeout = noop;
1128
+ if ('WScript' in this) {
1129
+ localSetTimeout = function (fn, time) {
1130
+ WScript.Sleep(time);
1131
+ fn();
1132
+ };
1133
+ } else if (!!root.setTimeout) {
1134
+ localSetTimeout = root.setTimeout;
1135
+ localClearTimeout = root.clearTimeout;
1136
+ } else {
1137
+ throw new Error('No concurrency detected!');
1138
+ }
1131
1139
 
1132
- var reNative = RegExp('^' +
1133
- String(toString)
1134
- .replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
1135
- .replace(/toString| for [^\]]+/g, '.*?') + '$'
1136
- );
1140
+ return {
1141
+ setTimeout: localSetTimeout,
1142
+ clearTimeout: localClearTimeout
1143
+ };
1144
+ }());
1145
+ var localSetTimeout = localTimer.setTimeout,
1146
+ localClearTimeout = localTimer.clearTimeout;
1147
+
1148
+ (function () {
1149
+
1150
+ var reNative = RegExp('^' +
1151
+ String(toString)
1152
+ .replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
1153
+ .replace(/toString| for [^\]]+/g, '.*?') + '$'
1154
+ );
1155
+
1156
+ var setImmediate = typeof (setImmediate = freeGlobal && moduleExports && freeGlobal.setImmediate) == 'function' &&
1157
+ !reNative.test(setImmediate) && setImmediate,
1158
+ clearImmediate = typeof (clearImmediate = freeGlobal && moduleExports && freeGlobal.clearImmediate) == 'function' &&
1159
+ !reNative.test(clearImmediate) && clearImmediate;
1160
+
1161
+ function postMessageSupported () {
1162
+ // Ensure not in a worker
1163
+ if (!root.postMessage || root.importScripts) { return false; }
1164
+ var isAsync = false,
1165
+ oldHandler = root.onmessage;
1166
+ // Test for async
1167
+ root.onmessage = function () { isAsync = true; };
1168
+ root.postMessage('','*');
1169
+ root.onmessage = oldHandler;
1170
+
1171
+ return isAsync;
1172
+ }
1137
1173
 
1138
- var setImmediate = typeof (setImmediate = freeGlobal && moduleExports && freeGlobal.setImmediate) == 'function' &&
1139
- !reNative.test(setImmediate) && setImmediate,
1140
- clearImmediate = typeof (clearImmediate = freeGlobal && moduleExports && freeGlobal.clearImmediate) == 'function' &&
1141
- !reNative.test(clearImmediate) && clearImmediate;
1142
-
1143
- function postMessageSupported () {
1144
- // Ensure not in a worker
1145
- if (!root.postMessage || root.importScripts) { return false; }
1146
- var isAsync = false,
1147
- oldHandler = root.onmessage;
1148
- // Test for async
1149
- root.onmessage = function () { isAsync = true; };
1150
- root.postMessage('','*');
1151
- root.onmessage = oldHandler;
1152
-
1153
- return isAsync;
1174
+ // Use in order, nextTick, setImmediate, postMessage, MessageChannel, script readystatechanged, setTimeout
1175
+ if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
1176
+ scheduleMethod = process.nextTick;
1177
+ } else if (typeof setImmediate === 'function') {
1178
+ scheduleMethod = setImmediate;
1179
+ clearMethod = clearImmediate;
1180
+ } else if (postMessageSupported()) {
1181
+ var MSG_PREFIX = 'ms.rx.schedule' + Math.random(),
1182
+ tasks = {},
1183
+ taskId = 0;
1184
+
1185
+ function onGlobalPostMessage(event) {
1186
+ // Only if we're a match to avoid any other global events
1187
+ if (typeof event.data === 'string' && event.data.substring(0, MSG_PREFIX.length) === MSG_PREFIX) {
1188
+ var handleId = event.data.substring(MSG_PREFIX.length),
1189
+ action = tasks[handleId];
1190
+ action();
1191
+ delete tasks[handleId];
1192
+ }
1154
1193
  }
1155
1194
 
1156
- // Use in order, nextTick, setImmediate, postMessage, MessageChannel, script readystatechanged, setTimeout
1157
- if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
1158
- scheduleMethod = process.nextTick;
1159
- } else if (typeof setImmediate === 'function') {
1160
- scheduleMethod = setImmediate;
1161
- clearMethod = clearImmediate;
1162
- } else if (postMessageSupported()) {
1163
- var MSG_PREFIX = 'ms.rx.schedule' + Math.random(),
1164
- tasks = {},
1165
- taskId = 0;
1166
-
1167
- function onGlobalPostMessage(event) {
1168
- // Only if we're a match to avoid any other global events
1169
- if (typeof event.data === 'string' && event.data.substring(0, MSG_PREFIX.length) === MSG_PREFIX) {
1170
- var handleId = event.data.substring(MSG_PREFIX.length),
1171
- action = tasks[handleId];
1172
- action();
1173
- delete tasks[handleId];
1174
- }
1175
- }
1195
+ if (root.addEventListener) {
1196
+ root.addEventListener('message', onGlobalPostMessage, false);
1197
+ } else {
1198
+ root.attachEvent('onmessage', onGlobalPostMessage, false);
1199
+ }
1176
1200
 
1177
- if (root.addEventListener) {
1178
- root.addEventListener('message', onGlobalPostMessage, false);
1179
- } else {
1180
- root.attachEvent('onmessage', onGlobalPostMessage, false);
1181
- }
1201
+ scheduleMethod = function (action) {
1202
+ var currentId = taskId++;
1203
+ tasks[currentId] = action;
1204
+ root.postMessage(MSG_PREFIX + currentId, '*');
1205
+ };
1206
+ } else if (!!root.MessageChannel) {
1207
+ var channel = new root.MessageChannel(),
1208
+ channelTasks = {},
1209
+ channelTaskId = 0;
1210
+
1211
+ channel.port1.onmessage = function (event) {
1212
+ var id = event.data,
1213
+ action = channelTasks[id];
1214
+ action();
1215
+ delete channelTasks[id];
1216
+ };
1182
1217
 
1183
- scheduleMethod = function (action) {
1184
- var currentId = taskId++;
1185
- tasks[currentId] = action;
1186
- root.postMessage(MSG_PREFIX + currentId, '*');
1187
- };
1188
- } else if (!!root.MessageChannel) {
1189
- var channel = new root.MessageChannel(),
1190
- channelTasks = {},
1191
- channelTaskId = 0;
1192
-
1193
- channel.port1.onmessage = function (event) {
1194
- var id = event.data,
1195
- action = channelTasks[id];
1196
- action();
1197
- delete channelTasks[id];
1198
- };
1199
-
1200
- scheduleMethod = function (action) {
1201
- var id = channelTaskId++;
1202
- channelTasks[id] = action;
1203
- channel.port2.postMessage(id);
1204
- };
1205
- } else if ('document' in root && 'onreadystatechange' in root.document.createElement('script')) {
1206
-
1207
- scheduleMethod = function (action) {
1208
- var scriptElement = root.document.createElement('script');
1209
- scriptElement.onreadystatechange = function () {
1210
- action();
1211
- scriptElement.onreadystatechange = null;
1212
- scriptElement.parentNode.removeChild(scriptElement);
1213
- scriptElement = null;
1214
- };
1215
- root.document.documentElement.appendChild(scriptElement);
1218
+ scheduleMethod = function (action) {
1219
+ var id = channelTaskId++;
1220
+ channelTasks[id] = action;
1221
+ channel.port2.postMessage(id);
1222
+ };
1223
+ } else if ('document' in root && 'onreadystatechange' in root.document.createElement('script')) {
1224
+
1225
+ scheduleMethod = function (action) {
1226
+ var scriptElement = root.document.createElement('script');
1227
+ scriptElement.onreadystatechange = function () {
1228
+ action();
1229
+ scriptElement.onreadystatechange = null;
1230
+ scriptElement.parentNode.removeChild(scriptElement);
1231
+ scriptElement = null;
1216
1232
  };
1233
+ root.document.documentElement.appendChild(scriptElement);
1234
+ };
1217
1235
 
1218
- } else {
1219
- scheduleMethod = function (action) { return setTimeout(action, 0); };
1220
- clearMethod = clearTimeout;
1221
- }
1236
+ } else {
1237
+ scheduleMethod = function (action) { return localSetTimeout(action, 0); };
1238
+ clearMethod = localClearTimeout;
1239
+ }
1222
1240
  }());
1223
1241
 
1224
1242
  /**
@@ -1227,33 +1245,33 @@
1227
1245
  var timeoutScheduler = Scheduler.timeout = (function () {
1228
1246
 
1229
1247
  function scheduleNow(state, action) {
1230
- var scheduler = this,
1231
- disposable = new SingleAssignmentDisposable();
1232
- var id = scheduleMethod(function () {
1233
- if (!disposable.isDisposed) {
1234
- disposable.setDisposable(action(scheduler, state));
1235
- }
1236
- });
1237
- return new CompositeDisposable(disposable, disposableCreate(function () {
1238
- clearMethod(id);
1239
- }));
1248
+ var scheduler = this,
1249
+ disposable = new SingleAssignmentDisposable();
1250
+ var id = scheduleMethod(function () {
1251
+ if (!disposable.isDisposed) {
1252
+ disposable.setDisposable(action(scheduler, state));
1253
+ }
1254
+ });
1255
+ return new CompositeDisposable(disposable, disposableCreate(function () {
1256
+ clearMethod(id);
1257
+ }));
1240
1258
  }
1241
1259
 
1242
1260
  function scheduleRelative(state, dueTime, action) {
1243
- var scheduler = this,
1244
- dt = Scheduler.normalize(dueTime);
1245
- if (dt === 0) {
1246
- return scheduler.scheduleWithState(state, action);
1261
+ var scheduler = this,
1262
+ dt = Scheduler.normalize(dueTime);
1263
+ if (dt === 0) {
1264
+ return scheduler.scheduleWithState(state, action);
1265
+ }
1266
+ var disposable = new SingleAssignmentDisposable();
1267
+ var id = localSetTimeout(function () {
1268
+ if (!disposable.isDisposed) {
1269
+ disposable.setDisposable(action(scheduler, state));
1247
1270
  }
1248
- var disposable = new SingleAssignmentDisposable();
1249
- var id = setTimeout(function () {
1250
- if (!disposable.isDisposed) {
1251
- disposable.setDisposable(action(scheduler, state));
1252
- }
1253
- }, dt);
1254
- return new CompositeDisposable(disposable, disposableCreate(function () {
1255
- clearTimeout(id);
1256
- }));
1271
+ }, dt);
1272
+ return new CompositeDisposable(disposable, disposableCreate(function () {
1273
+ localClearTimeout(id);
1274
+ }));
1257
1275
  }
1258
1276
 
1259
1277
  function scheduleAbsolute(state, dueTime, action) {
@@ -1731,11 +1749,11 @@
1731
1749
  return Observable;
1732
1750
  })();
1733
1751
 
1734
- var ScheduledObserver = Rx.internals.ScheduledObserver = (function (_super) {
1735
- inherits(ScheduledObserver, _super);
1752
+ var ScheduledObserver = Rx.internals.ScheduledObserver = (function (__super__) {
1753
+ inherits(ScheduledObserver, __super__);
1736
1754
 
1737
1755
  function ScheduledObserver(scheduler, observer) {
1738
- _super.call(this);
1756
+ __super__.call(this);
1739
1757
  this.scheduler = scheduler;
1740
1758
  this.observer = observer;
1741
1759
  this.isAcquired = false;
@@ -1751,10 +1769,10 @@
1751
1769
  });
1752
1770
  };
1753
1771
 
1754
- ScheduledObserver.prototype.error = function (exception) {
1772
+ ScheduledObserver.prototype.error = function (err) {
1755
1773
  var self = this;
1756
1774
  this.queue.push(function () {
1757
- self.observer.onError(exception);
1775
+ self.observer.onError(err);
1758
1776
  });
1759
1777
  };
1760
1778
 
@@ -1793,7 +1811,7 @@
1793
1811
  };
1794
1812
 
1795
1813
  ScheduledObserver.prototype.dispose = function () {
1796
- _super.prototype.dispose.call(this);
1814
+ __super__.prototype.dispose.call(this);
1797
1815
  this.disposable.dispose();
1798
1816
  };
1799
1817
 
@@ -1985,15 +2003,15 @@
1985
2003
  });
1986
2004
  };
1987
2005
 
1988
- /**
1989
- * Returns a non-terminating observable sequence, which can be used to denote an infinite duration (e.g. when using reactive joins).
1990
- * @returns {Observable} An observable sequence whose observers will never get called.
1991
- */
1992
- var observableNever = Observable.never = function () {
1993
- return new AnonymousObservable(function () {
1994
- return disposableEmpty;
1995
- });
1996
- };
2006
+ /**
2007
+ * Returns a non-terminating observable sequence, which can be used to denote an infinite duration (e.g. when using reactive joins).
2008
+ * @returns {Observable} An observable sequence whose observers will never get called.
2009
+ */
2010
+ var observableNever = Observable.never = function () {
2011
+ return new AnonymousObservable(function () {
2012
+ return disposableEmpty;
2013
+ });
2014
+ };
1997
2015
 
1998
2016
  /**
1999
2017
  * This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments.
@@ -2086,16 +2104,12 @@
2086
2104
 
2087
2105
  /**
2088
2106
  * Returns an observable sequence that terminates with an exception, using the specified scheduler to send out the single onError message.
2089
- * There is an alias to this method called 'throwException' for browsers <IE9.
2090
- *
2091
- * @example
2092
- * var res = Rx.Observable.throw(new Error('Error'));
2093
- * var res = Rx.Observable.throw(new Error('Error'), Rx.Scheduler.timeout);
2107
+ * There is an alias to this method called 'throwError' for browsers <IE9.
2094
2108
  * @param {Mixed} exception An object used for the sequence's termination.
2095
2109
  * @param {Scheduler} scheduler Scheduler to send the exceptional termination call on. If not specified, defaults to Scheduler.immediate.
2096
2110
  * @returns {Observable} The observable sequence that terminates exceptionally with the specified exception object.
2097
2111
  */
2098
- var observableThrow = Observable['throw'] = Observable.throwException = function (exception, scheduler) {
2112
+ var observableThrow = Observable['throw'] = Observable.throwException = Observable.throwError = function (exception, scheduler) {
2099
2113
  isScheduler(scheduler) || (scheduler = immediateScheduler);
2100
2114
  return new AnonymousObservable(function (observer) {
2101
2115
  return scheduler.schedule(function () {
@@ -2366,20 +2380,16 @@
2366
2380
  var innerSubscription = new SingleAssignmentDisposable();
2367
2381
  group.add(innerSubscription);
2368
2382
 
2369
- // Check if Promise or Observable
2370
- if (isPromise(innerSource)) {
2371
- innerSource = observableFromPromise(innerSource);
2372
- }
2383
+ // Check for promises support
2384
+ isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
2373
2385
 
2374
- innerSubscription.setDisposable(innerSource.subscribe(function (x) {
2375
- observer.onNext(x);
2376
- }, observer.onError.bind(observer), function () {
2377
- group.remove(innerSubscription);
2378
- if (isStopped && group.length === 1) { observer.onCompleted(); }
2386
+ innerSubscription.setDisposable(innerSource.subscribe(observer.onNext.bind(observer), observer.onError.bind(observer), function () {
2387
+ group.remove(innerSubscription);
2388
+ isStopped && group.length === 1 && observer.onCompleted();
2379
2389
  }));
2380
2390
  }, observer.onError.bind(observer), function () {
2381
2391
  isStopped = true;
2382
- if (group.length === 1) { observer.onCompleted(); }
2392
+ group.length === 1 && observer.onCompleted();
2383
2393
  }));
2384
2394
  return group;
2385
2395
  });
@@ -2415,52 +2425,44 @@
2415
2425
  });
2416
2426
  };
2417
2427
 
2418
- /**
2419
- * Transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.
2420
- * @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.
2421
- */
2422
- observableProto['switch'] = observableProto.switchLatest = function () {
2423
- var sources = this;
2424
- return new AnonymousObservable(function (observer) {
2425
- var hasLatest = false,
2426
- innerSubscription = new SerialDisposable(),
2427
- isStopped = false,
2428
- latest = 0,
2429
- subscription = sources.subscribe(function (innerSource) {
2430
- var d = new SingleAssignmentDisposable(), id = ++latest;
2431
- hasLatest = true;
2432
- innerSubscription.setDisposable(d);
2433
-
2434
- // Check if Promise or Observable
2435
- if (isPromise(innerSource)) {
2436
- innerSource = observableFromPromise(innerSource);
2437
- }
2428
+ /**
2429
+ * Transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.
2430
+ * @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.
2431
+ */
2432
+ observableProto['switch'] = observableProto.switchLatest = function () {
2433
+ var sources = this;
2434
+ return new AnonymousObservable(function (observer) {
2435
+ var hasLatest = false,
2436
+ innerSubscription = new SerialDisposable(),
2437
+ isStopped = false,
2438
+ latest = 0,
2439
+ subscription = sources.subscribe(
2440
+ function (innerSource) {
2441
+ var d = new SingleAssignmentDisposable(), id = ++latest;
2442
+ hasLatest = true;
2443
+ innerSubscription.setDisposable(d);
2444
+
2445
+ // Check if Promise or Observable
2446
+ isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
2438
2447
 
2439
- d.setDisposable(innerSource.subscribe(function (x) {
2440
- if (latest === id) {
2441
- observer.onNext(x);
2442
- }
2443
- }, function (e) {
2444
- if (latest === id) {
2445
- observer.onError(e);
2446
- }
2447
- }, function () {
2448
- if (latest === id) {
2449
- hasLatest = false;
2450
- if (isStopped) {
2451
- observer.onCompleted();
2452
- }
2453
- }
2454
- }));
2455
- }, observer.onError.bind(observer), function () {
2456
- isStopped = true;
2457
- if (!hasLatest) {
2458
- observer.onCompleted();
2459
- }
2460
- });
2461
- return new CompositeDisposable(subscription, innerSubscription);
2462
- });
2463
- };
2448
+ d.setDisposable(innerSource.subscribe(
2449
+ function (x) { latest === id && observer.onNext(x); },
2450
+ function (e) { latest === id && observer.onError(e); },
2451
+ function () {
2452
+ if (latest === id) {
2453
+ hasLatest = false;
2454
+ isStopped && observer.onCompleted();
2455
+ }
2456
+ }));
2457
+ },
2458
+ observer.onError.bind(observer),
2459
+ function () {
2460
+ isStopped = true;
2461
+ !hasLatest && observer.onCompleted();
2462
+ });
2463
+ return new CompositeDisposable(subscription, innerSubscription);
2464
+ });
2465
+ };
2464
2466
 
2465
2467
  /**
2466
2468
  * Returns the values from the source observable sequence until the other observable sequence produces a value.
@@ -2625,16 +2627,13 @@
2625
2627
  });
2626
2628
  };
2627
2629
 
2628
- /**
2629
- * Hides the identity of an observable sequence.
2630
- * @returns {Observable} An observable sequence that hides the identity of the source sequence.
2631
- */
2632
- observableProto.asObservable = function () {
2633
- var source = this;
2634
- return new AnonymousObservable(function (observer) {
2635
- return source.subscribe(observer);
2636
- });
2637
- };
2630
+ /**
2631
+ * Hides the identity of an observable sequence.
2632
+ * @returns {Observable} An observable sequence that hides the identity of the source sequence.
2633
+ */
2634
+ observableProto.asObservable = function () {
2635
+ return new AnonymousObservable(this.subscribe.bind(this));
2636
+ };
2638
2637
 
2639
2638
  /**
2640
2639
  * Dematerializes the explicit notification values of an observable sequence as implicit notifications.
@@ -2778,35 +2777,35 @@
2778
2777
  });
2779
2778
  };
2780
2779
 
2781
- /**
2782
- * Ignores all elements in an observable sequence leaving only the termination messages.
2783
- * @returns {Observable} An empty observable sequence that signals termination, successful or exceptional, of the source sequence.
2784
- */
2785
- observableProto.ignoreElements = function () {
2786
- var source = this;
2787
- return new AnonymousObservable(function (observer) {
2788
- return source.subscribe(noop, observer.onError.bind(observer), observer.onCompleted.bind(observer));
2789
- });
2790
- };
2780
+ /**
2781
+ * Ignores all elements in an observable sequence leaving only the termination messages.
2782
+ * @returns {Observable} An empty observable sequence that signals termination, successful or exceptional, of the source sequence.
2783
+ */
2784
+ observableProto.ignoreElements = function () {
2785
+ var source = this;
2786
+ return new AnonymousObservable(function (observer) {
2787
+ return source.subscribe(noop, observer.onError.bind(observer), observer.onCompleted.bind(observer));
2788
+ });
2789
+ };
2791
2790
 
2792
- /**
2793
- * Materializes the implicit notifications of an observable sequence as explicit notification values.
2794
- * @returns {Observable} An observable sequence containing the materialized notification values from the source sequence.
2795
- */
2796
- observableProto.materialize = function () {
2797
- var source = this;
2798
- return new AnonymousObservable(function (observer) {
2799
- return source.subscribe(function (value) {
2800
- observer.onNext(notificationCreateOnNext(value));
2801
- }, function (e) {
2802
- observer.onNext(notificationCreateOnError(e));
2803
- observer.onCompleted();
2804
- }, function () {
2805
- observer.onNext(notificationCreateOnCompleted());
2806
- observer.onCompleted();
2807
- });
2808
- });
2809
- };
2791
+ /**
2792
+ * Materializes the implicit notifications of an observable sequence as explicit notification values.
2793
+ * @returns {Observable} An observable sequence containing the materialized notification values from the source sequence.
2794
+ */
2795
+ observableProto.materialize = function () {
2796
+ var source = this;
2797
+ return new AnonymousObservable(function (observer) {
2798
+ return source.subscribe(function (value) {
2799
+ observer.onNext(notificationCreateOnNext(value));
2800
+ }, function (e) {
2801
+ observer.onNext(notificationCreateOnError(e));
2802
+ observer.onCompleted();
2803
+ }, function () {
2804
+ observer.onNext(notificationCreateOnCompleted());
2805
+ observer.onCompleted();
2806
+ });
2807
+ });
2808
+ };
2810
2809
 
2811
2810
  /**
2812
2811
  * Repeats the observable sequence a specified number of times. If the repeat count is not specified, the sequence repeats indefinitely.
@@ -2835,112 +2834,100 @@
2835
2834
  return enumerableRepeat(this, retryCount).catchException();
2836
2835
  };
2837
2836
 
2838
- /**
2839
- * Applies an accumulator function over an observable sequence and returns each intermediate result. The optional seed value is used as the initial accumulator value.
2840
- * For aggregation behavior with no intermediate results, see Observable.aggregate.
2841
- * @example
2842
- * var res = source.scan(function (acc, x) { return acc + x; });
2843
- * var res = source.scan(0, function (acc, x) { return acc + x; });
2844
- * @param {Mixed} [seed] The initial accumulator value.
2845
- * @param {Function} accumulator An accumulator function to be invoked on each element.
2846
- * @returns {Observable} An observable sequence containing the accumulated values.
2847
- */
2848
- observableProto.scan = function () {
2849
- var hasSeed = false, seed, accumulator, source = this;
2850
- if (arguments.length === 2) {
2851
- hasSeed = true;
2852
- seed = arguments[0];
2853
- accumulator = arguments[1];
2854
- } else {
2855
- accumulator = arguments[0];
2856
- }
2857
- return new AnonymousObservable(function (observer) {
2858
- var hasAccumulation, accumulation, hasValue;
2859
- return source.subscribe (
2860
- function (x) {
2861
- try {
2862
- if (!hasValue) {
2863
- hasValue = true;
2864
- }
2865
-
2866
- if (hasAccumulation) {
2867
- accumulation = accumulator(accumulation, x);
2868
- } else {
2869
- accumulation = hasSeed ? accumulator(seed, x) : x;
2870
- hasAccumulation = true;
2871
- }
2872
- } catch (e) {
2873
- observer.onError(e);
2874
- return;
2875
- }
2876
-
2877
- observer.onNext(accumulation);
2878
- },
2879
- observer.onError.bind(observer),
2880
- function () {
2881
- if (!hasValue && hasSeed) {
2882
- observer.onNext(seed);
2883
- }
2884
- observer.onCompleted();
2885
- }
2886
- );
2887
- });
2888
- };
2889
-
2890
- /**
2891
- * Bypasses a specified number of elements at the end of an observable sequence.
2892
- * @description
2893
- * This operator accumulates a queue with a length enough to store the first `count` elements. As more elements are
2894
- * received, elements are taken from the front of the queue and produced on the result sequence. This causes elements to be delayed.
2895
- * @param count Number of elements to bypass at the end of the source sequence.
2896
- * @returns {Observable} An observable sequence containing the source sequence elements except for the bypassed ones at the end.
2897
- */
2898
- observableProto.skipLast = function (count) {
2899
- var source = this;
2900
- return new AnonymousObservable(function (observer) {
2901
- var q = [];
2902
- return source.subscribe(function (x) {
2903
- q.push(x);
2904
- if (q.length > count) {
2905
- observer.onNext(q.shift());
2906
- }
2907
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
2908
- });
2909
- };
2837
+ /**
2838
+ * Applies an accumulator function over an observable sequence and returns each intermediate result. The optional seed value is used as the initial accumulator value.
2839
+ * For aggregation behavior with no intermediate results, see Observable.aggregate.
2840
+ * @example
2841
+ * var res = source.scan(function (acc, x) { return acc + x; });
2842
+ * var res = source.scan(0, function (acc, x) { return acc + x; });
2843
+ * @param {Mixed} [seed] The initial accumulator value.
2844
+ * @param {Function} accumulator An accumulator function to be invoked on each element.
2845
+ * @returns {Observable} An observable sequence containing the accumulated values.
2846
+ */
2847
+ observableProto.scan = function () {
2848
+ var hasSeed = false, seed, accumulator, source = this;
2849
+ if (arguments.length === 2) {
2850
+ hasSeed = true;
2851
+ seed = arguments[0];
2852
+ accumulator = arguments[1];
2853
+ } else {
2854
+ accumulator = arguments[0];
2855
+ }
2856
+ return new AnonymousObservable(function (observer) {
2857
+ var hasAccumulation, accumulation, hasValue;
2858
+ return source.subscribe (
2859
+ function (x) {
2860
+ !hasValue && (hasValue = true);
2861
+ try {
2862
+ if (hasAccumulation) {
2863
+ accumulation = accumulator(accumulation, x);
2864
+ } else {
2865
+ accumulation = hasSeed ? accumulator(seed, x) : x;
2866
+ hasAccumulation = true;
2867
+ }
2868
+ } catch (e) {
2869
+ observer.onError(e);
2870
+ return;
2871
+ }
2910
2872
 
2911
- /**
2912
- * Prepends a sequence of values to an observable sequence with an optional scheduler and an argument list of values to prepend.
2913
- *
2914
- * var res = source.startWith(1, 2, 3);
2915
- * var res = source.startWith(Rx.Scheduler.timeout, 1, 2, 3);
2916
- *
2917
- * @memberOf Observable#
2918
- * @returns {Observable} The source sequence prepended with the specified values.
2919
- */
2920
- observableProto.startWith = function () {
2921
- var values, scheduler, start = 0;
2922
- if (!!arguments.length && 'now' in Object(arguments[0])) {
2923
- scheduler = arguments[0];
2924
- start = 1;
2925
- } else {
2926
- scheduler = immediateScheduler;
2873
+ observer.onNext(accumulation);
2874
+ },
2875
+ observer.onError.bind(observer),
2876
+ function () {
2877
+ !hasValue && hasSeed && observer.onNext(seed);
2878
+ observer.onCompleted();
2927
2879
  }
2928
- values = slice.call(arguments, start);
2929
- return enumerableFor([observableFromArray(values, scheduler), this]).concat();
2930
- };
2880
+ );
2881
+ });
2882
+ };
2931
2883
 
2932
2884
  /**
2933
- * Returns a specified number of contiguous elements from the end of an observable sequence.
2934
- *
2935
- * @example
2936
- * var res = source.takeLast(5);
2937
- *
2885
+ * Bypasses a specified number of elements at the end of an observable sequence.
2938
2886
  * @description
2939
- * This operator accumulates a buffer with a length enough to store elements count elements. Upon completion of
2940
- * the source sequence, this buffer is drained on the result sequence. This causes the elements to be delayed.
2941
- * @param {Number} count Number of elements to take from the end of the source sequence.
2942
- * @returns {Observable} An observable sequence containing the specified number of elements from the end of the source sequence.
2943
- */
2887
+ * This operator accumulates a queue with a length enough to store the first `count` elements. As more elements are
2888
+ * received, elements are taken from the front of the queue and produced on the result sequence. This causes elements to be delayed.
2889
+ * @param count Number of elements to bypass at the end of the source sequence.
2890
+ * @returns {Observable} An observable sequence containing the source sequence elements except for the bypassed ones at the end.
2891
+ */
2892
+ observableProto.skipLast = function (count) {
2893
+ var source = this;
2894
+ return new AnonymousObservable(function (observer) {
2895
+ var q = [];
2896
+ return source.subscribe(function (x) {
2897
+ q.push(x);
2898
+ q.length > count && observer.onNext(q.shift());
2899
+ }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
2900
+ });
2901
+ };
2902
+
2903
+ /**
2904
+ * Prepends a sequence of values to an observable sequence with an optional scheduler and an argument list of values to prepend.
2905
+ * @example
2906
+ * var res = source.startWith(1, 2, 3);
2907
+ * var res = source.startWith(Rx.Scheduler.timeout, 1, 2, 3);
2908
+ * @param {Arguments} args The specified values to prepend to the observable sequence
2909
+ * @returns {Observable} The source sequence prepended with the specified values.
2910
+ */
2911
+ observableProto.startWith = function () {
2912
+ var values, scheduler, start = 0;
2913
+ if (!!arguments.length && isScheduler(arguments[0])) {
2914
+ scheduler = arguments[0];
2915
+ start = 1;
2916
+ } else {
2917
+ scheduler = immediateScheduler;
2918
+ }
2919
+ values = slice.call(arguments, start);
2920
+ return enumerableFor([observableFromArray(values, scheduler), this]).concat();
2921
+ };
2922
+
2923
+ /**
2924
+ * Returns a specified number of contiguous elements from the end of an observable sequence.
2925
+ * @description
2926
+ * This operator accumulates a buffer with a length enough to store elements count elements. Upon completion of
2927
+ * the source sequence, this buffer is drained on the result sequence. This causes the elements to be delayed.
2928
+ * @param {Number} count Number of elements to take from the end of the source sequence.
2929
+ * @returns {Observable} An observable sequence containing the specified number of elements from the end of the source sequence.
2930
+ */
2944
2931
  observableProto.takeLast = function (count) {
2945
2932
  var source = this;
2946
2933
  return new AnonymousObservable(function (observer) {
@@ -3020,14 +3007,14 @@
3020
3007
  });
3021
3008
  };
3022
3009
 
3023
- /**
3024
- * Retrieves the value of a specified property from all elements in the Observable sequence.
3025
- * @param {String} property The property to pluck.
3026
- * @returns {Observable} Returns a new Observable sequence of property values.
3027
- */
3028
- observableProto.pluck = function (property) {
3029
- return this.select(function (x) { return x[property]; });
3030
- };
3010
+ /**
3011
+ * Retrieves the value of a specified property from all elements in the Observable sequence.
3012
+ * @param {String} prop The property to pluck.
3013
+ * @returns {Observable} Returns a new Observable sequence of property values.
3014
+ */
3015
+ observableProto.pluck = function (prop) {
3016
+ return this.map(function (x) { return x[prop]; });
3017
+ };
3031
3018
 
3032
3019
  function flatMap(source, selector, thisArg) {
3033
3020
  return source.map(function (x, i) {
@@ -3072,133 +3059,118 @@
3072
3059
  flatMap(this, function () { return selector; });
3073
3060
  };
3074
3061
 
3075
- /**
3076
- * Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then
3077
- * transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.
3078
- * @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.
3079
- * @param {Any} [thisArg] Object to use as this when executing callback.
3080
- * @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
3081
- * and that at any point in time produces the elements of the most recent inner observable sequence that has been received.
3082
- */
3083
- observableProto.selectSwitch = observableProto.flatMapLatest = observableProto.switchMap = function (selector, thisArg) {
3084
- return this.select(selector, thisArg).switchLatest();
3085
- };
3062
+ /**
3063
+ * Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then
3064
+ * transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.
3065
+ * @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.
3066
+ * @param {Any} [thisArg] Object to use as this when executing callback.
3067
+ * @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
3068
+ * and that at any point in time produces the elements of the most recent inner observable sequence that has been received.
3069
+ */
3070
+ observableProto.selectSwitch = observableProto.flatMapLatest = observableProto.switchMap = function (selector, thisArg) {
3071
+ return this.select(selector, thisArg).switchLatest();
3072
+ };
3086
3073
 
3087
- /**
3088
- * Bypasses a specified number of elements in an observable sequence and then returns the remaining elements.
3089
- * @param {Number} count The number of elements to skip before returning the remaining elements.
3090
- * @returns {Observable} An observable sequence that contains the elements that occur after the specified index in the input sequence.
3091
- */
3092
- observableProto.skip = function (count) {
3093
- if (count < 0) {
3094
- throw new Error(argumentOutOfRange);
3074
+ /**
3075
+ * Bypasses a specified number of elements in an observable sequence and then returns the remaining elements.
3076
+ * @param {Number} count The number of elements to skip before returning the remaining elements.
3077
+ * @returns {Observable} An observable sequence that contains the elements that occur after the specified index in the input sequence.
3078
+ */
3079
+ observableProto.skip = function (count) {
3080
+ if (count < 0) { throw new Error(argumentOutOfRange); }
3081
+ var source = this;
3082
+ return new AnonymousObservable(function (observer) {
3083
+ var remaining = count;
3084
+ return source.subscribe(function (x) {
3085
+ if (remaining <= 0) {
3086
+ observer.onNext(x);
3087
+ } else {
3088
+ remaining--;
3089
+ }
3090
+ }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3091
+ });
3092
+ };
3093
+
3094
+ /**
3095
+ * Bypasses elements in an observable sequence as long as a specified condition is true and then returns the remaining elements.
3096
+ * The element's index is used in the logic of the predicate function.
3097
+ *
3098
+ * var res = source.skipWhile(function (value) { return value < 10; });
3099
+ * var res = source.skipWhile(function (value, index) { return value < 10 || index < 10; });
3100
+ * @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.
3101
+ * @param {Any} [thisArg] Object to use as this when executing callback.
3102
+ * @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.
3103
+ */
3104
+ observableProto.skipWhile = function (predicate, thisArg) {
3105
+ var source = this;
3106
+ return new AnonymousObservable(function (observer) {
3107
+ var i = 0, running = false;
3108
+ return source.subscribe(function (x) {
3109
+ if (!running) {
3110
+ try {
3111
+ running = !predicate.call(thisArg, x, i++, source);
3112
+ } catch (e) {
3113
+ observer.onError(e);
3114
+ return;
3115
+ }
3095
3116
  }
3096
- var observable = this;
3097
- return new AnonymousObservable(function (observer) {
3098
- var remaining = count;
3099
- return observable.subscribe(function (x) {
3100
- if (remaining <= 0) {
3101
- observer.onNext(x);
3102
- } else {
3103
- remaining--;
3104
- }
3105
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3106
- });
3107
- };
3117
+ running && observer.onNext(x);
3118
+ }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3119
+ });
3120
+ };
3108
3121
 
3109
- /**
3110
- * Bypasses elements in an observable sequence as long as a specified condition is true and then returns the remaining elements.
3111
- * The element's index is used in the logic of the predicate function.
3112
- *
3113
- * var res = source.skipWhile(function (value) { return value < 10; });
3114
- * var res = source.skipWhile(function (value, index) { return value < 10 || index < 10; });
3115
- * @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.
3116
- * @param {Any} [thisArg] Object to use as this when executing callback.
3117
- * @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.
3118
- */
3119
- observableProto.skipWhile = function (predicate, thisArg) {
3120
- var source = this;
3121
- return new AnonymousObservable(function (observer) {
3122
- var i = 0, running = false;
3123
- return source.subscribe(function (x) {
3124
- if (!running) {
3125
- try {
3126
- running = !predicate.call(thisArg, x, i++, source);
3127
- } catch (e) {
3128
- observer.onError(e);
3129
- return;
3130
- }
3131
- }
3132
- if (running) {
3133
- observer.onNext(x);
3134
- }
3135
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3136
- });
3137
- };
3122
+ /**
3123
+ * 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).
3124
+ *
3125
+ * var res = source.take(5);
3126
+ * var res = source.take(0, Rx.Scheduler.timeout);
3127
+ * @param {Number} count The number of elements to return.
3128
+ * @param {Scheduler} [scheduler] Scheduler used to produce an OnCompleted message in case <paramref name="count count</paramref> is set to 0.
3129
+ * @returns {Observable} An observable sequence that contains the specified number of elements from the start of the input sequence.
3130
+ */
3131
+ observableProto.take = function (count, scheduler) {
3132
+ if (count < 0) { throw new RangeError(argumentOutOfRange); }
3133
+ if (count === 0) { return observableEmpty(scheduler); }
3134
+ var observable = this;
3135
+ return new AnonymousObservable(function (observer) {
3136
+ var remaining = count;
3137
+ return observable.subscribe(function (x) {
3138
+ if (remaining-- > 0) {
3139
+ observer.onNext(x);
3140
+ remaining === 0 && observer.onCompleted();
3141
+ }
3142
+ }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3143
+ });
3144
+ };
3138
3145
 
3139
- /**
3140
- * 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).
3141
- *
3142
- * var res = source.take(5);
3143
- * var res = source.take(0, Rx.Scheduler.timeout);
3144
- * @param {Number} count The number of elements to return.
3145
- * @param {Scheduler} [scheduler] Scheduler used to produce an OnCompleted message in case <paramref name="count count</paramref> is set to 0.
3146
- * @returns {Observable} An observable sequence that contains the specified number of elements from the start of the input sequence.
3147
- */
3148
- observableProto.take = function (count, scheduler) {
3149
- if (count < 0) {
3150
- throw new Error(argumentOutOfRange);
3151
- }
3152
- if (count === 0) {
3153
- return observableEmpty(scheduler);
3146
+ /**
3147
+ * Returns elements from an observable sequence as long as a specified condition is true.
3148
+ * The element's index is used in the logic of the predicate function.
3149
+ * @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.
3150
+ * @param {Any} [thisArg] Object to use as this when executing callback.
3151
+ * @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.
3152
+ */
3153
+ observableProto.takeWhile = function (predicate, thisArg) {
3154
+ var observable = this;
3155
+ return new AnonymousObservable(function (observer) {
3156
+ var i = 0, running = true;
3157
+ return observable.subscribe(function (x) {
3158
+ if (running) {
3159
+ try {
3160
+ running = predicate.call(thisArg, x, i++, observable);
3161
+ } catch (e) {
3162
+ observer.onError(e);
3163
+ return;
3164
+ }
3165
+ if (running) {
3166
+ observer.onNext(x);
3167
+ } else {
3168
+ observer.onCompleted();
3169
+ }
3154
3170
  }
3155
- var observable = this;
3156
- return new AnonymousObservable(function (observer) {
3157
- var remaining = count;
3158
- return observable.subscribe(function (x) {
3159
- if (remaining > 0) {
3160
- remaining--;
3161
- observer.onNext(x);
3162
- if (remaining === 0) {
3163
- observer.onCompleted();
3164
- }
3165
- }
3166
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3167
- });
3168
- };
3169
-
3170
- /**
3171
- * Returns elements from an observable sequence as long as a specified condition is true.
3172
- * The element's index is used in the logic of the predicate function.
3173
- *
3174
- * @example
3175
- * var res = source.takeWhile(function (value) { return value < 10; });
3176
- * var res = source.takeWhile(function (value, index) { return value < 10 || index < 10; });
3177
- * @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.
3178
- * @param {Any} [thisArg] Object to use as this when executing callback.
3179
- * @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.
3180
- */
3181
- observableProto.takeWhile = function (predicate, thisArg) {
3182
- var observable = this;
3183
- return new AnonymousObservable(function (observer) {
3184
- var i = 0, running = true;
3185
- return observable.subscribe(function (x) {
3186
- if (running) {
3187
- try {
3188
- running = predicate.call(thisArg, x, i++, observable);
3189
- } catch (e) {
3190
- observer.onError(e);
3191
- return;
3192
- }
3193
- if (running) {
3194
- observer.onNext(x);
3195
- } else {
3196
- observer.onCompleted();
3197
- }
3198
- }
3199
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3200
- });
3201
- };
3171
+ }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3172
+ });
3173
+ };
3202
3174
 
3203
3175
  /**
3204
3176
  * Filters the elements of an observable sequence based on a predicate by incorporating the element's index.
@@ -3474,38 +3446,32 @@
3474
3446
  return subject;
3475
3447
  });
3476
3448
  };
3477
- /*
3478
- * Converts an existing observable sequence to an ES6 Compatible Promise
3479
- * @example
3480
- * var promise = Rx.Observable.return(42).toPromise(RSVP.Promise);
3481
- *
3482
- * // With config
3483
- * Rx.config.Promise = RSVP.Promise;
3484
- * var promise = Rx.Observable.return(42).toPromise();
3485
- * @param {Function} [promiseCtor] The constructor of the promise. If not provided, it looks for it in Rx.config.Promise.
3486
- * @returns {Promise} An ES6 compatible promise with the last value from the observable sequence.
3487
- */
3488
- observableProto.toPromise = function (promiseCtor) {
3489
- promiseCtor || (promiseCtor = Rx.config.Promise);
3490
- if (!promiseCtor) {
3491
- throw new Error('Promise type not provided nor in Rx.config.Promise');
3492
- }
3493
- var source = this;
3494
- return new promiseCtor(function (resolve, reject) {
3495
- // No cancellation can be done
3496
- var value, hasValue = false;
3497
- source.subscribe(function (v) {
3498
- value = v;
3499
- hasValue = true;
3500
- }, function (err) {
3501
- reject(err);
3502
- }, function () {
3503
- if (hasValue) {
3504
- resolve(value);
3505
- }
3506
- });
3507
- });
3508
- };
3449
+ /*
3450
+ * Converts an existing observable sequence to an ES6 Compatible Promise
3451
+ * @example
3452
+ * var promise = Rx.Observable.return(42).toPromise(RSVP.Promise);
3453
+ *
3454
+ * // With config
3455
+ * Rx.config.Promise = RSVP.Promise;
3456
+ * var promise = Rx.Observable.return(42).toPromise();
3457
+ * @param {Function} [promiseCtor] The constructor of the promise. If not provided, it looks for it in Rx.config.Promise.
3458
+ * @returns {Promise} An ES6 compatible promise with the last value from the observable sequence.
3459
+ */
3460
+ observableProto.toPromise = function (promiseCtor) {
3461
+ promiseCtor || (promiseCtor = Rx.config.Promise);
3462
+ if (!promiseCtor) { throw new TypeError('Promise type not provided nor in Rx.config.Promise'); }
3463
+ var source = this;
3464
+ return new promiseCtor(function (resolve, reject) {
3465
+ // No cancellation can be done
3466
+ var value, hasValue = false;
3467
+ source.subscribe(function (v) {
3468
+ value = v;
3469
+ hasValue = true;
3470
+ }, reject, function () {
3471
+ hasValue && resolve(value);
3472
+ });
3473
+ });
3474
+ };
3509
3475
  /**
3510
3476
  * Invokes the asynchronous function, surfacing the result through an observable sequence.
3511
3477
  * @param {Function} functionAsync Asynchronous function which returns a Promise to run.
@@ -3542,121 +3508,114 @@
3542
3508
  var source = this;
3543
3509
  return typeof subjectOrSubjectSelector === 'function' ?
3544
3510
  new AnonymousObservable(function (observer) {
3545
- var connectable = source.multicast(subjectOrSubjectSelector());
3546
- return new CompositeDisposable(selector(connectable).subscribe(observer), connectable.connect());
3511
+ var connectable = source.multicast(subjectOrSubjectSelector());
3512
+ return new CompositeDisposable(selector(connectable).subscribe(observer), connectable.connect());
3547
3513
  }) :
3548
3514
  new ConnectableObservable(source, subjectOrSubjectSelector);
3549
3515
  };
3550
3516
 
3551
- /**
3552
- * 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.
3553
- * This operator is a specialization of Multicast using a regular Subject.
3554
- *
3555
- * @example
3556
- * var resres = source.publish();
3557
- * var res = source.publish(function (x) { return x; });
3558
- *
3559
- * @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.
3560
- * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
3561
- */
3562
- observableProto.publish = function (selector) {
3563
- return !selector ?
3564
- this.multicast(new Subject()) :
3565
- this.multicast(function () {
3566
- return new Subject();
3567
- }, selector);
3568
- };
3517
+ /**
3518
+ * 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.
3519
+ * This operator is a specialization of Multicast using a regular Subject.
3520
+ *
3521
+ * @example
3522
+ * var resres = source.publish();
3523
+ * var res = source.publish(function (x) { return x; });
3524
+ *
3525
+ * @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.
3526
+ * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
3527
+ */
3528
+ observableProto.publish = function (selector) {
3529
+ return selector && isFunction(selector) ?
3530
+ this.multicast(function () { return new Subject(); }, selector) :
3531
+ this.multicast(new Subject());
3532
+ };
3569
3533
 
3570
- /**
3571
- * Returns an observable sequence that shares a single subscription to the underlying sequence.
3572
- * 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.
3573
- *
3574
- * @example
3575
- * var res = source.share();
3576
- *
3577
- * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence.
3578
- */
3579
- observableProto.share = function () {
3580
- return this.publish(null).refCount();
3581
- };
3534
+ /**
3535
+ * Returns an observable sequence that shares a single subscription to the underlying sequence.
3536
+ * 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.
3537
+ *
3538
+ * @example
3539
+ * var res = source.share();
3540
+ *
3541
+ * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence.
3542
+ */
3543
+ observableProto.share = function () {
3544
+ return this.publish().refCount();
3545
+ };
3582
3546
 
3583
- /**
3584
- * 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.
3585
- * This operator is a specialization of Multicast using a AsyncSubject.
3586
- *
3587
- * @example
3588
- * var res = source.publishLast();
3589
- * var res = source.publishLast(function (x) { return x; });
3590
- *
3591
- * @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.
3592
- * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
3593
- */
3594
- observableProto.publishLast = function (selector) {
3595
- return !selector ?
3596
- this.multicast(new AsyncSubject()) :
3597
- this.multicast(function () {
3598
- return new AsyncSubject();
3599
- }, selector);
3600
- };
3547
+ /**
3548
+ * 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.
3549
+ * This operator is a specialization of Multicast using a AsyncSubject.
3550
+ *
3551
+ * @example
3552
+ * var res = source.publishLast();
3553
+ * var res = source.publishLast(function (x) { return x; });
3554
+ *
3555
+ * @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.
3556
+ * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
3557
+ */
3558
+ observableProto.publishLast = function (selector) {
3559
+ return selector && isFunction(selector) ?
3560
+ this.multicast(function () { return new AsyncSubject(); }, selector) :
3561
+ this.multicast(new AsyncSubject());
3562
+ };
3601
3563
 
3602
- /**
3603
- * 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.
3604
- * This operator is a specialization of Multicast using a BehaviorSubject.
3605
- *
3606
- * @example
3607
- * var res = source.publishValue(42);
3608
- * var res = source.publishValue(function (x) { return x.select(function (y) { return y * y; }) }, 42);
3609
- *
3610
- * @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.
3611
- * @param {Mixed} initialValue Initial value received by observers upon subscription.
3612
- * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
3613
- */
3614
- observableProto.publishValue = function (initialValueOrSelector, initialValue) {
3615
- return arguments.length === 2 ?
3616
- this.multicast(function () {
3617
- return new BehaviorSubject(initialValue);
3618
- }, initialValueOrSelector) :
3619
- this.multicast(new BehaviorSubject(initialValueOrSelector));
3620
- };
3564
+ /**
3565
+ * 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.
3566
+ * This operator is a specialization of Multicast using a BehaviorSubject.
3567
+ *
3568
+ * @example
3569
+ * var res = source.publishValue(42);
3570
+ * var res = source.publishValue(function (x) { return x.select(function (y) { return y * y; }) }, 42);
3571
+ *
3572
+ * @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.
3573
+ * @param {Mixed} initialValue Initial value received by observers upon subscription.
3574
+ * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
3575
+ */
3576
+ observableProto.publishValue = function (initialValueOrSelector, initialValue) {
3577
+ return arguments.length === 2 ?
3578
+ this.multicast(function () {
3579
+ return new BehaviorSubject(initialValue);
3580
+ }, initialValueOrSelector) :
3581
+ this.multicast(new BehaviorSubject(initialValueOrSelector));
3582
+ };
3621
3583
 
3622
- /**
3623
- * Returns an observable sequence that shares a single subscription to the underlying sequence and starts with an initialValue.
3624
- * 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.
3625
- *
3626
- * @example
3627
- * var res = source.shareValue(42);
3628
- *
3629
- * @param {Mixed} initialValue Initial value received by observers upon subscription.
3630
- * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence.
3631
- */
3632
- observableProto.shareValue = function (initialValue) {
3633
- return this.publishValue(initialValue).
3634
- refCount();
3635
- };
3584
+ /**
3585
+ * Returns an observable sequence that shares a single subscription to the underlying sequence and starts with an initialValue.
3586
+ * 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.
3587
+ *
3588
+ * @example
3589
+ * var res = source.shareValue(42);
3590
+ *
3591
+ * @param {Mixed} initialValue Initial value received by observers upon subscription.
3592
+ * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence.
3593
+ */
3594
+ observableProto.shareValue = function (initialValue) {
3595
+ return this.publishValue(initialValue).refCount();
3596
+ };
3636
3597
 
3637
- /**
3638
- * 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.
3639
- * This operator is a specialization of Multicast using a ReplaySubject.
3640
- *
3641
- * @example
3642
- * var res = source.replay(null, 3);
3643
- * var res = source.replay(null, 3, 500);
3644
- * var res = source.replay(null, 3, 500, scheduler);
3645
- * var res = source.replay(function (x) { return x.take(6).repeat(); }, 3, 500, scheduler);
3646
- *
3647
- * @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.
3648
- * @param bufferSize [Optional] Maximum element count of the replay buffer.
3649
- * @param window [Optional] Maximum time length of the replay buffer.
3650
- * @param scheduler [Optional] Scheduler where connected observers within the selector function will be invoked on.
3651
- * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
3652
- */
3653
- observableProto.replay = function (selector, bufferSize, window, scheduler) {
3654
- return !selector ?
3655
- this.multicast(new ReplaySubject(bufferSize, window, scheduler)) :
3656
- this.multicast(function () {
3657
- return new ReplaySubject(bufferSize, window, scheduler);
3658
- }, selector);
3659
- };
3598
+ /**
3599
+ * 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.
3600
+ * This operator is a specialization of Multicast using a ReplaySubject.
3601
+ *
3602
+ * @example
3603
+ * var res = source.replay(null, 3);
3604
+ * var res = source.replay(null, 3, 500);
3605
+ * var res = source.replay(null, 3, 500, scheduler);
3606
+ * var res = source.replay(function (x) { return x.take(6).repeat(); }, 3, 500, scheduler);
3607
+ *
3608
+ * @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.
3609
+ * @param bufferSize [Optional] Maximum element count of the replay buffer.
3610
+ * @param window [Optional] Maximum time length of the replay buffer.
3611
+ * @param scheduler [Optional] Scheduler where connected observers within the selector function will be invoked on.
3612
+ * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
3613
+ */
3614
+ observableProto.replay = function (selector, bufferSize, window, scheduler) {
3615
+ return selector && isFunction(selector) ?
3616
+ this.multicast(function () { return new ReplaySubject(bufferSize, window, scheduler); }, selector) :
3617
+ this.multicast(new ReplaySubject(bufferSize, window, scheduler));
3618
+ };
3660
3619
 
3661
3620
  /**
3662
3621
  * 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.
@@ -3776,18 +3735,6 @@
3776
3735
 
3777
3736
  /**
3778
3737
  * Returns an observable sequence that produces a value after dueTime has elapsed and then after each period.
3779
- *
3780
- * @example
3781
- * 1 - res = Rx.Observable.timer(new Date());
3782
- * 2 - res = Rx.Observable.timer(new Date(), 1000);
3783
- * 3 - res = Rx.Observable.timer(new Date(), Rx.Scheduler.timeout);
3784
- * 4 - res = Rx.Observable.timer(new Date(), 1000, Rx.Scheduler.timeout);
3785
- *
3786
- * 5 - res = Rx.Observable.timer(5000);
3787
- * 6 - res = Rx.Observable.timer(5000, 1000);
3788
- * 7 - res = Rx.Observable.timer(5000, Rx.Scheduler.timeout);
3789
- * 8 - res = Rx.Observable.timer(5000, 1000, Rx.Scheduler.timeout);
3790
- *
3791
3738
  * @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.
3792
3739
  * @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.
3793
3740
  * @param {Scheduler} [scheduler] Scheduler to run the timer on. If not specified, the timeout scheduler is used.
@@ -3798,7 +3745,7 @@
3798
3745
  isScheduler(scheduler) || (scheduler = timeoutScheduler);
3799
3746
  if (periodOrScheduler !== undefined && typeof periodOrScheduler === 'number') {
3800
3747
  period = periodOrScheduler;
3801
- } else if (periodOrScheduler !== undefined && typeof periodOrScheduler === 'object') {
3748
+ } else if (isScheduler(periodOrScheduler)) {
3802
3749
  scheduler = periodOrScheduler;
3803
3750
  }
3804
3751
  if (dueTime instanceof Date && period === undefined) {
@@ -3917,7 +3864,37 @@
3917
3864
  */
3918
3865
  observableProto.throttle = function (dueTime, scheduler) {
3919
3866
  isScheduler(scheduler) || (scheduler = timeoutScheduler);
3920
- return this.throttleWithSelector(function () { return observableTimer(dueTime, scheduler); })
3867
+ var source = this;
3868
+ return new AnonymousObservable(function (observer) {
3869
+ var cancelable = new SerialDisposable(), hasvalue = false, value, id = 0;
3870
+ var subscription = source.subscribe(
3871
+ function (x) {
3872
+ hasvalue = true;
3873
+ value = x;
3874
+ id++;
3875
+ var currentId = id,
3876
+ d = new SingleAssignmentDisposable();
3877
+ cancelable.setDisposable(d);
3878
+ d.setDisposable(scheduler.scheduleWithRelative(dueTime, function () {
3879
+ hasValue && id === currentId && observer.onNext(value);
3880
+ hasvalue = false;
3881
+ }));
3882
+ },
3883
+ function (e) {
3884
+ cancelable.dispose();
3885
+ observer.onError(e);
3886
+ hasvalue = false;
3887
+ id++;
3888
+ },
3889
+ function () {
3890
+ cancelable.dispose();
3891
+ hasvalue && observer.onNext(value);
3892
+ observer.onCompleted();
3893
+ hasvalue = false;
3894
+ id++;
3895
+ });
3896
+ return new CompositeDisposable(subscription, cancelable);
3897
+ });
3921
3898
  };
3922
3899
 
3923
3900
  /**
@@ -3982,16 +3959,7 @@
3982
3959
  };
3983
3960
 
3984
3961
  /**
3985
- * Returns the source observable sequence or the other observable sequence if dueTime elapses.
3986
- *
3987
- * @example
3988
- * 1 - res = source.timeout(new Date()); // As a date
3989
- * 2 - res = source.timeout(5000); // 5 seconds
3990
- * 3 - res = source.timeout(new Date(), Rx.Observable.returnValue(42)); // As a date and timeout observable
3991
- * 4 - res = source.timeout(5000, Rx.Observable.returnValue(42)); // 5 seconds and timeout observable
3992
- * 5 - res = source.timeout(new Date(), Rx.Observable.returnValue(42), Rx.Scheduler.timeout); // As a date and timeout observable
3993
- * 6 - res = source.timeout(5000, Rx.Observable.returnValue(42), Rx.Scheduler.timeout); // 5 seconds and timeout observable
3994
- *
3962
+ * Returns the source observable sequence or the other observable sequence if dueTime elapses.
3995
3963
  * @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) when a timeout occurs.
3996
3964
  * @param {Observable} [other] Sequence to return in case of a timeout. If not specified, a timeout error throwing sequence will be used.
3997
3965
  * @param {Scheduler} [scheduler] Scheduler to run the timeout timers on. If not specified, the timeout scheduler is used.
@@ -4014,7 +3982,7 @@
4014
3982
 
4015
3983
  subscription.setDisposable(original);
4016
3984
 
4017
- var createTimer = function () {
3985
+ function createTimer() {
4018
3986
  var myId = id;
4019
3987
  timer.setDisposable(scheduler[schedulerMethod](dueTime, function () {
4020
3988
  if (id === myId) {
@@ -4022,7 +3990,7 @@
4022
3990
  subscription.setDisposable(other.subscribe(observer));
4023
3991
  }
4024
3992
  }));
4025
- };
3993
+ }
4026
3994
 
4027
3995
  createTimer();
4028
3996
 
@@ -4125,143 +4093,6 @@
4125
4093
  });
4126
4094
  };
4127
4095
 
4128
- /**
4129
- * Returns the source observable sequence, switching to the other observable sequence if a timeout is signaled.
4130
- *
4131
- * @example
4132
- * 1 - res = source.timeoutWithSelector(Rx.Observable.timer(500));
4133
- * 2 - res = source.timeoutWithSelector(Rx.Observable.timer(500), function (x) { return Rx.Observable.timer(200); });
4134
- * 3 - res = source.timeoutWithSelector(Rx.Observable.timer(500), function (x) { return Rx.Observable.timer(200); }, Rx.Observable.returnValue(42));
4135
- *
4136
- * @param {Observable} [firstTimeout] Observable sequence that represents the timeout for the first element. If not provided, this defaults to Observable.never().
4137
- * @param {Function} [timeoutDurationSelector] Selector to retrieve an observable sequence that represents the timeout between the current element and the next element.
4138
- * @param {Observable} [other] Sequence to return in case of a timeout. If not provided, this is set to Observable.throwException().
4139
- * @returns {Observable} The source sequence switching to the other sequence in case of a timeout.
4140
- */
4141
- observableProto.timeoutWithSelector = function (firstTimeout, timeoutdurationSelector, other) {
4142
- if (arguments.length === 1) {
4143
- timeoutdurationSelector = firstTimeout;
4144
- var firstTimeout = observableNever();
4145
- }
4146
- other || (other = observableThrow(new Error('Timeout')));
4147
- var source = this;
4148
- return new AnonymousObservable(function (observer) {
4149
- var subscription = new SerialDisposable(), timer = new SerialDisposable(), original = new SingleAssignmentDisposable();
4150
-
4151
- subscription.setDisposable(original);
4152
-
4153
- var id = 0, switched = false, setTimer = function (timeout) {
4154
- var myId = id, timerWins = function () {
4155
- return id === myId;
4156
- };
4157
- var d = new SingleAssignmentDisposable();
4158
- timer.setDisposable(d);
4159
- d.setDisposable(timeout.subscribe(function () {
4160
- if (timerWins()) {
4161
- subscription.setDisposable(other.subscribe(observer));
4162
- }
4163
- d.dispose();
4164
- }, function (e) {
4165
- if (timerWins()) {
4166
- observer.onError(e);
4167
- }
4168
- }, function () {
4169
- if (timerWins()) {
4170
- subscription.setDisposable(other.subscribe(observer));
4171
- }
4172
- }));
4173
- };
4174
-
4175
- setTimer(firstTimeout);
4176
- var observerWins = function () {
4177
- var res = !switched;
4178
- if (res) {
4179
- id++;
4180
- }
4181
- return res;
4182
- };
4183
-
4184
- original.setDisposable(source.subscribe(function (x) {
4185
- if (observerWins()) {
4186
- observer.onNext(x);
4187
- var timeout;
4188
- try {
4189
- timeout = timeoutdurationSelector(x);
4190
- } catch (e) {
4191
- observer.onError(e);
4192
- return;
4193
- }
4194
- setTimer(timeout);
4195
- }
4196
- }, function (e) {
4197
- if (observerWins()) {
4198
- observer.onError(e);
4199
- }
4200
- }, function () {
4201
- if (observerWins()) {
4202
- observer.onCompleted();
4203
- }
4204
- }));
4205
- return new CompositeDisposable(subscription, timer);
4206
- });
4207
- };
4208
-
4209
- /**
4210
- * Ignores values from an observable sequence which are followed by another value within a computed throttle duration.
4211
- *
4212
- * @example
4213
- * 1 - res = source.delayWithSelector(function (x) { return Rx.Scheduler.timer(x + x); });
4214
- *
4215
- * @param {Function} throttleDurationSelector Selector function to retrieve a sequence indicating the throttle duration for each given element.
4216
- * @returns {Observable} The throttled sequence.
4217
- */
4218
- observableProto.throttleWithSelector = function (throttleDurationSelector) {
4219
- var source = this;
4220
- return new AnonymousObservable(function (observer) {
4221
- var value, hasValue = false, cancelable = new SerialDisposable(), id = 0, subscription = source.subscribe(function (x) {
4222
- var throttle;
4223
- try {
4224
- throttle = throttleDurationSelector(x);
4225
- } catch (e) {
4226
- observer.onError(e);
4227
- return;
4228
- }
4229
- hasValue = true;
4230
- value = x;
4231
- id++;
4232
- var currentid = id, d = new SingleAssignmentDisposable();
4233
- cancelable.setDisposable(d);
4234
- d.setDisposable(throttle.subscribe(function () {
4235
- if (hasValue && id === currentid) {
4236
- observer.onNext(value);
4237
- }
4238
- hasValue = false;
4239
- d.dispose();
4240
- }, observer.onError.bind(observer), function () {
4241
- if (hasValue && id === currentid) {
4242
- observer.onNext(value);
4243
- }
4244
- hasValue = false;
4245
- d.dispose();
4246
- }));
4247
- }, function (e) {
4248
- cancelable.dispose();
4249
- observer.onError(e);
4250
- hasValue = false;
4251
- id++;
4252
- }, function () {
4253
- cancelable.dispose();
4254
- if (hasValue) {
4255
- observer.onNext(value);
4256
- }
4257
- observer.onCompleted();
4258
- hasValue = false;
4259
- id++;
4260
- });
4261
- return new CompositeDisposable(subscription, cancelable);
4262
- });
4263
- };
4264
-
4265
4096
  /**
4266
4097
  * Skips elements for the specified duration from the end of the observable source sequence, using the specified scheduler to run timers.
4267
4098
  *
@@ -4299,9 +4130,6 @@
4299
4130
 
4300
4131
  /**
4301
4132
  * 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.
4302
- *
4303
- * @example
4304
- * 1 - res = source.takeLastWithTime(5000, [optional timer scheduler], [optional loop scheduler]);
4305
4133
  * @description
4306
4134
  * This operator accumulates a queue with a length enough to store elements received during the initial duration window.
4307
4135
  * As more elements are received, elements older than the specified duration are taken from the queue and produced on the
@@ -4315,7 +4143,6 @@
4315
4143
  isScheduler(scheduler) || (scheduler = timeoutScheduler);
4316
4144
  return new AnonymousObservable(function (observer) {
4317
4145
  var q = [];
4318
-
4319
4146
  return source.subscribe(function (x) {
4320
4147
  var now = scheduler.now();
4321
4148
  q.push({ interval: now, value: x });
@@ -4326,11 +4153,8 @@
4326
4153
  var now = scheduler.now();
4327
4154
  while (q.length > 0) {
4328
4155
  var next = q.shift();
4329
- if (now - next.interval <= duration) {
4330
- observer.onNext(next.value);
4331
- }
4156
+ if (now - next.interval <= duration) { observer.onNext(next.value); }
4332
4157
  }
4333
-
4334
4158
  observer.onCompleted();
4335
4159
  });
4336
4160
  });
@@ -4502,6 +4326,7 @@
4502
4326
  .subscribe(
4503
4327
  function (results) {
4504
4328
  if (previousShouldFire !== undefined && results.shouldFire != previousShouldFire) {
4329
+ previousShouldFire = results.shouldFire;
4505
4330
  // change in shouldFire
4506
4331
  if (results.shouldFire) {
4507
4332
  while (q.length > 0) {
@@ -4509,6 +4334,7 @@
4509
4334
  }
4510
4335
  }
4511
4336
  } else {
4337
+ previousShouldFire = results.shouldFire;
4512
4338
  // new data
4513
4339
  if (results.shouldFire) {
4514
4340
  observer.onNext(results.data);
@@ -4516,9 +4342,7 @@
4516
4342
  q.push(results.data);
4517
4343
  }
4518
4344
  }
4519
- previousShouldFire = results.shouldFire;
4520
-
4521
- },
4345
+ },
4522
4346
  function (err) {
4523
4347
  // Empty buffer before sending error
4524
4348
  while (q.length > 0) {
@@ -5226,267 +5050,247 @@
5226
5050
  return AnonymousSubject;
5227
5051
  }(Observable));
5228
5052
 
5229
- /**
5230
- * Represents a value that changes over time.
5231
- * Observers can subscribe to the subject to receive the last (or initial) value and all subsequent notifications.
5232
- */
5233
- var BehaviorSubject = Rx.BehaviorSubject = (function (_super) {
5234
- function subscribe(observer) {
5235
- checkDisposed.call(this);
5236
- if (!this.isStopped) {
5237
- this.observers.push(observer);
5238
- observer.onNext(this.value);
5239
- return new InnerSubscription(this, observer);
5240
- }
5241
- var ex = this.exception;
5242
- if (ex) {
5243
- observer.onError(ex);
5244
- } else {
5245
- observer.onCompleted();
5246
- }
5247
- return disposableEmpty;
5248
- }
5053
+ /**
5054
+ * Represents a value that changes over time.
5055
+ * Observers can subscribe to the subject to receive the last (or initial) value and all subsequent notifications.
5056
+ */
5057
+ var BehaviorSubject = Rx.BehaviorSubject = (function (__super__) {
5058
+ function subscribe(observer) {
5059
+ checkDisposed.call(this);
5060
+ if (!this.isStopped) {
5061
+ this.observers.push(observer);
5062
+ observer.onNext(this.value);
5063
+ return new InnerSubscription(this, observer);
5064
+ }
5065
+ var ex = this.exception;
5066
+ if (ex) {
5067
+ observer.onError(ex);
5068
+ } else {
5069
+ observer.onCompleted();
5070
+ }
5071
+ return disposableEmpty;
5072
+ }
5249
5073
 
5250
- inherits(BehaviorSubject, _super);
5074
+ inherits(BehaviorSubject, __super__);
5251
5075
 
5252
- /**
5253
- * @constructor
5254
- * Initializes a new instance of the BehaviorSubject class which creates a subject that caches its last value and starts with the specified value.
5255
- * @param {Mixed} value Initial value sent to observers when no other value has been received by the subject yet.
5256
- */
5257
- function BehaviorSubject(value) {
5258
- _super.call(this, subscribe);
5076
+ /**
5077
+ * @constructor
5078
+ * Initializes a new instance of the BehaviorSubject class which creates a subject that caches its last value and starts with the specified value.
5079
+ * @param {Mixed} value Initial value sent to observers when no other value has been received by the subject yet.
5080
+ */
5081
+ function BehaviorSubject(value) {
5082
+ __super__.call(this, subscribe);
5083
+ this.value = value,
5084
+ this.observers = [],
5085
+ this.isDisposed = false,
5086
+ this.isStopped = false,
5087
+ this.exception = null;
5088
+ }
5259
5089
 
5260
- this.value = value,
5261
- this.observers = [],
5262
- this.isDisposed = false,
5263
- this.isStopped = false,
5264
- this.exception = null;
5090
+ addProperties(BehaviorSubject.prototype, Observer, {
5091
+ /**
5092
+ * Indicates whether the subject has observers subscribed to it.
5093
+ * @returns {Boolean} Indicates whether the subject has observers subscribed to it.
5094
+ */
5095
+ hasObservers: function () {
5096
+ return this.observers.length > 0;
5097
+ },
5098
+ /**
5099
+ * Notifies all subscribed observers about the end of the sequence.
5100
+ */
5101
+ onCompleted: function () {
5102
+ checkDisposed.call(this);
5103
+ if (this.isStopped) { return; }
5104
+ this.isStopped = true;
5105
+ for (var i = 0, os = this.observers.slice(0), len = os.length; i < len; i++) {
5106
+ os[i].onCompleted();
5265
5107
  }
5266
5108
 
5267
- addProperties(BehaviorSubject.prototype, Observer, {
5268
- /**
5269
- * Indicates whether the subject has observers subscribed to it.
5270
- * @returns {Boolean} Indicates whether the subject has observers subscribed to it.
5271
- */
5272
- hasObservers: function () {
5273
- return this.observers.length > 0;
5274
- },
5275
- /**
5276
- * Notifies all subscribed observers about the end of the sequence.
5277
- */
5278
- onCompleted: function () {
5279
- checkDisposed.call(this);
5280
- if (!this.isStopped) {
5281
- var os = this.observers.slice(0);
5282
- this.isStopped = true;
5283
- for (var i = 0, len = os.length; i < len; i++) {
5284
- os[i].onCompleted();
5285
- }
5286
-
5287
- this.observers = [];
5288
- }
5289
- },
5290
- /**
5291
- * Notifies all subscribed observers about the exception.
5292
- * @param {Mixed} error The exception to send to all observers.
5293
- */
5294
- onError: function (error) {
5295
- checkDisposed.call(this);
5296
- if (!this.isStopped) {
5297
- var os = this.observers.slice(0);
5298
- this.isStopped = true;
5299
- this.exception = error;
5109
+ this.observers = [];
5110
+ },
5111
+ /**
5112
+ * Notifies all subscribed observers about the exception.
5113
+ * @param {Mixed} error The exception to send to all observers.
5114
+ */
5115
+ onError: function (error) {
5116
+ checkDisposed.call(this);
5117
+ if (this.isStopped) { return; }
5118
+ this.isStopped = true;
5119
+ this.exception = error;
5300
5120
 
5301
- for (var i = 0, len = os.length; i < len; i++) {
5302
- os[i].onError(error);
5303
- }
5121
+ for (var i = 0, os = this.observers.slice(0), len = os.length; i < len; i++) {
5122
+ os[i].onError(error);
5123
+ }
5304
5124
 
5305
- this.observers = [];
5306
- }
5307
- },
5308
- /**
5309
- * Notifies all subscribed observers about the arrival of the specified element in the sequence.
5310
- * @param {Mixed} value The value to send to all observers.
5311
- */
5312
- onNext: function (value) {
5313
- checkDisposed.call(this);
5314
- if (!this.isStopped) {
5315
- this.value = value;
5316
- var os = this.observers.slice(0);
5317
- for (var i = 0, len = os.length; i < len; i++) {
5318
- os[i].onNext(value);
5319
- }
5320
- }
5321
- },
5322
- /**
5323
- * Unsubscribe all observers and release resources.
5324
- */
5325
- dispose: function () {
5326
- this.isDisposed = true;
5327
- this.observers = null;
5328
- this.value = null;
5329
- this.exception = null;
5330
- }
5331
- });
5125
+ this.observers = [];
5126
+ },
5127
+ /**
5128
+ * Notifies all subscribed observers about the arrival of the specified element in the sequence.
5129
+ * @param {Mixed} value The value to send to all observers.
5130
+ */
5131
+ onNext: function (value) {
5132
+ checkDisposed.call(this);
5133
+ if (this.isStopped) { return; }
5134
+ this.value = value;
5135
+ for (var i = 0, os = this.observers.slice(0), len = os.length; i < len; i++) {
5136
+ os[i].onNext(value);
5137
+ }
5138
+ },
5139
+ /**
5140
+ * Unsubscribe all observers and release resources.
5141
+ */
5142
+ dispose: function () {
5143
+ this.isDisposed = true;
5144
+ this.observers = null;
5145
+ this.value = null;
5146
+ this.exception = null;
5147
+ }
5148
+ });
5332
5149
 
5333
- return BehaviorSubject;
5334
- }(Observable));
5150
+ return BehaviorSubject;
5151
+ }(Observable));
5335
5152
 
5336
- /**
5337
- * Represents an object that is both an observable sequence as well as an observer.
5338
- * Each notification is broadcasted to all subscribed and future observers, subject to buffer trimming policies.
5339
- */
5340
- var ReplaySubject = Rx.ReplaySubject = (function (_super) {
5153
+ /**
5154
+ * Represents an object that is both an observable sequence as well as an observer.
5155
+ * Each notification is broadcasted to all subscribed and future observers, subject to buffer trimming policies.
5156
+ */
5157
+ var ReplaySubject = Rx.ReplaySubject = (function (__super__) {
5341
5158
 
5342
- function RemovableDisposable (subject, observer) {
5343
- this.subject = subject;
5344
- this.observer = observer;
5345
- };
5159
+ function createRemovableDisposable(subject, observer) {
5160
+ return disposableCreate(function () {
5161
+ observer.dispose();
5162
+ !subject.isDisposed && subject.observers.splice(subject.observers.indexOf(observer), 1);
5163
+ });
5164
+ }
5346
5165
 
5347
- RemovableDisposable.prototype.dispose = function () {
5348
- this.observer.dispose();
5349
- if (!this.subject.isDisposed) {
5350
- var idx = this.subject.observers.indexOf(this.observer);
5351
- this.subject.observers.splice(idx, 1);
5352
- }
5353
- };
5166
+ function subscribe(observer) {
5167
+ var so = new ScheduledObserver(this.scheduler, observer),
5168
+ subscription = createRemovableDisposable(this, so);
5169
+ checkDisposed.call(this);
5170
+ this._trim(this.scheduler.now());
5171
+ this.observers.push(so);
5354
5172
 
5355
- function subscribe(observer) {
5356
- var so = new ScheduledObserver(this.scheduler, observer),
5357
- subscription = new RemovableDisposable(this, so);
5358
- checkDisposed.call(this);
5359
- this._trim(this.scheduler.now());
5360
- this.observers.push(so);
5173
+ var n = this.q.length;
5361
5174
 
5362
- var n = this.q.length;
5175
+ for (var i = 0, len = this.q.length; i < len; i++) {
5176
+ so.onNext(this.q[i].value);
5177
+ }
5363
5178
 
5364
- for (var i = 0, len = this.q.length; i < len; i++) {
5365
- so.onNext(this.q[i].value);
5366
- }
5179
+ if (this.hasError) {
5180
+ n++;
5181
+ so.onError(this.error);
5182
+ } else if (this.isStopped) {
5183
+ n++;
5184
+ so.onCompleted();
5185
+ }
5367
5186
 
5368
- if (this.hasError) {
5369
- n++;
5370
- so.onError(this.error);
5371
- } else if (this.isStopped) {
5372
- n++;
5373
- so.onCompleted();
5374
- }
5187
+ so.ensureActive(n);
5188
+ return subscription;
5189
+ }
5375
5190
 
5376
- so.ensureActive(n);
5377
- return subscription;
5378
- }
5191
+ inherits(ReplaySubject, __super__);
5379
5192
 
5380
- inherits(ReplaySubject, _super);
5193
+ /**
5194
+ * Initializes a new instance of the ReplaySubject class with the specified buffer size, window size and scheduler.
5195
+ * @param {Number} [bufferSize] Maximum element count of the replay buffer.
5196
+ * @param {Number} [windowSize] Maximum time length of the replay buffer.
5197
+ * @param {Scheduler} [scheduler] Scheduler the observers are invoked on.
5198
+ */
5199
+ function ReplaySubject(bufferSize, windowSize, scheduler) {
5200
+ this.bufferSize = bufferSize == null ? Number.MAX_VALUE : bufferSize;
5201
+ this.windowSize = windowSize == null ? Number.MAX_VALUE : windowSize;
5202
+ this.scheduler = scheduler || currentThreadScheduler;
5203
+ this.q = [];
5204
+ this.observers = [];
5205
+ this.isStopped = false;
5206
+ this.isDisposed = false;
5207
+ this.hasError = false;
5208
+ this.error = null;
5209
+ __super__.call(this, subscribe);
5210
+ }
5381
5211
 
5382
- /**
5383
- * Initializes a new instance of the ReplaySubject class with the specified buffer size, window size and scheduler.
5384
- * @param {Number} [bufferSize] Maximum element count of the replay buffer.
5385
- * @param {Number} [windowSize] Maximum time length of the replay buffer.
5386
- * @param {Scheduler} [scheduler] Scheduler the observers are invoked on.
5387
- */
5388
- function ReplaySubject(bufferSize, windowSize, scheduler) {
5389
- this.bufferSize = bufferSize == null ? Number.MAX_VALUE : bufferSize;
5390
- this.windowSize = windowSize == null ? Number.MAX_VALUE : windowSize;
5391
- this.scheduler = scheduler || currentThreadScheduler;
5392
- this.q = [];
5393
- this.observers = [];
5394
- this.isStopped = false;
5395
- this.isDisposed = false;
5396
- this.hasError = false;
5397
- this.error = null;
5398
- _super.call(this, subscribe);
5212
+ addProperties(ReplaySubject.prototype, Observer, {
5213
+ /**
5214
+ * Indicates whether the subject has observers subscribed to it.
5215
+ * @returns {Boolean} Indicates whether the subject has observers subscribed to it.
5216
+ */
5217
+ hasObservers: function () {
5218
+ return this.observers.length > 0;
5219
+ },
5220
+ _trim: function (now) {
5221
+ while (this.q.length > this.bufferSize) {
5222
+ this.q.shift();
5223
+ }
5224
+ while (this.q.length > 0 && (now - this.q[0].interval) > this.windowSize) {
5225
+ this.q.shift();
5399
5226
  }
5227
+ },
5228
+ /**
5229
+ * Notifies all subscribed observers about the arrival of the specified element in the sequence.
5230
+ * @param {Mixed} value The value to send to all observers.
5231
+ */
5232
+ onNext: function (value) {
5233
+ checkDisposed.call(this);
5234
+ if (this.isStopped) { return; }
5235
+ var now = this.scheduler.now();
5236
+ this.q.push({ interval: now, value: value });
5237
+ this._trim(now);
5400
5238
 
5401
- addProperties(ReplaySubject.prototype, Observer, {
5402
- /**
5403
- * Indicates whether the subject has observers subscribed to it.
5404
- * @returns {Boolean} Indicates whether the subject has observers subscribed to it.
5405
- */
5406
- hasObservers: function () {
5407
- return this.observers.length > 0;
5408
- },
5409
- /* @private */
5410
- _trim: function (now) {
5411
- while (this.q.length > this.bufferSize) {
5412
- this.q.shift();
5413
- }
5414
- while (this.q.length > 0 && (now - this.q[0].interval) > this.windowSize) {
5415
- this.q.shift();
5416
- }
5417
- },
5418
- /**
5419
- * Notifies all subscribed observers about the arrival of the specified element in the sequence.
5420
- * @param {Mixed} value The value to send to all observers.
5421
- */
5422
- onNext: function (value) {
5423
- var observer;
5424
- checkDisposed.call(this);
5425
- if (!this.isStopped) {
5426
- var now = this.scheduler.now();
5427
- this.q.push({ interval: now, value: value });
5428
- this._trim(now);
5429
-
5430
- var o = this.observers.slice(0);
5431
- for (var i = 0, len = o.length; i < len; i++) {
5432
- observer = o[i];
5433
- observer.onNext(value);
5434
- observer.ensureActive();
5435
- }
5436
- }
5437
- },
5438
- /**
5439
- * Notifies all subscribed observers about the exception.
5440
- * @param {Mixed} error The exception to send to all observers.
5441
- */
5442
- onError: function (error) {
5443
- var observer;
5444
- checkDisposed.call(this);
5445
- if (!this.isStopped) {
5446
- this.isStopped = true;
5447
- this.error = error;
5448
- this.hasError = true;
5449
- var now = this.scheduler.now();
5450
- this._trim(now);
5451
- var o = this.observers.slice(0);
5452
- for (var i = 0, len = o.length; i < len; i++) {
5453
- observer = o[i];
5454
- observer.onError(error);
5455
- observer.ensureActive();
5456
- }
5457
- this.observers = [];
5458
- }
5459
- },
5460
- /**
5461
- * Notifies all subscribed observers about the end of the sequence.
5462
- */
5463
- onCompleted: function () {
5464
- var observer;
5465
- checkDisposed.call(this);
5466
- if (!this.isStopped) {
5467
- this.isStopped = true;
5468
- var now = this.scheduler.now();
5469
- this._trim(now);
5470
- var o = this.observers.slice(0);
5471
- for (var i = 0, len = o.length; i < len; i++) {
5472
- observer = o[i];
5473
- observer.onCompleted();
5474
- observer.ensureActive();
5475
- }
5476
- this.observers = [];
5477
- }
5478
- },
5479
- /**
5480
- * Unsubscribe all observers and release resources.
5481
- */
5482
- dispose: function () {
5483
- this.isDisposed = true;
5484
- this.observers = null;
5485
- }
5486
- });
5239
+ var o = this.observers.slice(0);
5240
+ for (var i = 0, len = o.length; i < len; i++) {
5241
+ var observer = o[i];
5242
+ observer.onNext(value);
5243
+ observer.ensureActive();
5244
+ }
5245
+ },
5246
+ /**
5247
+ * Notifies all subscribed observers about the exception.
5248
+ * @param {Mixed} error The exception to send to all observers.
5249
+ */
5250
+ onError: function (error) {
5251
+ checkDisposed.call(this);
5252
+ if (this.isStopped) { return; }
5253
+ this.isStopped = true;
5254
+ this.error = error;
5255
+ this.hasError = true;
5256
+ var now = this.scheduler.now();
5257
+ this._trim(now);
5258
+ var o = this.observers.slice(0);
5259
+ for (var i = 0, len = o.length; i < len; i++) {
5260
+ var observer = o[i];
5261
+ observer.onError(error);
5262
+ observer.ensureActive();
5263
+ }
5264
+ this.observers = [];
5265
+ },
5266
+ /**
5267
+ * Notifies all subscribed observers about the end of the sequence.
5268
+ */
5269
+ onCompleted: function () {
5270
+ checkDisposed.call(this);
5271
+ if (this.isStopped) { return; }
5272
+ this.isStopped = true;
5273
+ var now = this.scheduler.now();
5274
+ this._trim(now);
5275
+ var o = this.observers.slice(0);
5276
+ for (var i = 0, len = o.length; i < len; i++) {
5277
+ var observer = o[i];
5278
+ observer.onCompleted();
5279
+ observer.ensureActive();
5280
+ }
5281
+ this.observers = [];
5282
+ },
5283
+ /**
5284
+ * Unsubscribe all observers and release resources.
5285
+ */
5286
+ dispose: function () {
5287
+ this.isDisposed = true;
5288
+ this.observers = null;
5289
+ }
5290
+ });
5487
5291
 
5488
- return ReplaySubject;
5489
- }(Observable));
5292
+ return ReplaySubject;
5293
+ }(Observable));
5490
5294
 
5491
5295
  if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
5492
5296
  root.Rx = Rx;