-
-
Couldn't load subscription status.
- Fork 3.5k
feat(query-core): add custom reducer support to streamedQuery #9532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
d2c4807
9474d4c
890e373
0a4e065
d46d488
42b9908
14b6241
5f68a62
20e1d8d
da93cc7
7876335
e3a54ea
ade50e9
d627594
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -350,13 +350,18 @@ describe('streamedQuery', () => { | |||||
| unsubscribe() | ||||||
| }) | ||||||
|
|
||||||
| test('should support maxChunks', async () => { | ||||||
| test('should support custom reducer', async () => { | ||||||
| const key = queryKey() | ||||||
|
|
||||||
| const observer = new QueryObserver(queryClient, { | ||||||
| queryKey: key, | ||||||
| queryFn: streamedQuery({ | ||||||
| queryFn: () => createAsyncNumberGenerator(3), | ||||||
| maxChunks: 2, | ||||||
| queryFn: streamedQuery<number, Record<number, boolean>>({ | ||||||
|
||||||
| queryFn: () => createAsyncNumberGenerator(2), | ||||||
| reducer: (acc, chunk) => ({ | ||||||
| ...acc, | ||||||
| [chunk]: true, | ||||||
| }), | ||||||
| initialValue: {} | ||||||
| }), | ||||||
| }) | ||||||
|
|
||||||
|
|
@@ -368,41 +373,34 @@ describe('streamedQuery', () => { | |||||
| data: undefined, | ||||||
| }) | ||||||
|
|
||||||
| await vi.advanceTimersByTimeAsync(50) | ||||||
|
|
||||||
| expect(observer.getCurrentResult()).toMatchObject({ | ||||||
| status: 'success', | ||||||
| fetchStatus: 'fetching', | ||||||
| data: [0], | ||||||
| }) | ||||||
|
|
||||||
| await vi.advanceTimersByTimeAsync(50) | ||||||
|
|
||||||
| expect(observer.getCurrentResult()).toMatchObject({ | ||||||
| status: 'success', | ||||||
| fetchStatus: 'fetching', | ||||||
| data: [0, 1], | ||||||
| }) | ||||||
|
|
||||||
| await vi.advanceTimersByTimeAsync(50) | ||||||
| await vi.advanceTimersByTimeAsync(100) | ||||||
|
|
||||||
| expect(observer.getCurrentResult()).toMatchObject({ | ||||||
| status: 'success', | ||||||
| fetchStatus: 'idle', | ||||||
| data: [1, 2], | ||||||
| data: { | ||||||
| 0: true, | ||||||
| 1: true, | ||||||
| }, | ||||||
| }) | ||||||
|
|
||||||
| unsubscribe() | ||||||
| }) | ||||||
|
|
||||||
| test('maxChunks with append refetch', async () => { | ||||||
| test('should support custom reducer with initialValue', async () => { | ||||||
| const key = queryKey() | ||||||
| const observer = new QueryObserver(queryClient, { | ||||||
| queryKey: key, | ||||||
| queryFn: streamedQuery({ | ||||||
| queryFn: () => createAsyncNumberGenerator(3), | ||||||
| maxChunks: 2, | ||||||
| refetchMode: 'append', | ||||||
| queryFn: streamedQuery<number, Record<number, boolean>>({ | ||||||
|
||||||
| queryFn: streamedQuery<number, Record<number, boolean>>({ | |
| queryFn: streamedQuery({ |
Uh oh!
There was an error while loading. Please reload this page.