rxjs-rails 2.2.27 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +0 -3
  3. data/lib/rxjs/rails/version.rb +1 -1
  4. data/vendor/assets/javascripts/rx.aggregates.min.js +1 -1
  5. data/vendor/assets/javascripts/rx.all.compat.js +1545 -1441
  6. data/vendor/assets/javascripts/rx.all.compat.min.js +3 -3
  7. data/vendor/assets/javascripts/rx.all.js +1545 -1441
  8. data/vendor/assets/javascripts/rx.all.min.js +3 -3
  9. data/vendor/assets/javascripts/rx.async.compat.js +149 -152
  10. data/vendor/assets/javascripts/rx.async.compat.min.js +1 -1
  11. data/vendor/assets/javascripts/rx.async.js +140 -143
  12. data/vendor/assets/javascripts/rx.async.min.js +1 -1
  13. data/vendor/assets/javascripts/rx.backpressure.min.js +1 -1
  14. data/vendor/assets/javascripts/rx.binding.js +18 -18
  15. data/vendor/assets/javascripts/rx.binding.min.js +1 -1
  16. data/vendor/assets/javascripts/rx.coincidence.min.js +1 -1
  17. data/vendor/assets/javascripts/rx.compat.js +490 -339
  18. data/vendor/assets/javascripts/rx.compat.min.js +2 -2
  19. data/vendor/assets/javascripts/rx.core.compat.js +109 -141
  20. data/vendor/assets/javascripts/rx.core.compat.min.js +1 -1
  21. data/vendor/assets/javascripts/rx.core.js +109 -141
  22. data/vendor/assets/javascripts/rx.core.min.js +1 -1
  23. data/vendor/assets/javascripts/rx.experimental.js +129 -136
  24. data/vendor/assets/javascripts/rx.experimental.min.js +1 -1
  25. data/vendor/assets/javascripts/rx.joinpatterns.js +59 -59
  26. data/vendor/assets/javascripts/rx.joinpatterns.min.js +1 -1
  27. data/vendor/assets/javascripts/rx.js +490 -339
  28. data/vendor/assets/javascripts/rx.lite.compat.js +1099 -954
  29. data/vendor/assets/javascripts/rx.lite.compat.min.js +2 -2
  30. data/vendor/assets/javascripts/rx.lite.extras.min.js +1 -1
  31. data/vendor/assets/javascripts/rx.lite.js +1099 -954
  32. data/vendor/assets/javascripts/rx.lite.min.js +2 -2
  33. data/vendor/assets/javascripts/rx.min.js +2 -2
  34. data/vendor/assets/javascripts/rx.testing.min.js +1 -1
  35. data/vendor/assets/javascripts/rx.time.js +715 -747
  36. data/vendor/assets/javascripts/rx.time.min.js +1 -1
  37. data/vendor/assets/javascripts/rx.virtualtime.min.js +1 -1
  38. metadata +11 -10
@@ -31,6 +31,8 @@
31
31
 
32
32
  // Defaults
33
33
  var noop = Rx.helpers.noop = function () { },
34
+ notDefined = Rx.helpers.notDefined = function (x) { return typeof x === 'undefined'; },
35
+ isScheduler = Rx.helpers.isScheduler = function (x) { return x instanceof Rx.Scheduler; },
34
36
  identity = Rx.helpers.identity = function (x) { return x; },
35
37
  pluck = Rx.helpers.pluck = function (property) { return function (x) { return x[property]; }; },
36
38
  just = Rx.helpers.just = function (value) { return function () { return value; }; },
@@ -50,14 +52,13 @@
50
52
  function checkDisposed() { if (this.isDisposed) { throw new Error(objectDisposed); } }
51
53
 
52
54
  // Shim in iterator support
53
- var $iterator$ = (typeof Symbol === 'object' && Symbol.iterator) ||
55
+ var $iterator$ = (typeof Symbol === 'function' && Symbol.iterator) ||
54
56
  '_es6shim_iterator_';
55
- // Firefox ships a partial implementation using the name @@iterator.
56
- // https://bugzilla.mozilla.org/show_bug.cgi?id=907077#c14
57
- // So use that name if we detect it.
57
+ // Bug for mozilla version
58
58
  if (root.Set && typeof new root.Set()['@@iterator'] === 'function') {
59
59
  $iterator$ = '@@iterator';
60
60
  }
61
+
61
62
  var doneEnumerator = { done: true, value: undefined };
62
63
 
63
64
  /** `Object#toString` result shortcuts */
@@ -1512,140 +1513,111 @@
1512
1513
  return CatchScheduler;
1513
1514
  }(Scheduler));
1514
1515
 
