@tanstack/query-core 4.29.10 → 4.29.14
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/mutation.esm.js +1 -1
- package/build/lib/mutation.esm.js.map +1 -1
- package/build/lib/mutation.js +1 -1
- package/build/lib/mutation.js.map +1 -1
- package/build/lib/mutation.mjs +1 -1
- package/build/lib/mutation.mjs.map +1 -1
- package/build/lib/notifyManager.d.ts +3 -2
- package/build/lib/notifyManager.d.ts.map +1 -1
- package/build/lib/notifyManager.esm.js.map +1 -1
- package/build/lib/notifyManager.js.map +1 -1
- package/build/lib/notifyManager.mjs.map +1 -1
- package/build/lib/query.esm.js +2 -2
- package/build/lib/query.esm.js.map +1 -1
- package/build/lib/query.js +2 -2
- package/build/lib/query.js.map +1 -1
- package/build/lib/query.mjs +2 -2
- package/build/lib/query.mjs.map +1 -1
- package/build/lib/utils.esm.js +1 -1
- package/build/lib/utils.esm.js.map +1 -1
- package/build/lib/utils.js +1 -1
- package/build/lib/utils.js.map +1 -1
- package/build/lib/utils.mjs +1 -1
- package/build/lib/utils.mjs.map +1 -1
- package/build/umd/index.development.js +4 -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/mutation.ts +1 -1
- package/src/notifyManager.ts +7 -3
- package/src/query.ts +2 -2
- package/src/tests/notifyManager.test.tsx +15 -0
- package/src/utils.ts +1 -1
package/package.json
CHANGED
package/src/mutation.ts
CHANGED
|
@@ -129,7 +129,7 @@ export class Mutation<
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
addObserver(observer: MutationObserver<any, any, any, any>): void {
|
|
132
|
-
if (this.observers.
|
|
132
|
+
if (!this.observers.includes(observer)) {
|
|
133
133
|
this.observers.push(observer)
|
|
134
134
|
|
|
135
135
|
// Stop the mutation from being garbage collected
|
package/src/notifyManager.ts
CHANGED
|
@@ -8,6 +8,8 @@ type NotifyFunction = (callback: () => void) => void
|
|
|
8
8
|
|
|
9
9
|
type BatchNotifyFunction = (callback: () => void) => void
|
|
10
10
|
|
|
11
|
+
type BatchCallsCallback<T extends unknown[]> = (...args: T) => void
|
|
12
|
+
|
|
11
13
|
export function createNotifyManager() {
|
|
12
14
|
let queue: NotifyCallback[] = []
|
|
13
15
|
let transactions = 0
|
|
@@ -45,12 +47,14 @@ export function createNotifyManager() {
|
|
|
45
47
|
/**
|
|
46
48
|
* All calls to the wrapped function will be batched.
|
|
47
49
|
*/
|
|
48
|
-
const batchCalls = <T extends
|
|
49
|
-
|
|
50
|
+
const batchCalls = <T extends unknown[]>(
|
|
51
|
+
callback: BatchCallsCallback<T>,
|
|
52
|
+
): BatchCallsCallback<T> => {
|
|
53
|
+
return (...args) => {
|
|
50
54
|
schedule(() => {
|
|
51
55
|
callback(...args)
|
|
52
56
|
})
|
|
53
|
-
}
|
|
57
|
+
}
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
const flush = (): void => {
|
package/src/query.ts
CHANGED
|
@@ -282,7 +282,7 @@ export class Query<
|
|
|
282
282
|
}
|
|
283
283
|
|
|
284
284
|
addObserver(observer: QueryObserver<any, any, any, any, any>): void {
|
|
285
|
-
if (this.observers.
|
|
285
|
+
if (!this.observers.includes(observer)) {
|
|
286
286
|
this.observers.push(observer)
|
|
287
287
|
|
|
288
288
|
// Stop the query from being garbage collected
|
|
@@ -293,7 +293,7 @@ export class Query<
|
|
|
293
293
|
}
|
|
294
294
|
|
|
295
295
|
removeObserver(observer: QueryObserver<any, any, any, any, any>): void {
|
|
296
|
-
if (this.observers.
|
|
296
|
+
if (this.observers.includes(observer)) {
|
|
297
297
|
this.observers = this.observers.filter((x) => x !== observer)
|
|
298
298
|
|
|
299
299
|
if (!this.observers.length) {
|
|
@@ -48,4 +48,19 @@ describe('notifyManager', () => {
|
|
|
48
48
|
|
|
49
49
|
expect(notifySpy).toHaveBeenCalledTimes(1)
|
|
50
50
|
})
|
|
51
|
+
|
|
52
|
+
it('typedefs should catch proper signatures', async () => {
|
|
53
|
+
const notifyManagerTest = createNotifyManager()
|
|
54
|
+
|
|
55
|
+
// we define some fn with its signature:
|
|
56
|
+
const fn: (a: string, b: number) => string = (a, b) => a + b
|
|
57
|
+
|
|
58
|
+
//now somefn expect to be called with args [a: string, b: number]
|
|
59
|
+
const someFn = notifyManagerTest.batchCalls(fn)
|
|
60
|
+
|
|
61
|
+
someFn('im happy', 4)
|
|
62
|
+
|
|
63
|
+
//@ts-expect-error
|
|
64
|
+
someFn('im not happy', false)
|
|
65
|
+
})
|
|
51
66
|
})
|
package/src/utils.ts
CHANGED
|
@@ -88,7 +88,7 @@ export function isValidTimeout(value: unknown): value is number {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
export function difference<T>(array1: T[], array2: T[]): T[] {
|
|
91
|
-
return array1.filter((x) => array2.
|
|
91
|
+
return array1.filter((x) => !array2.includes(x))
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
export function replaceAt<T>(array: T[], index: number, value: T): T[] {
|