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);
@@ -860,30 +860,30 @@ if (!Array.prototype.forEach) {
860
860
  });
861
861
  };
862
862
 
863
- var ScheduledItem = Rx.internals.ScheduledItem = function (scheduler, state, action, dueTime, comparer) {
864
- this.scheduler = scheduler;
865
- this.state = state;
866
- this.action = action;
867
- this.dueTime = dueTime;
868
- this.comparer = comparer || defaultSubComparer;
869
- this.disposable = new SingleAssignmentDisposable();
870
- }
863
+ var ScheduledItem = Rx.internals.ScheduledItem = function (scheduler, state, action, dueTime, comparer) {
864
+ this.scheduler = scheduler;
865
+ this.state = state;
866
+ this.action = action;
867
+ this.dueTime = dueTime;
868
+ this.comparer = comparer || defaultSubComparer;
869
+ this.disposable = new SingleAssignmentDisposable();
870
+ }
871
871
 
872
- ScheduledItem.prototype.invoke = function () {
873
- this.disposable.setDisposable(this.invokeCore());
874
- };
872
+ ScheduledItem.prototype.invoke = function () {
873
+ this.disposable.setDisposable(this.invokeCore());
874
+ };
875
875
 
876
- ScheduledItem.prototype.compareTo = function (other) {
877
- return this.comparer(this.dueTime, other.dueTime);
878
- };
876
+ ScheduledItem.prototype.compareTo = function (other) {
877
+ return this.comparer(this.dueTime, other.dueTime);
878
+ };
879
879
 
880
- ScheduledItem.prototype.isCancelled = function () {
881
- return this.disposable.isDisposed;
882
- };
880
+ ScheduledItem.prototype.isCancelled = function () {
881
+ return this.disposable.isDisposed;
882
+ };
883
883
 
884
- ScheduledItem.prototype.invokeCore = function () {
885
- return this.action(this.scheduler, this.state);
886
- };
884
+ ScheduledItem.prototype.invokeCore = function () {
885
+ return this.action(this.scheduler, this.state);
886
+ };
887
887
 
888
888
  /** Provides a set of static properties to access commonly used schedulers. */
