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) {
1315
-
1316
- function localNow() {
1317
- return this._scheduler.now();
1318
- }
1265
+ var CatchScheduler = (function (__super__) {
1319
1266
 
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.
@@ -3797,48 +3748,50 @@
3797
3748
  }).mergeAll();
3798
3749
  };
3799
3750
 
3800
- function flatMap(source, selector, thisArg) {
3801
- return source.map(function (x, i) {
3802
- var result = selector.call(thisArg, x, i);
3803
- return isPromise(result) ? observableFromPromise(result) : result;
3804
- }).mergeObservable();
3805
- }
3751
+ function flatMap(source, selector, thisArg) {
3752
+ return source.map(function (x, i) {
3753
+ var result = selector.call(thisArg, x, i, source);
3754
+ isPromise(result) && (result = observableFromPromise(result));
3755
+ (Array.isArray(result) || isIterable(result)) && (result = observableFrom(result));
3756
+ return result;
3757
+ }).mergeObservable();
3758
+ }
3806
3759
 
3807
- /**
3808
- * One of the Following:
3809
- * Projects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
3810
- *
3811
- * @example
3812
- * var res = source.selectMany(function (x) { return Rx.Observable.range(0, x); });
3813
- * Or:
3814
- * 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.
3815
- *
3816
- * var res = source.selectMany(function (x) { return Rx.Observable.range(0, x); }, function (x, y) { return x + y; });
3817
- * Or:
3818
- * Projects each element of the source observable sequence to the other observable sequence and merges the resulting observable sequences into one observable sequence.
3819
- *
3820
- * var res = source.selectMany(Rx.Observable.fromArray([1,2,3]));
3821
- * @param selector A transform function to apply to each element or an observable sequence to project each element from the
3822
- * source sequence onto which could be either an observable or Promise.
3823
- * @param {Function} [resultSelector] A transform function to apply to each element of the intermediate sequence.
3824
- * @param {Any} [thisArg] Object to use as this when executing callback.
3825
- * @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.
3826
- */
3827
- observableProto.selectMany = observableProto.flatMap = function (selector, resultSelector, thisArg) {
3828
- if (resultSelector) {
3829
- return this.flatMap(function (x, i) {
3830
- var selectorResult = selector(x, i),
3831
- result = isPromise(selectorResult) ? observableFromPromise(selectorResult) : selectorResult;
3832
-
3833
- return result.map(function (y) {
3834
- return resultSelector(x, y, i);
3835
- });
3836
- }, thisArg);
3837
- }
3838
- return typeof selector === 'function' ?
3839
- flatMap(this, selector, thisArg) :
3840
- flatMap(this, function () { return selector; });
3841
- };
3760
+ /**
3761
+ * One of the Following:
3762
+ * Projects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
3763
+ *
3764
+ * @example
3765
+ * var res = source.selectMany(function (x) { return Rx.Observable.range(0, x); });
3766
+ * Or:
3767
+ * 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.
3768
+ *
3769
+ * var res = source.selectMany(function (x) { return Rx.Observable.range(0, x); }, function (x, y) { return x + y; });
3770
+ * Or:
3771
+ * Projects each element of the source observable sequence to the other observable sequence and merges the resulting observable sequences into one observable sequence.
3772
+ *
3773
+ * var res = source.selectMany(Rx.Observable.fromArray([1,2,3]));
3774
+ * @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.
3775
+ * @param {Function} [resultSelector] A transform function to apply to each element of the intermediate sequence.
3776
+ * @param {Any} [thisArg] Object to use as this when executing callback.
3777
+ * @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.
3778
+ */
3779
+ observableProto.selectMany = observableProto.flatMap = function (selector, resultSelector, thisArg) {
3780
+ if (typeof selector === 'function' && typeof resultSelector === 'function') {
3781
+ return this.flatMap(function (x, i) {
3782
+ var selectorResult = selector(x, i);
3783
+ isPromise(selectorResult) && (selectorResult = observableFromPromise(selectorResult));
3784
+ (Array.isArray(selectorResult) || isIterable(selectorResult)) && (selectorResult = observableFrom(selectorResult));
3785
+
3786
+ return selectorResult.map(function (y, i2) {
3787
+ return resultSelector(x, y, i, i2);
3788
+ });
3789
+ }, thisArg);
3790
+ }
3791
+ return typeof selector === 'function' ?
3792
+ flatMap(this, selector, thisArg) :
3793
+ flatMap(this, function () { return selector; });
3794
+ };
3842
3795
 
