rxjs-rails 2.4.1 → 2.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rxjs/rails/version.rb +1 -1
  3. data/vendor/assets/javascripts/rx.aggregates.js +15 -19
  4. data/vendor/assets/javascripts/rx.aggregates.map +1 -1
  5. data/vendor/assets/javascripts/rx.aggregates.min.js +1 -1
  6. data/vendor/assets/javascripts/rx.all.compat.js +1014 -566
  7. data/vendor/assets/javascripts/rx.all.compat.map +1 -1
  8. data/vendor/assets/javascripts/rx.all.compat.min.js +4 -4
  9. data/vendor/assets/javascripts/rx.all.js +1009 -563
  10. data/vendor/assets/javascripts/rx.all.map +1 -1
  11. data/vendor/assets/javascripts/rx.all.min.js +4 -4
  12. data/vendor/assets/javascripts/rx.async.compat.js +17 -15
  13. data/vendor/assets/javascripts/rx.async.compat.map +1 -1
  14. data/vendor/assets/javascripts/rx.async.compat.min.js +1 -1
  15. data/vendor/assets/javascripts/rx.async.js +17 -15
  16. data/vendor/assets/javascripts/rx.async.map +1 -1
  17. data/vendor/assets/javascripts/rx.async.min.js +1 -1
  18. data/vendor/assets/javascripts/rx.backpressure.js +53 -43
  19. data/vendor/assets/javascripts/rx.backpressure.map +1 -1
  20. data/vendor/assets/javascripts/rx.backpressure.min.js +1 -1
  21. data/vendor/assets/javascripts/rx.binding.js +31 -12
  22. data/vendor/assets/javascripts/rx.binding.map +1 -1
  23. data/vendor/assets/javascripts/rx.binding.min.js +1 -1
  24. data/vendor/assets/javascripts/rx.coincidence.js +3 -2
  25. data/vendor/assets/javascripts/rx.coincidence.map +1 -1
  26. data/vendor/assets/javascripts/rx.coincidence.min.js +1 -1
  27. data/vendor/assets/javascripts/rx.compat.js +821 -444
  28. data/vendor/assets/javascripts/rx.compat.map +1 -1
  29. data/vendor/assets/javascripts/rx.compat.min.js +2 -2
  30. data/vendor/assets/javascripts/rx.experimental.js +2 -9
  31. data/vendor/assets/javascripts/rx.experimental.map +1 -1
  32. data/vendor/assets/javascripts/rx.experimental.min.js +1 -1
  33. data/vendor/assets/javascripts/rx.joinpatterns.js +14 -22
  34. data/vendor/assets/javascripts/rx.joinpatterns.map +1 -1
  35. data/vendor/assets/javascripts/rx.joinpatterns.min.js +1 -1
  36. data/vendor/assets/javascripts/rx.js +817 -442
  37. data/vendor/assets/javascripts/rx.lite.compat.js +897 -443
  38. data/vendor/assets/javascripts/rx.lite.compat.map +1 -1
  39. data/vendor/assets/javascripts/rx.lite.compat.min.js +3 -2
  40. data/vendor/assets/javascripts/rx.lite.extras.compat.js +621 -0
  41. data/vendor/assets/javascripts/rx.lite.extras.compat.map +1 -0
  42. data/vendor/assets/javascripts/rx.lite.extras.compat.min.js +3 -0
  43. data/vendor/assets/javascripts/rx.lite.extras.js +53 -76
  44. data/vendor/assets/javascripts/rx.lite.extras.map +1 -1
  45. data/vendor/assets/javascripts/rx.lite.extras.min.js +1 -1
  46. data/vendor/assets/javascripts/rx.lite.js +898 -444
  47. data/vendor/assets/javascripts/rx.lite.map +1 -1
  48. data/vendor/assets/javascripts/rx.lite.min.js +3 -2
  49. data/vendor/assets/javascripts/rx.map +1 -1
  50. data/vendor/assets/javascripts/rx.min.js +2 -2
  51. data/vendor/assets/javascripts/rx.testing.js +10 -11
  52. data/vendor/assets/javascripts/rx.testing.map +1 -1
  53. data/vendor/assets/javascripts/rx.testing.min.js +1 -1
  54. data/vendor/assets/javascripts/rx.time.js +80 -40
  55. data/vendor/assets/javascripts/rx.time.map +1 -1
  56. data/vendor/assets/javascripts/rx.time.min.js +1 -1
  57. data/vendor/assets/javascripts/rx.virtualtime.js +6 -13
  58. data/vendor/assets/javascripts/rx.virtualtime.map +1 -1
  59. data/vendor/assets/javascripts/rx.virtualtime.min.js +1 -1
  60. metadata +6 -3
@@ -32,7 +32,6 @@
32
32
  // Defaults
33
33
  var noop = Rx.helpers.noop = function () { },
34
34
  notDefined = Rx.helpers.notDefined = function (x) { return typeof x === 'undefined'; },
35
- isScheduler = Rx.helpers.isScheduler = function (x) { return x instanceof Rx.Scheduler; },
36
35
  identity = Rx.helpers.identity = function (x) { return x; },
37
36
  pluck = Rx.helpers.pluck = function (property) { return function (x) { return x[property]; }; },
38
37
  just = Rx.helpers.just = function (value) { return function () { return value; }; },
@@ -60,12 +59,11 @@
60
59
  return isFn;
61
60
  }());
62
61
 
63
- // Errors
64
- var sequenceContainsNoElements = 'Sequence contains no elements.';
65
- var argumentOutOfRange = 'Argument out of range';
66
- var objectDisposed = 'Object has been disposed';
67
- function checkDisposed(self) { if (self.isDisposed) { throw new Error(objectDisposed); } }
68
- function cloneArray(arr) { for(var a = [], i = 0, len = arr.length; i < len; i++) { a.push(arr[i]); } return a;}
62
+ function cloneArray(arr) {
63
+ var len = arr.length, a = new Array(len);
64
+ for(var i = 0; i < len; i++) { a[i] = arr[i]; }
65
+ return a;
66
+ }
69
67
 
70
68
  Rx.config.longStackSupport = false;
71
69
  var hasStacks = false;
@@ -163,6 +161,44 @@
163
161
  if (attempt3) { return [attempt3[1], Number(attempt3[2])]; }
164
162
  }
165
163
 
164
+ var EmptyError = Rx.EmptyError = function() {
165
+ this.message = 'Sequence contains no elements.';
166
+ Error.call(this);
167
+ };
168
+ EmptyError.prototype = Error.prototype;
169
+
170
+ var ObjectDisposedError = Rx.ObjectDisposedError = function() {
171
+ this.message = 'Object has been disposed';
172
+ Error.call(this);
173
+ };
174
+ ObjectDisposedError.prototype = Error.prototype;
175
+
176
+ var ArgumentOutOfRangeError = Rx.ArgumentOutOfRangeError = function () {
177
+ this.message = 'Argument out of range';
178
+ Error.call(this);
179
+ };
180
+ ArgumentOutOfRangeError.prototype = Error.prototype;
181
+
182
+ var NotSupportedError = Rx.NotSupportedError = function (message) {
183
+ this.message = message || 'This operation is not supported';
184
+ Error.call(this);
185
+ };
186
+ NotSupportedError.prototype = Error.prototype;
187
+
188
+ var NotImplementedError = Rx.NotImplementedError = function (message) {
189
+ this.message = message || 'This operation is not implemented';
190
+ Error.call(this);
191
+ };
192
+ NotImplementedError.prototype = Error.prototype;
193
+
194
+ var notImplemented = Rx.helpers.notImplemented = function () {
195
+ throw new NotImplementedError();
196
+ };
197
+
198
+ var notSupported = Rx.helpers.notSupported = function () {
199
+ throw new NotSupportedError();
200
+ };
201
+
166
202
  // Shim in iterator support
167
203
  var $iterator$ = (typeof Symbol === 'function' && Symbol.iterator) ||
168
204
  '_es6shim_iterator_';
@@ -827,13 +863,17 @@
827
863
  * @constructor
828
864
  */
829
865
  var CompositeDisposable = Rx.CompositeDisposable = function () {
830
- var args = [];
866
+ var args = [], i, len;
831
867
  if (Array.isArray(arguments[0])) {
832
868
  args = arguments[0];
869
+ len = args.length;
833
870
  } else {
834
- var len = arguments.length;
871
+ len = arguments.length;
835
872
  args = new Array(len);
836
- for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
873
+ for(i = 0; i < len; i++) { args[i] = arguments[i]; }
874
+ }
875
+ for(i = 0; i < len; i++) {
876
+ if (!isDisposable(args[i])) { throw new TypeError('Not a disposable'); }
837
877
  }
838
878
  this.disposables = args;
839
879
  this.isDisposed = false;
@@ -920,51 +960,67 @@
920
960
  */
921
961
  var disposableEmpty = Disposable.empty = { dispose: noop };
922
962
 
923
- var SingleAssignmentDisposable = Rx.SingleAssignmentDisposable = (function () {
924
- function BooleanDisposable () {
925
- this.isDisposed = false;
926
- this.current = null;
927
- }
928
-
929
- var booleanDisposablePrototype = BooleanDisposable.prototype;
930
-
931
- /**
932
- * Gets the underlying disposable.
933
- * @return The underlying disposable.
934
- */
935
- booleanDisposablePrototype.getDisposable = function () {
936
- return this.current;
937
- };
963
+ /**
964
+ * Validates whether the given object is a disposable
965
+ * @param {Object} Object to test whether it has a dispose method
966
+ * @returns {Boolean} true if a disposable object, else false.
967
+ */
968
+ var isDisposable = Disposable.isDisposable = function (d) {
969
+ return d && isFunction(d.dispose);
970
+ };
938
971
 
939
- /**
940
- * Sets the underlying disposable.
941
- * @param {Disposable} value The new underlying disposable.
942
- */
943
- booleanDisposablePrototype.setDisposable = function (value) {
944
- var shouldDispose = this.isDisposed;
945
- if (!shouldDispose) {
946
- var old = this.current;
947
- this.current = value;
948
- }
949
- old && old.dispose();
950
- shouldDispose && value && value.dispose();
951
- };
972
+ var checkDisposed = Disposable.checkDisposed = function (disposable) {
973
+ if (disposable.isDisposed) { throw new ObjectDisposedError(); }
974
+ };
952
975
 
953
- /**
954
- * Disposes the underlying disposable as well as all future replacements.
955
- */
956
- booleanDisposablePrototype.dispose = function () {
957
- if (!this.isDisposed) {
958
- this.isDisposed = true;
959
- var old = this.current;
960
- this.current = null;
961
- }
962
- old && old.dispose();
963
- };
976
+ // Single assignment
977
+ var SingleAssignmentDisposable = Rx.SingleAssignmentDisposable = function () {
978
+ this.isDisposed = false;
979
+ this.current = null;
980
+ };
981
+ SingleAssignmentDisposable.prototype.getDisposable = function () {
982
+ return this.current;
983
+ };
984
+ SingleAssignmentDisposable.prototype.setDisposable = function (value) {
985
+ if (this.current) { throw new Error('Disposable has already been assigned'); }
986
+ var shouldDispose = this.isDisposed;
987
+ !shouldDispose && (this.current = value);
988
+ shouldDispose && value && value.dispose();
989
+ };
990
+ SingleAssignmentDisposable.prototype.dispose = function () {
991
+ if (!this.isDisposed) {
992
+ this.isDisposed = true;
993
+ var old = this.current;
994
+ this.current = null;
995
+ }
996
+ old && old.dispose();
997
+ };
964
998
 
965
- return BooleanDisposable;
966
- }());
967
- var SerialDisposable = Rx.SerialDisposable = SingleAssignmentDisposable;
999
+ // Multiple assignment disposable
1000
+ var SerialDisposable = Rx.SerialDisposable = function () {
1001
+ this.isDisposed = false;
1002
+ this.current = null;
1003
+ };
1004
+ SerialDisposable.prototype.getDisposable = function () {
1005
+ return this.current;
1006
+ };
1007
+ SerialDisposable.prototype.setDisposable = function (value) {
1008
+ var shouldDispose = this.isDisposed;
1009
+ if (!shouldDispose) {
1010
+ var old = this.current;
1011
+ this.current = value;
1012
+ }
1013
+ old && old.dispose();
1014
+ shouldDispose && value && value.dispose();
1015
+ };
1016
+ SerialDisposable.prototype.dispose = function () {
1017
+ if (!this.isDisposed) {
1018
+ this.isDisposed = true;
1019
+ var old = this.current;
1020
+ this.current = null;
1021
+ }
1022
+ old && old.dispose();
1023
+ };
968
1024
 
969
1025
  /**
970
1026
  * Represents a disposable resource that only disposes its underlying disposable resource when all dependent disposable objects have been disposed.
@@ -1059,6 +1115,11 @@
1059
1115
  this._scheduleAbsolute = scheduleAbsolute;
1060
1116
  }
1061
1117
 
1118
+ /** Determines whether the given object is a scheduler */
1119
+ Scheduler.isScheduler = function (s) {
1120
+ return s instanceof Scheduler;
1121
+ }
1122
+
1062
1123
  function invokeAction(scheduler, action) {
1063
1124
  action();
1064
1125
  return disposableEmpty;
@@ -1143,12 +1204,14 @@
1143
1204
  return Scheduler;
1144
1205
  }());
