Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

using.js 898B

1234567891011121314151617181920212223242526272829303132
  1. import { Observable } from '../Observable';
  2. import { from } from './from';
  3. import { EMPTY } from './empty';
  4. export function using(resourceFactory, observableFactory) {
  5. return new Observable(subscriber => {
  6. let resource;
  7. try {
  8. resource = resourceFactory();
  9. }
  10. catch (err) {
  11. subscriber.error(err);
  12. return undefined;
  13. }
  14. let result;
  15. try {
  16. result = observableFactory(resource);
  17. }
  18. catch (err) {
  19. subscriber.error(err);
  20. return undefined;
  21. }
  22. const source = result ? from(result) : EMPTY;
  23. const subscription = source.subscribe(subscriber);
  24. return () => {
  25. subscription.unsubscribe();
  26. if (resource) {
  27. resource.unsubscribe();
  28. }
  29. };
  30. });
  31. }
  32. //# sourceMappingURL=using.js.map