rxjs-rails 2.3.11 → 2.3.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -307,7 +307,7 @@
307
307
  }
308
308
  }
309
309
  var size = 0;
310
- result = true;
310
+ var result = true;
311
311
 
312
312
  // add `a` and `b` to the stack of traversed objects
313
313
  stackA.push(a);
@@ -709,30 +709,30 @@
709
709
  });
710
710
  };
711
711
 
712
- var ScheduledItem = Rx.internals.ScheduledItem = function (scheduler, state, action, dueTime, comparer) {
713
- this.scheduler = scheduler;
714
- this.state = state;
715
- this.action = action;
716
- this.dueTime = dueTime;
717
- this.comparer = comparer || defaultSubComparer;
718
- this.disposable = new SingleAssignmentDisposable();
719
- }
712
+ var ScheduledItem = Rx.internals.ScheduledItem = function (scheduler, state, action, dueTime, comparer) {
713
+ this.scheduler = scheduler;
714
+ this.state = state;
715
+ this.action = action;
716
+ this.dueTime = dueTime;
717
+ this.comparer = comparer || defaultSubComparer;
718
+ this.disposable = new SingleAssignmentDisposable();
719
+ }
720
720
 
721
- ScheduledItem.prototype.invoke = function () {
722
- this.disposable.setDisposable(this.invokeCore());
723
- };
721
+ ScheduledItem.prototype.invoke = function () {
722
+ this.disposable.setDisposable(this.invokeCore());
723
+ };
724
724
 
725
- ScheduledItem.prototype.compareTo = function (other) {
726
- return this.comparer(this.dueTime, other.dueTime);
727
- };
725
+ ScheduledItem.prototype.compareTo = function (other) {
726
+ return this.comparer(this.dueTime, other.dueTime);
727
+ };
728
728
 
729
- ScheduledItem.prototype.isCancelled = function () {
730
- return this.disposable.isDisposed;
731
- };
729
+ ScheduledItem.prototype.isCancelled = function () {
730
+ return this.disposable.isDisposed;
731
+ };
732
732
 
733
- ScheduledItem.prototype.invokeCore = function () {
734
- return this.action(this.scheduler, this.state);
735
- };
733
+ ScheduledItem.prototype.invokeCore = function () {
734
+ return this.action(this.scheduler, this.state);
735
+ };
736
736
 
737
737
  /** Provides a set of static properties to access commonly used schedulers. */
738
738
  var Scheduler = Rx.Scheduler = (function () {
@@ -744,54 +744,6 @@
744
744
  this._scheduleAbsolute = scheduleAbsolute;
745
745
  }
746
746
 
747
- function invokeRecImmediate(scheduler, pair) {
748
- var state = pair.first, action = pair.second, group = new CompositeDisposable(),
749
- recursiveAction = function (state1) {
750
- action(state1, function (state2) {
751
- var isAdded = false, isDone = false,
752
- d = scheduler.scheduleWithState(state2, function (scheduler1, state3) {
753
- if (isAdded) {
754
- group.remove(d);
755
- } else {
756
- isDone = true;
757
- }
758
- recursiveAction(state3);
759
- return disposableEmpty;
760
- });
761
- if (!isDone) {
762
- group.add(d);
763
- isAdded = true;
764
- }
765
- });
766
- };
767
- recursiveAction(state);
768
- return group;
769
- }
770
-
771
- function invokeRecDate(scheduler, pair, method) {
772
- var state = pair.first, action = pair.second, group = new CompositeDisposable(),
773
- recursiveAction = function (state1) {
774
- action(state1, function (state2, dueTime1) {
775
- var isAdded = false, isDone = false,
776
- d = scheduler[method].call(scheduler, state2, dueTime1, function (scheduler1, state3) {
777
- if (isAdded) {
778
- group.remove(d);
779
- } else {
780
- isDone = true;
781
- }
782
- recursiveAction(state3);
783
- return disposableEmpty;
784
- });
785
- if (!isDone) {
786
- group.add(d);
787
- isAdded = true;
788
- }
789
- });
790
- };
791
- recursiveAction(state);
792
- return group;
793
- }
794
-
795
747
  function invokeAction(scheduler, action) {
796
748
  action();
797
749
  return disposableEmpty;
@@ -1043,34 +995,34 @@
1043
995
  };
1044
996
  }(Scheduler.prototype));
1045
997
 
