EmptyObservable.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /** PURE_IMPORTS_START .._Observable 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 { Observable } from '../Observable';
  10. /**
  11. * We need this JSDoc comment for affecting ESDoc.
  12. * @extends {Ignored}
  13. * @hide true
  14. */
  15. export var EmptyObservable = /*@__PURE__*/ (/*@__PURE__*/ function (_super) {
  16. __extends(EmptyObservable, _super);
  17. function EmptyObservable(scheduler) {
  18. _super.call(this);
  19. this.scheduler = scheduler;
  20. }
  21. /**
  22. * Creates an Observable that emits no items to the Observer and immediately
  23. * emits a complete notification.
  24. *
  25. * <span class="informal">Just emits 'complete', and nothing else.
  26. * </span>
  27. *
  28. * <img src="./img/empty.png" width="100%">
  29. *
  30. * This static operator is useful for creating a simple Observable that only
  31. * emits the complete notification. It can be used for composing with other
  32. * Observables, such as in a {@link mergeMap}.
  33. *
  34. * @example <caption>Emit the number 7, then complete.</caption>
  35. * var result = Rx.Observable.empty().startWith(7);
  36. * result.subscribe(x => console.log(x));
  37. *
  38. * @example <caption>Map and flatten only odd numbers to the sequence 'a', 'b', 'c'</caption>
  39. * var interval = Rx.Observable.interval(1000);
  40. * var result = interval.mergeMap(x =>
  41. * x % 2 === 1 ? Rx.Observable.of('a', 'b', 'c') : Rx.Observable.empty()
  42. * );
  43. * result.subscribe(x => console.log(x));
  44. *
  45. * // Results in the following to the console:
  46. * // x is equal to the count on the interval eg(0,1,2,3,...)
  47. * // x will occur every 1000ms
  48. * // if x % 2 is equal to 1 print abc
  49. * // if x % 2 is not equal to 1 nothing will be output
  50. *
  51. * @see {@link create}
  52. * @see {@link never}
  53. * @see {@link of}
  54. * @see {@link throw}
  55. *
  56. * @param {Scheduler} [scheduler] A {@link IScheduler} to use for scheduling
  57. * the emission of the complete notification.
  58. * @return {Observable} An "empty" Observable: emits only the complete
  59. * notification.
  60. * @static true
  61. * @name empty
  62. * @owner Observable
  63. */
  64. EmptyObservable.create = function (scheduler) {
  65. return new EmptyObservable(scheduler);
  66. };
  67. EmptyObservable.dispatch = function (arg) {
  68. var subscriber = arg.subscriber;
  69. subscriber.complete();
  70. };
  71. /** @deprecated internal use only */ EmptyObservable.prototype._subscribe = function (subscriber) {
  72. var scheduler = this.scheduler;
  73. if (scheduler) {
  74. return scheduler.schedule(EmptyObservable.dispatch, 0, { subscriber: subscriber });
  75. }
  76. else {
  77. subscriber.complete();
  78. }
  79. };
  80. return EmptyObservable;
  81. }(Observable));
  82. //# sourceMappingURL=EmptyObservable.js.map