ScalarObservable.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 ScalarObservable = /*@__PURE__*/ (/*@__PURE__*/ function (_super) {
  16. __extends(ScalarObservable, _super);
  17. function ScalarObservable(value, scheduler) {
  18. _super.call(this);
  19. this.value = value;
  20. this.scheduler = scheduler;
  21. this._isScalar = true;
  22. if (scheduler) {
  23. this._isScalar = false;
  24. }
  25. }
  26. ScalarObservable.create = function (value, scheduler) {
  27. return new ScalarObservable(value, scheduler);
  28. };
  29. ScalarObservable.dispatch = function (state) {
  30. var done = state.done, value = state.value, subscriber = state.subscriber;
  31. if (done) {
  32. subscriber.complete();
  33. return;
  34. }
  35. subscriber.next(value);
  36. if (subscriber.closed) {
  37. return;
  38. }
  39. state.done = true;
  40. this.schedule(state);
  41. };
  42. /** @deprecated internal use only */ ScalarObservable.prototype._subscribe = function (subscriber) {
  43. var value = this.value;
  44. var scheduler = this.scheduler;
  45. if (scheduler) {
  46. return scheduler.schedule(ScalarObservable.dispatch, 0, {
  47. done: false, value: value, subscriber: subscriber
  48. });
  49. }
  50. else {
  51. subscriber.next(value);
  52. if (!subscriber.closed) {
  53. subscriber.complete();
  54. }
  55. }
  56. };
  57. return ScalarObservable;
  58. }(Observable));
  59. //# sourceMappingURL=ScalarObservable.js.map