a zip code crypto-currency system good for red ONLY

UsingObservable.js 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { Observable } from '../Observable';
  2. import { subscribeToResult } from '../util/subscribeToResult';
  3. import { OuterSubscriber } from '../OuterSubscriber';
  4. /**
  5. * We need this JSDoc comment for affecting ESDoc.
  6. * @extends {Ignored}
  7. * @hide true
  8. */
  9. export class UsingObservable extends Observable {
  10. constructor(resourceFactory, observableFactory) {
  11. super();
  12. this.resourceFactory = resourceFactory;
  13. this.observableFactory = observableFactory;
  14. }
  15. static create(resourceFactory, observableFactory) {
  16. return new UsingObservable(resourceFactory, observableFactory);
  17. }
  18. /** @deprecated internal use only */ _subscribe(subscriber) {
  19. const { resourceFactory, observableFactory } = this;
  20. let resource;
  21. try {
  22. resource = resourceFactory();
  23. return new UsingSubscriber(subscriber, resource, observableFactory);
  24. }
  25. catch (err) {
  26. subscriber.error(err);
  27. }
  28. }
  29. }
  30. class UsingSubscriber extends OuterSubscriber {
  31. constructor(destination, resource, observableFactory) {
  32. super(destination);
  33. this.resource = resource;
  34. this.observableFactory = observableFactory;
  35. destination.add(resource);
  36. this.tryUse();
  37. }
  38. tryUse() {
  39. try {
  40. const source = this.observableFactory.call(this, this.resource);
  41. if (source) {
  42. this.add(subscribeToResult(this, source));
  43. }
  44. }
  45. catch (err) {
  46. this._error(err);
  47. }
  48. }
  49. }
  50. //# sourceMappingURL=UsingObservable.js.map