3843
3796
  /**
3844
3797
  * Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then
@@ -3980,115 +3933,41 @@
3980
3933
  });
3981
3934
  };
3982
3935
 
3983
- /*
3984
- * Performs a exclusive waiting for the first to finish before subscribing to another observable.
3985
- * Observables that come in between subscriptions will be dropped on the floor.
3986
- * @returns {Observable} A exclusive observable with only the results that happen when subscribed.
3936
+ /**
3937
+ * Executes a transducer to transform the observable sequence
3938
+ * @param {Transducer} transducer A transducer to execute
3939
+ * @returns {Observable} An Observable sequence containing the results from the transducer.
3987
3940
  */
3988
- observableProto.exclusive = function () {
3989
- var sources = this;
3990
- return new AnonymousObservable(function (observer) {
3991
- var hasCurrent = false,
3992
- isStopped = false,
3993
- m = new SingleAssignmentDisposable(),
3994
- g = new CompositeDisposable();
3995
-
3996
- g.add(m);
3997
-
3998
- m.setDisposable(sources.subscribe(
3999
- function (innerSource) {
4000
- if (!hasCurrent) {
4001
- hasCurrent = true;
4002
-
4003
- isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
4004
-
4005
- var innerSubscription = new SingleAssignmentDisposable();
4006
- g.add(innerSubscription);
3941
+ observableProto.transduce = function(transducer) {
3942
+ var source = this;
4007
3943
 
4008
- innerSubscription.setDisposable(innerSource.subscribe(
4009
- observer.onNext.bind(observer),
4010
- observer.onError.bind(observer),
4011
- function () {
4012
- g.remove(innerSubscription);
4013
- hasCurrent = false;
4014
- if (isStopped && g.length === 1) {
4015
- observer.onCompleted();
4016
- }
4017
- }));
4018
- }
3944
+ function transformForObserver(observer) {
3945
+ return {
3946
+ init: function() {
3947
+ return observer;
4019
3948
  },
4020
- observer.onError.bind(observer),
4021
- function () {
4022
- isStopped = true;
4023
- if (!hasCurrent && g.length === 1) {
4024
- observer.onCompleted();
4025
- }
4026
- }));
4027
-
4028
- return g;
4029
- });
4030
- };
4031
-
4032
- /*
4033
- * Performs a exclusive map waiting for the first to finish before subscribing to another observable.
4034
- * Observables that come in between subscriptions will be dropped on the floor.
4035
- * @param {Function} selector Selector to invoke for every item in the current subscription.
4036
- * @param {Any} [thisArg] An optional context to invoke with the selector parameter.
4037
- * @returns {Observable} An exclusive observable with only the results that happen when subscribed.
4038
- */
4039
- observableProto.exclusiveMap = function (selector, thisArg) {
4040
- var sources = this;
4041
- return new AnonymousObservable(function (observer) {
4042
- var index = 0,
4043
- hasCurrent = false,
4044
- isStopped = true,
4045
- m = new SingleAssignmentDisposable(),
4046
- g = new CompositeDisposable();
4047
-
4048
- g.add(m);
4049
-
4050
- m.setDisposable(sources.subscribe(
4051
- function (innerSource) {
4052
-
4053
- if (!hasCurrent) {
4054
- hasCurrent = true;
4055
-
4056
- innerSubscription = new SingleAssignmentDisposable();
4057
- g.add(innerSubscription);
4058
-
4059
- isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
4060
-
4061
- innerSubscription.setDisposable(innerSource.subscribe(
4062
- function (x) {
4063
- var result;
4064
- try {
4065
- result = selector.call(thisArg, x, index++, innerSource);
4066
- } catch (e) {
4067
- observer.onError(e);
4068
- return;
4069
- }
4070
-
4071
- observer.onNext(result);
4072
- },
4073
- observer.onError.bind(observer),
4074
- function () {
4075
- g.remove(innerSubscription);
4076
- hasCurrent = false;
4077
-
4078
- if (isStopped && g.length === 1) {
4079
- observer.onCompleted();
4080
- }
4081
- }));
4082
- }
3949
+ step: function(obs, input) {
3950
+ return obs.onNext(input);
4083
3951
  },
4084
- observer.onError.bind(observer),
4085
- function () {
4086
- isStopped = true;
4087
- if (g.length === 1 && !hasCurrent) {
4088
- observer.onCompleted();
3952
+ result: function(obs) {
3953
+ return obs.onCompleted();
3954
+ }
3955
+ };
3956
+ }
3957
+
3958
+ return new AnonymousObservable(function(observer) {
3959
+ var xform = transducer(transformForObserver(observer));
3960
+ return source.subscribe(
3961
+ function(v) {
3962
+ try {
3963
+ xform.step(observer, v);
3964
+ } catch (e) {
3965
+ observer.onError(e);
4089
3966
  }
4090
- }));
4091
- return g;
3967
+ },
3968
+ observer.onError.bind(observer),
3969
+ function() { xform.result(observer); }
3970
+ );
4092
3971
  });
4093
3972
  };
4094
3973