Skip to content

Commit 36d7543

Browse files
fix(fetch): missed optimized code segmentation
1 parent 9bcd2f3 commit 36d7543

File tree

5 files changed

+39
-95
lines changed

5 files changed

+39
-95
lines changed

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

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

packages/operators/src/fetch/response.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
import { shallowEqual } from 'fast-equals';
22
import { concatMap, distinctUntilChanged, map } from 'rxjs';
33

4+
export const resolve = (type = 'json') => {
5+
return source => source.pipe(concatMap(e => e[String(type)]()));
6+
};
7+
8+
export const resolveJSON = () => {
9+
return resolve('json');
10+
};
11+
12+
export const resolveText = () => {
13+
return resolve('text');
14+
};
15+
16+
export const resolveBlob = () => {
17+
return resolve('blob');
18+
};
19+
420
export const distinctUntilResponseChanged = () => {
521
return source =>
622
source.pipe(

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { of } from 'rxjs';
22
import { afterEach, test, describe, beforeEach, expect } from 'vitest';
33

44
import { log } from '../log';
5-
import { resolveText } from './resolve';
6-
import { distinctUntilResponseChanged } from './response';
5+
import { distinctUntilResponseChanged, resolveJSON, resolveText } from './response';
76

87
describe('response', function () {
98
beforeEach(function () {
@@ -14,6 +13,28 @@ describe('response', function () {
1413
//
1514
});
1615

16+
test('resolve json', () => {
17+
return new Promise(done => {
18+
of(new Response(JSON.stringify({ hello: 'world' })))
19+
.pipe(resolveJSON(), log(false))
20+
.subscribe({
21+
next: e => expect(e).includes({ hello: 'world' }),
22+
complete: () => done()
23+
});
24+
});
25+
});
26+
27+
test('resolve text', () => {
28+
return new Promise(done => {
29+
of(new Response('hello world'))
30+
.pipe(resolveText(), log(false))
31+
.subscribe({
32+
next: e => expect(e).toBe('hello world'),
33+
complete: () => done()
34+
});
35+
});
36+
});
37+
1738
test('emit only changed responses', () => {
1839
const triggerValues = [
1940
new Response('a'),

packages/operators/src/fetch/upload.js

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

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

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

0 commit comments

Comments
 (0)