@tanstack/query-core 4.29.22 → 4.29.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/lib/focusManager.esm.js +3 -2
- package/build/lib/focusManager.esm.js.map +1 -1
- package/build/lib/focusManager.js +3 -2
- package/build/lib/focusManager.js.map +1 -1
- package/build/lib/focusManager.mjs +3 -2
- package/build/lib/focusManager.mjs.map +1 -1
- package/build/lib/infiniteQueryObserver.d.ts +1 -1
- package/build/lib/infiniteQueryObserver.d.ts.map +1 -1
- package/build/lib/infiniteQueryObserver.esm.js.map +1 -1
- package/build/lib/infiniteQueryObserver.js.map +1 -1
- package/build/lib/infiniteQueryObserver.mjs.map +1 -1
- package/build/lib/mutation.d.ts +2 -2
- package/build/lib/mutation.d.ts.map +1 -1
- package/build/lib/mutation.esm.js.map +1 -1
- package/build/lib/mutation.js.map +1 -1
- package/build/lib/mutation.mjs.map +1 -1
- package/build/lib/mutationCache.d.ts +2 -2
- package/build/lib/mutationCache.d.ts.map +1 -1
- package/build/lib/mutationCache.esm.js.map +1 -1
- package/build/lib/mutationCache.js.map +1 -1
- package/build/lib/mutationCache.mjs.map +1 -1
- package/build/lib/mutationObserver.d.ts +3 -3
- package/build/lib/mutationObserver.d.ts.map +1 -1
- package/build/lib/mutationObserver.esm.js.map +1 -1
- package/build/lib/mutationObserver.js.map +1 -1
- package/build/lib/mutationObserver.mjs.map +1 -1
- package/build/lib/onlineManager.d.ts.map +1 -1
- package/build/lib/onlineManager.esm.js +3 -2
- package/build/lib/onlineManager.esm.js.map +1 -1
- package/build/lib/onlineManager.js +3 -2
- package/build/lib/onlineManager.js.map +1 -1
- package/build/lib/onlineManager.mjs +3 -2
- package/build/lib/onlineManager.mjs.map +1 -1
- package/build/lib/queriesObserver.d.ts +2 -2
- package/build/lib/queriesObserver.d.ts.map +1 -1
- package/build/lib/queriesObserver.esm.js.map +1 -1
- package/build/lib/queriesObserver.js.map +1 -1
- package/build/lib/queriesObserver.mjs.map +1 -1
- package/build/lib/query.d.ts +2 -2
- package/build/lib/query.d.ts.map +1 -1
- package/build/lib/query.esm.js.map +1 -1
- package/build/lib/query.js.map +1 -1
- package/build/lib/query.mjs.map +1 -1
- package/build/lib/queryCache.d.ts +2 -2
- package/build/lib/queryCache.d.ts.map +1 -1
- package/build/lib/queryCache.esm.js.map +1 -1
- package/build/lib/queryCache.js.map +1 -1
- package/build/lib/queryCache.mjs.map +1 -1
- package/build/lib/queryClient.d.ts +3 -3
- package/build/lib/queryClient.d.ts.map +1 -1
- package/build/lib/queryClient.esm.js.map +1 -1
- package/build/lib/queryClient.js.map +1 -1
- package/build/lib/queryClient.mjs.map +1 -1
- package/build/lib/queryObserver.d.ts +3 -3
- package/build/lib/queryObserver.d.ts.map +1 -1
- package/build/lib/queryObserver.esm.js.map +1 -1
- package/build/lib/queryObserver.js.map +1 -1
- package/build/lib/queryObserver.mjs.map +1 -1
- package/build/lib/tests/utils.d.ts +1 -1
- package/build/lib/tests/utils.d.ts.map +1 -1
- package/build/lib/types.d.ts +2 -2
- package/build/lib/types.d.ts.map +1 -1
- package/build/umd/index.development.js +6 -4
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/focusManager.ts +3 -3
- package/src/infiniteQueryObserver.ts +6 -6
- package/src/mutation.ts +5 -5
- package/src/mutationCache.ts +4 -4
- package/src/mutationObserver.ts +4 -4
- package/src/onlineManager.ts +3 -2
- package/src/queriesObserver.ts +3 -3
- package/src/query.ts +8 -8
- package/src/queryCache.ts +4 -4
- package/src/queryClient.ts +14 -14
- package/src/queryObserver.ts +5 -5
- package/src/tests/focusManager.test.tsx +21 -14
- package/src/tests/hydration.test.tsx +2 -2
- package/src/tests/infiniteQueryBehavior.test.tsx +3 -3
- package/src/tests/infiniteQueryObserver.test.tsx +1 -1
- package/src/tests/mutationCache.test.tsx +1 -1
- package/src/tests/mutationObserver.test.tsx +1 -1
- package/src/tests/mutations.test.tsx +3 -3
- package/src/tests/onlineManager.test.tsx +21 -0
- package/src/tests/queriesObserver.test.tsx +2 -2
- package/src/tests/query.test.tsx +6 -6
- package/src/tests/queryCache.test.tsx +3 -3
- package/src/tests/queryClient.test.tsx +4 -4
- package/src/tests/queryObserver.test.tsx +4 -4
- package/src/tests/utils.test.tsx +4 -4
- package/src/tests/utils.ts +1 -1
- package/src/types.ts +2 -2
package/package.json
CHANGED
package/src/focusManager.ts
CHANGED
|
@@ -58,9 +58,9 @@ export class FocusManager extends Subscribable {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
setFocused(focused?: boolean): void {
|
|
61
|
-
this.focused
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
const changed = this.focused !== focused
|
|
62
|
+
if (changed) {
|
|
63
|
+
this.focused = focused
|
|
64
64
|
this.onFocus()
|
|
65
65
|
}
|
|
66
66
|
}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import { QueryObserver } from './queryObserver'
|
|
2
|
+
import {
|
|
3
|
+
hasNextPage,
|
|
4
|
+
hasPreviousPage,
|
|
5
|
+
infiniteQueryBehavior,
|
|
6
|
+
} from './infiniteQueryBehavior'
|
|
1
7
|
import type {
|
|
2
8
|
DefaultedInfiniteQueryObserverOptions,
|
|
3
9
|
FetchNextPageOptions,
|
|
@@ -9,12 +15,6 @@ import type {
|
|
|
9
15
|
} from './types'
|
|
10
16
|
import type { QueryClient } from './queryClient'
|
|
11
17
|
import type { NotifyOptions, ObserverFetchOptions } from './queryObserver'
|
|
12
|
-
import { QueryObserver } from './queryObserver'
|
|
13
|
-
import {
|
|
14
|
-
hasNextPage,
|
|
15
|
-
hasPreviousPage,
|
|
16
|
-
infiniteQueryBehavior,
|
|
17
|
-
} from './infiniteQueryBehavior'
|
|
18
18
|
import type { Query } from './query'
|
|
19
19
|
|
|
20
20
|
type InfiniteQueryObserverListener<TData, TError> = (
|
package/src/mutation.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { MutationOptions, MutationStatus, MutationMeta } from './types'
|
|
2
|
-
import type { MutationCache } from './mutationCache'
|
|
3
|
-
import type { MutationObserver } from './mutationObserver'
|
|
4
|
-
import type { Logger } from './logger'
|
|
5
1
|
import { defaultLogger } from './logger'
|
|
6
2
|
import { notifyManager } from './notifyManager'
|
|
7
3
|
import { Removable } from './removable'
|
|
8
|
-
import type { Retryer } from './retryer'
|
|
9
4
|
import { canFetch, createRetryer } from './retryer'
|
|
5
|
+
import type { MutationMeta, MutationOptions, MutationStatus } from './types'
|
|
6
|
+
import type { MutationCache } from './mutationCache'
|
|
7
|
+
import type { MutationObserver } from './mutationObserver'
|
|
8
|
+
import type { Logger } from './logger'
|
|
9
|
+
import type { Retryer } from './retryer'
|
|
10
10
|
|
|
11
11
|
// TYPES
|
|
12
12
|
|
package/src/mutationCache.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { notifyManager } from './notifyManager'
|
|
2
|
+
import { Mutation } from './mutation'
|
|
3
|
+
import { matchMutation, noop } from './utils'
|
|
4
|
+
import { Subscribable } from './subscribable'
|
|
1
5
|
import type { MutationObserver } from './mutationObserver'
|
|
2
6
|
import type { MutationOptions, NotifyEvent } from './types'
|
|
3
7
|
import type { QueryClient } from './queryClient'
|
|
4
|
-
import { notifyManager } from './notifyManager'
|
|
5
8
|
import type { Action, MutationState } from './mutation'
|
|
6
|
-
import { Mutation } from './mutation'
|
|
7
9
|
import type { MutationFilters } from './utils'
|
|
8
|
-
import { matchMutation, noop } from './utils'
|
|
9
|
-
import { Subscribable } from './subscribable'
|
|
10
10
|
|
|
11
11
|
// TYPES
|
|
12
12
|
|
package/src/mutationObserver.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import type { Action, Mutation } from './mutation'
|
|
2
1
|
import { getDefaultState } from './mutation'
|
|
3
2
|
import { notifyManager } from './notifyManager'
|
|
4
|
-
import type { QueryClient } from './queryClient'
|
|
5
3
|
import { Subscribable } from './subscribable'
|
|
4
|
+
import { shallowEqualObjects } from './utils'
|
|
5
|
+
import type { QueryClient } from './queryClient'
|
|
6
6
|
import type {
|
|
7
7
|
MutateOptions,
|
|
8
8
|
MutationObserverBaseResult,
|
|
9
|
-
MutationObserverResult,
|
|
10
9
|
MutationObserverOptions,
|
|
10
|
+
MutationObserverResult,
|
|
11
11
|
} from './types'
|
|
12
|
-
import {
|
|
12
|
+
import type { Action, Mutation } from './mutation'
|
|
13
13
|
|
|
14
14
|
// TYPES
|
|
15
15
|
|
package/src/onlineManager.ts
CHANGED
|
@@ -63,9 +63,10 @@ export class OnlineManager extends Subscribable {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
setOnline(online?: boolean): void {
|
|
66
|
-
this.online
|
|
66
|
+
const changed = this.online !== online
|
|
67
67
|
|
|
68
|
-
if (
|
|
68
|
+
if (changed) {
|
|
69
|
+
this.online = online
|
|
69
70
|
this.onOnline()
|
|
70
71
|
}
|
|
71
72
|
}
|
package/src/queriesObserver.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { difference, replaceAt } from './utils'
|
|
2
2
|
import { notifyManager } from './notifyManager'
|
|
3
|
+
import { QueryObserver } from './queryObserver'
|
|
4
|
+
import { Subscribable } from './subscribable'
|
|
3
5
|
import type {
|
|
6
|
+
DefaultedQueryObserverOptions,
|
|
4
7
|
QueryObserverOptions,
|
|
5
8
|
QueryObserverResult,
|
|
6
|
-
DefaultedQueryObserverOptions,
|
|
7
9
|
} from './types'
|
|
8
10
|
import type { QueryClient } from './queryClient'
|
|
9
11
|
import type { NotifyOptions } from './queryObserver'
|
|
10
|
-
import { QueryObserver } from './queryObserver'
|
|
11
|
-
import { Subscribable } from './subscribable'
|
|
12
12
|
|
|
13
13
|
type QueriesObserverListener = (result: QueryObserverResult[]) => void
|
|
14
14
|
|
package/src/query.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { getAbortController, noop, replaceData, timeUntilStale } from './utils'
|
|
2
|
+
import { defaultLogger } from './logger'
|
|
3
|
+
import { notifyManager } from './notifyManager'
|
|
4
|
+
import { canFetch, createRetryer, isCancelledError } from './retryer'
|
|
5
|
+
import { Removable } from './removable'
|
|
2
6
|
import type {
|
|
7
|
+
CancelOptions,
|
|
8
|
+
FetchStatus,
|
|
3
9
|
InitialDataFunction,
|
|
10
|
+
QueryFunctionContext,
|
|
4
11
|
QueryKey,
|
|
12
|
+
QueryMeta,
|
|
5
13
|
QueryOptions,
|
|
6
14
|
QueryStatus,
|
|
7
|
-
QueryFunctionContext,
|
|
8
|
-
QueryMeta,
|
|
9
|
-
CancelOptions,
|
|
10
15
|
SetDataOptions,
|
|
11
|
-
FetchStatus,
|
|
12
16
|
} from './types'
|
|
13
17
|
import type { QueryCache } from './queryCache'
|
|
14
18
|
import type { QueryObserver } from './queryObserver'
|
|
15
19
|
import type { Logger } from './logger'
|
|
16
|
-
import { defaultLogger } from './logger'
|
|
17
|
-
import { notifyManager } from './notifyManager'
|
|
18
20
|
import type { Retryer } from './retryer'
|
|
19
|
-
import { isCancelledError, canFetch, createRetryer } from './retryer'
|
|
20
|
-
import { Removable } from './removable'
|
|
21
21
|
|
|
22
22
|
// TYPES
|
|
23
23
|
|
package/src/queryCache.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { QueryFilters } from './utils'
|
|
2
1
|
import { hashQueryKeyByOptions, matchQuery, parseFilterArgs } from './utils'
|
|
3
|
-
import type { Action, QueryState } from './query'
|
|
4
2
|
import { Query } from './query'
|
|
5
|
-
import type { NotifyEvent, QueryKey, QueryOptions } from './types'
|
|
6
3
|
import { notifyManager } from './notifyManager'
|
|
7
|
-
import type { QueryClient } from './queryClient'
|
|
8
4
|
import { Subscribable } from './subscribable'
|
|
5
|
+
import type { QueryFilters } from './utils'
|
|
6
|
+
import type { Action, QueryState } from './query'
|
|
7
|
+
import type { NotifyEvent, QueryKey, QueryOptions } from './types'
|
|
8
|
+
import type { QueryClient } from './queryClient'
|
|
9
9
|
import type { QueryObserver } from './queryObserver'
|
|
10
10
|
|
|
11
11
|
// TYPES
|
package/src/queryClient.ts
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
|
-
import type { QueryFilters, Updater, MutationFilters } from './utils'
|
|
2
1
|
import {
|
|
2
|
+
functionalUpdate,
|
|
3
3
|
hashQueryKey,
|
|
4
|
+
hashQueryKeyByOptions,
|
|
4
5
|
noop,
|
|
5
6
|
parseFilterArgs,
|
|
6
7
|
parseQueryArgs,
|
|
7
8
|
partialMatchKey,
|
|
8
|
-
hashQueryKeyByOptions,
|
|
9
|
-
functionalUpdate,
|
|
10
9
|
} from './utils'
|
|
10
|
+
import { QueryCache } from './queryCache'
|
|
11
|
+
import { MutationCache } from './mutationCache'
|
|
12
|
+
import { focusManager } from './focusManager'
|
|
13
|
+
import { onlineManager } from './onlineManager'
|
|
14
|
+
import { notifyManager } from './notifyManager'
|
|
15
|
+
import { infiniteQueryBehavior } from './infiniteQueryBehavior'
|
|
16
|
+
import { defaultLogger } from './logger'
|
|
17
|
+
import type { CancelOptions, DefaultedQueryObserverOptions } from './types'
|
|
18
|
+
import type { Logger } from './logger'
|
|
19
|
+
import type { QueryState } from './query'
|
|
11
20
|
import type {
|
|
12
|
-
QueryClientConfig,
|
|
13
21
|
DefaultOptions,
|
|
14
22
|
FetchInfiniteQueryOptions,
|
|
15
23
|
FetchQueryOptions,
|
|
@@ -19,6 +27,7 @@ import type {
|
|
|
19
27
|
MutationKey,
|
|
20
28
|
MutationObserverOptions,
|
|
21
29
|
MutationOptions,
|
|
30
|
+
QueryClientConfig,
|
|
22
31
|
QueryFunction,
|
|
23
32
|
QueryKey,
|
|
24
33
|
QueryObserverOptions,
|
|
@@ -30,16 +39,7 @@ import type {
|
|
|
30
39
|
SetDataOptions,
|
|
31
40
|
WithRequired,
|
|
32
41
|
} from './types'
|
|
33
|
-
import type {
|
|
34
|
-
import { QueryCache } from './queryCache'
|
|
35
|
-
import { MutationCache } from './mutationCache'
|
|
36
|
-
import { focusManager } from './focusManager'
|
|
37
|
-
import { onlineManager } from './onlineManager'
|
|
38
|
-
import { notifyManager } from './notifyManager'
|
|
39
|
-
import { infiniteQueryBehavior } from './infiniteQueryBehavior'
|
|
40
|
-
import type { CancelOptions, DefaultedQueryObserverOptions } from './types'
|
|
41
|
-
import type { Logger } from './logger'
|
|
42
|
-
import { defaultLogger } from './logger'
|
|
42
|
+
import type { MutationFilters, QueryFilters, Updater } from './utils'
|
|
43
43
|
|
|
44
44
|
// TYPES
|
|
45
45
|
|
package/src/queryObserver.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { DefaultedQueryObserverOptions, RefetchPageFilters } from './types'
|
|
2
1
|
import {
|
|
3
2
|
isServer,
|
|
4
3
|
isValidTimeout,
|
|
@@ -8,6 +7,9 @@ import {
|
|
|
8
7
|
timeUntilStale,
|
|
9
8
|
} from './utils'
|
|
10
9
|
import { notifyManager } from './notifyManager'
|
|
10
|
+
import { focusManager } from './focusManager'
|
|
11
|
+
import { Subscribable } from './subscribable'
|
|
12
|
+
import { canFetch, isCancelledError } from './retryer'
|
|
11
13
|
import type {
|
|
12
14
|
PlaceholderDataFunction,
|
|
13
15
|
QueryKey,
|
|
@@ -17,11 +19,9 @@ import type {
|
|
|
17
19
|
QueryOptions,
|
|
18
20
|
RefetchOptions,
|
|
19
21
|
} from './types'
|
|
20
|
-
import type {
|
|
22
|
+
import type { Action, FetchOptions, Query, QueryState } from './query'
|
|
21
23
|
import type { QueryClient } from './queryClient'
|
|
22
|
-
import {
|
|
23
|
-
import { Subscribable } from './subscribable'
|
|
24
|
-
import { canFetch, isCancelledError } from './retryer'
|
|
24
|
+
import type { DefaultedQueryObserverOptions, RefetchPageFilters } from './types'
|
|
25
25
|
|
|
26
26
|
type QueryObserverListener<TData, TError> = (
|
|
27
27
|
result: QueryObserverResult<TData, TError>,
|
|
@@ -38,20 +38,6 @@ describe('focusManager', () => {
|
|
|
38
38
|
expect(focusManager.isFocused()).toBeTruthy()
|
|
39
39
|
})
|
|
40
40
|
|
|
41
|
-
it('should not notify listeners on focus if already focused', async () => {
|
|
42
|
-
const subscriptionSpy = jest.fn()
|
|
43
|
-
const unsubscribe = focusManager.subscribe(subscriptionSpy)
|
|
44
|
-
|
|
45
|
-
focusManager.setFocused(true)
|
|
46
|
-
expect(subscriptionSpy).toHaveBeenCalledTimes(1)
|
|
47
|
-
subscriptionSpy.mockReset()
|
|
48
|
-
|
|
49
|
-
focusManager.setFocused(false)
|
|
50
|
-
expect(subscriptionSpy).toHaveBeenCalledTimes(0)
|
|
51
|
-
|
|
52
|
-
unsubscribe()
|
|
53
|
-
})
|
|
54
|
-
|
|
55
41
|
it('should return true for isFocused if document is undefined', async () => {
|
|
56
42
|
const { document } = globalThis
|
|
57
43
|
|
|
@@ -152,4 +138,25 @@ describe('focusManager', () => {
|
|
|
152
138
|
|
|
153
139
|
unsubscribe2()
|
|
154
140
|
})
|
|
141
|
+
|
|
142
|
+
test('should call listeners when setFocused is called', () => {
|
|
143
|
+
const listener = jest.fn()
|
|
144
|
+
|
|
145
|
+
focusManager.subscribe(listener)
|
|
146
|
+
|
|
147
|
+
focusManager.setFocused(true)
|
|
148
|
+
focusManager.setFocused(true)
|
|
149
|
+
|
|
150
|
+
expect(listener).toHaveBeenCalledTimes(1)
|
|
151
|
+
|
|
152
|
+
focusManager.setFocused(false)
|
|
153
|
+
focusManager.setFocused(false)
|
|
154
|
+
|
|
155
|
+
expect(listener).toHaveBeenCalledTimes(2)
|
|
156
|
+
|
|
157
|
+
focusManager.setFocused(undefined)
|
|
158
|
+
focusManager.setFocused(undefined)
|
|
159
|
+
|
|
160
|
+
expect(listener).toHaveBeenCalledTimes(3)
|
|
161
|
+
})
|
|
155
162
|
})
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import { QueryCache } from '../queryCache'
|
|
2
|
+
import { dehydrate, hydrate } from '../hydration'
|
|
1
3
|
import {
|
|
2
4
|
createQueryClient,
|
|
3
5
|
executeMutation,
|
|
4
6
|
mockNavigatorOnLine,
|
|
5
7
|
sleep,
|
|
6
8
|
} from './utils'
|
|
7
|
-
import { QueryCache } from '../queryCache'
|
|
8
|
-
import { dehydrate, hydrate } from '../hydration'
|
|
9
9
|
|
|
10
10
|
async function fetchData<TData>(value: TData, ms?: number): Promise<TData> {
|
|
11
11
|
await sleep(ms || 0)
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { waitFor } from '@testing-library/react'
|
|
2
|
+
import { InfiniteQueryObserver } from '@tanstack/query-core'
|
|
3
|
+
import { createQueryClient, queryKey } from './utils'
|
|
2
4
|
import type {
|
|
3
|
-
QueryClient,
|
|
4
5
|
InfiniteQueryObserverResult,
|
|
5
6
|
QueryCache,
|
|
7
|
+
QueryClient,
|
|
6
8
|
} from '@tanstack/query-core'
|
|
7
|
-
import { InfiniteQueryObserver } from '@tanstack/query-core'
|
|
8
|
-
import { createQueryClient, queryKey } from './utils'
|
|
9
9
|
|
|
10
10
|
describe('InfiniteQueryBehavior', () => {
|
|
11
11
|
let queryClient: QueryClient
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { waitFor } from '@testing-library/react'
|
|
2
|
-
import { queryKey, sleep, executeMutation, createQueryClient } from './utils'
|
|
3
2
|
import { MutationCache, MutationObserver } from '..'
|
|
3
|
+
import { createQueryClient, executeMutation, queryKey, sleep } from './utils'
|
|
4
4
|
|
|
5
5
|
describe('mutationCache', () => {
|
|
6
6
|
describe('MutationCacheConfig error callbacks', () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { waitFor } from '@testing-library/react'
|
|
2
|
+
import { MutationObserver } from '..'
|
|
2
3
|
import { createQueryClient, sleep } from './utils'
|
|
3
4
|
import type { QueryClient } from '..'
|
|
4
|
-
import { MutationObserver } from '..'
|
|
5
5
|
|
|
6
6
|
describe('mutationObserver', () => {
|
|
7
7
|
let queryClient: QueryClient
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { waitFor } from '@testing-library/react'
|
|
2
|
+
import { MutationObserver } from '../mutationObserver'
|
|
2
3
|
import { createQueryClient, executeMutation, queryKey, sleep } from './utils'
|
|
4
|
+
import type { QueryClient } from '..'
|
|
3
5
|
import type { MutationState } from '../mutation'
|
|
4
|
-
import { MutationObserver } from '../mutationObserver'
|
|
5
|
-
import { waitFor } from '@testing-library/react'
|
|
6
6
|
|
|
7
7
|
describe('mutations', () => {
|
|
8
8
|
let queryClient: QueryClient
|
|
@@ -145,4 +145,25 @@ describe('onlineManager', () => {
|
|
|
145
145
|
|
|
146
146
|
unsubscribe2()
|
|
147
147
|
})
|
|
148
|
+
|
|
149
|
+
test('should call listeners when setOnline is called', () => {
|
|
150
|
+
const listener = jest.fn()
|
|
151
|
+
|
|
152
|
+
onlineManager.subscribe(listener)
|
|
153
|
+
|
|
154
|
+
onlineManager.setOnline(true)
|
|
155
|
+
onlineManager.setOnline(true)
|
|
156
|
+
|
|
157
|
+
expect(listener).toHaveBeenCalledTimes(1)
|
|
158
|
+
|
|
159
|
+
onlineManager.setOnline(false)
|
|
160
|
+
onlineManager.setOnline(false)
|
|
161
|
+
|
|
162
|
+
expect(listener).toHaveBeenCalledTimes(2)
|
|
163
|
+
|
|
164
|
+
onlineManager.setOnline(undefined)
|
|
165
|
+
onlineManager.setOnline(undefined)
|
|
166
|
+
|
|
167
|
+
expect(listener).toHaveBeenCalledTimes(3)
|
|
168
|
+
})
|
|
148
169
|
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { waitFor } from '@testing-library/react'
|
|
2
|
-
import { sleep, queryKey, createQueryClient, mockLogger } from './utils'
|
|
3
|
-
import type { QueryClient, QueryObserverResult } from '..'
|
|
4
2
|
import { QueriesObserver, QueryObserver } from '..'
|
|
3
|
+
import { createQueryClient, mockLogger, queryKey, sleep } from './utils'
|
|
4
|
+
import type { QueryClient, QueryObserverResult } from '..'
|
|
5
5
|
import type { QueryKey } from '..'
|
|
6
6
|
|
|
7
7
|
describe('queriesObserver', () => {
|
package/src/tests/query.test.tsx
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { waitFor } from '@testing-library/react'
|
|
2
|
+
import { QueryObserver, isCancelledError, isError, onlineManager } from '..'
|
|
1
3
|
import {
|
|
2
|
-
sleep,
|
|
3
|
-
queryKey,
|
|
4
|
-
mockVisibilityState,
|
|
5
|
-
mockLogger,
|
|
6
4
|
createQueryClient,
|
|
5
|
+
mockLogger,
|
|
6
|
+
mockVisibilityState,
|
|
7
|
+
queryKey,
|
|
8
|
+
sleep,
|
|
7
9
|
} from './utils'
|
|
8
10
|
import type {
|
|
9
11
|
QueryCache,
|
|
@@ -11,8 +13,6 @@ import type {
|
|
|
11
13
|
QueryFunctionContext,
|
|
12
14
|
QueryObserverResult,
|
|
13
15
|
} from '..'
|
|
14
|
-
import { QueryObserver, isCancelledError, isError, onlineManager } from '..'
|
|
15
|
-
import { waitFor } from '@testing-library/react'
|
|
16
16
|
|
|
17
17
|
describe('query', () => {
|
|
18
18
|
let queryClient: QueryClient
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { QueryClient } from '..'
|
|
1
|
+
import { waitFor } from '@testing-library/react'
|
|
3
2
|
import { QueryCache, QueryObserver } from '..'
|
|
3
|
+
import { createQueryClient, queryKey, sleep } from './utils'
|
|
4
|
+
import type { QueryClient } from '..'
|
|
4
5
|
import type { Query } from '.././query'
|
|
5
|
-
import { waitFor } from '@testing-library/react'
|
|
6
6
|
|
|
7
7
|
describe('queryCache', () => {
|
|
8
8
|
let queryClient: QueryClient
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { waitFor } from '@testing-library/react'
|
|
2
2
|
import '@testing-library/jest-dom'
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { InfiniteQueryObserver, MutationObserver, QueryObserver } from '..'
|
|
5
|
+
import { focusManager, onlineManager } from '..'
|
|
6
|
+
import { noop } from '../utils'
|
|
7
|
+
import { createQueryClient, mockLogger, queryKey, sleep } from './utils'
|
|
5
8
|
import type {
|
|
6
9
|
QueryCache,
|
|
7
10
|
QueryClient,
|
|
8
11
|
QueryFunction,
|
|
9
12
|
QueryObserverOptions,
|
|
10
13
|
} from '..'
|
|
11
|
-
import { InfiniteQueryObserver, MutationObserver, QueryObserver } from '..'
|
|
12
|
-
import { focusManager, onlineManager } from '..'
|
|
13
|
-
import { noop } from '../utils'
|
|
14
14
|
|
|
15
15
|
describe('queryClient', () => {
|
|
16
16
|
let queryClient: QueryClient
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { QueryObserver, focusManager } from '..'
|
|
1
2
|
import {
|
|
2
|
-
|
|
3
|
-
queryKey,
|
|
3
|
+
createQueryClient,
|
|
4
4
|
expectType,
|
|
5
5
|
mockLogger,
|
|
6
|
-
|
|
6
|
+
queryKey,
|
|
7
|
+
sleep,
|
|
7
8
|
} from './utils'
|
|
8
9
|
import type { QueryClient, QueryObserverResult } from '..'
|
|
9
|
-
import { QueryObserver, focusManager } from '..'
|
|
10
10
|
|
|
11
11
|
describe('queryObserver', () => {
|
|
12
12
|
let queryClient: QueryClient
|
package/src/tests/utils.test.tsx
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
partialDeepEqual,
|
|
2
|
+
isPlainArray,
|
|
4
3
|
isPlainObject,
|
|
5
|
-
parseMutationArgs,
|
|
6
4
|
matchMutation,
|
|
5
|
+
parseMutationArgs,
|
|
6
|
+
partialDeepEqual,
|
|
7
|
+
replaceEqualDeep,
|
|
7
8
|
scheduleMicrotask,
|
|
8
9
|
sleep,
|
|
9
|
-
isPlainArray,
|
|
10
10
|
} from '../utils'
|
|
11
11
|
import { Mutation } from '../mutation'
|
|
12
12
|
import { createQueryClient } from './utils'
|
package/src/tests/utils.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { act } from '@testing-library/react'
|
|
2
2
|
|
|
3
|
-
import type { MutationOptions, QueryClientConfig } from '@tanstack/query-core'
|
|
4
3
|
import { QueryClient } from '@tanstack/query-core'
|
|
5
4
|
import * as utils from '../utils'
|
|
5
|
+
import type { MutationOptions, QueryClientConfig } from '@tanstack/query-core'
|
|
6
6
|
|
|
7
7
|
export function createQueryClient(config?: QueryClientConfig): QueryClient {
|
|
8
8
|
jest.spyOn(console, 'error').mockImplementation(() => undefined)
|
package/src/types.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* istanbul ignore file */
|
|
2
2
|
|
|
3
3
|
import type { MutationState } from './mutation'
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
4
|
+
import type { Query, QueryBehavior } from './query'
|
|
5
|
+
import type { RetryDelayValue, RetryValue } from './retryer'
|
|
6
6
|
import type { QueryFilters, QueryTypeFilter } from './utils'
|
|
7
7
|
import type { QueryCache } from './queryCache'
|
|
8
8
|
import type { MutationCache } from './mutationCache'
|