1515
- /**
1516
- * Represents a notification to an observer.
1517
- */
1518
- var Notification = Rx.Notification = (function () {
1519
- function Notification(kind, hasValue) {
1520
- this.hasValue = hasValue == null ? false : hasValue;
1521
- this.kind = kind;
1522
- }
1523
-
1524
- var NotificationPrototype = Notification.prototype;
1525
-
1526
- /**
1527
- * Invokes the delegate corresponding to the notification or the observer's method corresponding to the notification and returns the produced result.
1528
- *
1529
- * @memberOf Notification
1530
- * @param {Any} observerOrOnNext Delegate to invoke for an OnNext notification or Observer to invoke the notification on..
1531
- * @param {Function} onError Delegate to invoke for an OnError notification.
1532
- * @param {Function} onCompleted Delegate to invoke for an OnCompleted notification.
1533
- * @returns {Any} Result produced by the observation.
1534
- */
1535
- NotificationPrototype.accept = function (observerOrOnNext, onError, onCompleted) {
1536
- if (arguments.length === 1 && typeof observerOrOnNext === 'object') {
1537
- return this._acceptObservable(observerOrOnNext);
1538
- }
1539
- return this._accept(observerOrOnNext, onError, onCompleted);
1540
- };
1541
-
1542
- /**
1543
- * Returns an observable sequence with a single notification.
1544
- *
1545
- * @memberOf Notification
1546
- * @param {Scheduler} [scheduler] Scheduler to send out the notification calls on.
1547
- * @returns {Observable} The observable sequence that surfaces the behavior of the notification upon subscription.
1548
- */
1549
- NotificationPrototype.toObservable = function (scheduler) {
1550
- var notification = this;
1551
- scheduler || (scheduler = immediateScheduler);
1552
- return new AnonymousObservable(function (observer) {
1553
- return scheduler.schedule(function () {
1554
- notification._acceptObservable(observer);
1555
- if (notification.kind === 'N') {
1556
- observer.onCompleted();
1557
- }
1558
- });
1559
- });
1560
- };
1561
-
1562
- return Notification;
1563
- })();
1516
+ /**
1517
+ * Represents a notification to an observer.
1518
+ */
1519
+ var Notification = Rx.Notification = (function () {
1520
+ function Notification(kind, hasValue) {
1521
+ this.hasValue = hasValue == null ? false : hasValue;
1522
+ this.kind = kind;
1523
+ }
1564
1524
 
1565
1525
  /**
1566
- * Creates an object that represents an OnNext notification to an observer.
1567
- * @param {Any} value The value contained in the notification.
1568
- * @returns {Notification} The OnNext notification containing the value.
1526
+ * Invokes the delegate corresponding to the notification or the observer's method corresponding to the notification and returns the produced result.
1527
+ *
1528
+ * @memberOf Notification
1529
+ * @param {Any} observerOrOnNext Delegate to invoke for an OnNext notification or Observer to invoke the notification on..
1530
+ * @param {Function} onError Delegate to invoke for an OnError notification.
1531
+ * @param {Function} onCompleted Delegate to invoke for an OnCompleted notification.
1532
+ * @returns {Any} Result produced by the observation.
1569
1533
  */
1570
- var notificationCreateOnNext = Notification.createOnNext = (function () {
1571
-
1572
- function _accept (onNext) {
1573
- return onNext(this.value);
1574
- }
1575
-
1576
- function _acceptObservable(observer) {
1577
- return observer.onNext(this.value);
1578
- }
1579
-
1580
- function toString () {
1581
- return 'OnNext(' + this.value + ')';
1582
- }
1583
-
1584
- return function (value) {
1585
- var notification = new Notification('N', true);
1586
- notification.value = value;
1587
- notification._accept = _accept;
1588
- notification._acceptObservable = _acceptObservable;
1589
- notification.toString = toString;
1590
- return notification;
1591
- };
1592
- }());
1534
+ Notification.prototype.accept = function (observerOrOnNext, onError, onCompleted) {
1535
+ return observerOrOnNext && typeof observerOrOnNext === 'object' ?
1536
+ this._acceptObservable(observerOrOnNext) :
1537
+ this._accept(observerOrOnNext, onError, onCompleted);
1538
+ };
1593
1539
 
1594
1540
  /**
1595
- * Creates an object that represents an OnError notification to an observer.
1596
- * @param {Any} error The exception contained in the notification.
1597
- * @returns {Notification} The OnError notification containing the exception.
1541
+ * Returns an observable sequence with a single notification.
1542
+ *
1543
+ * @memberOf Notifications
1544
+ * @param {Scheduler} [scheduler] Scheduler to send out the notification calls on.
1545
+ * @returns {Observable} The observable sequence that surfaces the behavior of the notification upon subscription.
1598
1546
  */
1599
- var notificationCreateOnError = Notification.createOnError = (function () {
1600
-
1601
- function _accept (onNext, onError) {
1602
- return onError(this.exception);
1603
- }
1604
-
1605
- function _acceptObservable(observer) {
1606
- return observer.onError(this.exception);
1607
- }
1608
-
1609
- function toString () {
1610
- return 'OnError(' + this.exception + ')';
1611
- }
1547
+ Notification.prototype.toObservable = function (scheduler) {
1548
+ var notification = this;
1549
+ isScheduler(scheduler) || (scheduler = immediateScheduler);
1550
+ return new AnonymousObservable(function (observer) {
1551
+ return scheduler.schedule(function () {
1552
+ notification._acceptObservable(observer);
1553
+ notification.kind === 'N' && observer.onCompleted();
1554
+ });
1555
+ });
1556
+ };
1612
1557
 
1613
- return function (exception) {
1614
- var notification = new Notification('E');
1615
- notification.exception = exception;
1616
- notification._accept = _accept;
1617
- notification._acceptObservable = _acceptObservable;
1618
- notification.toString = toString;
1619
- return notification;
1620
- };
1621
- }());
1558
+ return Notification;
1559
+ })();
1622
1560
 