1046
- var SchedulePeriodicRecursive = Rx.internals.SchedulePeriodicRecursive = (function () {
1047
- function tick(command, recurse) {
1048
- recurse(0, this._period);
1049
- try {
1050
- this._state = this._action(this._state);
1051
- } catch (e) {
1052
- this._cancel.dispose();
1053
- throw e;
1054
- }
1055
- }
998
+ var SchedulePeriodicRecursive = Rx.internals.SchedulePeriodicRecursive = (function () {
999
+ function tick(command, recurse) {
1000
+ recurse(0, this._period);
1001
+ try {
1002
+ this._state = this._action(this._state);
1003
+ } catch (e) {
1004
+ this._cancel.dispose();
1005
+ throw e;
1006
+ }
1007
+ }
1056
1008
 
1057
- function SchedulePeriodicRecursive(scheduler, state, period, action) {
1058
- this._scheduler = scheduler;
1059
- this._state = state;
1060
- this._period = period;
1061
- this._action = action;
1062
- }
1009
+ function SchedulePeriodicRecursive(scheduler, state, period, action) {
1010
+ this._scheduler = scheduler;
1011
+ this._state = state;
1012
+ this._period = period;
1013
+ this._action = action;
1014
+ }
1063
1015
 
1064
- SchedulePeriodicRecursive.prototype.start = function () {
1065
- var d = new SingleAssignmentDisposable();
1066
- this._cancel = d;
1067
- d.setDisposable(this._scheduler.scheduleRecursiveWithRelativeAndState(0, this._period, tick.bind(this)));
1016
+ SchedulePeriodicRecursive.prototype.start = function () {
1017
+ var d = new SingleAssignmentDisposable();
1018
+ this._cancel = d;
1019
+ d.setDisposable(this._scheduler.scheduleRecursiveWithRelativeAndState(0, this._period, tick.bind(this)));
1068
1020
 
1069
- return d;
1070
- };
1021
+ return d;
1022
+ };
1071
1023
 
1072
- return SchedulePeriodicRecursive;
1073
- }());
1024
+ return SchedulePeriodicRecursive;
1025
+ }());
1074
1026
 
1075
1027
  /**
1076
1028
  * Gets a scheduler that schedules work immediately on the current thread.
@@ -1310,87 +1262,77 @@
1310
1262
  return new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
1311
1263
  })();
1312
1264
 
1313
- /** @private */
1314
- var CatchScheduler = (function (_super) {
1265
+ var CatchScheduler = (function (__super__) {
1315
1266
 
1316
- function localNow() {
1317
- return this._scheduler.now();
1318
- }
1319
-
1320
- function scheduleNow(state, action) {
1321
- return this._scheduler.scheduleWithState(state, this._wrap(action));
1322
- }
1267
+ function scheduleNow(state, action) {
1268
+ return this._scheduler.scheduleWithState(state, this._wrap(action));
1269
+ }
1323
1270
 
1324
- function scheduleRelative(state, dueTime, action) {
1325
- return this._scheduler.scheduleWithRelativeAndState(state, dueTime, this._wrap(action));
1326
- }
1271
+ function scheduleRelative(state, dueTime, action) {
1272
+ return this._scheduler.scheduleWithRelativeAndState(state, dueTime, this._wrap(action));
1273
+ }
1327
1274
 
1328
- function scheduleAbsolute(state, dueTime, action) {
1329
- return this._scheduler.scheduleWithAbsoluteAndState(state, dueTime, this._wrap(action));
1330
- }
1275
+ function scheduleAbsolute(state, dueTime, action) {
1276
+ return this._scheduler.scheduleWithAbsoluteAndState(state, dueTime, this._wrap(action));
1277
+ }
1331
1278
 
1332
- inherits(CatchScheduler, _super);
1279
+ inherits(CatchScheduler, __super__);
1333
1280
 
1334
- /** @private */
1335
- function CatchScheduler(scheduler, handler) {
1336
- this._scheduler = scheduler;
1337
- this._handler = handler;
1338
- this._recursiveOriginal = null;
1339
- this._recursiveWrapper = null;
1340
- _super.call(this, localNow, scheduleNow, scheduleRelative, scheduleAbsolute);
1341
- }
1281
+ function CatchScheduler(scheduler, handler) {
1282
+ this._scheduler = scheduler;
1283
+ this._handler = handler;
1284
+ this._recursiveOriginal = null;
1285
+ this._recursiveWrapper = null;
1286
+ __super__.call(this, this._scheduler.now.bind(this._scheduler), scheduleNow, scheduleRelative, scheduleAbsolute);
1287
+ }
1342
1288
 
1343
- /** @private */
1344
- CatchScheduler.prototype._clone = function (scheduler) {
1345
- return new CatchScheduler(scheduler, this._handler);
1346
- };
1289
+ CatchScheduler.prototype._clone = function (scheduler) {
1290
+ return new CatchScheduler(scheduler, this._handler);
1291
+ };
1347
1292
 
1348
- /** @private */
1349
- CatchScheduler.prototype._wrap = function (action) {
1350
- var parent = this;
1351
- return function (self, state) {
1352
- try {
1353
- return action(parent._getRecursiveWrapper(self), state);
1354
- } catch (e) {
1355
- if (!parent._handler(e)) { throw e; }
1356
- return disposableEmpty;
1357
- }
1358
- };
1359
- };
1293
+ CatchScheduler.prototype._wrap = function (action) {
1294
+ var parent = this;
1295
+ return function (self, state) {
1296
+ try {
1297
+ return action(parent._getRecursiveWrapper(self), state);
1298
+ } catch (e) {
1299
+ if (!parent._handler(e)) { throw e; }
1300
+ return disposableEmpty;
1301
+ }
1302
+ };
1303
+ };
1360
1304
 
1361
- /** @private */
1362
- CatchScheduler.prototype._getRecursiveWrapper = function (scheduler) {
1363
- if (this._recursiveOriginal !== scheduler) {
1364
- this._recursiveOriginal = scheduler;
1365
- var wrapper = this._clone(scheduler);
1366
- wrapper._recursiveOriginal = scheduler;
1367
- wrapper._recursiveWrapper = wrapper;
1368
- this._recursiveWrapper = wrapper;
1369
- }
1370
- return this._recursiveWrapper;
1371
- };
1305
+ CatchScheduler.prototype._getRecursiveWrapper = function (scheduler) {
1306
+ if (this._recursiveOriginal !== scheduler) {
1307
+ this._recursiveOriginal = scheduler;
1308
+ var wrapper = this._clone(scheduler);
1309
+ wrapper._recursiveOriginal = scheduler;
1310
+ wrapper._recursiveWrapper = wrapper;
1311
+ this._recursiveWrapper = wrapper;
1312
+ }
1313
+ return this._recursiveWrapper;
1314
+ };
1372
1315
 
1373
- /** @private */
1374
- CatchScheduler.prototype.schedulePeriodicWithState = function (state, period, action) {
1375
- var self = this, failed = false, d = new SingleAssignmentDisposable();
1316
+ CatchScheduler.prototype.schedulePeriodicWithState = function (state, period, action) {
1317
+ var self = this, failed = false, d = new SingleAssignmentDisposable();
1376
1318
 
1377
- d.setDisposable(this._scheduler.schedulePeriodicWithState(state, period, function (state1) {
1378
- if (failed) { return null; }
1379
- try {
1380
- return action(state1);
1381
- } catch (e) {
1382
- failed = true;
1383
- if (!self._handler(e)) { throw e; }
1384
- d.dispose();
1385
- return null;
1386
- }
1387
- }));
1319
+ d.setDisposable(this._scheduler.schedulePeriodicWithState(state, period, function (state1) {
1320
+ if (failed) { return null; }
1321
+ try {
1322
+ return action(state1);
1323
+ } catch (e) {
1324
+ failed = true;
1325
+ if (!self._handler(e)) { throw e; }
1326
+ d.dispose();
1327
+ return null;
1328
+ }
1329
+ }));
1388
1330
 
1389
- return d;
1390
- };
1331
+ return d;
1332
+ };
1391
1333
 
1392
- return CatchScheduler;
1393
- }(Scheduler));
1334
+ return CatchScheduler;
1335
+ }(Scheduler));
1394
1336
 
