using.js 574 B

1234567891011121314151617
  1. import { Observable } from '../Observable';
  2. import { innerFrom } from './innerFrom';
  3. import { EMPTY } from './empty';
  4. export function using(resourceFactory, observableFactory) {
  5. return new Observable((subscriber) => {
  6. const resource = resourceFactory();
  7. const result = observableFactory(resource);
  8. const source = result ? innerFrom(result) : EMPTY;
  9. source.subscribe(subscriber);
  10. return () => {
  11. if (resource) {
  12. resource.unsubscribe();
  13. }
  14. };
  15. });
  16. }
  17. //# sourceMappingURL=using.js.map