1623
- /**
1624
- * Creates an object that represents an OnCompleted notification to an observer.
1625
- * @returns {Notification} The OnCompleted notification.
1626
- */
1627
- var notificationCreateOnCompleted = Notification.createOnCompleted = (function () {
1561
+ /**
1562
+ * Creates an object that represents an OnNext notification to an observer.
1563
+ * @param {Any} value The value contained in the notification.
1564
+ * @returns {Notification} The OnNext notification containing the value.
1565
+ */
1566
+ var notificationCreateOnNext = Notification.createOnNext = (function () {
1567
+
1568
+ function _accept (onNext) { return onNext(this.value); }
1569
+ function _acceptObservable(observer) { return observer.onNext(this.value); }
1570
+ function toString () { return 'OnNext(' + this.value + ')'; }
1571
+
1572
+ return function (value) {
1573
+ var notification = new Notification('N', true);
1574
+ notification.value = value;
1575
+ notification._accept = _accept;
1576
+ notification._acceptObservable = _acceptObservable;
1577
+ notification.toString = toString;
1578
+ return notification;
1579
+ };
1580
+ }());
1628
1581
 
1629
- function _accept (onNext, onError, onCompleted) {
1630
- return onCompleted();
1631
- }
1582
+ /**
1583
+ * Creates an object that represents an OnError notification to an observer.
1584
+ * @param {Any} error The exception contained in the notification.
1585
+ * @returns {Notification} The OnError notification containing the exception.
1586
+ */
1587
+ var notificationCreateOnError = Notification.createOnError = (function () {
1588
+
1589
+ function _accept (onNext, onError) { return onError(this.exception); }
1590
+ function _acceptObservable(observer) { return observer.onError(this.exception); }
1591
+ function toString () { return 'OnError(' + this.exception + ')'; }
1592
+
1593
+ return function (exception) {
1594
+ var notification = new Notification('E');
1595
+ notification.exception = exception;
1596
+ notification._accept = _accept;
1597
+ notification._acceptObservable = _acceptObservable;
1598
+ notification.toString = toString;
1599
+ return notification;
1600
+ };
1601
+ }());
1632
1602
 
1633
- function _acceptObservable(observer) {
1634
- return observer.onCompleted();
1635
- }
1603
+ /**
1604
+ * Creates an object that represents an OnCompleted notification to an observer.
1605
+ * @returns {Notification} The OnCompleted notification.
1606
+ */
1607
+ var notificationCreateOnCompleted = Notification.createOnCompleted = (function () {
1636
1608
 
1637
- function toString () {
1638
- return 'OnCompleted()';
1639
- }
1609
+ function _accept (onNext, onError, onCompleted) { return onCompleted(); }
1610
+ function _acceptObservable(observer) { return observer.onCompleted(); }
1611
+ function toString () { return 'OnCompleted()'; }
1640
1612
 
1641
- return function () {
1642
- var notification = new Notification('C');
1643
- notification._accept = _accept;
1644
- notification._acceptObservable = _acceptObservable;
1645
- notification.toString = toString;
1646
- return notification;
1647
- };
1648
- }());
1613
+ return function () {
1614
+ var notification = new Notification('C');
1615
+ notification._accept = _accept;
1616
+ notification._acceptObservable = _acceptObservable;
1617
+ notification.toString = toString;
1618
+ return notification;
1619
+ };
1620
+ }());
1649
1621
 
1650
1622
  var Enumerator = Rx.internals.Enumerator = function (next) {
1651
1623
  this._next = next;
@@ -2325,130 +2297,180 @@
2325
2297
  });
2326
2298
  };
2327
2299
 
2328
- /**
2329
- * Returns an empty observable sequence, using the specified scheduler to send out the single OnCompleted message.
2330
- *
2331
- * @example
2332
- * var res = Rx.Observable.empty();
2333
- * var res = Rx.Observable.empty(Rx.Scheduler.timeout);
2334
- * @param {Scheduler} [scheduler] Scheduler to send the termination call on.
2335
- * @returns {Observable} An observable sequence with no elements.
2336
- */
2337
- var observableEmpty = Observable.empty = function (scheduler) {
2338
- scheduler || (scheduler = immediateScheduler);
2339
- return new AnonymousObservable(function (observer) {
2340
- return scheduler.schedule(function () {
2341
- observer.onCompleted();
2342
- });
2343
- });
2344
- };
2300
+ /**
2301
+ * Returns an empty observable sequence, using the specified scheduler to send out the single OnCompleted message.
2302
+ *
2303
+ * @example
2304
+ * var res = Rx.Observable.empty();
2305
+ * var res = Rx.Observable.empty(Rx.Scheduler.timeout);
2306
+ * @param {Scheduler} [scheduler] Scheduler to send the termination call on.
2307
+ * @returns {Observable} An observable sequence with no elements.
2308
+ */
2309
+ var observableEmpty = Observable.empty = function (scheduler) {
2310
+ isScheduler(scheduler) || (scheduler = immediateScheduler);
2311
+ return new AnonymousObservable(function (observer) {
2312
+ return scheduler.schedule(function () {
2313
+ observer.onCompleted();
2314
+ });
2315
+ });
2316
+ };
2345
2317
 