1145
1206
 
1146
- var normalizeTime = Scheduler.normalize;
1207
+ var normalizeTime = Scheduler.normalize, isScheduler = Scheduler.isScheduler;
1147
1208
 
1148
1209
  (function (schedulerProto) {
1210
+
1149
1211
  function invokeRecImmediate(scheduler, pair) {
1150
- var state = pair.first, action = pair.second, group = new CompositeDisposable(),
1151
- recursiveAction = function (state1) {
1212
+ var state = pair[0], action = pair[1], group = new CompositeDisposable();
1213
+
1214
+ function recursiveAction(state1) {
1152
1215
  action(state1, function (state2) {
1153
1216
  var isAdded = false, isDone = false,
1154
1217
  d = scheduler.scheduleWithState(state2, function (scheduler1, state3) {
@@ -1165,14 +1228,15 @@
1165
1228
  isAdded = true;
1166
1229
  }
1167
1230
  });
1168
- };
1231
+ }
1232
+
1169
1233
  recursiveAction(state);
1170
1234
  return group;
1171
1235
  }
1172
1236
 
1173
1237
  function invokeRecDate(scheduler, pair, method) {
1174
- var state = pair.first, action = pair.second, group = new CompositeDisposable(),
1175
- recursiveAction = function (state1) {
1238
+ var state = pair[0], action = pair[1], group = new CompositeDisposable();
1239
+ function recursiveAction(state1) {
1176
1240
  action(state1, function (state2, dueTime1) {
1177
1241
  var isAdded = false, isDone = false,
1178
1242
  d = scheduler[method](state2, dueTime1, function (scheduler1, state3) {
@@ -1215,7 +1279,7 @@
1215
1279
  * @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
1216
1280
  */
1217
1281
  schedulerProto.scheduleRecursiveWithState = function (state, action) {
1218
- return this.scheduleWithState({ first: state, second: action }, invokeRecImmediate);
1282
+ return this.scheduleWithState([state, action], invokeRecImmediate);
1219
1283
  };
1220
1284
 
1221
1285
  /**
@@ -1236,7 +1300,7 @@
1236
1300
  * @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
1237
1301
  */
1238
1302
  schedulerProto.scheduleRecursiveWithRelativeAndState = function (state, dueTime, action) {
1239
- return this._scheduleRelative({ first: state, second: action }, dueTime, function (s, p) {
1303
+ return this._scheduleRelative([state, action], dueTime, function (s, p) {
1240
1304
  return invokeRecDate(s, p, 'scheduleWithRelativeAndState');
1241
1305
  });
1242
1306
  };
@@ -1259,7 +1323,7 @@
1259
1323
  * @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
1260
1324
  */
1261
1325
  schedulerProto.scheduleRecursiveWithAbsoluteAndState = function (state, dueTime, action) {
1262
- return this._scheduleAbsolute({ first: state, second: action }, dueTime, function (s, p) {
1326
+ return this._scheduleAbsolute([state, action], dueTime, function (s, p) {
1263
1327
  return invokeRecDate(s, p, 'scheduleWithAbsoluteAndState');
1264
1328
  });
1265
1329
  };
@@ -1285,26 +1349,17 @@
1285
1349
  * @returns {Disposable} The disposable object used to cancel the scheduled recurring action (best effort).
1286
1350
  */
1287
1351
  Scheduler.prototype.schedulePeriodicWithState = function(state, period, action) {
1288
- if (typeof root.setInterval === 'undefined') { throw new Error('Periodic scheduling not supported.'); }
1289
- var s = state;
1290
-
1291
- var id = root.setInterval(function () {
1292
- s = action(s);
1293
- }, period);
1294
-
1295
- return disposableCreate(function () {
1296
- root.clearInterval(id);
1297
- });
1352
+ if (typeof root.setInterval === 'undefined') { throw new NotSupportedError(); }
1353
+ period = normalizeTime(period);
1354
+ var s = state, id = root.setInterval(function () { s = action(s); }, period);
1355
+ return disposableCreate(function () { root.clearInterval(id); });
1298
1356
  };
1299
1357
 
1300
1358
  }(Scheduler.prototype));
1301
1359
 
1302
1360
  /** Gets a scheduler that schedules work immediately on the current thread. */
1303
1361
  var immediateScheduler = Scheduler.immediate = (function () {
1304
-
1305
1362
  function scheduleNow(state, action) { return action(this, state); }
1306
- function notSupported() { throw new Error('Not supported'); }
1307
-
1308
1363
  return new Scheduler(defaultNow, scheduleNow, notSupported, notSupported);
1309
1364
  }());
1310
1365
 
@@ -1314,12 +1369,10 @@
1314
1369
  var currentThreadScheduler = Scheduler.currentThread = (function () {
1315
1370
  var queue;
1316
1371
 
1317
- function runTrampoline (q) {
1318
- while (q.length > 0) {
1319
- var item = q.dequeue();
1320
- if (!item.isCancelled()) {
1321
- !item.isCancelled() && item.invoke();
1322
- }
1372
+ function runTrampoline () {
1373
+ while (queue.length > 0) {
1374
+ var item = queue.dequeue();
1375
+ !item.isCancelled() && item.invoke();
1323
1376
  }
1324
1377
  }
1325
1378
 
@@ -1329,27 +1382,18 @@
1329
1382
  if (!queue) {
1330
1383
  queue = new PriorityQueue(4);
1331
1384
  queue.enqueue(si);
1332
- try {
1333
- runTrampoline(queue);
1334
- } catch (e) {
1335
- throw e;
1336
- } finally {
1337
- queue = null;
1338
- }
1385
+
1386
+ var result = tryCatch(runTrampoline)();
1387
+ queue = null;
1388
+ if (result === errorObj) { return thrower(result.e); }
1339
1389
  } else {
1340
1390
  queue.enqueue(si);
1341
1391
  }
1342
1392
  return si.disposable;
1343
1393
  }
1344
1394
 
1345
- function notSupported() { throw new Error('Not supported'); }
1346
-
1347
1395
  var currentScheduler = new Scheduler(defaultNow, scheduleNow, notSupported, notSupported);
1348
-
1349
1396
  currentScheduler.scheduleRequired = function () { return !queue; };
1350
- currentScheduler.ensureTrampoline = function (action) {
1351
- if (!queue) { this.schedule(action); } else { action(); }
1352
- };
1353
1397
 
1354
1398
  return currentScheduler;
1355
1399
  }());
@@ -1383,19 +1427,20 @@
1383
1427
  return SchedulePeriodicRecursive;
1384
1428
  }());
1385
1429
 
1386
- var scheduleMethod, clearMethod = noop;
1430
+ var scheduleMethod, clearMethod;
1431
+
1387
1432
  var localTimer = (function () {
1388
1433
  var localSetTimeout, localClearTimeout = noop;
1389
- if ('WScript' in this) {
1434
+ if (!!root.setTimeout) {
1435
+ localSetTimeout = root.setTimeout;
1436
+ localClearTimeout = root.clearTimeout;
1437
+ } else if (!!root.WScript) {
1390
1438
  localSetTimeout = function (fn, time) {
1391
- WScript.Sleep(time);
1439
+ root.WScript.Sleep(time);
1392
1440
  fn();
1393
1441
  };
1394
- } else if (!!root.setTimeout) {
1395
- localSetTimeout = root.setTimeout;
1396
- localClearTimeout = root.clearTimeout;
1397
1442
  } else {
1398
- throw new Error('No concurrency detected!');
1443
+ throw new NotSupportedError();
1399
1444
  }
1400
1445
 
1401
1446
  return {
@@ -1408,6 +1453,27 @@
1408
1453
 
1409
1454
  (function () {
1410
1455
 
1456
+ var nextHandle = 1, tasksByHandle = {}, currentlyRunning = false;
1457
+
1458
+ clearMethod = function (handle) {
1459
+ delete tasksByHandle[handle];
1460
+ };
1461
+
1462
+ function runTask(handle) {
1463
+ if (currentlyRunning) {
1464
+ localSetTimeout(function () { runTask(handle) }, 0);
1465
+ } else {
1466
+ var task = tasksByHandle[handle];
1467
+ if (task) {
1468
+ currentlyRunning = true;
1469
+ var result = tryCatch(task)();
1470
+ clearMethod(handle);
1471
+ currentlyRunning = false;
1472
+ if (result === errorObj) { return thrower(result.e); }
1473
+ }
1474
+ }
1475
+ }
1476
+
1411
1477
  var reNative = RegExp('^' +
1412
1478
  String(toString)
1413
1479
  .replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
@@ -1415,15 +1481,12 @@
1415
1481
  );
1416
1482
 
1417
1483
  var setImmediate = typeof (setImmediate = freeGlobal && moduleExports && freeGlobal.setImmediate) == 'function' &&
1418
- !reNative.test(setImmediate) && setImmediate,
1419
- clearImmediate = typeof (clearImmediate = freeGlobal && moduleExports && freeGlobal.clearImmediate) == 'function' &&
1420
- !reNative.test(clearImmediate) && clearImmediate;
1484
+ !reNative.test(setImmediate) && setImmediate;
1421
1485
 
1422
1486
  function postMessageSupported () {
1423
1487
  // Ensure not in a worker
1424
1488
  if (!root.postMessage || root.importScripts) { return false; }
1425
- var isAsync = false,
1426
- oldHandler = root.onmessage;
1489
+ var isAsync = false, oldHandler = root.onmessage;
1427
1490
  // Test for async
1428
1491
  root.onmessage = function () { isAsync = true; };
1429
1492
  root.postMessage('', '*');
@@ -1433,85 +1496,96 @@
1433
1496
  }
1434
1497
 
1435
1498
  // Use in order, setImmediate, nextTick, postMessage, MessageChannel, script readystatechanged, setTimeout
1436
- if (typeof setImmediate === 'function') {
1437
- scheduleMethod = setImmediate;
1438
- clearMethod = clearImmediate;
1499
+ if (isFunction(setImmediate)) {
1500
+ scheduleMethod = function (action) {
1501
+ var id = nextHandle++;
1502
+ tasksByHandle[id] = action;
1503
+ setImmediate(function () { runTask(id); });
1504
+
1505
+ return id;
1506
+ };
1439
1507
  } else if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
1440
- scheduleMethod = process.nextTick;
1508
+ scheduleMethod = function (action) {
1509
+ var id = nextHandle++;
1510
+ tasksByHandle[id] = action;
1511
+ process.nextTick(function () { runTask(id); });
1512
+
1513
+ return id;
1514
+ };
1441
1515
  } else if (postMessageSupported()) {
1442
- var MSG_PREFIX = 'ms.rx.schedule' + Math.random(),
1443
- tasks = {},
1444
- taskId = 0;
1516
+ var MSG_PREFIX = 'ms.rx.schedule' + Math.random();
1445
1517
 
1446
- var onGlobalPostMessage = function (event) {
1518
+ function onGlobalPostMessage(event) {
1447
1519
  // Only if we're a match to avoid any other global events
1448
1520
  if (typeof event.data === 'string' && event.data.substring(0, MSG_PREFIX.length) === MSG_PREFIX) {
1449
- var handleId = event.data.substring(MSG_PREFIX.length),
1450
- action = tasks[handleId];
1451
- action();
1452
- delete tasks[handleId];
1521
+ runTask(event.data.substring(MSG_PREFIX.length));
1453
1522
  }
1454
1523
  }
1455
1524
 
1456
1525
  if (root.addEventListener) {
1457
1526
  root.addEventListener('message', onGlobalPostMessage, false);
1527
+ } else if (root.attachEvent) {
1528
+ root.attachEvent('onmessage', onGlobalPostMessage);
1458
1529
  } else {
1459
- root.attachEvent('onmessage', onGlobalPostMessage, false);
1530
+ root.onmessage = onGlobalPostMessage;
1460
1531
  }
1461
1532
 
1462
1533
  scheduleMethod = function (action) {
1463
- var currentId = taskId++;
1464
- tasks[currentId] = action;
1534
+ var id = nextHandle++;
1535
+ tasksByHandle[id] = action;
1465
1536
  root.postMessage(MSG_PREFIX + currentId, '*');
1537
+ return id;
1466
1538
  };
1467
1539
  } else if (!!root.MessageChannel) {
1468
- var channel = new root.MessageChannel(),
1469
- channelTasks = {},
1470
- channelTaskId = 0;
1540
+ var channel = new root.MessageChannel();
1471
1541
 
1472
- channel.port1.onmessage = function (event) {
1473
- var id = event.data,
1474
- action = channelTasks[id];
1475
- action();
1476
- delete channelTasks[id];
1477
- };
1542
+ channel.port1.onmessage = function (e) { runTask(e.data); };
1478
1543
 
1479
1544
  scheduleMethod = function (action) {
1480
- var id = channelTaskId++;
1481
- channelTasks[id] = action;
1545
+ var id = nextHandle++;
1546
+ tasksByHandle[id] = action;
1482
1547
  channel.port2.postMessage(id);
1548
+ return id;
1483
1549
  };
1484
1550
  } else if ('document' in root && 'onreadystatechange' in root.document.createElement('script')) {
1485
1551
 
1486
1552
  scheduleMethod = function (action) {
1487
1553
  var scriptElement = root.document.createElement('script');
1554
+ var id = nextHandle++;
1555
+ tasksByHandle[id] = action;
1556
+
1488
1557
  scriptElement.onreadystatechange = function () {
1489
- action();
1558
+ runTask(id);
1490
1559
  scriptElement.onreadystatechange = null;
1491
1560
  scriptElement.parentNode.removeChild(scriptElement);
1492
1561
  scriptElement = null;
1493
1562
  };
1494
1563
  root.document.documentElement.appendChild(scriptElement);
1564
+ return id;
1495
1565
  };
1496
1566
 
1497
1567
  } else {
1498
- scheduleMethod = function (action) { return localSetTimeout(action, 0); };
1499
- clearMethod = localClearTimeout;
1568
+ scheduleMethod = function (action) {
1569
+ var id = nextHandle++;
1570
+ tasksByHandle[id] = action;
1571
+ localSetTimeout(function () {
1572
+ runTask(id);
1573
+ }, 0);
1574
+
1575
+ return id;
1576
+ };
1500
1577
  }
1501
1578
  }());
1502
1579
 
1503
1580
  /**
1504
1581
  * Gets a scheduler that schedules work via a timed callback based upon platform.
1505
1582
  */
1506
- var timeoutScheduler = Scheduler.timeout = (function () {
1583
+ var timeoutScheduler = Scheduler.timeout = Scheduler['default'] = (function () {
1507
1584
 
1508
1585
  function scheduleNow(state, action) {
1509
- var scheduler = this,
1510
- disposable = new SingleAssignmentDisposable();
1586
+ var scheduler = this, disposable = new SingleAssignmentDisposable();
1511
1587
  var id = scheduleMethod(function () {
1512
- if (!disposable.isDisposed) {
1513
- disposable.setDisposable(action(scheduler, state));
1514
- }
1588
+ !disposable.isDisposed && disposable.setDisposable(action(scheduler, state));
1515
1589
  });
1516
1590
  return new CompositeDisposable(disposable, disposableCreate(function () {
1517
1591
  clearMethod(id);
@@ -1519,16 +1593,10 @@
1519
1593
  }
1520
1594
 
1521
1595
  function scheduleRelative(state, dueTime, action) {
1522
- var scheduler = this,
1523
- dt = Scheduler.normalize(dueTime);
1524
- if (dt === 0) {
1525
- return scheduler.scheduleWithState(state, action);
1526
- }
1527
- var disposable = new SingleAssignmentDisposable();
1596
+ var scheduler = this, dt = Scheduler.normalize(dueTime), disposable = new SingleAssignmentDisposable();
1597
+ if (dt === 0) { return scheduler.scheduleWithState(state, action); }
1528
1598
  var id = localSetTimeout(function () {
1529
- if (!disposable.isDisposed) {
1530
- disposable.setDisposable(action(scheduler, state));
1531
- }
1599
+ !disposable.isDisposed && disposable.setDisposable(action(scheduler, state));
1532
1600
  }, dt);
1533
1601
  return new CompositeDisposable(disposable, disposableCreate(function () {
1534
1602
  localClearTimeout(id);
@@ -1546,9 +1614,13 @@
1546
1614
  * Represents a notification to an observer.
1547
1615
  */
1548
1616
  var Notification = Rx.Notification = (function () {
1549
- function Notification(kind, hasValue) {
1550
- this.hasValue = hasValue == null ? false : hasValue;
1617
+ function Notification(kind, value, exception, accept, acceptObservable, toString) {
1551
1618
  this.kind = kind;
1619
+ this.value = value;
1620
+ this.exception = exception;
1621
+ this._accept = accept;
1622
+ this._acceptObservable = acceptObservable;
1623
+ this.toString = toString;
1552
1624
  }
1553
1625
 
1554
1626
  /**
@@ -1574,10 +1646,10 @@
1574
1646
  * @returns {Observable} The observable sequence that surfaces the behavior of the notification upon subscription.
1575
1647
  */
1576
1648
  Notification.prototype.toObservable = function (scheduler) {
1577
- var notification = this;
1649
+ var self = this;
1578
1650
  isScheduler(scheduler) || (scheduler = immediateScheduler);
1579
1651
  return new AnonymousObservable(function (observer) {
1580
- return scheduler.schedule(function () {
1652
+ return scheduler.scheduleWithState(self, function (_, notification) {
1581
1653
  notification._acceptObservable(observer);
1582
1654
  notification.kind === 'N' && observer.onCompleted();
1583
1655
  });
@@ -1593,18 +1665,12 @@
1593
1665
  * @returns {Notification} The OnNext notification containing the value.
1594
1666
  */
1595
1667
  var notificationCreateOnNext = Notification.createOnNext = (function () {
1596
-
1597
- function _accept (onNext) { return onNext(this.value); }
1668
+ function _accept(onNext) { return onNext(this.value); }
1598
1669
  function _acceptObservable(observer) { return observer.onNext(this.value); }
1599
- function toString () { return 'OnNext(' + this.value + ')'; }
1670
+ function toString() { return 'OnNext(' + this.value + ')'; }
1600
1671
 
1601
1672
  return function (value) {
1602
- var notification = new Notification('N', true);
1603
- notification.value = value;
1604
- notification._accept = _accept;
1605
- notification._acceptObservable = _acceptObservable;
1606
- notification.toString = toString;
1607
- return notification;
1673
+ return new Notification('N', value, null, _accept, _acceptObservable, toString);
1608
1674
  };
1609
1675
  }());
1610
1676
 
@@ -1614,18 +1680,12 @@
1614
1680
  * @returns {Notification} The OnError notification containing the exception.
1615
1681
  */
1616
1682
  var notificationCreateOnError = Notification.createOnError = (function () {
1617
-
1618
1683
  function _accept (onNext, onError) { return onError(this.exception); }
1619
1684
  function _acceptObservable(observer) { return observer.onError(this.exception); }
1620
1685
  function toString () { return 'OnError(' + this.exception + ')'; }
1621
1686
 
1622
1687
  return function (e) {
1623
- var notification = new Notification('E');
1624
- notification.exception = e;
1625
- notification._accept = _accept;
1626
- notification._acceptObservable = _acceptObservable;
1627
- notification.toString = toString;
1628
- return notification;
1688
+ return new Notification('E', null, e, _accept, _acceptObservable, toString);
1629
1689
  };
1630
1690
  }());
1631
1691
 
@@ -1634,17 +1694,12 @@
1634
1694
  * @returns {Notification} The OnCompleted notification.
1635
1695
  */
1636
1696
  var notificationCreateOnCompleted = Notification.createOnCompleted = (function () {
1637
-
1638
1697
  function _accept (onNext, onError, onCompleted) { return onCompleted(); }
1639
1698
  function _acceptObservable(observer) { return observer.onCompleted(); }
1640
1699
  function toString () { return 'OnCompleted()'; }
1641
1700
 
1642
1701
  return function () {
1643
- var notification = new Notification('C');
1644
- notification._accept = _accept;
1645
- notification._acceptObservable = _acceptObservable;
1646
- notification.toString = toString;
1647
- return notification;
1702
+ return new Notification('C', null, null, _accept, _acceptObservable, toString);
1648
1703
  };
1649
1704
  }());
1650
1705
 
@@ -1864,10 +1919,6 @@
1864
1919
  __super__.call(this);
1865
1920
  }
1866
1921
 
1867
- function notImplemented() {
1868
- throw new Error('Method not implemented');
1869
- }
1870
-
1871
1922
  // Must be implemented by other observers
1872
1923
  AbstractObserver.prototype.next = notImplemented;
1873
1924
  AbstractObserver.prototype.error = notImplemented;
@@ -2047,25 +2098,21 @@
2047
2098
  })();
2048
2099
 
2049
2100
  var ObservableBase = Rx.ObservableBase = (function (__super__) {
2101
+ inherits(ObservableBase, __super__);
2050
2102
 
2051
- inherits(ObservableBase, __super__);
2052
-
2053
- // Fix subscriber to check for undefined or function returned to decorate as Disposable
2054
- function fixSubscriber(subscriber) {
2055
- if (subscriber && typeof subscriber.dispose === 'function') { return subscriber; }
2056
-
2057
- return typeof subscriber === 'function' ?
2058
- disposableCreate(subscriber) :
2059
- disposableEmpty;
2103
+ function fixSubscriber(subscriber) {
2104
+ return subscriber && isFunction(subscriber.dispose) ? subscriber :
2105
+ isFunction(subscriber) ? disposableCreate(subscriber) : disposableEmpty;
2060
2106
  }
2061
2107
 
2062
2108
  function setDisposable(s, state) {
2063
2109
  var ado = state[0], self = state[1];
2064
- try {
2065
- ado.setDisposable(fixSubscriber(self.subscribeCore(ado)));
2066
- } catch (e) {
2067
- if (!ado.fail(e)) { throw e; }
2110
+ var sub = tryCatch(self.subscribeCore).call(self, ado);
2111
+
2112
+ if (sub === errorObj) {
2113
+ if(!ado.fail(errorObj.e)) { return thrower(errorObj.e); }
2068
2114
  }
2115
+ ado.setDisposable(fixSubscriber(sub));
2069
2116
  }
2070
2117
 
2071
2118
  function subscribe(observer) {
@@ -2076,7 +2123,6 @@
2076
2123
  } else {
2077
2124
  setDisposable(null, state);
2078
2125
  }
2079
-
2080
2126
  return ado;
2081
2127
  }
2082
2128
 
@@ -2084,12 +2130,9 @@
2084
2130
  __super__.call(this, subscribe);
2085
2131
  }
2086
2132
 
2087
- ObservableBase.prototype.subscribeCore = function(observer) {
2088
- throw new Error('Not implemeneted');
2089
- }
2133
+ ObservableBase.prototype.subscribeCore = notImplemented;
2090
2134
 
2091
2135
  return ObservableBase;
2092
-
2093
2136
  }(Observable));
2094
2137
 
2095
2138
  var ScheduledObserver = Rx.internals.ScheduledObserver = (function (__super__) {
@@ -2241,6 +2284,34 @@
2241
2284
  });
2242
2285
  };
2243
2286
 
2287
+ var EmptyObservable = (function(__super__) {
2288
+ inherits(EmptyObservable, __super__);
2289
+ function EmptyObservable(scheduler) {
2290
+ this.scheduler = scheduler;
2291
+ __super__.call(this);
2292
+ }
2293
+
2294
+ EmptyObservable.prototype.subscribeCore = function (observer) {
2295
+ var sink = new EmptySink(observer, this);
2296
+ return sink.run();
2297
+ };
2298
+
2299
+ function EmptySink(observer, parent) {
2300
+ this.observer = observer;
2301
+ this.parent = parent;
2302
+ }
2303
+
2304
+ function scheduleItem(s, state) {
2305
+ state.onCompleted();
2306
+ }
2307
+
2308
+ EmptySink.prototype.run = function () {
2309
+ return this.parent.scheduler.scheduleWithState(this.observer, scheduleItem);
2310
+ };
2311
+
2312
+ return EmptyObservable;
2313
+ }(ObservableBase));
2314
+
2244
2315
  /**
2245
2316
  * Returns an empty observable sequence, using the specified scheduler to send out the single OnCompleted message.
2246
2317
  *
@@ -2252,11 +2323,7 @@
2252
2323
  */
2253
2324
  var observableEmpty = Observable.empty = function (scheduler) {
2254
2325
  isScheduler(scheduler) || (scheduler = immediateScheduler);
2255
- return new AnonymousObservable(function (observer) {
2256
- return scheduler.schedule(function () {
2257
- observer.onCompleted();
2258
- });
2259
- });
2326
+ return new EmptyObservable(scheduler);
2260
2327
  };
2261
2328
 
2262
2329
  var FromObservable = (function(__super__) {
@@ -2428,7 +2495,7 @@
2428
2495
  inherits(FromArrayObservable, __super__);
2429
2496
  function FromArrayObservable(args, scheduler) {
2430
2497
  this.args = args;
2431
- this.scheduler = scheduler || currentThreadScheduler;
2498
+ this.scheduler = scheduler;
2432
2499
  __super__.call(this);
2433
2500
  }
2434
2501
 
@@ -2466,20 +2533,33 @@
2466
2533
  * @returns {Observable} The observable sequence whose elements are pulled from the given enumerable sequence.
2467
2534
  */
2468
2535
  var observableFromArray = Observable.fromArray = function (array, scheduler) {
2536
+ isScheduler(scheduler) || (scheduler = currentThreadScheduler);
2469
2537
  return new FromArrayObservable(array, scheduler)
2470
2538
  };
2471
2539
 
2540
+ var NeverObservable = (function(__super__) {
2541
+ inherits(NeverObservable, __super__);
2542
+ function NeverObservable() {
2543
+ __super__.call(this);
2544
+ }
2545
+
2546
+ NeverObservable.prototype.subscribeCore = function (observer) {
2547
+ return disposableEmpty;
2548
+ };
2549
+
2550
+ return NeverObservable;
2551
+ }(ObservableBase));
2552
+
2472
2553
  /**
2473
- * Returns a non-terminating observable sequence, which can be used to denote an infinite duration (e.g. when using reactive joins).
2554
+ * Returns a non-terminating observable sequence, which can be used to denote an infinite duration (e.g. when using reactive joins).
2474
2555
  * @returns {Observable} An observable sequence whose observers will never get called.
2475
2556
  */
2476
2557
  var observableNever = Observable.never = function () {
2477
- return new AnonymousObservable(function () {
2478
- return disposableEmpty;
2479
- });
2558
+ return new NeverObservable();
2480
2559
  };
2481
2560
 
2482
2561
  function observableOf (scheduler, array) {
2562
+ isScheduler(scheduler) || (scheduler = currentThreadScheduler);
2483
2563
  return new FromArrayObservable(array, scheduler);
2484
2564
  }
2485
2565
 
@@ -2490,7 +2570,7 @@
2490
2570
  Observable.of = function () {
2491
2571
  var len = arguments.length, args = new Array(len);
2492
2572
  for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
2493
- return new FromArrayObservable(args);
2573
+ return new FromArrayObservable(args, currentThreadScheduler);
2494
2574
  };
2495
2575
 
2496
2576
  /**
@@ -2504,6 +2584,43 @@
2504
2584
  return new FromArrayObservable(args, scheduler);
2505
2585
  };
2506
2586
 
2587
+ var PairsObservable = (function(__super__) {
2588
+ inherits(PairsObservable, __super__);
2589
+ function PairsObservable(obj, scheduler) {
2590
+ this.obj = obj;
2591
+ this.keys = Object.keys(obj);
2592
+ this.scheduler = scheduler;
2593
+ __super__.call(this);
2594
+ }
2595
+
2596
+ PairsObservable.prototype.subscribeCore = function (observer) {
2597
+ var sink = new PairsSink(observer, this);
2598
+ return sink.run();
2599
+ };
2600
+
2601
+ return PairsObservable;
2602
+ }(ObservableBase));
2603
+
2604
+ function PairsSink(observer, parent) {
2605
+ this.observer = observer;
2606
+ this.parent = parent;
2607
+ }
2608
+
2609
+ PairsSink.prototype.run = function () {
2610
+ var observer = this.observer, obj = this.parent.obj, keys = this.parent.keys, len = keys.length;
2611
+ function loopRecursive(i, recurse) {
2612
+ if (i < len) {
2613
+ var key = keys[i];
2614
+ observer.onNext([key, obj[key]]);
2615
+ recurse(i + 1);
2616
+ } else {
2617
+ observer.onCompleted();
2618
+ }
2619
+ }
2620
+
2621
+ return this.parent.scheduler.scheduleRecursiveWithState(0, loopRecursive);
2622
+ };
2623
+
2507
2624
  /**
2508
2625
  * Convert an object into an observable sequence of [key, value] pairs.
2509
2626
  * @param {Object} obj The object to inspect.
@@ -2511,19 +2628,8 @@
2511
2628
  * @returns {Observable} An observable sequence of [key, value] pairs from the object.
2512
2629
  */
2513
2630
  Observable.pairs = function (obj, scheduler) {
2514
- scheduler || (scheduler = Rx.Scheduler.currentThread);
2515
- return new AnonymousObservable(function (observer) {
2516
- var keys = Object.keys(obj), len = keys.length;
2517
- return scheduler.scheduleRecursiveWithState(0, function (idx, self) {
2518
- if (idx < len) {
2519
- var key = keys[idx];
2520
- observer.onNext([key, obj[key]]);
2521
- self(idx + 1);
2522
- } else {
2523
- observer.onCompleted();
2524
- }
2525
- });
2526
- });
2631
+ scheduler || (scheduler = currentThreadScheduler);
2632
+ return new PairsObservable(obj, scheduler);
2527
2633
  };
2528
2634
 
2529
2635
  var RangeObservable = (function(__super__) {
@@ -2578,14 +2684,44 @@
2578
2684
  return new RangeObservable(start, count, scheduler);
2579
2685
  };
2580
2686
 
2687
+ var RepeatObservable = (function(__super__) {
2688
+ inherits(RepeatObservable, __super__);
2689
+ function RepeatObservable(value, repeatCount, scheduler) {
2690
+ this.value = value;
2691
+ this.repeatCount = repeatCount == null ? -1 : repeatCount;
2692
+ this.scheduler = scheduler;
2693
+ __super__.call(this);
2694
+ }
2695
+
2696
+ RepeatObservable.prototype.subscribeCore = function (observer) {
2697
+ var sink = new RepeatSink(observer, this);
2698
+ return sink.run();
2699
+ };
2700
+
2701
+ return RepeatObservable;
2702
+ }(ObservableBase));
2703
+
2704
+ function RepeatSink(observer, parent) {
2705
+ this.observer = observer;
2706
+ this.parent = parent;
2707
+ }
2708
+
2709
+ RepeatSink.prototype.run = function () {
2710
+ var observer = this.observer, value = this.parent.value;
2711
+ function loopRecursive(i, recurse) {
2712
+ if (i === -1 || i > 0) {
2713
+ observer.onNext(value);
2714
+ i > 0 && i--;
2715
+ }
2716
+ if (i === 0) { return observer.onCompleted(); }
2717
+ recurse(i);
2718
+ }
2719
+
2720
+ return this.parent.scheduler.scheduleRecursiveWithState(this.parent.repeatCount, loopRecursive);
2721
+ };
2722
+
2581
2723
  /**
2582
2724
  * Generates an observable sequence that repeats the given element the specified number of times, using the specified scheduler to send out observer messages.
2583
- *
2584
- * @example
2585
- * var res = Rx.Observable.repeat(42);
2586
- * var res = Rx.Observable.repeat(42, 4);
2587
- * 3 - res = Rx.Observable.repeat(42, 4, Rx.Scheduler.timeout);
2588
- * 4 - res = Rx.Observable.repeat(42, null, Rx.Scheduler.timeout);
2589
2725
  * @param {Mixed} value Element to repeat.
2590
2726
  * @param {Number} repeatCount [Optiona] Number of times to repeat the element. If not specified, repeats indefinitely.
2591
2727
  * @param {Scheduler} scheduler Scheduler to run the producer loop on. If not specified, defaults to Scheduler.immediate.
@@ -2593,31 +2729,81 @@
2593
2729
  */
2594
2730
  Observable.repeat = function (value, repeatCount, scheduler) {
2595
2731
  isScheduler(scheduler) || (scheduler = currentThreadScheduler);
2596
- return observableReturn(value, scheduler).repeat(repeatCount == null ? -1 : repeatCount);
2732
+ return new RepeatObservable(value, repeatCount, scheduler);
2597
2733
  };
2598
2734
 
2735
+ var JustObservable = (function(__super__) {
2736
+ inherits(JustObservable, __super__);
2737
+ function JustObservable(value, scheduler) {
2738
+ this.value = value;
2739
+ this.scheduler = scheduler;
2740
+ __super__.call(this);
2741
+ }
2742
+
2743
+ JustObservable.prototype.subscribeCore = function (observer) {
2744
+ var sink = new JustSink(observer, this);
2745
+ return sink.run();
2746
+ };
2747
+
2748
+ function JustSink(observer, parent) {
2749
+ this.observer = observer;
2750
+ this.parent = parent;
2751
+ }
2752
+
2753
+ function scheduleItem(s, state) {
2754
+ var value = state[0], observer = state[1];
2755
+ observer.onNext(value);
2756
+ observer.onCompleted();
2757
+ }
2758
+
2759
+ JustSink.prototype.run = function () {
2760
+ return this.parent.scheduler.scheduleWithState([this.parent.value, this.observer], scheduleItem);
2761
+ };
2762
+
2763
+ return JustObservable;
2764
+ }(ObservableBase));
2765
+
2599
2766
  /**
2600
2767
  * Returns an observable sequence that contains a single element, using the specified scheduler to send out observer messages.
2601
- * There is an alias called 'just', and 'returnValue' for browsers <IE9.
2768
+ * There is an alias called 'just' or browsers <IE9.
2602
2769
  * @param {Mixed} value Single element in the resulting observable sequence.
2603
2770
  * @param {Scheduler} scheduler Scheduler to send the single element on. If not specified, defaults to Scheduler.immediate.
2604
2771
  * @returns {Observable} An observable sequence containing the single specified element.
2605
2772
  */
2606
- var observableReturn = Observable['return'] = Observable.just = function (value, scheduler) {
2773
+ var observableReturn = Observable['return'] = Observable.just = Observable.returnValue = function (value, scheduler) {
2607
2774
  isScheduler(scheduler) || (scheduler = immediateScheduler);
2608
- return new AnonymousObservable(function (observer) {
2609
- return scheduler.schedule(function () {
2610
- observer.onNext(value);
2611
- observer.onCompleted();
2612
- });
2613
- });
2775
+ return new JustObservable(value, scheduler);
2614
2776
  };
2615
2777
 
2616
- /** @deprecated use return or just */
2617
- Observable.returnValue = function () {
2618
- //deprecate('returnValue', 'return or just');
2619
- return observableReturn.apply(null, arguments);
2620
- };
2778
+ var ThrowObservable = (function(__super__) {
2779
+ inherits(ThrowObservable, __super__);
2780
+ function ThrowObservable(error, scheduler) {
2781
+ this.error = error;
2782
+ this.scheduler = scheduler;
2783
+ __super__.call(this);
2784
+ }
2785
+
2786
+ ThrowObservable.prototype.subscribeCore = function (observer) {
2787
+ var sink = new ThrowSink(observer, this);
2788
+ return sink.run();
2789
+ };
2790
+
2791
+ function ThrowSink(observer, parent) {
2792
+ this.observer = observer;
2793
+ this.parent = parent;
2794
+ }
2795
+
2796
+ function scheduleItem(s, state) {
2797
+ var error = state[0], observer = state[1];
2798
+ observer.onError(error);
2799
+ }
2800
+
2801
+ ThrowSink.prototype.run = function () {
2802
+ return this.parent.scheduler.scheduleWithState([this.parent.error, this.observer], scheduleItem);
2803
+ };
2804
+
2805
+ return ThrowObservable;
2806
+ }(ObservableBase));
2621
2807
 
2622
2808
  /**
2623
2809
  * Returns an observable sequence that terminates with an exception, using the specified scheduler to send out the single onError message.
@@ -2626,19 +2812,9 @@
2626
2812
  * @param {Scheduler} scheduler Scheduler to send the exceptional termination call on. If not specified, defaults to Scheduler.immediate.
2627
2813
  * @returns {Observable} The observable sequence that terminates exceptionally with the specified exception object.
2628
2814
  */
2629
- var observableThrow = Observable['throw'] = Observable.throwError = function (error, scheduler) {
2815
+ var observableThrow = Observable['throw'] = Observable.throwError = Observable.throwException = function (error, scheduler) {
2630
2816
  isScheduler(scheduler) || (scheduler = immediateScheduler);
2631
- return new AnonymousObservable(function (observer) {
2632
- return scheduler.schedule(function () {
2633
- observer.onError(error);
2634
- });
2635
- });
2636
- };
2637
-
2638
- /** @deprecated use #some instead */
2639
- Observable.throwException = function () {
2640
- //deprecate('throwException', 'throwError');
2641
- return Observable.throwError.apply(null, arguments);
2817
+ return new ThrowObservable(error, scheduler);
2642
2818
  };
2643
2819
 
2644
2820
  function observableCatchHandler(source, handler) {
@@ -2723,24 +2899,23 @@
2723
2899
  var len = arguments.length, args = new Array(len);
2724
2900
  for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
2725
2901
  var resultSelector = args.pop();
2726
- len--;
2727
2902
  Array.isArray(args[0]) && (args = args[0]);
2728
2903
 
2729
2904
  return new AnonymousObservable(function (o) {
2730
- var falseFactory = function () { return false; },
2731
- hasValue = arrayInitialize(len, falseFactory),
2905
+ var n = args.length,
2906
+ falseFactory = function () { return false; },
2907
+ hasValue = arrayInitialize(n, falseFactory),
2732
2908
  hasValueAll = false,
2733
- isDone = arrayInitialize(len, falseFactory),
2734
- values = new Array(len);
2909
+ isDone = arrayInitialize(n, falseFactory),
2910
+ values = new Array(n);
2735
2911
 
2736
2912
  function next(i) {
2737
2913
  hasValue[i] = true;
2738
2914
  if (hasValueAll || (hasValueAll = hasValue.every(identity))) {
2739
2915
  try {
2740
2916
  var res = resultSelector.apply(null, values);
2741
- } catch (ex) {
2742
- o.onError(ex);
2743
- return;
2917
+ } catch (e) {
2918
+ return o.onError(e);
2744
2919
  }
2745
2920
  o.onNext(res);
2746
2921
  } else if (isDone.filter(function (x, j) { return j !== i; }).every(identity)) {
@@ -2753,8 +2928,8 @@
2753
2928
  isDone.every(identity) && o.onCompleted();
2754
2929
  }
2755
2930
 
2756
- var subscriptions = new Array(len);
2757
- for (var idx = 0; idx < len; idx++) {
2931
+ var subscriptions = new Array(n);
2932
+ for (var idx = 0; idx < n; idx++) {
2758
2933
  (function (i) {
2759
2934
  var source = args[i], sad = new SingleAssignmentDisposable();
2760
2935
  isPromise(source) && (source = observableFromPromise(source));
@@ -2807,52 +2982,131 @@
2807
2982
  return this.merge(1);
2808
2983
  };
2809
2984
 
2810
- /**
2811
- * Merges an observable sequence of observable sequences into an observable sequence, limiting the number of concurrent subscriptions to inner sequences.
2812
- * Or merges two observable sequences into a single observable sequence.
2813
- *
2814
- * @example
2815
- * 1 - merged = sources.merge(1);
2816
- * 2 - merged = source.merge(otherSource);
2817
- * @param {Mixed} [maxConcurrentOrOther] Maximum number of inner observable sequences being subscribed to concurrently or the second observable sequence.
2818
- * @returns {Observable} The observable sequence that merges the elements of the inner sequences.
2819
- */
2820
- observableProto.merge = function (maxConcurrentOrOther) {
2821
- if (typeof maxConcurrentOrOther !== 'number') { return observableMerge(this, maxConcurrentOrOther); }
2822
- var sources = this;
2823
- return new AnonymousObservable(function (o) {
2824
- var activeCount = 0, group = new CompositeDisposable(), isStopped = false, q = [];
2985
+ var MergeObservable = (function (__super__) {
2986
+ inherits(MergeObservable, __super__);
2987
+
2988
+ function MergeObservable(source, maxConcurrent) {
2989
+ this.source = source;
2990
+ this.maxConcurrent = maxConcurrent;
2991
+ __super__.call(this);
2992
+ }
2825
2993
 
2826
- function subscribe(xs) {
2827
- var subscription = new SingleAssignmentDisposable();
2828
- group.add(subscription);
2994
+ MergeObservable.prototype.subscribeCore = function(observer) {
2995
+ var g = new CompositeDisposable();
2996
+ g.add(this.source.subscribe(new MergeObserver(observer, this.maxConcurrent, g)));
2997
+ return g;
2998
+ };
2829
2999
 
2830
- // Check for promises support
2831
- isPromise(xs) && (xs = observableFromPromise(xs));
3000
+ return MergeObservable;
2832
3001
 
2833
- subscription.setDisposable(xs.subscribe(function (x) { o.onNext(x); }, function (e) { o.onError(e); }, function () {
2834
- group.remove(subscription);
2835
- if (q.length > 0) {
2836
- subscribe(q.shift());
3002
+ }(ObservableBase));
3003
+
3004
+ var MergeObserver = (function () {
3005
+ function MergeObserver(o, max, g) {
3006
+ this.o = o;
3007
+ this.max = max;
3008
+ this.g = g;
3009
+ this.done = false;
3010
+ this.q = [];
3011
+ this.activeCount = 0;
3012
+ this.isStopped = false;
3013
+ }
3014
+ MergeObserver.prototype.handleSubscribe = function (xs) {
3015
+ var sad = new SingleAssignmentDisposable();
3016
+ this.g.add(sad);
3017
+ isPromise(xs) && (xs = observableFromPromise(xs));
3018
+ sad.setDisposable(xs.subscribe(new InnerObserver(this, sad)));
3019
+ };
3020
+ MergeObserver.prototype.onNext = function (innerSource) {
3021
+ if (this.isStopped) { return; }
3022
+ if(this.activeCount < this.max) {
3023
+ this.activeCount++;
3024
+ this.handleSubscribe(innerSource);
3025
+ } else {
3026
+ this.q.push(innerSource);
3027
+ }
3028
+ };
3029
+ MergeObserver.prototype.onError = function (e) {
3030
+ if (!this.isStopped) {
3031
+ this.isStopped = true;
3032
+ this.o.onError(e);
3033
+ }
3034
+ };
3035
+ MergeObserver.prototype.onCompleted = function () {
3036
+ if (!this.isStopped) {
3037
+ this.isStopped = true;
3038
+ this.done = true;
3039
+ this.activeCount === 0 && this.o.onCompleted();
3040
+ }
3041
+ };
3042
+ MergeObserver.prototype.dispose = function() { this.isStopped = true; };
3043
+ MergeObserver.prototype.fail = function (e) {
3044
+ if (!this.isStopped) {
3045
+ this.isStopped = true;
3046
+ this.o.onError(e);
3047
+ return true;
3048
+ }
3049
+
3050
+ return false;
3051
+ };
3052
+
3053
+ function InnerObserver(parent, sad) {
3054
+ this.parent = parent;
3055
+ this.sad = sad;
3056
+ this.isStopped = false;
3057
+ }
3058
+ InnerObserver.prototype.onNext = function (x) { if(!this.isStopped) { this.parent.o.onNext(x); } };
3059
+ InnerObserver.prototype.onError = function (e) {
3060
+ if (!this.isStopped) {
3061
+ this.isStopped = true;
3062
+ this.parent.o.onError(e);
3063
+ }
3064
+ };
3065
+ InnerObserver.prototype.onCompleted = function () {
3066
+ if(!this.isStopped) {
3067
+ this.isStopped = true;
3068
+ var parent = this.parent;
3069
+ parent.g.remove(this.sad);
3070
+ if (parent.q.length > 0) {
3071
+ parent.handleSubscribe(parent.q.shift());
2837
3072
  } else {
2838
- activeCount--;
2839
- isStopped && activeCount === 0 && o.onCompleted();
3073
+ parent.activeCount--;
3074
+ parent.done && parent.activeCount === 0 && parent.o.onCompleted();
2840
3075
  }
2841
- }));
2842
- }
2843
- group.add(sources.subscribe(function (innerSource) {
2844
- if (activeCount < maxConcurrentOrOther) {
2845
- activeCount++;
2846
- subscribe(innerSource);
2847
- } else {
2848
- q.push(innerSource);
2849
3076
  }
2850
- }, function (e) { o.onError(e); }, function () {
2851
- isStopped = true;
2852
- activeCount === 0 && o.onCompleted();
2853
- }));
2854
- return group;
2855
- }, sources);
3077
+ };
3078
+ InnerObserver.prototype.dispose = function() { this.isStopped = true; };
3079
+ InnerObserver.prototype.fail = function (e) {
3080
+ if (!this.isStopped) {
3081
+ this.isStopped = true;
3082
+ this.parent.o.onError(e);
3083
+ return true;
3084
+ }
3085
+
3086
+ return false;
3087
+ };
3088
+
3089
+ return MergeObserver;
3090
+ }());
3091
+
3092
+
3093
+
3094
+
3095
+
3096
+ /**
3097
+ * Merges an observable sequence of observable sequences into an observable sequence, limiting the number of concurrent subscriptions to inner sequences.
3098
+ * Or merges two observable sequences into a single observable sequence.
3099
+ *
3100
+ * @example
3101
+ * 1 - merged = sources.merge(1);
3102
+ * 2 - merged = source.merge(otherSource);
3103
+ * @param {Mixed} [maxConcurrentOrOther] Maximum number of inner observable sequences being subscribed to concurrently or the second observable sequence.
3104
+ * @returns {Observable} The observable sequence that merges the elements of the inner sequences.
3105
+ */
3106
+ observableProto.merge = function (maxConcurrentOrOther) {
3107
+ return typeof maxConcurrentOrOther !== 'number' ?
3108
+ observableMerge(this, maxConcurrentOrOther) :
3109
+ new MergeObservable(this, maxConcurrentOrOther);
2856
3110
  };
2857
3111
 
2858
3112
  /**
@@ -2878,35 +3132,188 @@
2878
3132
  return observableOf(scheduler, sources).mergeAll();
2879
3133
  };
2880
3134
 
3135
+ var MergeAllObservable = (function (__super__) {
3136
+ inherits(MergeAllObservable, __super__);
3137
+
3138
+ function MergeAllObservable(source) {
3139
+ this.source = source;
3140
+ __super__.call(this);
3141
+ }
3142
+
3143
+ MergeAllObservable.prototype.subscribeCore = function (observer) {
3144
+ var g = new CompositeDisposable(), m = new SingleAssignmentDisposable();
3145
+ g.add(m);
3146
+ m.setDisposable(this.source.subscribe(new MergeAllObserver(observer, g)));
3147
+ return g;
3148
+ };
3149
+
3150
+ return MergeAllObservable;
3151
+ }(ObservableBase));
3152
+
3153
+ var MergeAllObserver = (function() {
3154
+
3155
+ function MergeAllObserver(o, g) {
3156
+ this.o = o;
3157
+ this.g = g;
3158
+ this.isStopped = false;
3159
+ this.done = false;
3160
+ }
3161
+ MergeAllObserver.prototype.onNext = function(innerSource) {
3162
+ if(this.isStopped) { return; }
3163
+ var sad = new SingleAssignmentDisposable();
3164
+ this.g.add(sad);
3165
+
3166
+ isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
3167
+
3168
+ sad.setDisposable(innerSource.subscribe(new InnerObserver(this, this.g, sad)));
3169
+ };
3170
+ MergeAllObserver.prototype.onError = function (e) {
3171
+ if(!this.isStopped) {
3172
+ this.isStopped = true;
3173
+ this.o.onError(e);
3174
+ }
3175
+ };
3176
+ MergeAllObserver.prototype.onCompleted = function () {
3177
+ if(!this.isStopped) {
3178
+ this.isStopped = true;
3179
+ this.done = true;
3180
+ this.g.length === 1 && this.o.onCompleted();
3181
+ }
3182
+ };
3183
+ MergeAllObserver.prototype.dispose = function() { this.isStopped = true; };
3184
+ MergeAllObserver.prototype.fail = function (e) {
3185
+ if (!this.isStopped) {
3186
+ this.isStopped = true;
3187
+ this.o.onError(e);
3188
+ return true;
3189
+ }
3190
+
3191
+ return false;
3192
+ };
3193
+
3194
+ function InnerObserver(parent, g, sad) {
3195
+ this.parent = parent;
3196
+ this.g = g;
3197
+ this.sad = sad;
3198
+ this.isStopped = false;
3199
+ }
3200
+ InnerObserver.prototype.onNext = function (x) { if (!this.isStopped) { this.parent.o.onNext(x); } };
3201
+ InnerObserver.prototype.onError = function (e) {
3202
+ if(!this.isStopped) {
3203
+ this.isStopped = true;
3204
+ this.parent.o.onError(e);
3205
+ }
3206
+ };
3207
+ InnerObserver.prototype.onCompleted = function () {
3208
+ if(!this.isStopped) {
3209
+ var parent = this.parent;
3210
+ this.isStopped = true;
3211
+ parent.g.remove(this.sad);
3212
+ parent.done && parent.g.length === 1 && parent.o.onCompleted();
3213
+ }
3214
+ };
3215
+ InnerObserver.prototype.dispose = function() { this.isStopped = true; };
3216
+ InnerObserver.prototype.fail = function (e) {
3217
+ if (!this.isStopped) {
3218
+ this.isStopped = true;
3219
+ this.parent.o.onError(e);
3220
+ return true;
3221
+ }
3222
+
3223
+ return false;
3224
+ };
3225
+
3226
+ return MergeAllObserver;
3227
+
3228
+ }());
3229
+
2881
3230
  /**
2882
- * Merges an observable sequence of observable sequences into an observable sequence.
2883
- * @returns {Observable} The observable sequence that merges the elements of the inner sequences.
2884
- */
3231
+ * Merges an observable sequence of observable sequences into an observable sequence.
3232
+ * @returns {Observable} The observable sequence that merges the elements of the inner sequences.
3233
+ */
2885
3234
  observableProto.mergeAll = observableProto.mergeObservable = function () {
2886
- var sources = this;
3235
+ return new MergeAllObservable(this);
3236
+ };
3237
+
3238
+ var CompositeError = Rx.CompositeError = function(errors) {
3239
+ this.name = "NotImplementedError";
3240
+ this.innerErrors = errors;
3241
+ this.message = 'This contains multiple errors. Check the innerErrors';
3242
+ Error.call(this);
3243
+ }
3244
+ CompositeError.prototype = Error.prototype;
3245
+
3246
+ /**
3247
+ * Flattens an Observable that emits Observables into one Observable, in a way that allows an Observer to
3248
+ * receive all successfully emitted items from all of the source Observables without being interrupted by
3249
+ * an error notification from one of them.
3250
+ *
3251
+ * This behaves like Observable.prototype.mergeAll except that if any of the merged Observables notify of an
3252
+ * error via the Observer's onError, mergeDelayError will refrain from propagating that
3253
+ * error notification until all of the merged Observables have finished emitting items.
3254
+ * @param {Array | Arguments} args Arguments or an array to merge.
3255
+ * @returns {Observable} an Observable that emits all of the items emitted by the Observables emitted by the Observable
3256
+ */
3257
+ Observable.mergeDelayError = function() {
3258
+ var args;
3259
+ if (Array.isArray(arguments[0])) {
3260
+ args = arguments[0];
3261
+ } else {
3262
+ var len = arguments.length;
3263
+ args = new Array(len);
3264
+ for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
3265
+ }
3266
+ var source = observableOf(null, args);
3267
+
2887
3268
  return new AnonymousObservable(function (o) {
2888
3269
  var group = new CompositeDisposable(),
3270
+ m = new SingleAssignmentDisposable(),
2889
3271
  isStopped = false,
2890
- m = new SingleAssignmentDisposable();
3272
+ errors = [];
3273
+
3274
+ function setCompletion() {
3275
+ if (errors.length === 0) {
3276
+ o.onCompleted();
3277
+ } else if (errors.length === 1) {
3278
+ o.onError(errors[0]);
3279
+ } else {
3280
+ o.onError(new CompositeError(errors));
3281
+ }
3282
+ }
2891
3283
 
2892
3284
  group.add(m);
2893
- m.setDisposable(sources.subscribe(function (innerSource) {
2894
- var innerSubscription = new SingleAssignmentDisposable();
2895
- group.add(innerSubscription);
2896
3285
 
2897
- // Check for promises support
2898
- isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
3286
+ m.setDisposable(source.subscribe(
3287
+ function (innerSource) {
3288
+ var innerSubscription = new SingleAssignmentDisposable();
3289
+ group.add(innerSubscription);
2899
3290
 
2900
- innerSubscription.setDisposable(innerSource.subscribe(function (x) { o.onNext(x); }, function (e) { o.onError(e); }, function () {
2901
- group.remove(innerSubscription);
2902
- isStopped && group.length === 1 && o.onCompleted();
3291
+ // Check for promises support
3292
+ isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
3293
+
3294
+ innerSubscription.setDisposable(innerSource.subscribe(
3295
+ function (x) { o.onNext(x); },
3296
+ function (e) {
3297
+ errors.push(e);
3298
+ group.remove(innerSubscription);
3299
+ isStopped && group.length === 1 && setCompletion();
3300
+ },
3301
+ function () {
3302
+ group.remove(innerSubscription);
3303
+ isStopped && group.length === 1 && setCompletion();
3304
+ }));
3305
+ },
3306
+ function (e) {
3307
+ errors.push(e);
3308
+ isStopped = true;
3309
+ group.length === 1 && setCompletion();
3310
+ },
3311
+ function () {
3312
+ isStopped = true;
3313
+ group.length === 1 && setCompletion();
2903
3314
  }));
2904
- }, function (e) { o.onError(e); }, function () {
2905
- isStopped = true;
2906
- group.length === 1 && o.onCompleted();
2907
- }));
2908
3315
  return group;
2909
- }, sources);
3316
+ });
2910
3317
  };
2911
3318
 
2912
3319
  /**
@@ -3003,7 +3410,8 @@
3003
3410
  * @returns {Observable} An observable sequence containing the result of combining elements of the sources using the specified result selector function.
3004
3411
  */
3005
3412
  observableProto.withLatestFrom = function () {
3006
- for(var args = [], i = 0, len = arguments.length; i < len; i++) { args.push(arguments[i]); }
3413
+ var len = arguments.length, args = new Array(len)
3414
+ for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
3007
3415
  var resultSelector = args.pop(), source = this;
3008
3416
 
3009
3417
  if (typeof source === 'undefined') {
@@ -3283,10 +3691,12 @@
3283
3691
  * @returns {Observable} The source sequence with the side-effecting behavior applied.
3284
3692
  */
3285
3693
  observableProto['do'] = observableProto.tap = observableProto.doAction = function (observerOrOnNext, onError, onCompleted) {
3286
- var source = this, tapObserver = typeof observerOrOnNext === 'function' || typeof observerOrOnNext === 'undefined'?
3287
- observerCreate(observerOrOnNext || noop, onError || noop, onCompleted || noop) :
3288
- observerOrOnNext;
3694
+ var source = this;
3289
3695
  return new AnonymousObservable(function (observer) {
3696
+ var tapObserver = !observerOrOnNext || isFunction(observerOrOnNext) ?
3697
+ observerCreate(observerOrOnNext || noop, onError || noop, onCompleted || noop) :
3698
+ observerOrOnNext;
3699
+
3290
3700
  return source.subscribe(function (x) {
3291
3701
  try {
3292
3702
  tapObserver.onNext(x);
@@ -3502,6 +3912,7 @@
3502
3912
  * @returns {Observable} An observable sequence containing the source sequence elements except for the bypassed ones at the end.
3503
3913
  */
3504
3914
  observableProto.skipLast = function (count) {
3915
+ if (count < 0) { throw new ArgumentOutOfRangeError(); }
3505
3916
  var source = this;
3506
3917
  return new AnonymousObservable(function (o) {
3507
3918
  var q = [];
@@ -3541,6 +3952,7 @@
3541
3952
  * @returns {Observable} An observable sequence containing the specified number of elements from the end of the source sequence.
3542
3953
  */
3543
3954
  observableProto.takeLast = function (count) {
3955
+ if (count < 0) { throw new ArgumentOutOfRangeError(); }
3544
3956
  var source = this;
3545
3957
  return new AnonymousObservable(function (o) {
3546
3958
  var q = [];
@@ -3611,7 +4023,7 @@
3611
4023
 
3612
4024
  MapObservable.prototype.internalMap = function (selector, thisArg) {
3613
4025
  var self = this;
3614
- return new MapObservable(this.source, function (x, i, o) { return selector(self.selector(x, i, o), i, o); }, thisArg)
4026
+ return new MapObservable(this.source, function (x, i, o) { return selector.call(this, self.selector(x, i, o), i, o); }, thisArg)
3615
4027
  };
3616
4028
 
3617
4029
  MapObservable.prototype.subscribeCore = function (observer) {
@@ -3632,10 +4044,9 @@
3632
4044
 
3633
4045
  MapObserver.prototype.onNext = function(x) {
3634
4046
  if (this.isStopped) { return; }
3635
- try {
3636
- var result = this.selector(x, this.i++, this.source);
3637
- } catch (e) {
3638
- return this.observer.onError(e);
4047
+ var result = tryCatch(this.selector).call(this, x, this.i++, this.source);
4048
+ if (result === errorObj) {
4049
+ return this.observer.onError(result.e);
3639
4050
  }
3640
4051
  this.observer.onNext(result);
3641
4052
  };
@@ -3756,7 +4167,7 @@
3756
4167
  * @returns {Observable} An observable sequence that contains the elements that occur after the specified index in the input sequence.
3757
4168
  */
3758
4169
  observableProto.skip = function (count) {
3759
- if (count < 0) { throw new Error(argumentOutOfRange); }
4170
+ if (count < 0) { throw new ArgumentOutOfRangeError(); }
3760
4171
  var source = this;
3761
4172
  return new AnonymousObservable(function (o) {
3762
4173
  var remaining = count;
@@ -3809,7 +4220,7 @@
3809
4220
  * @returns {Observable} An observable sequence that contains the specified number of elements from the start of the input sequence.
3810
4221
  */
3811
4222
  observableProto.take = function (count, scheduler) {
3812
- if (count < 0) { throw new RangeError(argumentOutOfRange); }
4223
+ if (count < 0) { throw new ArgumentOutOfRangeError(); }
3813
4224
  if (count === 0) { return observableEmpty(scheduler); }
3814
4225
  var source = this;
3815
4226
  return new AnonymousObservable(function (o) {
@@ -3868,7 +4279,7 @@
3868
4279
 
3869
4280
  FilterObservable.prototype.internalFilter = function(predicate, thisArg) {
3870
4281
  var self = this;
3871
- return new FilterObservable(this.source, function(x, i, o) { return self.predicate(x, i, o) && predicate(x, i, o); }, thisArg);
4282
+ return new FilterObservable(this.source, function(x, i, o) { return self.predicate(x, i, o) && predicate.call(this, x, i, o); }, thisArg);
3872
4283
  };
3873
4284
 
3874
4285
  return FilterObservable;
@@ -3885,10 +4296,9 @@
3885
4296
 
3886
4297
  FilterObserver.prototype.onNext = function(x) {
3887
4298
  if (this.isStopped) { return; }
3888
- try {
3889
- var shouldYield = this.predicate(x, this.i++, this.source);
3890
- } catch (e) {
3891
- return this.observer.onError(e);
4299
+ var shouldYield = tryCatch(this.predicate).call(this, x, this.i++, this.source);
4300
+ if (shouldYield === errorObj) {
4301
+ return this.observer.onError(shouldYield.e);
3892
4302
  }
3893
4303
  shouldYield && this.observer.onNext(x);
3894
4304
  };
@@ -3929,17 +4339,19 @@
3929
4339
  */
3930
4340
  Observable.fromCallback = function (func, context, selector) {
3931
4341
  return function () {
3932
- for(var args = [], i = 0, len = arguments.length; i < len; i++) { args.push(arguments[i]); }
4342
+ var len = arguments.length, args = new Array(len)
4343
+ for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
3933
4344
 
3934
4345
  return new AnonymousObservable(function (observer) {
3935
4346
  function handler() {
3936
- var results = arguments;
4347
+ var len = arguments.length, results = new Array(len);
4348
+ for(var i = 0; i < len; i++) { results[i] = arguments[i]; }
3937
4349
 
3938
4350
  if (selector) {
3939
4351
  try {
3940
- results = selector(results);
3941
- } catch (err) {
3942
- return observer.onError(err);
4352
+ results = selector.apply(context, results);
4353
+ } catch (e) {
4354
+ return observer.onError(e);
3943
4355
  }
3944
4356
 
3945
4357
  observer.onNext(results);
@@ -3969,7 +4381,8 @@
3969
4381
  */
3970
4382
  Observable.fromNodeCallback = function (func, context, selector) {
3971
4383
  return function () {
3972
- for(var args = [], i = 0, len = arguments.length; i < len; i++) { args.push(arguments[i]); }
4384
+ var len = arguments.length, args = new Array(len);
4385
+ for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
3973
4386
 
3974
4387
  return new AnonymousObservable(function (observer) {
3975
4388
  function handler(err) {
@@ -3978,11 +4391,12 @@
3978
4391
  return;
3979
4392
  }
3980
4393
 
3981
- for(var results = [], i = 1, len = arguments.length; i < len; i++) { results.push(arguments[i]); }
4394
+ var len = arguments.length, results = [];
4395
+ for(var i = 1; i < len; i++) { results[i - 1] = arguments[i]; }
3982
4396
 
3983
4397
  if (selector) {
3984
4398
  try {
3985
- results = selector(results);
4399
+ results = selector.apply(context, results);
3986
4400
  } catch (e) {
3987
4401
  return observer.onError(e);
3988
4402
  }
@@ -4143,8 +4557,7 @@
4143
4557
  try {
4144
4558
  results = selector(arguments);
4145
4559
  } catch (err) {
4146
- observer.onError(err);
4147
- return
4560
+ return observer.onError(err);
4148
4561
  }
4149
4562
  }
4150
4563
 
@@ -4168,8 +4581,7 @@
4168
4581
  try {
4169
4582
  result = selector(arguments);
4170
4583
  } catch (err) {
4171
- observer.onError(err);
4172
- return;
4584
+ return observer.onError(err);
4173
4585
  }
4174
4586
  }
4175
4587
  observer.onNext(result);
@@ -4217,7 +4629,7 @@
4217
4629
  */
4218
4630
  observableProto.toPromise = function (promiseCtor) {
4219
4631
  promiseCtor || (promiseCtor = Rx.config.Promise);
4220
- if (!promiseCtor) { throw new TypeError('Promise type not provided nor in Rx.config.Promise'); }
4632
+ if (!promiseCtor) { throw new NotSupportedError('Promise type not provided nor in Rx.config.Promise'); }
4221
4633
  var source = this;
4222
4634
  return new promiseCtor(function (resolve, reject) {
4223
4635
  // No cancellation can be done
@@ -4358,14 +4770,14 @@
4358
4770
  *
4359
4771
  * @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.
4360
4772
  * @param bufferSize [Optional] Maximum element count of the replay buffer.
4361
- * @param window [Optional] Maximum time length of the replay buffer.
4773
+ * @param windowSize [Optional] Maximum time length of the replay buffer.
4362
4774
  * @param scheduler [Optional] Scheduler where connected observers within the selector function will be invoked on.
4363
4775
  * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
4364
4776
  */
4365
- observableProto.replay = function (selector, bufferSize, window, scheduler) {
4777
+ observableProto.replay = function (selector, bufferSize, windowSize, scheduler) {
4366
4778
  return selector && isFunction(selector) ?
4367
- this.multicast(function () { return new ReplaySubject(bufferSize, window, scheduler); }, selector) :
4368
- this.multicast(new ReplaySubject(bufferSize, window, scheduler));
4779
+ this.multicast(function () { return new ReplaySubject(bufferSize, windowSize, scheduler); }, selector) :
4780
+ this.multicast(new ReplaySubject(bufferSize, windowSize, scheduler));
4369
4781
  };
4370
4782
 
4371
4783
  /**
@@ -4383,8 +4795,8 @@
4383
4795
  * @param scheduler [Optional] Scheduler where connected observers within the selector function will be invoked on.
4384
4796
  * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence.
4385
4797
  */
4386
- observableProto.shareReplay = function (bufferSize, window, scheduler) {
4387
- return this.replay(null, bufferSize, window, scheduler).refCount();
4798
+ observableProto.shareReplay = function (bufferSize, windowSize, scheduler) {
4799
+ return this.replay(null, bufferSize, windowSize, scheduler).refCount();
4388
4800
  };
4389
4801
 
4390
4802
  var ConnectableObservable = Rx.ConnectableObservable = (function (__super__) {
@@ -4657,9 +5069,9 @@
4657
5069
  *
4658
5070
  * @example
4659
5071
  * 1 - res = source.timestamp(); // produces { value: x, timestamp: ts }
4660
- * 2 - res = source.timestamp(Rx.Scheduler.timeout);
5072
+ * 2 - res = source.timestamp(Rx.Scheduler.default);
4661
5073
  *
4662
- * @param {Scheduler} [scheduler] Scheduler used to compute timestamps. If not specified, the timeout scheduler is used.
5074
+ * @param {Scheduler} [scheduler] Scheduler used to compute timestamps. If not specified, the default scheduler is used.
4663
5075
  * @returns {Observable} An observable sequence with timestamp information on values.
4664
5076
  */
4665
5077
  observableProto.timestamp = function (scheduler) {
@@ -5010,15 +5422,14 @@
5010
5422
  return this.source.subscribe(observer);
5011
5423
  }
5012
5424
 
5013
- function ControlledObservable (source, enableQueue) {
5425
+ function ControlledObservable (source, enableQueue, scheduler) {
5014
5426
  __super__.call(this, subscribe, source);
5015
- this.subject = new ControlledSubject(enableQueue);
5427
+ this.subject = new ControlledSubject(enableQueue, scheduler);
5016
5428
  this.source = source.multicast(this.subject).refCount();
5017
5429
  }
5018
5430
 
5019
5431
  ControlledObservable.prototype.request = function (numberOfItems) {
5020
- if (numberOfItems == null) { numberOfItems = -1; }
5021
- return this.subject.request(numberOfItems);
5432
+ return this.subject.request(numberOfItems == null ? -1 : numberOfItems);
5022
5433
  };
5023
5434
 
5024
5435
  return ControlledObservable;
@@ -5033,7 +5444,7 @@
5033
5444
 
5034
5445
  inherits(ControlledSubject, __super__);
5035
5446
 
5036
- function ControlledSubject(enableQueue) {
5447
+ function ControlledSubject(enableQueue, scheduler) {
5037
5448
  enableQueue == null && (enableQueue = true);
5038
5449
 
5039
5450
  __super__.call(this, subscribe);
@@ -5045,24 +5456,32 @@
5045
5456
  this.error = null;
5046
5457
  this.hasFailed = false;
5047
5458
  this.hasCompleted = false;
5048
- this.controlledDisposable = disposableEmpty;
5459
+ this.scheduler = scheduler || currentThreadScheduler;
5049
5460
  }
5050
5461
 
5051
5462
  addProperties(ControlledSubject.prototype, Observer, {
5052
5463
  onCompleted: function () {
5053
5464
  this.hasCompleted = true;
5054
- (!this.enableQueue || this.queue.length === 0) && this.subject.onCompleted();
5465
+ if (!this.enableQueue || this.queue.length === 0) {
5466
+ this.subject.onCompleted();
5467
+ } else {
5468
+ this.queue.push(Notification.createOnCompleted());
5469
+ }
5055
5470
  },
5056
5471
  onError: function (error) {
5057
5472
  this.hasFailed = true;
5058
5473
  this.error = error;
5059
- (!this.enableQueue || this.queue.length === 0) && this.subject.onError(error);
5474
+ if (!this.enableQueue || this.queue.length === 0) {
5475
+ this.subject.onError(error);
5476
+ } else {
5477
+ this.queue.push(Notification.createOnError(error));
5478
+ }
5060
5479
  },
5061
5480
  onNext: function (value) {
5062
5481
  var hasRequested = false;
5063
5482
 
5064
5483
  if (this.requestedCount === 0) {
5065
- this.enableQueue && this.queue.push(value);
5484
+ this.enableQueue && this.queue.push(Notification.createOnNext(value));
5066
5485
  } else {
5067
5486
  (this.requestedCount !== -1 && this.requestedCount-- === 0) && this.disposeCurrentRequest();
5068
5487
  hasRequested = true;
@@ -5071,43 +5490,39 @@
5071
5490
  },
5072
5491
  _processRequest: function (numberOfItems) {
5073
5492
  if (this.enableQueue) {
5074
- while (this.queue.length >= numberOfItems && numberOfItems > 0) {
5075
- this.subject.onNext(this.queue.shift());
5076
- numberOfItems--;
5493
+ while ((this.queue.length >= numberOfItems && numberOfItems > 0) ||
5494
+ (this.queue.length > 0 && this.queue[0].kind !== 'N')) {
5495
+ var first = this.queue.shift();
5496
+ first.accept(this.subject);
5497
+ if (first.kind === 'N') {
5498
+ numberOfItems--;
5499
+ } else {
5500
+ this.disposeCurrentRequest();
5501
+ this.queue = [];
5502
+ }
5077
5503
  }
5078
5504
 
5079
- return this.queue.length !== 0 ?
5080
- { numberOfItems: numberOfItems, returnValue: true } :
5081
- { numberOfItems: numberOfItems, returnValue: false };
5082
- }
5083
-
5084
- if (this.hasFailed) {
5085
- this.subject.onError(this.error);
5086
- this.controlledDisposable.dispose();
5087
- this.controlledDisposable = disposableEmpty;
5088
- } else if (this.hasCompleted) {
5089
- this.subject.onCompleted();
5090
- this.controlledDisposable.dispose();
5091
- this.controlledDisposable = disposableEmpty;
5505
+ return { numberOfItems : numberOfItems, returnValue: this.queue.length !== 0};
5092
5506
  }
5093
5507
 
5094
5508
  return { numberOfItems: numberOfItems, returnValue: false };
5095
5509
  },
5096
5510
  request: function (number) {
5097
5511
  this.disposeCurrentRequest();
5098
- var self = this, r = this._processRequest(number);
5512
+ var self = this;
5099
5513
 
5100
- var number = r.numberOfItems;
5101
- if (!r.returnValue) {
5102
- this.requestedCount = number;
5103
- this.requestedDisposable = disposableCreate(function () {
5104
- self.requestedCount = 0;
5105
- });
5514
+ this.requestedDisposable = this.scheduler.scheduleWithState(number,
5515
+ function(s, i) {
5516
+ var r = self._processRequest(i), remaining = r.numberOfItems;
5517
+ if (!r.returnValue) {
5518
+ self.requestedCount = remaining;
5519
+ self.requestedDisposable = disposableCreate(function () {
5520
+ self.requestedCount = 0;
5521
+ });
5522
+ }
5523
+ });
5106
5524
 
5107
- return this.requestedDisposable
5108
- } else {
5109
- return disposableEmpty;
5110
- }
5525
+ return this.requestedDisposable;
5111
5526
  },
5112
5527
  disposeCurrentRequest: function () {
5113
5528
  this.requestedDisposable.dispose();
@@ -5123,12 +5538,51 @@
5123
5538
  * @example
5124
5539
  * var source = Rx.Observable.interval(100).controlled();
5125
5540
  * source.request(3); // Reads 3 values
5126
- * @param {Observable} pauser The observable sequence used to pause the underlying sequence.
5541
+ * @param {bool} enableQueue truthy value to determine if values should be queued pending the next request
5542
+ * @param {Scheduler} scheduler determines how the requests will be scheduled
5127
5543
  * @returns {Observable} The observable sequence which is paused based upon the pauser.
5128
5544
  */
5129
- observableProto.controlled = function (enableQueue) {
5545
+ observableProto.controlled = function (enableQueue, scheduler) {
5546
+
5547
+ if (enableQueue && isScheduler(enableQueue)) {
5548
+ scheduler = enableQueue;
5549
+ enableQueue = true;
5550
+ }
5551
+
5130
5552
  if (enableQueue == null) { enableQueue = true; }
5131
- return new ControlledObservable(this, enableQueue);
5553
+ return new ControlledObservable(this, enableQueue, scheduler);
5554
+ };
5555
+
5556
+ /**
5557
+ * Pipes the existing Observable sequence into a Node.js Stream.
5558
+ * @param {Stream} dest The destination Node.js stream.
5559
+ * @returns {Stream} The destination stream.
5560
+ */
5561
+ observableProto.pipe = function (dest) {
5562
+ var source = this.pausableBuffered();
5563
+
5564
+ function onDrain() {
5565
+ source.resume();
5566
+ }
5567
+
5568
+ dest.addListener('drain', onDrain);
5569
+
5570
+ source.subscribe(
5571
+ function (x) {
5572
+ !dest.write(String(x)) && source.pause();
5573
+ },
5574
+ function (err) {
5575
+ dest.emit('error', err);
5576
+ },
5577
+ function () {
5578
+ // Hack check because STDIO is not closable
5579
+ !dest._isStdio && dest.end();
5580
+ dest.removeListener('drain', onDrain);
5581
+ });
5582
+
5583
+ source.resume();
5584
+
5585
+ return dest;
5132
5586
  };
5133
5587
 
5134
5588
  /**
@@ -5139,32 +5593,32 @@
5139
5593
  observableProto.transduce = function(transducer) {
5140
5594
  var source = this;
5141
5595
 
5142
- function transformForObserver(observer) {
5596
+ function transformForObserver(o) {
5143
5597
  return {
5144
- init: function() {
5145
- return observer;
5598
+ '@@transducer/init': function() {
5599
+ return o;
5146
5600
  },
5147
- step: function(obs, input) {
5601
+ '@@transducer/step': function(obs, input) {
5148
5602
  return obs.onNext(input);
5149
5603
  },
5150
- result: function(obs) {
5604
+ '@@transducer/result': function(obs) {
5151
5605
  return obs.onCompleted();
5152
5606
  }
5153
5607
  };
5154
5608
  }
5155
5609
 
5156
- return new AnonymousObservable(function(observer) {
5157
- var xform = transducer(transformForObserver(observer));
5610
+ return new AnonymousObservable(function(o) {
5611
+ var xform = transducer(transformForObserver(o));
5158
5612
  return source.subscribe(
5159
5613
  function(v) {
5160
5614
  try {
5161
- xform.step(observer, v);
5615
+ xform['@@transducer/step'](o, v);
5162
5616
  } catch (e) {
5163
- observer.onError(e);
5617
+ o.onError(e);
5164
5618
  }
5165
5619
  },
5166
- observer.onError.bind(observer),
5167
- function() { xform.result(observer); }
5620
+ function (e) { o.onError(e); },
5621
+ function() { xform['@@transducer/result'](o); }
5168
5622
  );
5169
5623
  }, source);
5170
5624
  };
@@ -5174,27 +5628,24 @@
5174
5628
 
5175
5629
  // Fix subscriber to check for undefined or function returned to decorate as Disposable
5176
5630
  function fixSubscriber(subscriber) {
5177
- if (subscriber && typeof subscriber.dispose === 'function') { return subscriber; }
5178
-
5179
- return typeof subscriber === 'function' ?
5180
- disposableCreate(subscriber) :
5181
- disposableEmpty;
5631
+ return subscriber && isFunction(subscriber.dispose) ? subscriber :
5632
+ isFunction(subscriber) ? disposableCreate(subscriber) : disposableEmpty;
5182
5633
  }
5183
5634
 
5184
5635
  function setDisposable(s, state) {
5185
5636
  var ado = state[0], subscribe = state[1];
5186
- try {
5187
- ado.setDisposable(fixSubscriber(subscribe(ado)));
5188
- } catch (e) {
5189
- if (!ado.fail(e)) { throw e; }
5637
+ var sub = tryCatch(subscribe)(ado);
5638
+
5639
+ if (sub === errorObj) {
5640
+ if(!ado.fail(errorObj.e)) { return thrower(errorObj.e); }
5190
5641
  }
5642
+ ado.setDisposable(fixSubscriber(sub));
5191
5643
  }
5192
5644
 
5193
5645
  function AnonymousObservable(subscribe, parent) {
5194
5646
  this.source = parent;
5195
5647
 
5196
5648
  function s(observer) {
5197
-
5198
5649
  var ado = new AutoDetachObserver(observer), state = [ado, subscribe];
5199
5650
 
5200
5651
  if (currentThreadScheduler.scheduleRequired()) {
@@ -5202,7 +5653,6 @@
5202
5653
  } else {
5203
5654
  setDisposable(null, state);
5204
5655
  }
5205
-
5206
5656
  return ado;
5207
5657
  }
5208
5658
 
@@ -5225,35 +5675,23 @@
5225
5675
  var AutoDetachObserverPrototype = AutoDetachObserver.prototype;
5226
5676
 
5227
5677
  AutoDetachObserverPrototype.next = function (value) {
5228
- var noError = false;
5229
- try {
5230
- this.observer.onNext(value);
5231
- noError = true;
5232
- } catch (e) {
5233
- return thrower(e);
5234
- } finally {
5235
- !noError && this.dispose();
5678
+ var result = tryCatch(this.observer.onNext).call(this.observer, value);
5679
+ if (result === errorObj) {
5680
+ this.dispose();
5681
+ thrower(result.e);
5236
5682
  }
5237
5683
  };
5238
5684
 
5239
5685
  AutoDetachObserverPrototype.error = function (err) {
5240
- try {
5241
- this.observer.onError(err);
5242
- } catch (e) {
5243
- return thrower(e);
5244
- } finally {
5245
- this.dispose();
5246
- }
5686
+ var result = tryCatch(this.observer.onError).call(this.observer, err);
5687
+ this.dispose();
5688
+ result === errorObj && thrower(result.e);
5247
5689
  };
5248
5690
 
5249
5691
  AutoDetachObserverPrototype.completed = function () {
5250
- try {
5251
- this.observer.onCompleted();
5252
- } catch (e) {
5253
- return thrower(e);
5254
- } finally {
5255
- this.dispose();
5256
- }
5692
+ var result = tryCatch(this.observer.onCompleted).call(this.observer);
5693
+ this.dispose();
5694
+ result === errorObj && thrower(result.e);
5257
5695
  };
5258
5696
 
5259
5697
  AutoDetachObserverPrototype.setDisposable = function (value) { this.m.setDisposable(value); };
@@ -5565,6 +6003,20 @@
5565
6003
  }
5566
6004
 
5567
6005
  addProperties(BehaviorSubject.prototype, Observer, {
6006
+ /**
6007
+ * Gets the current value or throws an exception.
6008
+ * Value is frozen after onCompleted is called.
6009
+ * After onError is called always throws the specified exception.
6010
+ * An exception is always thrown after dispose is called.
6011
+ * @returns {Mixed} The initial value passed to the constructor until onNext is called; after which, the last value passed to onNext.
6012
+ */
6013
+ getValue: function () {
6014
+ checkDisposed(this);
6015
+ if (this.hasError) {
6016
+ throw this.error;
6017
+ }
6018
+ return this.value;
6019
+ },
5568
6020
  /**
5569
6021
  * Indicates whether the subject has observers subscribed to it.
5570
6022
  * @returns {Boolean} Indicates whether the subject has observers subscribed to it.
@@ -5632,6 +6084,8 @@
5632
6084
  */
5633
6085
  var ReplaySubject = Rx.ReplaySubject = (function (__super__) {
5634
6086
 
6087
+ var maxSafeInteger = Math.pow(2, 53) - 1;
6088
+
5635
6089
  function createRemovableDisposable(subject, observer) {
5636
6090
  return disposableCreate(function () {
5637
6091
  observer.dispose();
@@ -5669,8 +6123,8 @@
5669
6123
  * @param {Scheduler} [scheduler] Scheduler the observers are invoked on.
5670
6124
  */
5671
6125
  function ReplaySubject(bufferSize, windowSize, scheduler) {
5672
- this.bufferSize = bufferSize == null ? Number.MAX_VALUE : bufferSize;
5673
- this.windowSize = windowSize == null ? Number.MAX_VALUE : windowSize;
6126
+ this.bufferSize = bufferSize == null ? maxSafeInteger : bufferSize;
6127
+ this.windowSize = windowSize == null ? maxSafeInteger : windowSize;
5674
6128
  this.scheduler = scheduler || currentThreadScheduler;
5675
6129
  this.q = [];
5676
6130
  this.observers = [];