1395
1337
  /**
1396
1338
  * Represents a notification to an observer.
@@ -1469,14 +1411,14 @@
1469
1411
  function _acceptObservable(observer) { return observer.onError(this.exception); }
1470
1412
  function toString () { return 'OnError(' + this.exception + ')'; }
1471
1413
 
1472
- return function (exception) {
1414
+ return function (e) {
1473
1415
  var notification = new Notification('E');
1474
- notification.exception = exception;
1416
+ notification.exception = e;
1475
1417
  notification._accept = _accept;
1476
1418
  notification._acceptObservable = _acceptObservable;
1477
1419
  notification.toString = toString;
1478
1420
  return notification;
1479
- };
1421
+ };
1480
1422
  }());
1481
1423
 
1482
1424
  /**
@@ -1485,17 +1427,17 @@
1485
1427
  */
1486
1428
  var notificationCreateOnCompleted = Notification.createOnCompleted = (function () {
1487
1429
 
1488
- function _accept (onNext, onError, onCompleted) { return onCompleted(); }
1489
- function _acceptObservable(observer) { return observer.onCompleted(); }
1490
- function toString () { return 'OnCompleted()'; }
1430
+ function _accept (onNext, onError, onCompleted) { return onCompleted(); }
1431
+ function _acceptObservable(observer) { return observer.onCompleted(); }
1432
+ function toString () { return 'OnCompleted()'; }
1491
1433
 
1492
- return function () {
1493
- var notification = new Notification('C');
1494
- notification._accept = _accept;
1495
- notification._acceptObservable = _acceptObservable;
1496
- notification.toString = toString;
1497
- return notification;
1498
- };
1434
+ return function () {
1435
+ var notification = new Notification('C');
1436
+ notification._accept = _accept;
1437
+ notification._acceptObservable = _acceptObservable;
1438
+ notification.toString = toString;
1439
+ return notification;
1440
+ };
1499
1441
  }());
1500
1442
 