2346
- /**
2347
- * Converts an array to an observable sequence, using an optional scheduler to enumerate the array.
2348
- *
2349
- * @example
2350
- * var res = Rx.Observable.fromArray([1,2,3]);
2351
- * var res = Rx.Observable.fromArray([1,2,3], Rx.Scheduler.timeout);
2352
- * @param {Scheduler} [scheduler] Scheduler to run the enumeration of the input sequence on.
2353
- * @returns {Observable} The observable sequence whose elements are pulled from the given enumerable sequence.
2354
- */
2355
- var observableFromArray = Observable.fromArray = function (array, scheduler) {
2356
- scheduler || (scheduler = currentThreadScheduler);
2357
- return new AnonymousObservable(function (observer) {
2358
- var count = 0;
2359
- return scheduler.scheduleRecursive(function (self) {
2360
- if (count < array.length) {
2361
- observer.onNext(array[count++]);
2362
- self();
2363
- } else {
2364
- observer.onCompleted();
2365
- }
2366
- });
2367
- });
2368
- };
2318
+ var maxSafeInteger = Math.pow(2, 53) - 1;
2319
+
2320
+ function numberIsFinite(value) {
2321
+ return typeof value === 'number' && root.isFinite(value);
2322
+ }
2323
+
2324
+ function isNan(n) {
2325
+ return n !== n;
2326
+ }
2327
+
2328
+ function isIterable(o) {
2329
+ return o[$iterator$] !== undefined;
2330
+ }
2331
+
2332
+ function sign(value) {
2333
+ var number = +value;
2334
+ if (number === 0) { return number; }
2335
+ if (isNaN(number)) { return number; }
2336
+ return number < 0 ? -1 : 1;
2337
+ }
2338
+
2339
+ function toLength(o) {
2340
+ var len = +o.length;
2341
+ if (isNaN(len)) { return 0; }
2342
+ if (len === 0 || !numberIsFinite(len)) { return len; }
2343
+ len = sign(len) * Math.floor(Math.abs(len));
2344
+ if (len <= 0) { return 0; }
2345
+ if (len > maxSafeInteger) { return maxSafeInteger; }
2346
+ return len;
2347
+ }
2348
+
2349
+ function isCallable(f) {
2350
+ return Object.prototype.toString.call(f) === '[object Function]' && typeof f === 'function';
2351
+ }
2369
2352
 
2370
2353
  /**
2371
- * Converts an iterable into an Observable sequence
2354
+ * This method creates a new Observable sequence from an array-like or iterable object.
2355
+ * @param {Any} arrayLike An array-like or iterable object to convert to an Observable sequence.
2356
+ * @param {Function} [mapFn] Map function to call on every element of the array.
2357
+ * @param {Any} [thisArg] The context to use calling the mapFn if provided.
2358
+ * @param {Scheduler} [scheduler] Optional scheduler to use for scheduling. If not provided, defaults to Scheduler.currentThread.
2359
+ */
2360
+ Observable.from = function (iterable, mapFn, thisArg, scheduler) {
2361
+ if (iterable == null) {
2362
+ throw new Error('iterable cannot be null.')
2363
+ }
2364
+ if (mapFn && !isCallable(mapFn)) {
2365
+ throw new Error('mapFn when provided must be a function');
2366
+ }
2367
+ isScheduler(scheduler) || (scheduler = currentThreadScheduler);
2368
+ return new AnonymousObservable(function (observer) {
2369
+ var list = Object(iterable),
2370
+ objIsIterable = isIterable(list),
2371
+ len = objIsIterable ? 0 : toLength(list),
2372
+ it = objIsIterable ? list[$iterator$]() : null,
2373
+ i = 0;
2374
+ return scheduler.scheduleRecursive(function (self) {
2375
+ if (i < len || objIsIterable) {
2376
+ var result;
2377
+ if (objIsIterable) {
2378
+ var next = it.next();
2379
+ if (next.done) {
2380
+ observer.onCompleted();
2381
+ return;
2382
+ }
2383
+
2384
+ result = next.value;
2385
+ } else {
2386
+ result = list[i];
2387
+ }
2388
+
2389
+ if (mapFn && isCallable(mapFn)) {
2390
+ try {
2391
+ result = thisArg ? mapFn.call(thisArg, result, i) : mapFn(result, i);
2392
+ } catch (e) {
2393
+ observer.onError(e);
2394
+ return;
2395
+ }
2396
+ }
2397
+
2398
+ observer.onNext(result);
2399
+ i++;
2400
+ self();
2401
+ } else {
2402
+ observer.onCompleted();
2403
+ }
2404
+ });
2405
+ });
2406
+ };
2407
+ /**
2408
+ * Converts an array to an observable sequence, using an optional scheduler to enumerate the array.
2372
2409
  *
2373
2410
  * @example
2374
- * var res = Rx.Observable.fromIterable(new Map());
2375
- * var res = Rx.Observable.fromIterable(new Set(), Rx.Scheduler.timeout);
2411
+ * var res = Rx.Observable.fromArray([1,2,3]);
2412
+ * var res = Rx.Observable.fromArray([1,2,3], Rx.Scheduler.timeout);
2376
2413
  * @param {Scheduler} [scheduler] Scheduler to run the enumeration of the input sequence on.
2377
- * @returns {Observable} The observable sequence whose elements are pulled from the given generator sequence.
2414
+ * @returns {Observable} The observable sequence whose elements are pulled from the given enumerable sequence.
2378
2415
  */
