Last change
on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
898 bytes
|
Line | |
---|
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 |
---|
Note:
See
TracBrowser
for help on using the repository browser.