IfObservable.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /** PURE_IMPORTS_START .._Observable,.._util_subscribeToResult,.._OuterSubscriber 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. import { subscribeToResult } from '../util/subscribeToResult';
  11. import { OuterSubscriber } from '../OuterSubscriber';
  12. /**
  13. * We need this JSDoc comment for affecting ESDoc.
  14. * @extends {Ignored}
  15. * @hide true
  16. */
  17. export var IfObservable = /*@__PURE__*/ (/*@__PURE__*/ function (_super) {
  18. __extends(IfObservable, _super);
  19. function IfObservable(condition, thenSource, elseSource) {
  20. _super.call(this);
  21. this.condition = condition;
  22. this.thenSource = thenSource;
  23. this.elseSource = elseSource;
  24. }
  25. IfObservable.create = function (condition, thenSource, elseSource) {
  26. return new IfObservable(condition, thenSource, elseSource);
  27. };
  28. /** @deprecated internal use only */ IfObservable.prototype._subscribe = function (subscriber) {
  29. var _a = this, condition = _a.condition, thenSource = _a.thenSource, elseSource = _a.elseSource;
  30. return new IfSubscriber(subscriber, condition, thenSource, elseSource);
  31. };
  32. return IfObservable;
  33. }(Observable));
  34. var IfSubscriber = /*@__PURE__*/ (/*@__PURE__*/ function (_super) {
  35. __extends(IfSubscriber, _super);
  36. function IfSubscriber(destination, condition, thenSource, elseSource) {
  37. _super.call(this, destination);
  38. this.condition = condition;
  39. this.thenSource = thenSource;
  40. this.elseSource = elseSource;
  41. this.tryIf();
  42. }
  43. IfSubscriber.prototype.tryIf = function () {
  44. var _a = this, condition = _a.condition, thenSource = _a.thenSource, elseSource = _a.elseSource;
  45. var result;
  46. try {
  47. result = condition();
  48. var source = result ? thenSource : elseSource;
  49. if (source) {
  50. this.add(subscribeToResult(this, source));
  51. }
  52. else {
  53. this._complete();
  54. }
  55. }
  56. catch (err) {
  57. this._error(err);
  58. }
  59. };
  60. return IfSubscriber;
  61. }(OuterSubscriber));
  62. //# sourceMappingURL=IfObservable.js.map