2379
- Observable.fromIterable = function (iterable, scheduler) {
2380
- scheduler || (scheduler = currentThreadScheduler);
2416
+ var observableFromArray = Observable.fromArray = function (array, scheduler) {
2417
+ isScheduler(scheduler) || (scheduler = currentThreadScheduler);
2381
2418
  return new AnonymousObservable(function (observer) {
2382
- var iterator;
2383
- try {
2384
- iterator = iterable[$iterator$]();
2385
- } catch (e) {
2386
- observer.onError(e);
2387
- return;
2388
- }
2419
+ var count = 0, len = array.length;
2420
+ return scheduler.scheduleRecursive(function (self) {
2421
+ if (count < len) {
2422
+ observer.onNext(array[count++]);
2423
+ self();
2424
+ } else {
2425
+ observer.onCompleted();
2426
+ }
2427
+ });
2428
+ });
2429
+ };
2389
2430
 
2431
+ /**
2432
+ * Generates an observable sequence by running a state-driven loop producing the sequence's elements, using the specified scheduler to send out observer messages.
2433
+ *
2434
+ * @example
2435
+ * var res = Rx.Observable.generate(0, function (x) { return x < 10; }, function (x) { return x + 1; }, function (x) { return x; });
2436
+ * var res = Rx.Observable.generate(0, function (x) { return x < 10; }, function (x) { return x + 1; }, function (x) { return x; }, Rx.Scheduler.timeout);
2437
+ * @param {Mixed} initialState Initial state.
2438
+ * @param {Function} condition Condition to terminate generation (upon returning false).
2439
+ * @param {Function} iterate Iteration step function.
2440
+ * @param {Function} resultSelector Selector function for results produced in the sequence.
2441
+ * @param {Scheduler} [scheduler] Scheduler on which to run the generator loop. If not provided, defaults to Scheduler.currentThread.
2442
+ * @returns {Observable} The generated sequence.
2443
+ */
2444
+ Observable.generate = function (initialState, condition, iterate, resultSelector, scheduler) {
2445
+ isScheduler(scheduler) || (scheduler = currentThreadScheduler);
2446
+ return new AnonymousObservable(function (observer) {
2447
+ var first = true, state = initialState;
2390
2448
  return scheduler.scheduleRecursive(function (self) {
2391
- var next;
2449
+ var hasResult, result;
2392
2450
  try {
2393
- next = iterator.next();
2394
- } catch (err) {
2395
- observer.onError(err);
2451
+ if (first) {
2452
+ first = false;
2453
+ } else {
2454
+ state = iterate(state);
2455
+ }
2456
+ hasResult = condition(state);
2457
+ if (hasResult) {
2458
+ result = resultSelector(state);
2459
+ }
2460
+ } catch (exception) {
2461
+ observer.onError(exception);
2396
2462
  return;
2397
2463
  }
2398
-
2399
- if (next.done) {
2400
- observer.onCompleted();
2401
- } else {
2402
- observer.onNext(next.value);
2464
+ if (hasResult) {
2465
+ observer.onNext(result);
2403
2466
  self();
2467
+ } else {
2468
+ observer.onCompleted();
2404
2469
  }
2405
2470
  });
2406
2471
  });
2407
2472
  };
2408
2473
 
2409
- /**
2410
- * Generates an observable sequence by running a state-driven loop producing the sequence's elements, using the specified scheduler to send out observer messages.
2411
- *
2412
- * @example
2413
- * var res = Rx.Observable.generate(0, function (x) { return x < 10; }, function (x) { return x + 1; }, function (x) { return x; });
2414
- * var res = Rx.Observable.generate(0, function (x) { return x < 10; }, function (x) { return x + 1; }, function (x) { return x; }, Rx.Scheduler.timeout);
2415
- * @param {Mixed} initialState Initial state.
2416
- * @param {Function} condition Condition to terminate generation (upon returning false).
2417
- * @param {Function} iterate Iteration step function.
2418
- * @param {Function} resultSelector Selector function for results produced in the sequence.
2419
- * @param {Scheduler} [scheduler] Scheduler on which to run the generator loop. If not provided, defaults to Scheduler.currentThread.
2420
- * @returns {Observable} The generated sequence.
2421
- */
2422
- Observable.generate = function (initialState, condition, iterate, resultSelector, scheduler) {
2423
- scheduler || (scheduler = currentThreadScheduler);
2424
- return new AnonymousObservable(function (observer) {
2425
- var first = true, state = initialState;
2426
- return scheduler.scheduleRecursive(function (self) {
2427
- var hasResult, result;
2428
- try {
2429
- if (first) {
2430
- first = false;
2431
- } else {
2432
- state = iterate(state);
2433
- }
2434
- hasResult = condition(state);
2435
- if (hasResult) {
2436
- result = resultSelector(state);
2437
- }
2438
- } catch (exception) {
2439
- observer.onError(exception);
2440
- return;
2441
- }
2442
- if (hasResult) {
2443
- observer.onNext(result);
2444
- self();
2445
- } else {
2446
- observer.onCompleted();
2447
- }
2448
- });
2449
- });
2450
- };
2451
-
2452
2474
  /**
2453
2475
  * Returns a non-terminating observable sequence, which can be used to denote an infinite duration (e.g. when using reactive joins).
2454
2476
  * @returns {Observable} An observable sequence whose observers will never get called.
@@ -2459,92 +2481,114 @@
2459
2481
  });
2460
2482
  };
2461
2483
 
2462
- /**
2463
- * Generates an observable sequence of integral numbers within a specified range, using the specified scheduler to send out observer messages.
2464
- *
2465
- * @example
2466
- * var res = Rx.Observable.range(0, 10);
2467
- * var res = Rx.Observable.range(0, 10, Rx.Scheduler.timeout);
2468
- * @param {Number} start The value of the first integer in the sequence.
2469
- * @param {Number} count The number of sequential integers to generate.
2470
- * @param {Scheduler} [scheduler] Scheduler to run the generator loop on. If not specified, defaults to Scheduler.currentThread.
2471
- * @returns {Observable} An observable sequence that contains a range of sequential integral numbers.
2472
- */
2473
- Observable.range = function (start, count, scheduler) {
2474
- scheduler || (scheduler = currentThreadScheduler);
2475
- return new AnonymousObservable(function (observer) {
2476
- return scheduler.scheduleRecursiveWithState(0, function (i, self) {
2477
- if (i < count) {
2478
- observer.onNext(start + i);
2479
- self(i + 1);
2480
- } else {
2481
- observer.onCompleted();
2482
- }
2483
- });
2484
- });
2485
- };
2484
+ /**
2485
+ * This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments.
2486
+ * @example
2487
+ * var res = Rx.Observable.of(1,2,3);
2488
+ * @returns {Observable} The observable sequence whose elements are pulled from the given arguments.
2489
+ */
2490
+ Observable.of = function () {
2491
+ var len = arguments.length, args = new Array(len);
2492
+ for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
2493
+ return observableFromArray(args);
2494
+ };
2486
2495
 
2487
- /**
2488
- * Generates an observable sequence that repeats the given element the specified number of times, using the specified scheduler to send out observer messages.
2489
- *
2490
- * @example
2491
- * var res = Rx.Observable.repeat(42);
2492
- * var res = Rx.Observable.repeat(42, 4);
2493
- * 3 - res = Rx.Observable.repeat(42, 4, Rx.Scheduler.timeout);
2494
- * 4 - res = Rx.Observable.repeat(42, null, Rx.Scheduler.timeout);
2495
- * @param {Mixed} value Element to repeat.
2496
- * @param {Number} repeatCount [Optiona] Number of times to repeat the element. If not specified, repeats indefinitely.
2497
- * @param {Scheduler} scheduler Scheduler to run the producer loop on. If not specified, defaults to Scheduler.immediate.
2498
- * @returns {Observable} An observable sequence that repeats the given element the specified number of times.
2499
- */
2500
- Observable.repeat = function (value, repeatCount, scheduler) {
2501
- scheduler || (scheduler = currentThreadScheduler);
2502
- if (repeatCount == null) {
2503
- repeatCount = -1;
2496
+ /**
2497
+ * This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments.
2498
+ * @example
2499
+ * var res = Rx.Observable.of(1,2,3);
2500
+ * @param {Scheduler} scheduler A scheduler to use for scheduling the arguments.
2501
+ * @returns {Observable} The observable sequence whose elements are pulled from the given arguments.
2502
+ */
2503
+ var observableOf = Observable.ofWithScheduler = function (scheduler) {
2504
+ var len = arguments.length - 1, args = new Array(len);
2505
+ for(var i = 0; i < len; i++) { args[i] = arguments[i + 1]; }
2506
+ return observableFromArray(args, scheduler);
2507
+ };
2508
+
2509
+ /**
2510
+ * Generates an observable sequence of integral numbers within a specified range, using the specified scheduler to send out observer messages.
2511
+ *
2512
+ * @example
2513
+ * var res = Rx.Observable.range(0, 10);
2514
+ * var res = Rx.Observable.range(0, 10, Rx.Scheduler.timeout);
2515
+ * @param {Number} start The value of the first integer in the sequence.
2516
+ * @param {Number} count The number of sequential integers to generate.
2517
+ * @param {Scheduler} [scheduler] Scheduler to run the generator loop on. If not specified, defaults to Scheduler.currentThread.
2518
+ * @returns {Observable} An observable sequence that contains a range of sequential integral numbers.
2519
+ */
2520
+ Observable.range = function (start, count, scheduler) {
2521
+ isScheduler(scheduler) || (scheduler = currentThreadScheduler);
2522
+ return new AnonymousObservable(function (observer) {
2523
+ return scheduler.scheduleRecursiveWithState(0, function (i, self) {
2524
+ if (i < count) {
2525
+ observer.onNext(start + i);
2526
+ self(i + 1);
2527
+ } else {
2528
+ observer.onCompleted();
2504
2529
  }
2505
- return observableReturn(value, scheduler).repeat(repeatCount);
2506
- };
2530
+ });
2531
+ });
2532
+ };
2507
2533
 
2508
- /**
2509
- * Returns an observable sequence that contains a single element, using the specified scheduler to send out observer messages.
2510
- * There is an alias called 'returnValue' for browsers <IE9.
2511
- *
2512
- * @example
2513
- * var res = Rx.Observable.return(42);
2514
- * var res = Rx.Observable.return(42, Rx.Scheduler.timeout);
2515
- * @param {Mixed} value Single element in the resulting observable sequence.
2516
- * @param {Scheduler} scheduler Scheduler to send the single element on. If not specified, defaults to Scheduler.immediate.
2517
- * @returns {Observable} An observable sequence containing the single specified element.
2518
- */
2519
- var observableReturn = Observable['return'] = Observable.returnValue = function (value, scheduler) {
2520
- scheduler || (scheduler = immediateScheduler);
2521
- return new AnonymousObservable(function (observer) {
2522
- return scheduler.schedule(function () {
2523
- observer.onNext(value);
2524
- observer.onCompleted();
2525
- });
2526
- });
2527
- };
2534
+ /**
2535
+ * Generates an observable sequence that repeats the given element the specified number of times, using the specified scheduler to send out observer messages.
2536
+ *
2537
+ * @example
2538
+ * var res = Rx.Observable.repeat(42);
2539
+ * var res = Rx.Observable.repeat(42, 4);
2540
+ * 3 - res = Rx.Observable.repeat(42, 4, Rx.Scheduler.timeout);
2541
+ * 4 - res = Rx.Observable.repeat(42, null, Rx.Scheduler.timeout);
2542
+ * @param {Mixed} value Element to repeat.
2543
+ * @param {Number} repeatCount [Optiona] Number of times to repeat the element. If not specified, repeats indefinitely.
2544
+ * @param {Scheduler} scheduler Scheduler to run the producer loop on. If not specified, defaults to Scheduler.immediate.
2545
+ * @returns {Observable} An observable sequence that repeats the given element the specified number of times.
2546
+ */
2547
+ Observable.repeat = function (value, repeatCount, scheduler) {
2548
+ isScheduler(scheduler) || (scheduler = currentThreadScheduler);
2549
+ return observableReturn(value, scheduler).repeat(repeatCount == null ? -1 : repeatCount);
2550
+ };
2528
2551
 
2529
- /**
2530
- * Returns an observable sequence that terminates with an exception, using the specified scheduler to send out the single onError message.
2531
- * There is an alias to this method called 'throwException' for browsers <IE9.
2532
- *
2533
- * @example
2534
- * var res = Rx.Observable.throwException(new Error('Error'));
2535
- * var res = Rx.Observable.throwException(new Error('Error'), Rx.Scheduler.timeout);
2536
- * @param {Mixed} exception An object used for the sequence's termination.
2537
- * @param {Scheduler} scheduler Scheduler to send the exceptional termination call on. If not specified, defaults to Scheduler.immediate.
2538
- * @returns {Observable} The observable sequence that terminates exceptionally with the specified exception object.
2539
- */
2540
- var observableThrow = Observable['throw'] = Observable.throwException = function (exception, scheduler) {
2541
- scheduler || (scheduler = immediateScheduler);
2542
- return new AnonymousObservable(function (observer) {
2543
- return scheduler.schedule(function () {
2544
- observer.onError(exception);
2545
- });
2546
- });
2547
- };
2552
+ /**
2553
+ * Returns an observable sequence that contains a single element, using the specified scheduler to send out observer messages.
2554
+ * There is an alias called 'just', and 'returnValue' for browsers <IE9.
2555
+ *
2556
+ * @example
2557
+ * var res = Rx.Observable.return(42);
2558
+ * var res = Rx.Observable.return(42, Rx.Scheduler.timeout);
2559
+ * @param {Mixed} value Single element in the resulting observable sequence.
2560
+ * @param {Scheduler} scheduler Scheduler to send the single element on. If not specified, defaults to Scheduler.immediate.
2561
+ * @returns {Observable} An observable sequence containing the single specified element.
2562
+ */
2563
+ var observableReturn = Observable['return'] = Observable.returnValue = Observable.just = function (value, scheduler) {
2564
+ isScheduler(scheduler) || (scheduler = immediateScheduler);
2565
+ return new AnonymousObservable(function (observer) {
2566
+ return scheduler.schedule(function () {
2567
+ observer.onNext(value);
2568
+ observer.onCompleted();
2569
+ });
2570
+ });
2571
+ };
2572
+
2573
+ /**
2574
+ * Returns an observable sequence that terminates with an exception, using the specified scheduler to send out the single onError message.
2575
+ * There is an alias to this method called 'throwException' for browsers <IE9.
2576
+ *
2577
+ * @example
2578
+ * var res = Rx.Observable.throw(new Error('Error'));
2579
+ * var res = Rx.Observable.throw(new Error('Error'), Rx.Scheduler.timeout);
2580
+ * @param {Mixed} exception An object used for the sequence's termination.
2581
+ * @param {Scheduler} scheduler Scheduler to send the exceptional termination call on. If not specified, defaults to Scheduler.immediate.
2582
+ * @returns {Observable} The observable sequence that terminates exceptionally with the specified exception object.
2583
+ */
2584
+ var observableThrow = Observable['throw'] = Observable.throwException = function (exception, scheduler) {
2585
+ isScheduler(scheduler) || (scheduler = immediateScheduler);
2586
+ return new AnonymousObservable(function (observer) {
2587
+ return scheduler.schedule(function () {
2588
+ observer.onError(exception);
2589
+ });
2590
+ });
2591
+ };
2548
2592
 
2549
2593
  /**
2550
2594
  * Constructs an observable sequence that depends on a resource object, whose lifetime is tied to the resulting observable sequence's lifetime.
@@ -3449,18 +3493,19 @@
3449
3493
  return enumerableRepeat(this, repeatCount).concat();
3450
3494
  };
3451
3495
 
3452
- /**
3453
- * Repeats the source observable sequence the specified number of times or until it successfully terminates. If the retry count is not specified, it retries indefinitely.
3454
- *
3455
- * @example
3456
- * var res = retried = retry.repeat();
3457
- * var res = retried = retry.repeat(42);
3458
- * @param {Number} [retryCount] Number of times to retry the sequence. If not provided, retry the sequence indefinitely.
3459
- * @returns {Observable} An observable sequence producing the elements of the given sequence repeatedly until it terminates successfully.
3460
- */
3461
- observableProto.retry = function (retryCount) {
3462
- return enumerableRepeat(this, retryCount).catchException();
3463
- };
3496
+ /**
3497
+ * Repeats the source observable sequence the specified number of times or until it successfully terminates. If the retry count is not specified, it retries indefinitely.
3498
+ * Note if you encounter an error and want it to retry once, then you must use .retry(2);
3499
+ *
3500
+ * @example
3501
+ * var res = retried = retry.repeat();
3502
+ * var res = retried = retry.repeat(2);
3503
+ * @param {Number} [retryCount] Number of times to retry the sequence. If not provided, retry the sequence indefinitely.
3504
+ * @returns {Observable} An observable sequence producing the elements of the given sequence repeatedly until it terminates successfully.
3505
+ */
3506
+ observableProto.retry = function (retryCount) {
3507
+ return enumerableRepeat(this, retryCount).catchException();
3508
+ };
3464
3509
 
3465
3510
  /**
3466
3511
  * Applies an accumulator function over an observable sequence and returns each intermediate result. The optional seed value is used as the initial accumulator value.
@@ -4025,7 +4070,7 @@
4025
4070
  * @returns {Observable} An observable sequence whose elements are the result of invoking the transform function on each element of source producing an Observable of Observable sequences
4026
4071
  * and that at any point in time produces the elements of the most recent inner observable sequence that has been received.
4027
4072
  */
4028
- observableProto.selectSwitch = observableProto.flatMapLatest = function (selector, thisArg) {
4073
+ observableProto.selectSwitch = observableProto.flatMapLatest = observableProto.switchMap = function (selector, thisArg) {
4029
4074
  return this.select(selector, thisArg).switchLatest();
4030
4075
  };
4031
4076
 
@@ -4174,6 +4219,116 @@
4174
4219
  });
4175
4220
  };
4176
4221
 
4222
+ /*
4223
+ * Performs a exclusive waiting for the first to finish before subscribing to another observable.
4224
+ * Observables that come in between subscriptions will be dropped on the floor.
4225
+ * @returns {Observable} A exclusive observable with only the results that happen when subscribed.
4226
+ */
4227
+ observableProto.exclusive = function () {
4228
+ var sources = this;
4229
+ return new AnonymousObservable(function (observer) {
4230
+ var hasCurrent = false,
4231
+ isStopped = false,
4232
+ m = new SingleAssignmentDisposable(),
4233
+ g = new CompositeDisposable();
4234
+
4235
+ g.add(m);
4236
+
4237
+ m.setDisposable(sources.subscribe(
4238
+ function (innerSource) {
4239
+ if (!hasCurrent) {
4240
+ hasCurrent = true;
4241
+
4242
+ isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
4243
+
4244
+ var innerSubscription = new SingleAssignmentDisposable();
4245
+ g.add(innerSubscription);
4246
+
4247
+ innerSubscription.setDisposable(innerSource.subscribe(
4248
+ observer.onNext.bind(observer),
4249
+ observer.onError.bind(observer),
4250
+ function () {
4251
+ g.remove(innerSubscription);
4252
+ hasCurrent = false;
4253
+ if (isStopped && g.length === 1) {
4254
+ observer.onCompleted();
4255
+ }
4256
+ }));
4257
+ }
4258
+ },
4259
+ observer.onError.bind(observer),
4260
+ function () {
4261
+ isStopped = true;
4262
+ if (!hasCurrent && g.length === 1) {
4263
+ observer.onCompleted();
4264
+ }
4265
+ }));
4266
+
4267
+ return g;
4268
+ });
4269
+ };
4270
+ /*
4271
+ * Performs a exclusive map waiting for the first to finish before subscribing to another observable.
4272
+ * Observables that come in between subscriptions will be dropped on the floor.
4273
+ * @param {Function} selector Selector to invoke for every item in the current subscription.
4274
+ * @param {Any} [thisArg] An optional context to invoke with the selector parameter.
4275
+ * @returns {Observable} An exclusive observable with only the results that happen when subscribed.
4276
+ */
4277
+ observableProto.exclusiveMap = function (selector, thisArg) {
4278
+ var sources = this;
4279
+ return new AnonymousObservable(function (observer) {
4280
+ var index = 0,
4281
+ hasCurrent = false,
4282
+ isStopped = true,
4283
+ m = new SingleAssignmentDisposable(),
4284
+ g = new CompositeDisposable();
4285
+
4286
+ g.add(m);
4287
+
4288
+ m.setDisposable(sources.subscribe(
4289
+ function (innerSource) {
4290
+
4291
+ if (!hasCurrent) {
4292
+ hasCurrent = true;
4293
+
4294
+ innerSubscription = new SingleAssignmentDisposable();
4295
+ g.add(innerSubscription);
4296
+
4297
+ isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
4298
+
4299
+ innerSubscription.setDisposable(innerSource.subscribe(
4300
+ function (x) {
4301
+ var result;
4302
+ try {
4303
+ result = selector.call(thisArg, x, index++, innerSource);
4304
+ } catch (e) {
4305
+ observer.onError(e);
4306
+ return;
4307
+ }
4308
+
4309
+ observer.onNext(result);
4310
+ },
4311
+ observer.onError.bind(observer),
4312
+ function () {
4313
+ g.remove(innerSubscription);
4314
+ hasCurrent = false;
4315
+
4316
+ if (isStopped && g.length === 1) {
4317
+ observer.onCompleted();
4318
+ }
4319
+ }));
4320
+ }
4321
+ },
4322
+ observer.onError.bind(observer),
4323
+ function () {
4324
+ isStopped = true;
4325
+ if (g.length === 1 && !hasCurrent) {
4326
+ observer.onCompleted();
4327
+ }
4328
+ }));
4329
+ return g;
4330
+ });
4331
+ };
4177
4332
  var AnonymousObservable = Rx.AnonymousObservable = (function (__super__) {
4178
4333
  inherits(AnonymousObservable, __super__);
4179
4334
 
@@ -4194,25 +4349,21 @@
4194
4349
  }
4195
4350
 
4196
4351
  function s(observer) {
4197
- var autoDetachObserver = new AutoDetachObserver(observer);
4198
- if (currentThreadScheduler.scheduleRequired()) {
4199
- currentThreadScheduler.schedule(function () {
4200
- try {
4201
- autoDetachObserver.setDisposable(fixSubscriber(subscribe(autoDetachObserver)));
4202
- } catch (e) {
4203
- if (!autoDetachObserver.fail(e)) {
4204
- throw e;
4205
- }
4206
- }
4207
- });
4208
- } else {
4352
+ var setDisposable = function () {
4209
4353
  try {
4210
4354
  autoDetachObserver.setDisposable(fixSubscriber(subscribe(autoDetachObserver)));
4211
4355
  } catch (e) {
4212
4356
  if (!autoDetachObserver.fail(e)) {
4213
4357
  throw e;
4214
- }
4358
+ }
4215
4359
  }
4360
+ };
4361
+
4362
+ var autoDetachObserver = new AutoDetachObserver(observer);
4363
+ if (currentThreadScheduler.scheduleRequired()) {
4364
+ currentThreadScheduler.schedule(setDisposable);
4365
+ } else {
4366
+ setDisposable();
4216
4367
  }
4217
4368
 
4218
4369
  return autoDetachObserver;