ScalarObservable.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { Observable } from '../Observable';
  2. /**
  3. * We need this JSDoc comment for affecting ESDoc.
  4. * @extends {Ignored}
  5. * @hide true
  6. */
  7. export class ScalarObservable extends Observable {
  8. constructor(value, scheduler) {
  9. super();
  10. this.value = value;
  11. this.scheduler = scheduler;
  12. this._isScalar = true;
  13. if (scheduler) {
  14. this._isScalar = false;
  15. }
  16. }
  17. static create(value, scheduler) {
  18. return new ScalarObservable(value, scheduler);
  19. }
  20. static dispatch(state) {
  21. const { done, value, subscriber } = state;
  22. if (done) {
  23. subscriber.complete();
  24. return;
  25. }
  26. subscriber.next(value);
  27. if (subscriber.closed) {
  28. return;
  29. }
  30. state.done = true;
  31. this.schedule(state);
  32. }
  33. /** @deprecated internal use only */ _subscribe(subscriber) {
  34. const value = this.value;
  35. const scheduler = this.scheduler;
  36. if (scheduler) {
  37. return scheduler.schedule(ScalarObservable.dispatch, 0, {
  38. done: false, value, subscriber
  39. });
  40. }
  41. else {
  42. subscriber.next(value);
  43. if (!subscriber.closed) {
  44. subscriber.complete();
  45. }
  46. }
  47. }
  48. }
  49. //# sourceMappingURL=ScalarObservable.js.map