a zip code crypto-currency system good for red ONLY

defaultIfEmpty.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /** PURE_IMPORTS_START .._Subscriber PURE_IMPORTS_END */
  2. var __extends = (this && this.__extends) || function (d, b) {
  3. for (var p in b)
  4. if (b.hasOwnProperty(p))
  5. d[p] = b[p];
  6. function __() { this.constructor = d; }
  7. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  8. };
  9. import { Subscriber } from '../Subscriber';
  10. /* tslint:enable:max-line-length */
  11. /**
  12. * Emits a given value if the source Observable completes without emitting any
  13. * `next` value, otherwise mirrors the source Observable.
  14. *
  15. * <span class="informal">If the source Observable turns out to be empty, then
  16. * this operator will emit a default value.</span>
  17. *
  18. * <img src="./img/defaultIfEmpty.png" width="100%">
  19. *
  20. * `defaultIfEmpty` emits the values emitted by the source Observable or a
  21. * specified default value if the source Observable is empty (completes without
  22. * having emitted any `next` value).
  23. *
  24. * @example <caption>If no clicks happen in 5 seconds, then emit "no clicks"</caption>
  25. * var clicks = Rx.Observable.fromEvent(document, 'click');
  26. * var clicksBeforeFive = clicks.takeUntil(Rx.Observable.interval(5000));
  27. * var result = clicksBeforeFive.defaultIfEmpty('no clicks');
  28. * result.subscribe(x => console.log(x));
  29. *
  30. * @see {@link empty}
  31. * @see {@link last}
  32. *
  33. * @param {any} [defaultValue=null] The default value used if the source
  34. * Observable is empty.
  35. * @return {Observable} An Observable that emits either the specified
  36. * `defaultValue` if the source Observable emits no items, or the values emitted
  37. * by the source Observable.
  38. * @method defaultIfEmpty
  39. * @owner Observable
  40. */
  41. export function defaultIfEmpty(defaultValue) {
  42. if (defaultValue === void 0) {
  43. defaultValue = null;
  44. }
  45. return function (source) { return source.lift(new DefaultIfEmptyOperator(defaultValue)); };
  46. }
  47. var DefaultIfEmptyOperator = /*@__PURE__*/ (/*@__PURE__*/ function () {
  48. function DefaultIfEmptyOperator(defaultValue) {
  49. this.defaultValue = defaultValue;
  50. }
  51. DefaultIfEmptyOperator.prototype.call = function (subscriber, source) {
  52. return source.subscribe(new DefaultIfEmptySubscriber(subscriber, this.defaultValue));
  53. };
  54. return DefaultIfEmptyOperator;
  55. }());
  56. /**
  57. * We need this JSDoc comment for affecting ESDoc.
  58. * @ignore
  59. * @extends {Ignored}
  60. */
  61. var DefaultIfEmptySubscriber = /*@__PURE__*/ (/*@__PURE__*/ function (_super) {
  62. __extends(DefaultIfEmptySubscriber, _super);
  63. function DefaultIfEmptySubscriber(destination, defaultValue) {
  64. _super.call(this, destination);
  65. this.defaultValue = defaultValue;
  66. this.isEmpty = true;
  67. }
  68. DefaultIfEmptySubscriber.prototype._next = function (value) {
  69. this.isEmpty = false;
  70. this.destination.next(value);
  71. };
  72. DefaultIfEmptySubscriber.prototype._complete = function () {
  73. if (this.isEmpty) {
  74. this.destination.next(this.defaultValue);
  75. }
  76. this.destination.complete();
  77. };
  78. return DefaultIfEmptySubscriber;
  79. }(Subscriber));
  80. //# sourceMappingURL=defaultIfEmpty.js.map