Skip to content

Commit 9bcd2f3

Browse files
fix(fetch): optimized code segmentation
1 parent 9d4f909 commit 9bcd2f3

12 files changed

+94
-94
lines changed

packages/operators/src/fetch/autoPagination.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { concatMap, expand, filter, from, map } from 'rxjs';
22

3-
import { download } from './download';
3+
import { request } from './request';
44

55
export const autoPagination = ({ resolveRoute }) => {
66
return source =>
77
source.pipe(
88
concatMap(({ url }) => {
99
return from(resolveRoute(url)).pipe(
10-
download(),
10+
request(),
1111
expand(resp =>
1212
from(resolveRoute(url, resp)).pipe(
1313
filter(url => !!url),
14-
download()
14+
request()
1515
)
1616
)
1717
);

packages/operators/src/fetch/autoPagination.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { beforeEach, describe, expect, test } from 'vitest';
33

44
import { log } from '../log';
55
import { autoPagination } from './autoPagination';
6-
import { resolveJSON } from './resolve';
6+
import { resolveJSON } from './response';
77

88
describe('auto pagination', function () {
99
beforeEach(function () {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { mergeMap, of } from 'rxjs';
22

3-
import { download } from './download';
3+
import { request } from './request';
44

55
export const concurrentDownload = (concurrent = 1) => {
6-
return source => source.pipe(mergeMap(url => of(url).pipe(download()), concurrent));
6+
return source => source.pipe(mergeMap(url => of(url).pipe(request()), concurrent));
77
};

packages/operators/src/fetch/concurrentDownload.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { beforeEach, describe, expect, test } from 'vitest';
33

44
import { log } from '../log';
55
import { concurrentDownload } from './concurrentDownload';
6-
import { resolveJSON } from './resolve';
6+
import { resolveJSON } from './response';
77

88
describe('multi fetch', function () {
99
beforeEach(function () {

packages/operators/src/fetch/download.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

packages/operators/src/fetch/download.test.js

Lines changed: 0 additions & 46 deletions
This file was deleted.

packages/operators/src/fetch/lazyPagination.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { beforeEach, describe, expect, test } from 'vitest';
33

44
import { log } from '../log';
55
import { lazyPagination } from './lazyPagination';
6-
import { resolveJSON } from './resolve';
6+
import { resolveJSON } from './response';
77

88
describe('lazy pagination operator', function () {
99
beforeEach(function () {
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { delay, expand, of } from 'rxjs';
22

3-
import { download } from './download';
3+
import { request } from './request';
44
import { distinctUntilResponseChanged } from './response';
55

66
export const polling = (timeout = 1000) => {
77
return source =>
88
source.pipe(
9-
download(),
10-
expand(resp => of(resp.url).pipe(delay(timeout), download())),
9+
request(),
10+
expand(resp => of(resp.url).pipe(delay(timeout), request())),
1111
distinctUntilResponseChanged()
1212
);
1313
};

packages/operators/src/fetch/polling.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { afterEach, beforeEach, describe, expect, test } from 'vitest';
44

55
import { log } from '../log';
66
import { polling } from './polling';
7-
import { resolveJSON } from './resolve';
7+
import { resolveJSON } from './response';
88

99
describe('polling', function () {
1010
beforeEach(function () {

packages/operators/src/fetch/request.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { concatMap } from 'rxjs';
22

3+
import { resolveBlob, resolveJSON, resolveText } from './response';
34
import { networkRetry } from './retry';
45

56
export const request = () => {
@@ -9,3 +10,15 @@ export const request = () => {
910
networkRetry()
1011
);
1112
};
13+
14+
export const requestJSON = () => {
15+
return source => source.pipe(request(), resolveJSON());
16+
};
17+
18+
export const requestText = () => {
19+
return source => source.pipe(request(), resolveText());
20+
};
21+
22+
export const requestBlob = () => {
23+
return source => source.pipe(request(), resolveBlob());
24+
};

0 commit comments

Comments
 (0)