@qiaopeng/tanstack-query-plus 0.2.11 → 0.2.13

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.
@@ -0,0 +1,4 @@
1
+ import { QueryClient } from "@tanstack/react-query";
2
+ export declare function scheduleInvalidations(queryClient: QueryClient, tasks: any[], delay: number): void;
3
+ export declare function cancelScheduledInvalidations(tasks: any[]): void;
4
+ //# sourceMappingURL=invalidationManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invalidationManager.d.ts","sourceRoot":"","sources":["../../src/utils/invalidationManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAUpD,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,MAAM,QAe1F;AAED,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,GAAG,EAAE,QAQxD"}
@@ -0,0 +1,28 @@
1
+ const timers = new Map();
2
+ function getTaskKey(task) {
3
+ // Serialize the task to identify duplicates.
4
+ // We mainly care about queryKey and exact/refetchType properties.
5
+ return JSON.stringify(task);
6
+ }
7
+ export function scheduleInvalidations(queryClient, tasks, delay) {
8
+ tasks.forEach(task => {
9
+ const key = getTaskKey(task);
10
+ if (timers.has(key)) {
11
+ clearTimeout(timers.get(key));
12
+ }
13
+ const timer = setTimeout(() => {
14
+ queryClient.invalidateQueries(task);
15
+ timers.delete(key);
16
+ }, delay);
17
+ timers.set(key, timer);
18
+ });
19
+ }
20
+ export function cancelScheduledInvalidations(tasks) {
21
+ tasks.forEach(task => {
22
+ const key = getTaskKey(task);
23
+ if (timers.has(key)) {
24
+ clearTimeout(timers.get(key));
25
+ timers.delete(key);
26
+ }
27
+ });
28
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qiaopeng/tanstack-query-plus",
3
- "version": "0.2.11",
3
+ "version": "0.2.13",
4
4
  "description": "Enhanced TanStack Query toolkit: defaults, hooks, persistence, offline, utils",
5
5
  "author": "qiaopeng",
6
6
  "license": "MIT",