UsingObservable.js 2.3 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 UsingObservable = /*@__PURE__*/ (/*@__PURE__*/ function (_super) {
  18. __extends(UsingObservable, _super);
  19. function UsingObservable(resourceFactory, observableFactory) {
  20. _super.call(this);
  21. this.resourceFactory = resourceFactory;
  22. this.observableFactory = observableFactory;
  23. }
  24. UsingObservable.create = function (resourceFactory, observableFactory) {
  25. return new UsingObservable(resourceFactory, observableFactory);
  26. };
  27. /** @deprecated internal use only */ UsingObservable.prototype._subscribe = function (subscriber) {
  28. var _a = this, resourceFactory = _a.resourceFactory, observableFactory = _a.observableFactory;
  29. var resource;
  30. try {
  31. resource = resourceFactory();
  32. return new UsingSubscriber(subscriber, resource, observableFactory);
  33. }
  34. catch (err) {
  35. subscriber.error(err);
  36. }
  37. };
  38. return UsingObservable;
  39. }(Observable));
  40. var UsingSubscriber = /*@__PURE__*/ (/*@__PURE__*/ function (_super) {
  41. __extends(UsingSubscriber, _super);
  42. function UsingSubscriber(destination, resource, observableFactory) {
  43. _super.call(this, destination);
  44. this.resource = resource;
  45. this.observableFactory = observableFactory;
  46. destination.add(resource);
  47. this.tryUse();
  48. }
  49. UsingSubscriber.prototype.tryUse = function () {
  50. try {
  51. var source = this.observableFactory.call(this, this.resource);
  52. if (source) {
  53. this.add(subscribeToResult(this, source));
  54. }
  55. }
  56. catch (err) {
  57. this._error(err);
  58. }
  59. };
  60. return UsingSubscriber;
  61. }(OuterSubscriber));
  62. //# sourceMappingURL=UsingObservable.js.map