1501
1443
  var Enumerator = Rx.internals.Enumerator = function (next) {
@@ -2229,7 +2171,7 @@
2229
2171
  * @param {Any} [thisArg] The context to use calling the mapFn if provided.
2230
2172
  * @param {Scheduler} [scheduler] Optional scheduler to use for scheduling. If not provided, defaults to Scheduler.currentThread.
2231
2173
  */
2232
- Observable.from = function (iterable, mapFn, thisArg, scheduler) {
2174
+ var observableFrom = Observable.from = function (iterable, mapFn, thisArg, scheduler) {
2233
2175
  if (iterable == null) {
2234
2176
  throw new Error('iterable cannot be null.')
2235
2177
  }
@@ -2247,7 +2189,13 @@
2247
2189
  if (i < len || objIsIterable) {
2248
2190
  var result;
2249
2191
  if (objIsIterable) {
2250
- var next = it.next();
2192
+ var next;
2193
+ try {
2194
+ next = it.next();
2195
+ } catch (e) {
2196
+ observer.onError(e);
2197
+ return;
2198
+ }
2251
2199
  if (next.done) {
2252
2200
  observer.onCompleted();
2253
2201
  return;
@@ -2255,7 +2203,7 @@
2255
2203
 
2256
2204
  result = next.value;
2257
2205
  } else {
2258
- result = list[i];
2206
+ result = !!list.charAt ? list.charAt(i) : list[i];
2259
2207
  }
2260
2208
 
2261
2209
  if (mapFn && isCallable(mapFn)) {
@@ -3537,47 +3485,50 @@
3537
3485
  });
3538
3486
  };
3539
3487
 
3540
- function concatMap(source, selector, thisArg) {
3541
- return source.map(function (x, i) {
3542
- var result = selector.call(thisArg, x, i);
3543
- return isPromise(result) ? observableFromPromise(result) : result;
3544
- }).concatAll();
3545
- }
3488
+ function concatMap(source, selector, thisArg) {
3489
+ return source.map(function (x, i) {
3490
+ var result = selector.call(thisArg, x, i, source);
3491
+ isPromise(result) && (result = observableFromPromise(result));
3492
+ (Array.isArray(result) || isIterable(result)) && (result = observableFrom(result));
3493
+ return result;
3494
+ }).concatAll();
3495
+ }
3546
3496
 
3547
- /**
3548
- * One of the Following:
3549
- * Projects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
3550
- *
3551
- * @example
3552
- * var res = source.concatMap(function (x) { return Rx.Observable.range(0, x); });
3553
- * Or:
3554
- * Projects each element of an observable sequence to an observable sequence, invokes the result selector for the source element and each of the corresponding inner sequence's elements, and merges the results into one observable sequence.
3555
- *
3556
- * var res = source.concatMap(function (x) { return Rx.Observable.range(0, x); }, function (x, y) { return x + y; });
3557
- * Or:
3558
- * Projects each element of the source observable sequence to the other observable sequence and merges the resulting observable sequences into one observable sequence.
3559
- *
3560
- * var res = source.concatMap(Rx.Observable.fromArray([1,2,3]));
3561
- * @param selector A transform function to apply to each element or an observable sequence to project each element from the
3562
- * source sequence onto which could be either an observable or Promise.
3563
- * @param {Function} [resultSelector] A transform function to apply to each element of the intermediate sequence.
3564
- * @returns {Observable} An observable sequence whose elements are the result of invoking the one-to-many transform function collectionSelector on each element of the input sequence and then mapping each of those sequence elements and their corresponding source element to a result element.
3565
- */
3566
- observableProto.selectConcat = observableProto.concatMap = function (selector, resultSelector, thisArg) {
3567
- if (resultSelector) {
3568
- return this.concatMap(function (x, i) {
3569
- var selectorResult = selector(x, i),
3570
- result = isPromise(selectorResult) ? observableFromPromise(selectorResult) : selectorResult;
3571
-
3572
- return result.map(function (y) {
3573
- return resultSelector(x, y, i);
3574
- });
3575
- });
3576
- }
3577
- return typeof selector === 'function' ?
3578
- concatMap(this, selector, thisArg) :
3579
- concatMap(this, function () { return selector; });
3580
- };
3497
+ /**
3498
+ * One of the Following:
3499
+ * Projects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
3500
+ *
3501
+ * @example
3502
+ * var res = source.concatMap(function (x) { return Rx.Observable.range(0, x); });
3503
+ * Or:
3504
+ * Projects each element of an observable sequence to an observable sequence, invokes the result selector for the source element and each of the corresponding inner sequence's elements, and merges the results into one observable sequence.
3505
+ *
3506
+ * var res = source.concatMap(function (x) { return Rx.Observable.range(0, x); }, function (x, y) { return x + y; });
3507
+ * Or:
3508
+ * Projects each element of the source observable sequence to the other observable sequence and merges the resulting observable sequences into one observable sequence.
3509
+ *
3510
+ * var res = source.concatMap(Rx.Observable.fromArray([1,2,3]));
3511
+ * @param {Function} selector A transform function to apply to each element or an observable sequence to project each element from the
3512
+ * source sequence onto which could be either an observable or Promise.
3513
+ * @param {Function} [resultSelector] A transform function to apply to each element of the intermediate sequence.
3514
+ * @returns {Observable} An observable sequence whose elements are the result of invoking the one-to-many transform function collectionSelector on each element of the input sequence and then mapping each of those sequence elements and their corresponding source element to a result element.
3515
+ */
3516
+ observableProto.selectConcat = observableProto.concatMap = function (selector, resultSelector, thisArg) {
3517
+ if (typeof selector === 'function' && typeof resultSelector === 'function') {
3518
+ return this.concatMap(function (x, i) {
3519
+ var selectorResult = selector(x, i);
3520
+ isPromise(selectorResult) && (selectorResult = observableFromPromise(selectorResult));
3521
+ (Array.isArray(selectorResult) || isIterable(selectorResult)) && (selectorResult = observableFrom(selectorResult));
3522
+
3523
+ return selectorResult.map(function (y, i2) {
3524
+ return resultSelector(x, y, i, i2);
3525
+ });
3526
+ });
3527
+ }
3528
+ return typeof selector === 'function' ?
3529
+ concatMap(this, selector, thisArg) :
3530
+ concatMap(this, function () { return selector; });
3531
+ };
3581
3532
 
3582
3533
  /**
3583
3534
  * Projects each notification of an observable sequence to an observable sequence and concats the resulting observable sequences into one observable sequence.
@@ -3859,48 +3810,50 @@
3859
3810
  return this.map(function (x) { return x[prop]; });
3860
3811
  };
3861
3812
 
3862
- function flatMap(source, selector, thisArg) {
3863
- return source.map(function (x, i) {
3864
- var result = selector.call(thisArg, x, i);
3865
- return isPromise(result) ? observableFromPromise(result) : result;
3866
- }).mergeObservable();
3867
- }
3813
+ function flatMap(source, selector, thisArg) {
3814
+ return source.map(function (x, i) {
3815
+ var result = selector.call(thisArg, x, i, source);
3816
+ isPromise(result) && (result = observableFromPromise(result));
3817
+ (Array.isArray(result) || isIterable(result)) && (result = observableFrom(result));
3818
+ return result;
3819
+ }).mergeObservable();
3820
+ }
3868
3821
 
3869
- /**
3870
- * One of the Following:
3871
- * Projects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
3872
- *
3873
- * @example
3874
- * var res = source.selectMany(function (x) { return Rx.Observable.range(0, x); });
3875
- * Or:
3876
- * Projects each element of an observable sequence to an observable sequence, invokes the result selector for the source element and each of the corresponding inner sequence's elements, and merges the results into one observable sequence.
3877
- *
3878
- * var res = source.selectMany(function (x) { return Rx.Observable.range(0, x); }, function (x, y) { return x + y; });
3879
- * Or:
3880
- * Projects each element of the source observable sequence to the other observable sequence and merges the resulting observable sequences into one observable sequence.
3881
- *
3882
- * var res = source.selectMany(Rx.Observable.fromArray([1,2,3]));
3883
- * @param selector A transform function to apply to each element or an observable sequence to project each element from the
3884
- * source sequence onto which could be either an observable or Promise.
3885
- * @param {Function} [resultSelector] A transform function to apply to each element of the intermediate sequence.
3886
- * @param {Any} [thisArg] Object to use as this when executing callback.
3887
- * @returns {Observable} An observable sequence whose elements are the result of invoking the one-to-many transform function collectionSelector on each element of the input sequence and then mapping each of those sequence elements and their corresponding source element to a result element.
3888
- */
3889
- observableProto.selectMany = observableProto.flatMap = function (selector, resultSelector, thisArg) {
3890
- if (resultSelector) {
3891
- return this.flatMap(function (x, i) {
3892
- var selectorResult = selector(x, i),
3893
- result = isPromise(selectorResult) ? observableFromPromise(selectorResult) : selectorResult;
3894
-
3895
- return result.map(function (y) {
3896
- return resultSelector(x, y, i);
3897
- });
3898
- }, thisArg);
3899
- }
3900
- return typeof selector === 'function' ?
3901
- flatMap(this, selector, thisArg) :
3902
- flatMap(this, function () { return selector; });
3903
- };
3822
+ /**
3823
+ * One of the Following:
3824
+ * Projects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
3825
+ *
3826
+ * @example
3827
+ * var res = source.selectMany(function (x) { return Rx.Observable.range(0, x); });
3828
+ * Or:
3829
+ * Projects each element of an observable sequence to an observable sequence, invokes the result selector for the source element and each of the corresponding inner sequence's elements, and merges the results into one observable sequence.
3830
+ *
3831
+ * var res = source.selectMany(function (x) { return Rx.Observable.range(0, x); }, function (x, y) { return x + y; });
3832
+ * Or:
3833
+ * Projects each element of the source observable sequence to the other observable sequence and merges the resulting observable sequences into one observable sequence.
3834
+ *
3835
+ * var res = source.selectMany(Rx.Observable.fromArray([1,2,3]));
3836
+ * @param {Function} selector A transform function to apply to each element or an observable sequence to project each element from the source sequence onto which could be either an observable or Promise.
3837
+ * @param {Function} [resultSelector] A transform function to apply to each element of the intermediate sequence.
3838
+ * @param {Any} [thisArg] Object to use as this when executing callback.
3839
+ * @returns {Observable} An observable sequence whose elements are the result of invoking the one-to-many transform function collectionSelector on each element of the input sequence and then mapping each of those sequence elements and their corresponding source element to a result element.
3840
+ */
3841
+ observableProto.selectMany = observableProto.flatMap = function (selector, resultSelector, thisArg) {
3842
+ if (typeof selector === 'function' && typeof resultSelector === 'function') {
3843
+ return this.flatMap(function (x, i) {
3844
+ var selectorResult = selector(x, i);
3845
+ isPromise(selectorResult) && (selectorResult = observableFromPromise(selectorResult));
3846
+ (Array.isArray(selectorResult) || isIterable(selectorResult)) && (selectorResult = observableFrom(selectorResult));
3847
+
3848
+ return selectorResult.map(function (y, i2) {
3849
+ return resultSelector(x, y, i, i2);
3850
+ });
3851
+ }, thisArg);
3852
+ }
3853
+ return typeof selector === 'function' ?
3854
+ flatMap(this, selector, thisArg) :
3855
+ flatMap(this, function () { return selector; });
3856
+ };
3904
3857
 
3905
3858
  /**
3906
3859
  * Projects each notification of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
@@ -4154,46 +4107,40 @@
4154
4107
  return x[0];
4155
4108
  }
4156
4109
 
4157
- /**
4158
- * Applies an accumulator function over an observable sequence, returning the result of the aggregation as a single element in the result sequence. The specified seed value is used as the initial accumulator value.
4159
- * For aggregation behavior with incremental intermediate results, see Observable.scan.
4160
- * @example
4161
- * 1 - res = source.aggregate(function (acc, x) { return acc + x; });
4162
- * 2 - res = source.aggregate(0, function (acc, x) { return acc + x; });
4163
- * @param {Mixed} [seed] The initial accumulator value.
4164
- * @param {Function} accumulator An accumulator function to be invoked on each element.
4165
- * @returns {Observable} An observable sequence containing a single element with the final accumulator value.
4166
- */
4167
- observableProto.aggregate = function () {
4168
- var seed, hasSeed, accumulator;
4169
- if (arguments.length === 2) {
4170
- seed = arguments[0];
4171
- hasSeed = true;
4172
- accumulator = arguments[1];
4173
- } else {
4174
- accumulator = arguments[0];
4175
- }
4176
- return hasSeed ? this.scan(seed, accumulator).startWith(seed).finalValue() : this.scan(accumulator).finalValue();
4177
- };
4110
+ /**
4111
+ * Applies an accumulator function over an observable sequence, returning the result of the aggregation as a single element in the result sequence. The specified seed value is used as the initial accumulator value.
4112
+ * For aggregation behavior with incremental intermediate results, see Observable.scan.
4113
+ * @param {Mixed} [seed] The initial accumulator value.
4114
+ * @param {Function} accumulator An accumulator function to be invoked on each element.
4115
+ * @returns {Observable} An observable sequence containing a single element with the final accumulator value.
4116
+ */
4117
+ observableProto.aggregate = function () {
4118
+ var seed, hasSeed, accumulator;
4119
+ if (arguments.length === 2) {
4120
+ seed = arguments[0];
4121
+ hasSeed = true;
4122
+ accumulator = arguments[1];
4123
+ } else {
4124
+ accumulator = arguments[0];
4125
+ }
4126
+ return hasSeed ? this.scan(seed, accumulator).startWith(seed).finalValue() : this.scan(accumulator).finalValue();
4127
+ };
4178
4128
 
4179
- /**
4180
- * Applies an accumulator function over an observable sequence, returning the result of the aggregation as a single element in the result sequence. The specified seed value is used as the initial accumulator value.
4181
- * For aggregation behavior with incremental intermediate results, see Observable.scan.
4182
- * @example
4183
- * 1 - res = source.reduce(function (acc, x) { return acc + x; });
4184
- * 2 - res = source.reduce(function (acc, x) { return acc + x; }, 0);
4185
- * @param {Function} accumulator An accumulator function to be invoked on each element.
4186
- * @param {Any} [seed] The initial accumulator value.
4187
- * @returns {Observable} An observable sequence containing a single element with the final accumulator value.
4188
- */
4189
- observableProto.reduce = function (accumulator) {
4190
- var seed, hasSeed;
4191
- if (arguments.length === 2) {
4192
- hasSeed = true;
4193
- seed = arguments[1];
4194
- }
4195
- return hasSeed ? this.scan(seed, accumulator).startWith(seed).finalValue() : this.scan(accumulator).finalValue();
4196
- };
4129
+ /**
4130
+ * Applies an accumulator function over an observable sequence, returning the result of the aggregation as a single element in the result sequence. The specified seed value is used as the initial accumulator value.
4131
+ * For aggregation behavior with incremental intermediate results, see Observable.scan.
4132
+ * @param {Function} accumulator An accumulator function to be invoked on each element.
4133
+ * @param {Any} [seed] The initial accumulator value.
4134
+ * @returns {Observable} An observable sequence containing a single element with the final accumulator value.
4135
+ */
4136
+ observableProto.reduce = function (accumulator) {
4137
+ var seed, hasSeed;
4138
+ if (arguments.length === 2) {
4139
+ hasSeed = true;
4140
+ seed = arguments[1];
4141
+ }
4142
+ return hasSeed ? this.scan(seed, accumulator).startWith(seed).finalValue() : this.scan(accumulator).finalValue();
4143
+ };
4197
4144
 
4198
4145
  /**
4199
4146
  * Determines whether any element of an observable sequence satisfies a condition if present, else if any items are in the sequence.
@@ -4400,33 +4347,27 @@
4400
4347
  });
4401
4348
  };
4402
4349
 
4403
- /**
4404
- * Computes the average of an observable sequence of values that are in the sequence or obtained by invoking a transform function on each element of the input sequence if present.
4405
- * @example
4406
- * var res = res = source.average();
4407
- * var res = res = source.average(function (x) { return x.value; });
4408
- * @param {Function} [selector] A transform function to apply to each element.
4409
- * @param {Any} [thisArg] Object to use as this when executing callback.
4410
- * @returns {Observable} An observable sequence containing a single element with the average of the sequence of values.
4411
- */
4412
- observableProto.average = function (keySelector, thisArg) {
4413
- return keySelector ?
4414
- this.select(keySelector, thisArg).average() :
4415
- this.scan({
4416
- sum: 0,
4417
- count: 0
4418
- }, function (prev, cur) {
4419
- return {
4420
- sum: prev.sum + cur,
4421
- count: prev.count + 1
4422
- };
4423
- }).finalValue().select(function (s) {
4424
- if (s.count === 0) {
4425
- throw new Error('The input sequence was empty');
4426
- }
4427
- return s.sum / s.count;
4428
- });
4429
- };
4350
+ /**
4351
+ * Computes the average of an observable sequence of values that are in the sequence or obtained by invoking a transform function on each element of the input sequence if present.
4352
+ * @param {Function} [selector] A transform function to apply to each element.
4353
+ * @param {Any} [thisArg] Object to use as this when executing callback.
4354
+ * @returns {Observable} An observable sequence containing a single element with the average of the sequence of values.
4355
+ */
4356
+ observableProto.average = function (keySelector, thisArg) {
4357
+ return keySelector && isFunction(keySelector) ?
4358
+ this.select(keySelector, thisArg).average() :
4359
+ this.scan({sum: 0, count: 0 }, function (prev, cur) {
4360
+ return {
4361
+ sum: prev.sum + cur,
4362
+ count: prev.count + 1
4363
+ };
4364
+ }).finalValue().map(function (s) {
4365
+ if (s.count === 0) {
4366
+ throw new Error('The input sequence was empty');
4367
+ }
4368
+ return s.sum / s.count;
4369
+ });
4370
+ };
4430
4371
 
4431
4372
  function sequenceEqualArray(first, second, comparer) {
4432
4373
  return new AnonymousObservable(function (observer) {
@@ -4848,36 +4789,17 @@
4848
4789
  };
4849
4790
  }
4850
4791
 
4851
- var fnString = 'function';
4792
+ var fnString = 'function',
4793
+ throwString = 'throw';
4852
4794
 
4853
4795
  function toThunk(obj, ctx) {
4854
- if (Array.isArray(obj)) {
4855
- return objectToThunk.call(ctx, obj);
4856
- }
4857
-
4858
- if (isGeneratorFunction(obj)) {
4859
- return observableSpawn(obj.call(ctx));
4860
- }
4861
-
4862
- if (isGenerator(obj)) {
4863
- return observableSpawn(obj);
4864
- }
4865
-
4866
- if (isObservable(obj)) {
4867
- return observableToThunk(obj);
4868
- }
4869
-
4870
- if (isPromise(obj)) {
4871
- return promiseToThunk(obj);
4872
- }
4873
-
4874
- if (typeof obj === fnString) {
4875
- return obj;
4876
- }
4877
-
4878
- if (isObject(obj) || Array.isArray(obj)) {
4879
- return objectToThunk.call(ctx, obj);
4880
- }
4796
+ if (Array.isArray(obj)) { return objectToThunk.call(ctx, obj); }
4797
+ if (isGeneratorFunction(obj)) { return observableSpawn(obj.call(ctx)); }
4798
+ if (isGenerator(obj)) { return observableSpawn(obj); }
4799
+ if (isObservable(obj)) { return observableToThunk(obj); }
4800
+ if (isPromise(obj)) { return promiseToThunk(obj); }
4801
+ if (typeof obj === fnString) { return obj; }
4802
+ if (isObject(obj) || Array.isArray(obj)) { return objectToThunk.call(ctx, obj); }
4881
4803
 
4882
4804
  return obj;
4883
4805
  }
@@ -4929,7 +4851,7 @@
4929
4851
  }
4930
4852
  }
4931
4853
 
4932
- function observableToThink(observable) {
4854
+ function observableToThunk(observable) {
4933
4855
  return function (fn) {
4934
4856
  var value, hasValue = false;
4935
4857
  observable.subscribe(
@@ -4953,7 +4875,7 @@
4953
4875
  }
4954
4876
 
4955
4877
  function isObservable(obj) {
4956
- return obj && obj.prototype.subscribe === fnString;
4878
+ return obj && typeof obj.subscribe === fnString;
4957
4879
  }
4958
4880
 
4959
4881
  function isGeneratorFunction(obj) {
@@ -4961,7 +4883,7 @@
4961
4883
  }
4962
4884
 
4963
4885
  function isGenerator(obj) {
4964
- return obj && typeof obj.next === fnString && typeof obj.throw === fnString;
4886
+ return obj && typeof obj.next === fnString && typeof obj[throwString] === fnString;
4965
4887
  }
4966
4888
 
4967
4889
  function isObject(val) {
@@ -4978,7 +4900,7 @@
4978
4900
 
4979
4901
  return function (done) {
4980
4902
  var ctx = this,
4981
- gen = fan;
4903
+ gen = fn;
4982
4904
 
4983
4905
  if (isGenFun) {
4984
4906
  var args = slice.call(arguments),
@@ -5005,7 +4927,7 @@
5005
4927
 
5006
4928
  if (err) {
5007
4929
  try {
5008
- ret = gen.throw(err);
4930
+ ret = gen[throwString](err);
5009
4931
  } catch (e) {
5010
4932
  return exit(e);
5011
4933
  }
@@ -5089,6 +5011,13 @@
5089
5011
  }
5090
5012
  };
5091
5013
 
5014
+ function error(err) {
5015
+ if (!err) { return; }
5016
+ timeoutScheduler.schedule(function(){
5017
+ throw err;
5018
+ });
5019
+ }
5020
+
5092
5021
  /**
5093
5022
  * Invokes the specified function asynchronously on the specified scheduler, surfacing the result through an observable sequence.
5094
5023
  *
@@ -7941,7 +7870,7 @@
7941
7870
  * @returns {Observable} The source sequence switching to the other sequence in case of a timeout.
7942
7871
  */
7943
7872
  observableProto.timeout = function (dueTime, other, scheduler) {
7944
- other || (other = observableThrow(new Error('Timeout')));
7873
+ (other == null || typeof other === 'string') && (other = observableThrow(new Error(other || 'Timeout')));
7945
7874
  isScheduler(scheduler) || (scheduler = timeoutScheduler);
7946
7875
 
7947
7876
  var source = this, schedulerMethod = dueTime instanceof Date ?
@@ -8493,6 +8422,44 @@
8493
8422
  });
8494
8423
  };
8495
8424
 
8425
+ /**
8426
+ * Executes a transducer to transform the observable sequence
8427
+ * @param {Transducer} transducer A transducer to execute
8428
+ * @returns {Observable} An Observable sequence containing the results from the transducer.
8429
+ */
8430
+ observableProto.transduce = function(transducer) {
8431
+ var source = this;
8432
+
8433
+ function transformForObserver(observer) {
8434
+ return {
8435
+ init: function() {
8436
+ return observer;
8437
+ },
8438
+ step: function(obs, input) {
8439
+ return obs.onNext(input);
8440
+ },
8441
+ result: function(obs) {
8442
+ return obs.onCompleted();
8443
+ }
8444
+ };
8445
+ }
8446
+
8447
+ return new AnonymousObservable(function(observer) {
8448
+ var xform = transducer(transformForObserver(observer));
8449
+ return source.subscribe(
8450
+ function(v) {
8451
+ try {
8452
+ xform.step(observer, v);
8453
+ } catch (e) {
8454
+ observer.onError(e);
8455
+ }
8456
+ },
8457
+ observer.onError.bind(observer),
8458
+ function() { xform.result(observer); }
8459
+ );
8460
+ });
8461
+ };
8462
+
8496
8463
  /*
8497
8464
  * Performs a exclusive waiting for the first to finish before subscribing to another observable.
8498
8465
  * Observables that come in between subscriptions will be dropped on the floor.