889
889
  var Scheduler = Rx.Scheduler = (function () {
@@ -895,54 +895,6 @@ if (!Array.prototype.forEach) {
895
895
  this._scheduleAbsolute = scheduleAbsolute;
896
896
  }
897
897
 
898
- function invokeRecImmediate(scheduler, pair) {
899
- var state = pair.first, action = pair.second, group = new CompositeDisposable(),
900
- recursiveAction = function (state1) {
901
- action(state1, function (state2) {
902
- var isAdded = false, isDone = false,
903
- d = scheduler.scheduleWithState(state2, function (scheduler1, state3) {
904
- if (isAdded) {
905
- group.remove(d);
906
- } else {
907
- isDone = true;
908
- }
909
- recursiveAction(state3);
910
- return disposableEmpty;
911
- });
912
- if (!isDone) {
913
- group.add(d);
914
- isAdded = true;
915
- }
916
- });
917
- };
918
- recursiveAction(state);
919
- return group;
920
- }
921
-
922
- function invokeRecDate(scheduler, pair, method) {
923
- var state = pair.first, action = pair.second, group = new CompositeDisposable(),
924
- recursiveAction = function (state1) {
925
- action(state1, function (state2, dueTime1) {
926
- var isAdded = false, isDone = false,
927
- d = scheduler[method].call(scheduler, state2, dueTime1, function (scheduler1, state3) {
928
- if (isAdded) {
929
- group.remove(d);
930
- } else {
931
- isDone = true;
932
- }
933
- recursiveAction(state3);
934
- return disposableEmpty;
935
- });
936
- if (!isDone) {
937
- group.add(d);
938
- isAdded = true;
939
- }
940
- });
941
- };
942
- recursiveAction(state);
943
- return group;
944
- }
945
-
946
898
  function invokeAction(scheduler, action) {
947
899
  action();
948
900
  return disposableEmpty;
@@ -1194,34 +1146,34 @@ if (!Array.prototype.forEach) {
1194
1146
  };
1195
1147
  }(Scheduler.prototype));
1196
1148
 
1197
- var SchedulePeriodicRecursive = Rx.internals.SchedulePeriodicRecursive = (function () {
1198
- function tick(command, recurse) {
1199
- recurse(0, this._period);
1200
- try {
1201
- this._state = this._action(this._state);
1202
- } catch (e) {
1203
- this._cancel.dispose();
1204
- throw e;
1205
- }
1206
- }
1149
+ var SchedulePeriodicRecursive = Rx.internals.SchedulePeriodicRecursive = (function () {
1150
+ function tick(command, recurse) {
1151
+ recurse(0, this._period);
1152
+ try {
1153
+ this._state = this._action(this._state);
1154
+ } catch (e) {
1155
+ this._cancel.dispose();
1156
+ throw e;
1157
+ }
1158
+ }
1207
1159
 
1208
- function SchedulePeriodicRecursive(scheduler, state, period, action) {
1209
- this._scheduler = scheduler;
1210
- this._state = state;
1211
- this._period = period;
1212
- this._action = action;
1213
- }
1160
+ function SchedulePeriodicRecursive(scheduler, state, period, action) {
1161
+ this._scheduler = scheduler;
1162
+ this._state = state;
1163
+ this._period = period;
1164
+ this._action = action;
1165
+ }
1214
1166
 
1215
- SchedulePeriodicRecursive.prototype.start = function () {
1216
- var d = new SingleAssignmentDisposable();
1217
- this._cancel = d;
1218
- d.setDisposable(this._scheduler.scheduleRecursiveWithRelativeAndState(0, this._period, tick.bind(this)));
1167
+ SchedulePeriodicRecursive.prototype.start = function () {
1168
+ var d = new SingleAssignmentDisposable();
1169
+ this._cancel = d;
1170
+ d.setDisposable(this._scheduler.scheduleRecursiveWithRelativeAndState(0, this._period, tick.bind(this)));
1219
1171
 
1220
- return d;
1221
- };
1172
+ return d;
1173
+ };
1222
1174
 
1223
- return SchedulePeriodicRecursive;
1224
- }());
1175
+ return SchedulePeriodicRecursive;
1176
+ }());
1225
1177
 
1226
1178
  /**
1227
1179
  * Gets a scheduler that schedules work immediately on the current thread.
@@ -1461,87 +1413,77 @@ if (!Array.prototype.forEach) {
1461
1413
  return new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
1462
1414
  })();
1463
1415
 
1464
- /** @private */
1465
- var CatchScheduler = (function (_super) {
1466
-
1467
- function localNow() {
1468
- return this._scheduler.now();
1469
- }
1416
+ var CatchScheduler = (function (__super__) {
1470
1417
 
1471
- function scheduleNow(state, action) {
1472
- return this._scheduler.scheduleWithState(state, this._wrap(action));
1473
- }
1418
+ function scheduleNow(state, action) {
1419
+ return this._scheduler.scheduleWithState(state, this._wrap(action));
1420
+ }
1474
1421
 
1475
- function scheduleRelative(state, dueTime, action) {
1476
- return this._scheduler.scheduleWithRelativeAndState(state, dueTime, this._wrap(action));
1477
- }
1422
+ function scheduleRelative(state, dueTime, action) {
1423
+ return this._scheduler.scheduleWithRelativeAndState(state, dueTime, this._wrap(action));
1424
+ }
1478
1425
 
1479
- function scheduleAbsolute(state, dueTime, action) {
1480
- return this._scheduler.scheduleWithAbsoluteAndState(state, dueTime, this._wrap(action));
1481
- }
1426
+ function scheduleAbsolute(state, dueTime, action) {
1427
+ return this._scheduler.scheduleWithAbsoluteAndState(state, dueTime, this._wrap(action));
1428
+ }
1482
1429
 
1483
- inherits(CatchScheduler, _super);
1430
+ inherits(CatchScheduler, __super__);
1484
1431
 
1485
- /** @private */
1486
- function CatchScheduler(scheduler, handler) {
1487
- this._scheduler = scheduler;
1488
- this._handler = handler;
1489
- this._recursiveOriginal = null;
1490
- this._recursiveWrapper = null;
1491
- _super.call(this, localNow, scheduleNow, scheduleRelative, scheduleAbsolute);
1492
- }
1432
+ function CatchScheduler(scheduler, handler) {
1433
+ this._scheduler = scheduler;
1434
+ this._handler = handler;
1435
+ this._recursiveOriginal = null;
1436
+ this._recursiveWrapper = null;
1437
+ __super__.call(this, this._scheduler.now.bind(this._scheduler), scheduleNow, scheduleRelative, scheduleAbsolute);
1438
+ }
1493
1439
 
1494
- /** @private */
1495
- CatchScheduler.prototype._clone = function (scheduler) {
1496
- return new CatchScheduler(scheduler, this._handler);
1497
- };
1440
+ CatchScheduler.prototype._clone = function (scheduler) {
1441
+ return new CatchScheduler(scheduler, this._handler);
1442
+ };
1498
1443
 
1499
- /** @private */
1500
- CatchScheduler.prototype._wrap = function (action) {
1501
- var parent = this;
1502
- return function (self, state) {
1503
- try {
1504
- return action(parent._getRecursiveWrapper(self), state);
1505
- } catch (e) {
1506
- if (!parent._handler(e)) { throw e; }
1507
- return disposableEmpty;
1508
- }
1509
- };
1510
- };
1444
+ CatchScheduler.prototype._wrap = function (action) {
1445
+ var parent = this;
1446
+ return function (self, state) {
1447
+ try {
1448
+ return action(parent._getRecursiveWrapper(self), state);
1449
+ } catch (e) {
1450
+ if (!parent._handler(e)) { throw e; }
1451
+ return disposableEmpty;
1452
+ }
1453
+ };
1454
+ };
1511
1455
 
1512
- /** @private */
1513
- CatchScheduler.prototype._getRecursiveWrapper = function (scheduler) {
1514
- if (this._recursiveOriginal !== scheduler) {
1515
- this._recursiveOriginal = scheduler;
1516
- var wrapper = this._clone(scheduler);
1517
- wrapper._recursiveOriginal = scheduler;
1518
- wrapper._recursiveWrapper = wrapper;
1519
- this._recursiveWrapper = wrapper;
1520
- }
1521
- return this._recursiveWrapper;
1522
- };
1456
+ CatchScheduler.prototype._getRecursiveWrapper = function (scheduler) {
1457
+ if (this._recursiveOriginal !== scheduler) {
1458
+ this._recursiveOriginal = scheduler;
1459
+ var wrapper = this._clone(scheduler);
1460
+ wrapper._recursiveOriginal = scheduler;
1461
+ wrapper._recursiveWrapper = wrapper;
1462
+ this._recursiveWrapper = wrapper;
1463
+ }
1464
+ return this._recursiveWrapper;
1465
+ };
1523
1466
 
1524
- /** @private */
1525
- CatchScheduler.prototype.schedulePeriodicWithState = function (state, period, action) {
1526
- var self = this, failed = false, d = new SingleAssignmentDisposable();
1467
+ CatchScheduler.prototype.schedulePeriodicWithState = function (state, period, action) {
1468
+ var self = this, failed = false, d = new SingleAssignmentDisposable();
1527
1469
 
1528
- d.setDisposable(this._scheduler.schedulePeriodicWithState(state, period, function (state1) {
1529
- if (failed) { return null; }
1530
- try {
1531
- return action(state1);
1532
- } catch (e) {
1533
- failed = true;
1534
- if (!self._handler(e)) { throw e; }
1535
- d.dispose();
1536
- return null;
1537
- }
1538
- }));
1470
+ d.setDisposable(this._scheduler.schedulePeriodicWithState(state, period, function (state1) {
1471
+ if (failed) { return null; }
1472
+ try {
1473
+ return action(state1);
1474
+ } catch (e) {
1475
+ failed = true;
1476
+ if (!self._handler(e)) { throw e; }
1477
+ d.dispose();
1478
+ return null;
1479
+ }
1480
+ }));
1539
1481
 
1540
- return d;
1541
- };
1482
+ return d;
1483
+ };
1542
1484
 
1543
- return CatchScheduler;
1544
- }(Scheduler));
1485
+ return CatchScheduler;
1486
+ }(Scheduler));
1545
1487
 
1546
1488
  /**
1547
1489
  * Represents a notification to an observer.
@@ -1620,14 +1562,14 @@ if (!Array.prototype.forEach) {
1620
1562
  function _acceptObservable(observer) { return observer.onError(this.exception); }
1621
1563
  function toString () { return 'OnError(' + this.exception + ')'; }
1622
1564
 
1623
- return function (exception) {
1565
+ return function (e) {
1624
1566
  var notification = new Notification('E');
1625
- notification.exception = exception;
1567
+ notification.exception = e;
1626
1568
  notification._accept = _accept;
1627
1569
  notification._acceptObservable = _acceptObservable;
1628
1570
  notification.toString = toString;
1629
1571
  return notification;
1630
- };
1572
+ };
1631
1573
  }());
1632
1574
 
1633
1575
  /**
@@ -1636,17 +1578,17 @@ if (!Array.prototype.forEach) {
1636
1578
  */
1637
1579
  var notificationCreateOnCompleted = Notification.createOnCompleted = (function () {
1638
1580
 
1639
- function _accept (onNext, onError, onCompleted) { return onCompleted(); }
1640
- function _acceptObservable(observer) { return observer.onCompleted(); }
1641
- function toString () { return 'OnCompleted()'; }
1581
+ function _accept (onNext, onError, onCompleted) { return onCompleted(); }
1582
+ function _acceptObservable(observer) { return observer.onCompleted(); }
1583
+ function toString () { return 'OnCompleted()'; }
1642
1584
 
1643
- return function () {
1644
- var notification = new Notification('C');
1645
- notification._accept = _accept;
1646
- notification._acceptObservable = _acceptObservable;
1647
- notification.toString = toString;
1648
- return notification;
1649
- };
1585
+ return function () {
1586
+ var notification = new Notification('C');
1587
+ notification._accept = _accept;
1588
+ notification._acceptObservable = _acceptObservable;
1589
+ notification.toString = toString;
1590
+ return notification;
1591
+ };
1650
1592
  }());
1651
1593
 
1652
1594
  var Enumerator = Rx.internals.Enumerator = function (next) {
@@ -2380,7 +2322,7 @@ if (!Array.prototype.forEach) {
2380
2322
  * @param {Any} [thisArg] The context to use calling the mapFn if provided.
2381
2323
  * @param {Scheduler} [scheduler] Optional scheduler to use for scheduling. If not provided, defaults to Scheduler.currentThread.
2382
2324
  */
2383
- Observable.from = function (iterable, mapFn, thisArg, scheduler) {
2325
+ var observableFrom = Observable.from = function (iterable, mapFn, thisArg, scheduler) {
2384
2326
  if (iterable == null) {
2385
2327
  throw new Error('iterable cannot be null.')
2386
2328
  }
@@ -2398,7 +2340,13 @@ if (!Array.prototype.forEach) {
2398
2340
  if (i < len || objIsIterable) {
2399
2341
  var result;
2400
2342
  if (objIsIterable) {
2401
- var next = it.next();
2343
+ var next;
2344
+ try {
2345
+ next = it.next();
2346
+ } catch (e) {
2347
+ observer.onError(e);
2348
+ return;
2349
+ }
2402
2350
  if (next.done) {
2403
2351
  observer.onCompleted();
2404
2352
  return;
@@ -2406,7 +2354,7 @@ if (!Array.prototype.forEach) {
2406
2354
 
2407
2355
  result = next.value;
2408
2356
  } else {
2409
- result = list[i];
2357
+ result = !!list.charAt ? list.charAt(i) : list[i];
2410
2358
  }
2411
2359
 
2412
2360
  if (mapFn && isCallable(mapFn)) {
@@ -3688,47 +3636,50 @@ if (!Array.prototype.forEach) {
3688
3636
  });
3689
3637
  };
3690
3638
 
3691
- function concatMap(source, selector, thisArg) {
3692
- return source.map(function (x, i) {
3693
- var result = selector.call(thisArg, x, i);
3694
- return isPromise(result) ? observableFromPromise(result) : result;
3695
- }).concatAll();
3696
- }
3639
+ function concatMap(source, selector, thisArg) {
3640
+ return source.map(function (x, i) {
3641
+ var result = selector.call(thisArg, x, i, source);
3642
+ isPromise(result) && (result = observableFromPromise(result));
3643
+ (Array.isArray(result) || isIterable(result)) && (result = observableFrom(result));
3644
+ return result;
3645
+ }).concatAll();
3646
+ }
3697
3647
 
3698
- /**
3699
- * One of the Following:
3700
- * Projects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
3701
- *
3702
- * @example
3703
- * var res = source.concatMap(function (x) { return Rx.Observable.range(0, x); });
3704
- * Or:
3705
- * 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.
3706
- *
3707
- * var res = source.concatMap(function (x) { return Rx.Observable.range(0, x); }, function (x, y) { return x + y; });
3708
- * Or:
3709
- * Projects each element of the source observable sequence to the other observable sequence and merges the resulting observable sequences into one observable sequence.
3710
- *
3711
- * var res = source.concatMap(Rx.Observable.fromArray([1,2,3]));
3712
- * @param selector A transform function to apply to each element or an observable sequence to project each element from the
3713
- * source sequence onto which could be either an observable or Promise.
3714
- * @param {Function} [resultSelector] A transform function to apply to each element of the intermediate sequence.
3715
- * @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.
3716
- */
3717
- observableProto.selectConcat = observableProto.concatMap = function (selector, resultSelector, thisArg) {
3718
- if (resultSelector) {
3719
- return this.concatMap(function (x, i) {
3720
- var selectorResult = selector(x, i),
3721
- result = isPromise(selectorResult) ? observableFromPromise(selectorResult) : selectorResult;
3722
-
3723
- return result.map(function (y) {
3724
- return resultSelector(x, y, i);
3725
- });
3726
- });
3727
- }
3728
- return typeof selector === 'function' ?
3729
- concatMap(this, selector, thisArg) :
3730
- concatMap(this, function () { return selector; });
3731
- };
3648
+ /**
3649
+ * One of the Following:
3650
+ * Projects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
3651
+ *
3652
+ * @example
3653
+ * var res = source.concatMap(function (x) { return Rx.Observable.range(0, x); });
3654
+ * Or:
3655
+ * 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.
3656
+ *
3657
+ * var res = source.concatMap(function (x) { return Rx.Observable.range(0, x); }, function (x, y) { return x + y; });
3658
+ * Or:
3659
+ * Projects each element of the source observable sequence to the other observable sequence and merges the resulting observable sequences into one observable sequence.
3660
+ *
3661
+ * var res = source.concatMap(Rx.Observable.fromArray([1,2,3]));
3662
+ * @param {Function} selector A transform function to apply to each element or an observable sequence to project each element from the
3663
+ * source sequence onto which could be either an observable or Promise.
3664
+ * @param {Function} [resultSelector] A transform function to apply to each element of the intermediate sequence.
3665
+ * @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.
3666
+ */
3667
+ observableProto.selectConcat = observableProto.concatMap = function (selector, resultSelector, thisArg) {
3668
+ if (typeof selector === 'function' && typeof resultSelector === 'function') {
3669
+ return this.concatMap(function (x, i) {
3670
+ var selectorResult = selector(x, i);
3671
+ isPromise(selectorResult) && (selectorResult = observableFromPromise(selectorResult));
3672
+ (Array.isArray(selectorResult) || isIterable(selectorResult)) && (selectorResult = observableFrom(selectorResult));
3673
+
3674
+ return selectorResult.map(function (y, i2) {
3675
+ return resultSelector(x, y, i, i2);
3676
+ });
3677
+ });
3678
+ }
3679
+ return typeof selector === 'function' ?
3680
+ concatMap(this, selector, thisArg) :
3681
+ concatMap(this, function () { return selector; });
3682
+ };
3732
3683
 
3733
3684
  /**
3734
3685
  * Projects each notification of an observable sequence to an observable sequence and concats the resulting observable sequences into one observable sequence.
@@ -3896,48 +3847,50 @@ if (!Array.prototype.forEach) {
3896
3847
  return this.map(function (x) { return x[prop]; });
3897
3848
  };
3898
3849
 
3899
- function flatMap(source, selector, thisArg) {
3900
- return source.map(function (x, i) {
3901
- var result = selector.call(thisArg, x, i);
3902
- return isPromise(result) ? observableFromPromise(result) : result;
3903
- }).mergeObservable();
3904
- }
3850
+ function flatMap(source, selector, thisArg) {
3851
+ return source.map(function (x, i) {
3852
+ var result = selector.call(thisArg, x, i, source);
3853
+ isPromise(result) && (result = observableFromPromise(result));
3854
+ (Array.isArray(result) || isIterable(result)) && (result = observableFrom(result));
3855
+ return result;
3856
+ }).mergeObservable();
3857
+ }
3905
3858
 
3906
- /**
3907
- * One of the Following:
3908
- * Projects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
3909
- *
3910
- * @example
3911
- * var res = source.selectMany(function (x) { return Rx.Observable.range(0, x); });
3912
- * Or:
3913
- * 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.
3914
- *
3915
- * var res = source.selectMany(function (x) { return Rx.Observable.range(0, x); }, function (x, y) { return x + y; });
3916
- * Or:
3917
- * Projects each element of the source observable sequence to the other observable sequence and merges the resulting observable sequences into one observable sequence.
3918
- *
3919
- * var res = source.selectMany(Rx.Observable.fromArray([1,2,3]));
3920
- * @param selector A transform function to apply to each element or an observable sequence to project each element from the
3921
- * source sequence onto which could be either an observable or Promise.
3922
- * @param {Function} [resultSelector] A transform function to apply to each element of the intermediate sequence.
3923
- * @param {Any} [thisArg] Object to use as this when executing callback.
3924
- * @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.
3925
- */
3926
- observableProto.selectMany = observableProto.flatMap = function (selector, resultSelector, thisArg) {
3927
- if (resultSelector) {
3928
- return this.flatMap(function (x, i) {
3929
- var selectorResult = selector(x, i),
3930
- result = isPromise(selectorResult) ? observableFromPromise(selectorResult) : selectorResult;
3931
-
3932
- return result.map(function (y) {
3933
- return resultSelector(x, y, i);
3934
- });
3935
- }, thisArg);
3936
- }
3937
- return typeof selector === 'function' ?
3938
- flatMap(this, selector, thisArg) :
3939
- flatMap(this, function () { return selector; });
3940
- };
3859
+ /**
3860
+ * One of the Following:
3861
+ * Projects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
3862
+ *
3863
+ * @example
3864
+ * var res = source.selectMany(function (x) { return Rx.Observable.range(0, x); });
3865
+ * Or:
3866
+ * 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.
3867
+ *
3868
+ * var res = source.selectMany(function (x) { return Rx.Observable.range(0, x); }, function (x, y) { return x + y; });
3869
+ * Or:
3870
+ * Projects each element of the source observable sequence to the other observable sequence and merges the resulting observable sequences into one observable sequence.
3871
+ *
3872
+ * var res = source.selectMany(Rx.Observable.fromArray([1,2,3]));
3873
+ * @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.
3874
+ * @param {Function} [resultSelector] A transform function to apply to each element of the intermediate sequence.
3875
+ * @param {Any} [thisArg] Object to use as this when executing callback.
3876
+ * @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.
3877
+ */
3878
+ observableProto.selectMany = observableProto.flatMap = function (selector, resultSelector, thisArg) {
3879
+ if (typeof selector === 'function' && typeof resultSelector === 'function') {
3880
+ return this.flatMap(function (x, i) {
3881
+ var selectorResult = selector(x, i);
3882
+ isPromise(selectorResult) && (selectorResult = observableFromPromise(selectorResult));
3883
+ (Array.isArray(selectorResult) || isIterable(selectorResult)) && (selectorResult = observableFrom(selectorResult));
3884
+
3885
+ return selectorResult.map(function (y, i2) {
3886
+ return resultSelector(x, y, i, i2);
3887
+ });
3888
+ }, thisArg);
3889
+ }
3890
+ return typeof selector === 'function' ?
3891
+ flatMap(this, selector, thisArg) :
3892
+ flatMap(this, function () { return selector; });
3893
+ };
3941
3894
 
3942
3895
  /**
3943
3896
  * Projects each notification of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
@@ -4131,115 +4084,41 @@ if (!Array.prototype.forEach) {
4131
4084
  });
4132
4085
  };
4133
4086
 
4134
- /*
4135
- * Performs a exclusive waiting for the first to finish before subscribing to another observable.
4136
- * Observables that come in between subscriptions will be dropped on the floor.
4137
- * @returns {Observable} A exclusive observable with only the results that happen when subscribed.
4087
+ /**
4088
+ * Executes a transducer to transform the observable sequence
4089
+ * @param {Transducer} transducer A transducer to execute
4090
+ * @returns {Observable} An Observable sequence containing the results from the transducer.
4138
4091
  */
4139
- observableProto.exclusive = function () {
4140
- var sources = this;
4141
- return new AnonymousObservable(function (observer) {
4142
- var hasCurrent = false,
4143
- isStopped = false,
4144
- m = new SingleAssignmentDisposable(),
4145
- g = new CompositeDisposable();
4146
-
4147
- g.add(m);
4148
-
4149
- m.setDisposable(sources.subscribe(
4150
- function (innerSource) {
4151
- if (!hasCurrent) {
4152
- hasCurrent = true;
4153
-
4154
- isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
4155
-
4156
- var innerSubscription = new SingleAssignmentDisposable();
4157
- g.add(innerSubscription);
4092
+ observableProto.transduce = function(transducer) {
4093
+ var source = this;
4158
4094
 
4159
- innerSubscription.setDisposable(innerSource.subscribe(
4160
- observer.onNext.bind(observer),
4161
- observer.onError.bind(observer),
4162
- function () {
4163
- g.remove(innerSubscription);
4164
- hasCurrent = false;
4165
- if (isStopped && g.length === 1) {
4166
- observer.onCompleted();
4167
- }
4168
- }));
4169
- }
4095
+ function transformForObserver(observer) {
4096
+ return {
4097
+ init: function() {
4098
+ return observer;
4170
4099
  },
4171
- observer.onError.bind(observer),
4172
- function () {
4173
- isStopped = true;
4174
- if (!hasCurrent && g.length === 1) {
4175
- observer.onCompleted();
4176
- }
4177
- }));
4178
-
4179
- return g;
4180
- });
4181
- };
4182
-
4183
- /*
4184
- * Performs a exclusive map waiting for the first to finish before subscribing to another observable.
4185
- * Observables that come in between subscriptions will be dropped on the floor.
4186
- * @param {Function} selector Selector to invoke for every item in the current subscription.
4187
- * @param {Any} [thisArg] An optional context to invoke with the selector parameter.
4188
- * @returns {Observable} An exclusive observable with only the results that happen when subscribed.
4189
- */
4190
- observableProto.exclusiveMap = function (selector, thisArg) {
4191
- var sources = this;
4192
- return new AnonymousObservable(function (observer) {
4193
- var index = 0,
4194
- hasCurrent = false,
4195
- isStopped = true,
4196
- m = new SingleAssignmentDisposable(),
4197
- g = new CompositeDisposable();
4198
-
4199
- g.add(m);
4200
-
4201
- m.setDisposable(sources.subscribe(
4202
- function (innerSource) {
4203
-
4204
- if (!hasCurrent) {
4205
- hasCurrent = true;
4206
-
4207
- innerSubscription = new SingleAssignmentDisposable();
4208
- g.add(innerSubscription);
4209
-
4210
- isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
4211
-
4212
- innerSubscription.setDisposable(innerSource.subscribe(
4213
- function (x) {
4214
- var result;
4215
- try {
4216
- result = selector.call(thisArg, x, index++, innerSource);
4217
- } catch (e) {
4218
- observer.onError(e);
4219
- return;
4220
- }
4221
-
4222
- observer.onNext(result);
4223
- },
4224
- observer.onError.bind(observer),
4225
- function () {
4226
- g.remove(innerSubscription);
4227
- hasCurrent = false;
4228
-
4229
- if (isStopped && g.length === 1) {
4230
- observer.onCompleted();
4231
- }
4232
- }));
4233
- }
4100
+ step: function(obs, input) {
4101
+ return obs.onNext(input);
4234
4102
  },
4235
- observer.onError.bind(observer),
4236
- function () {
4237
- isStopped = true;
4238
- if (g.length === 1 && !hasCurrent) {
4239
- observer.onCompleted();
4103
+ result: function(obs) {
4104
+ return obs.onCompleted();
4105
+ }
4106
+ };
4107
+ }
4108
+
4109
+ return new AnonymousObservable(function(observer) {
4110
+ var xform = transducer(transformForObserver(observer));
4111
+ return source.subscribe(
4112
+ function(v) {
4113
+ try {
4114
+ xform.step(observer, v);
4115
+ } catch (e) {
4116
+ observer.onError(e);
4240
4117
  }
4241
- }));
4242
- return g;
4118
+ },
4119
+ observer.onError.bind(observer),
4120
+ function() { xform.result(observer); }
4121
+ );
4243
4122
  });
4244
4123
  };
4245
4124