UI for Zipcoin Blue

RangeObservable.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. "use strict";
  2. var __extends = (this && this.__extends) || function (d, b) {
  3. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  4. function __() { this.constructor = d; }
  5. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  6. };
  7. var Observable_1 = require('../Observable');
  8. /**
  9. * We need this JSDoc comment for affecting ESDoc.
  10. * @extends {Ignored}
  11. * @hide true
  12. */
  13. var RangeObservable = (function (_super) {
  14. __extends(RangeObservable, _super);
  15. function RangeObservable(start, count, scheduler) {
  16. _super.call(this);
  17. this.start = start;
  18. this._count = count;
  19. this.scheduler = scheduler;
  20. }
  21. /**
  22. * Creates an Observable that emits a sequence of numbers within a specified
  23. * range.
  24. *
  25. * <span class="informal">Emits a sequence of numbers in a range.</span>
  26. *
  27. * <img src="./img/range.png" width="100%">
  28. *
  29. * `range` operator emits a range of sequential integers, in order, where you
  30. * select the `start` of the range and its `length`. By default, uses no
  31. * IScheduler and just delivers the notifications synchronously, but may use
  32. * an optional IScheduler to regulate those deliveries.
  33. *
  34. * @example <caption>Emits the numbers 1 to 10</caption>
  35. * var numbers = Rx.Observable.range(1, 10);
  36. * numbers.subscribe(x => console.log(x));
  37. *
  38. * @see {@link timer}
  39. * @see {@link interval}
  40. *
  41. * @param {number} [start=0] The value of the first integer in the sequence.
  42. * @param {number} [count=0] The number of sequential integers to generate.
  43. * @param {Scheduler} [scheduler] A {@link IScheduler} to use for scheduling
  44. * the emissions of the notifications.
  45. * @return {Observable} An Observable of numbers that emits a finite range of
  46. * sequential integers.
  47. * @static true
  48. * @name range
  49. * @owner Observable
  50. */
  51. RangeObservable.create = function (start, count, scheduler) {
  52. if (start === void 0) { start = 0; }
  53. if (count === void 0) { count = 0; }
  54. return new RangeObservable(start, count, scheduler);
  55. };
  56. RangeObservable.dispatch = function (state) {
  57. var start = state.start, index = state.index, count = state.count, subscriber = state.subscriber;
  58. if (index >= count) {
  59. subscriber.complete();
  60. return;
  61. }
  62. subscriber.next(start);
  63. if (subscriber.closed) {
  64. return;
  65. }
  66. state.index = index + 1;
  67. state.start = start + 1;
  68. this.schedule(state);
  69. };
  70. /** @deprecated internal use only */ RangeObservable.prototype._subscribe = function (subscriber) {
  71. var index = 0;
  72. var start = this.start;
  73. var count = this._count;
  74. var scheduler = this.scheduler;
  75. if (scheduler) {
  76. return scheduler.schedule(RangeObservable.dispatch, 0, {
  77. index: index, count: count, start: start, subscriber: subscriber
  78. });
  79. }
  80. else {
  81. do {
  82. if (index++ >= count) {
  83. subscriber.complete();
  84. break;
  85. }
  86. subscriber.next(start++);
  87. if (subscriber.closed) {
  88. break;
  89. }
  90. } while (true);
  91. }
  92. };
  93. return RangeObservable;
  94. }(Observable_1.Observable));
  95. exports.RangeObservable = RangeObservable;
  96. //# sourceMappingURL=RangeObservable.js.map