@ahoo-wang/fetcher-react 3.3.8 → 3.4.0
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/README.md +597 -1
- package/README.zh-CN.md +604 -1
- package/dist/index.es.js +510 -402
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/wow/index.d.ts +10 -3
- package/dist/wow/index.d.ts.map +1 -1
- package/dist/wow/useFetcherCountQuery.d.ts +67 -0
- package/dist/wow/useFetcherCountQuery.d.ts.map +1 -0
- package/dist/wow/useFetcherListQuery.d.ts +100 -0
- package/dist/wow/useFetcherListQuery.d.ts.map +1 -0
- package/dist/wow/useFetcherListStreamQuery.d.ts +107 -0
- package/dist/wow/useFetcherListStreamQuery.d.ts.map +1 -0
- package/dist/wow/useFetcherPagedQuery.d.ts +111 -0
- package/dist/wow/useFetcherPagedQuery.d.ts.map +1 -0
- package/dist/wow/useFetcherQuery.d.ts +106 -0
- package/dist/wow/useFetcherQuery.d.ts.map +1 -0
- package/dist/wow/useFetcherSingleQuery.d.ts +85 -0
- package/dist/wow/useFetcherSingleQuery.d.ts.map +1 -0
- package/dist/wow/useQuery.d.ts +2 -7
- package/dist/wow/useQuery.d.ts.map +1 -1
- package/dist/wow/useQueryState.d.ts +72 -0
- package/dist/wow/useQueryState.d.ts.map +1 -0
- package/package.json +8 -8
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { AutoExecuteCapable } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration options for the useQueryState hook
|
|
4
|
+
* @template Q - The type of the query parameters
|
|
5
|
+
*/
|
|
6
|
+
export interface UseQueryStateOptions<Q> extends AutoExecuteCapable {
|
|
7
|
+
/** The initial query parameters to be stored and managed */
|
|
8
|
+
initialQuery: Q;
|
|
9
|
+
/** Function to execute with the current query parameters. Called when autoExecute is true */
|
|
10
|
+
execute: (query: Q) => Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Return type of the useQueryState hook
|
|
14
|
+
* @template Q - The type of the query parameters
|
|
15
|
+
*/
|
|
16
|
+
export interface UseQueryStateReturn<Q> {
|
|
17
|
+
/** Function to retrieve the current query parameters */
|
|
18
|
+
getQuery: () => Q;
|
|
19
|
+
/** Function to update the query parameters. Triggers execution if autoExecute is true */
|
|
20
|
+
setQuery: (query: Q) => void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A React hook for managing query state with automatic execution capabilities
|
|
24
|
+
*
|
|
25
|
+
* This hook provides a centralized way to manage query parameters, including
|
|
26
|
+
* getting and setting the current query, and optionally automatically executing
|
|
27
|
+
* queries when the query changes or on component mount.
|
|
28
|
+
*
|
|
29
|
+
* @template Q - The type of the query parameters
|
|
30
|
+
* @param options - Configuration options for the hook
|
|
31
|
+
* @returns An object containing getQuery and setQuery functions
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* interface UserQuery {
|
|
36
|
+
* id: string;
|
|
37
|
+
* name?: string;
|
|
38
|
+
* }
|
|
39
|
+
*
|
|
40
|
+
* function UserComponent() {
|
|
41
|
+
* const executeQuery = async (query: UserQuery) => {
|
|
42
|
+
* // Perform query execution logic here
|
|
43
|
+
* console.log('Executing query:', query);
|
|
44
|
+
* };
|
|
45
|
+
*
|
|
46
|
+
* const { getQuery, setQuery } = useQueryState<UserQuery>({
|
|
47
|
+
* initialQuery: { id: '1' },
|
|
48
|
+
* autoExecute: true,
|
|
49
|
+
* execute: executeQuery,
|
|
50
|
+
* });
|
|
51
|
+
*
|
|
52
|
+
* const handleQueryChange = (newQuery: UserQuery) => {
|
|
53
|
+
* setQuery(newQuery); // Will automatically execute if autoExecute is true
|
|
54
|
+
* };
|
|
55
|
+
*
|
|
56
|
+
* const currentQuery = getQuery(); // Get current query parameters
|
|
57
|
+
*
|
|
58
|
+
* return (
|
|
59
|
+
* <div>
|
|
60
|
+
* <button onClick={() => handleQueryChange({ id: '2', name: 'John' })}>
|
|
61
|
+
* Update Query
|
|
62
|
+
* </button>
|
|
63
|
+
* </div>
|
|
64
|
+
* );
|
|
65
|
+
* }
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @throws This hook does not throw exceptions directly, but the execute function
|
|
69
|
+
* may throw exceptions that should be handled by the caller.
|
|
70
|
+
*/
|
|
71
|
+
export declare function useQueryState<Q>(options: UseQueryStateOptions<Q>): UseQueryStateReturn<Q>;
|
|
72
|
+
//# sourceMappingURL=useQueryState.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useQueryState.d.ts","sourceRoot":"","sources":["../../src/wow/useQueryState.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C;;;GAGG;AACH,MAAM,WAAW,oBAAoB,CAAC,CAAC,CAAE,SAAQ,kBAAkB;IACjE,4DAA4D;IAC5D,YAAY,EAAE,CAAC,CAAC;IAChB,6FAA6F;IAC7F,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB,CAAC,CAAC;IACpC,wDAAwD;IACxD,QAAQ,EAAE,MAAM,CAAC,CAAC;IAClB,yFAAyF;IACzF,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC7B,OAAO,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAC/B,mBAAmB,CAAC,CAAC,CAAC,CA0BxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ahoo-wang/fetcher-react",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "React integration for Fetcher HTTP client. Provides React Hooks and components for seamless data fetching with automatic re-rendering and loading states.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fetch",
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"@ahoo-wang/fetcher-eventbus": "^3.0.0",
|
|
48
48
|
"@ahoo-wang/fetcher-storage": "^3.0.0",
|
|
49
49
|
"@ahoo-wang/fetcher-wow": "^3.0.0",
|
|
50
|
-
"react": "
|
|
51
|
-
"react-dom": "
|
|
50
|
+
"react": "^19.2.1",
|
|
51
|
+
"react-dom": "^19.2.1"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@eslint/js": "^9.39.1",
|
|
@@ -60,18 +60,18 @@
|
|
|
60
60
|
"globals": "^16.5.0",
|
|
61
61
|
"prettier": "^3.7.4",
|
|
62
62
|
"typescript": "^5.9.3",
|
|
63
|
-
"typescript-eslint": "^8.
|
|
63
|
+
"typescript-eslint": "^8.49.0",
|
|
64
64
|
"eslint-plugin-react-hooks": "^7.0.1",
|
|
65
65
|
"eslint-plugin-react-compiler": "^19.1.0-rc.2",
|
|
66
66
|
"unplugin-dts": "1.0.0-beta.6",
|
|
67
|
-
"vite": "^7.2.
|
|
68
|
-
"vite-bundle-analyzer": "^1.
|
|
67
|
+
"vite": "^7.2.7",
|
|
68
|
+
"vite-bundle-analyzer": "^1.3.1",
|
|
69
69
|
"vitest": "^3.2.4",
|
|
70
70
|
"@testing-library/react": "^16.0.0",
|
|
71
71
|
"@types/react": "^19.2.7",
|
|
72
72
|
"@types/react-dom": "^19.2.3",
|
|
73
|
-
"jsdom": "^27.
|
|
74
|
-
"@vitejs/plugin-react": "^5.1.
|
|
73
|
+
"jsdom": "^27.3.0",
|
|
74
|
+
"@vitejs/plugin-react": "^5.1.2"
|
|
75
75
|
},
|
|
76
76
|
"scripts": {
|
|
77
77
|
"build": "vite build",
|