@ahoo-wang/fetcher-react 2.5.6 → 2.5.8

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 CHANGED
@@ -17,6 +17,7 @@ automatic re-rendering and loading states.
17
17
  - 🌐 **TypeScript Support**: Full TypeScript support with comprehensive type definitions
18
18
  - 🚀 **Modern**: Built with modern React patterns and best practices
19
19
  - 🧠 **Smart Caching**: Built-in caching and automatic revalidation
20
+ - ⚡ **Promise State Management**: Hooks for managing async operations and promise states
20
21
 
21
22
  ## Installation
22
23
 
@@ -26,83 +27,91 @@ npm install @ahoo-wang/fetcher-react
26
27
 
27
28
  ## Usage
28
29
 
29
- ### useFetcher Hook
30
+ ### usePromiseState Hook
30
31
 
31
- The `useFetcher` hook provides a convenient way to fetch data in React components with automatic state management for
32
- loading, error, and result states.
32
+ The `usePromiseState` hook provides state management for promise operations without execution logic.
33
33
 
34
34
  ```typescript jsx
35
- import { useFetcher } from '@ahoo-wang/fetcher-react';
35
+ import { usePromiseState, PromiseStatus } from '@ahoo-wang/fetcher-react';
36
36
 
37
37
  const MyComponent = () => {
38
- const { loading, error, result, execute, cancel } = useFetcher({
39
- url: '/api/users',
40
- method: 'GET'
41
- });
38
+ const { status, loading, result, error, setSuccess, setError, setIdle } = usePromiseState<string>();
42
39
 
43
- if (loading) return <div>Loading...</div>;
44
- if (error) return <div>Error: {error.message}</div>;
40
+ const handleSuccess = () => setSuccess('Data loaded');
41
+ const handleError = () => setError(new Error('Failed to load'));
45
42
 
46
43
  return (
47
44
  <div>
48
- <pre>{JSON.stringify(result, null, 2)}</pre>
49
- <button onClick={execute}>Refresh</button>
50
- <button onClick={cancel}>Cancel</button>
45
+ <button onClick={handleSuccess}>Set Success</button>
46
+ <button onClick={handleError}>Set Error</button>
47
+ <button onClick={setIdle}>Reset</button>
48
+ <p>Status: {status}</p>
49
+ {loading && <p>Loading...</p>}
50
+ {result && <p>Result: {result}</p>}
51
+ {error && <p>Error: {error.message}</p>}
51
52
  </div>
52
53
  );
53
54
  };
54
55
  ```
55
56
 
56
- ### Manual Execution
57
+ ### useExecutePromise Hook
57
58
 
58
- To manually control when the fetch occurs, set the `immediate` option to `false`:
59
+ The `useExecutePromise` hook manages asynchronous operations with automatic state handling.
59
60
 
60
61
  ```typescript jsx
61
- import { useFetcher } from '@ahoo-wang/fetcher-react';
62
+ import { useExecutePromise } from '@ahoo-wang/fetcher-react';
62
63
 
63
64
  const MyComponent = () => {
64
- const { loading, error, result, execute } = useFetcher({
65
- url: '/api/users',
66
- method: 'POST',
67
- body: JSON.stringify({ name: 'John' })
68
- }, { immediate: false });
69
-
70
- const handleSubmit = async () => {
71
- await execute();
65
+ const { loading, result, error, execute, reset } = useExecutePromise<string>();
66
+
67
+ const fetchData = async () => {
68
+ const response = await fetch('/api/data');
69
+ return response.text();
72
70
  };
73
71
 
74
- if (loading) return <div>Submitting...</div>;
75
- if (error) return <div>Error: {error.message}</div>;
72
+ const handleFetch = () => {
73
+ execute(fetchData); // Using a promise supplier
74
+ };
76
75
 
76
+ const handleDirectPromise = () => {
77
+ const promise = fetch('/api/data').then(res => res.text());
78
+ execute(promise); // Using a direct promise
79
+ };
80
+
81
+ if (loading) return <div>Loading...</div>;
82
+ if (error) return <div>Error: {error.message}</div>;
77
83
  return (
78
84
  <div>
79
- {result && <pre>{JSON.stringify(result, null, 2)}</pre>}
80
- <button onClick={handleSubmit}>Submit</button>
85
+ <button onClick={handleFetch}>Fetch with Supplier</button>
86
+ <button onClick={handleDirectPromise}>Fetch with Promise</button>
87
+ <button onClick={reset}>Reset</button>
88
+ {result && <p>{result}</p>}
81
89
  </div>
82
90
  );
83
91
  };
84
92
  ```
85
93
 
86
- ### Custom Dependencies
94
+ ### useFetcher Hook
87
95
 
88
- You can specify dependencies that will trigger a refetch when they change:
96
+ The `useFetcher` hook provides data fetching capabilities with automatic state management.
89
97
 
90
98
  ```typescript jsx
91
99
  import { useFetcher } from '@ahoo-wang/fetcher-react';
92
100
 
93
- const UserProfile = ({ userId }: { userId: string }) => {
94
- const { loading, error, result } = useFetcher({
95
- url: `/api/users/${userId}`,
96
- method: 'GET'
97
- }, { deps: [userId] });
101
+ const MyComponent = () => {
102
+ const { loading, error, result, execute } = useFetcher<string>();
103
+
104
+ const handleFetch = () => {
105
+ execute({ url: '/api/users', method: 'GET' });
106
+ };
98
107
 
99
108
  if (loading) return <div>Loading...</div>;
100
109
  if (error) return <div>Error: {error.message}</div>;
101
110
 
102
111
  return (
103
112
  <div>
104
- <h1>{result?.name}</h1>
105
- <p>{result?.email}</p>
113
+ <pre>{JSON.stringify(result, null, 2)}</pre>
114
+ <button onClick={handleFetch}>Fetch Data</button>
106
115
  </div>
107
116
  );
108
117
  };
@@ -159,36 +168,78 @@ const [user, setUser] = useKeyStorage(userStorage);
159
168
 
160
169
  ## API Reference
161
170
 
171
+ ### usePromiseState
172
+
173
+ ```typescript
174
+ function usePromiseState<R = unknown>(
175
+ options?: UsePromiseStateOptions<R>,
176
+ ): UsePromiseStateReturn<R>;
177
+ ```
178
+
179
+ A React hook for managing promise state without execution logic.
180
+
181
+ **Parameters:**
182
+
183
+ - `options`: Configuration options
184
+ - `initialStatus`: Initial status, defaults to IDLE
185
+ - `onSuccess`: Callback invoked on success
186
+ - `onError`: Callback invoked on error
187
+
188
+ **Returns:**
189
+
190
+ An object containing:
191
+
192
+ - `status`: Current status (IDLE, LOADING, SUCCESS, ERROR)
193
+ - `loading`: Indicates if currently loading
194
+ - `result`: The result value
195
+ - `error`: The error value
196
+ - `setLoading`: Set status to LOADING
197
+ - `setSuccess`: Set status to SUCCESS with result
198
+ - `setError`: Set status to ERROR with error
199
+ - `setIdle`: Set status to IDLE
200
+
201
+ ### useExecutePromise
202
+
203
+ ```typescript
204
+ function useExecutePromise<R = unknown>(): UseExecutePromiseReturn<R>;
205
+ ```
206
+
207
+ A React hook for managing asynchronous operations with proper state handling.
208
+
209
+ **Returns:**
210
+
211
+ An object containing:
212
+
213
+ - `status`: Current status
214
+ - `loading`: Indicates if currently loading
215
+ - `result`: The result value
216
+ - `error`: The error value
217
+ - `execute`: Function to execute a promise supplier
218
+ - `reset`: Function to reset the state to initial values
219
+
162
220
  ### useFetcher
163
221
 
164
222
  ```typescript
165
- function useFetcher<R>(
166
- request: FetchRequest,
167
- options?: UseFetcherOptions,
168
- ): UseFetcherResult<R>;
223
+ function useFetcher<R>(options?: UseFetcherOptions): UseFetcherReturn<R>;
169
224
  ```
170
225
 
171
- A React hook that provides data fetching capabilities with automatic state management.
226
+ A React hook for managing asynchronous fetch operations with proper state handling.
172
227
 
173
228
  **Parameters:**
174
229
 
175
- - `request`: The fetch request configuration
176
- - `options`: Configuration options for the fetch operation
177
- - `deps`: Dependencies list for the fetch operation. When provided, the hook will re-fetch when any of these values
178
- change.
179
- - `immediate`: Whether the fetch operation should execute immediately upon component mount. Defaults to `true`.
230
+ - `options`: Configuration options
180
231
  - `fetcher`: Custom fetcher instance to use. Defaults to the default fetcher.
181
232
 
182
233
  **Returns:**
183
234
 
184
235
  An object containing:
185
236
 
186
- - `loading`: Indicates if the fetch operation is currently in progress
187
- - `exchange`: The FetchExchange object representing the ongoing fetch operation
188
- - `result`: The data returned by the fetch operation
189
- - `error`: Any error that occurred during the fetch operation
190
- - `execute`: Function to manually trigger the fetch operation
191
- - `cancel`: Function to cancel the ongoing fetch operation
237
+ - `status`: Current status
238
+ - `loading`: Indicates if currently loading
239
+ - `result`: The result value
240
+ - `error`: The error value
241
+ - `exchange`: The FetchExchange object
242
+ - `execute`: Function to execute a fetch request
192
243
 
193
244
  ### useKeyStorage
194
245
 
package/README.zh-CN.md CHANGED
@@ -16,6 +16,7 @@ Fetcher 生态的 React 集成包。提供 React Hooks 和组件,实现无缝
16
16
  - 🌐 **TypeScript 支持**: 完整的 TypeScript 支持和全面的类型定义
17
17
  - 🚀 **现代化**: 使用现代 React 模式和最佳实践构建
18
18
  - 🧠 **智能缓存**: 内置缓存和自动重新验证
19
+ - ⚡ **Promise 状态管理**: 用于管理异步操作和 promise 状态的 hooks
19
20
 
20
21
  ## 安装
21
22
 
@@ -25,82 +26,91 @@ npm install @ahoo-wang/fetcher-react
25
26
 
26
27
  ## 使用方法
27
28
 
28
- ### useFetcher Hook
29
+ ### usePromiseState Hook
29
30
 
30
- `useFetcher` hook 提供了一种在 React 组件中获取数据的便捷方式,具有自动管理加载、错误和结果状态的功能。
31
+ `usePromiseState` hook 提供 promise 操作的状态管理,无执行逻辑。
31
32
 
32
33
  ```typescript jsx
33
- import { useFetcher } from '@ahoo-wang/fetcher-react';
34
+ import { usePromiseState, PromiseStatus } from '@ahoo-wang/fetcher-react';
34
35
 
35
36
  const MyComponent = () => {
36
- const { loading, error, result, execute, cancel } = useFetcher({
37
- url: '/api/users',
38
- method: 'GET'
39
- });
37
+ const { status, loading, result, error, setSuccess, setError, setIdle } = usePromiseState<string>();
40
38
 
41
- if (loading) return <div>加载中...</div>;
42
- if (error) return <div>错误: {error.message}</div>;
39
+ const handleSuccess = () => setSuccess('数据加载成功');
40
+ const handleError = () => setError(new Error('加载失败'));
43
41
 
44
42
  return (
45
43
  <div>
46
- <pre>{JSON.stringify(result, null, 2)}</pre>
47
- <button onClick={execute}>刷新</button>
48
- <button onClick={cancel}>取消</button>
44
+ <button onClick={handleSuccess}>设置成功</button>
45
+ <button onClick={handleError}>设置错误</button>
46
+ <button onClick={setIdle}>重置</button>
47
+ <p>状态: {status}</p>
48
+ {loading && <p>加载中...</p>}
49
+ {result && <p>结果: {result}</p>}
50
+ {error && <p>错误: {error.message}</p>}
49
51
  </div>
50
52
  );
51
53
  };
52
54
  ```
53
55
 
54
- ### 手动执行
56
+ ### useExecutePromise Hook
55
57
 
56
- 要手动控制获取数据的时机,请将 `immediate` 选项设置为 `false`:
58
+ `useExecutePromise` hook 管理异步操作,具有自动状态处理。
57
59
 
58
60
  ```typescript jsx
59
- import { useFetcher } from '@ahoo-wang/fetcher-react';
61
+ import { useExecutePromise } from '@ahoo-wang/fetcher-react';
60
62
 
61
63
  const MyComponent = () => {
62
- const { loading, error, result, execute } = useFetcher({
63
- url: '/api/users',
64
- method: 'POST',
65
- body: JSON.stringify({ name: 'John' })
66
- }, { immediate: false });
67
-
68
- const handleSubmit = async () => {
69
- await execute();
64
+ const { loading, result, error, execute, reset } = useExecutePromise<string>();
65
+
66
+ const fetchData = async () => {
67
+ const response = await fetch('/api/data');
68
+ return response.text();
70
69
  };
71
70
 
72
- if (loading) return <div>提交中...</div>;
73
- if (error) return <div>错误: {error.message}</div>;
71
+ const handleFetch = () => {
72
+ execute(fetchData); // 使用 promise supplier
73
+ };
74
74
 
75
+ const handleDirectPromise = () => {
76
+ const promise = fetch('/api/data').then(res => res.text());
77
+ execute(promise); // 使用直接 promise
78
+ };
79
+
80
+ if (loading) return <div>加载中...</div>;
81
+ if (error) return <div>错误: {error.message}</div>;
75
82
  return (
76
83
  <div>
77
- {result && <pre>{JSON.stringify(result, null, 2)}</pre>}
78
- <button onClick={handleSubmit}>提交</button>
84
+ <button onClick={handleFetch}>使用 Supplier 获取</button>
85
+ <button onClick={handleDirectPromise}>使用 Promise 获取</button>
86
+ <button onClick={reset}>重置</button>
87
+ {result && <p>{result}</p>}
79
88
  </div>
80
89
  );
81
90
  };
82
91
  ```
83
92
 
84
- ### 自定义依赖项
93
+ ### useFetcher Hook
85
94
 
86
- 您可以指定依赖项,当它们发生变化时会触发重新获取:
95
+ `useFetcher` hook 提供数据获取功能,具有自动状态管理。
87
96
 
88
97
  ```typescript jsx
89
98
  import { useFetcher } from '@ahoo-wang/fetcher-react';
90
99
 
91
- const UserProfile = ({ userId }: { userId: string }) => {
92
- const { loading, error, result } = useFetcher({
93
- url: `/api/users/${userId}`,
94
- method: 'GET'
95
- }, { deps: [userId] });
100
+ const MyComponent = () => {
101
+ const { loading, error, result, execute } = useFetcher<string>();
102
+
103
+ const handleFetch = () => {
104
+ execute({ url: '/api/users', method: 'GET' });
105
+ };
96
106
 
97
107
  if (loading) return <div>加载中...</div>;
98
108
  if (error) return <div>错误: {error.message}</div>;
99
109
 
100
110
  return (
101
111
  <div>
102
- <h1>{result?.name}</h1>
103
- <p>{result?.email}</p>
112
+ <pre>{JSON.stringify(result, null, 2)}</pre>
113
+ <button onClick={handleFetch}>获取数据</button>
104
114
  </div>
105
115
  );
106
116
  };
@@ -153,35 +163,78 @@ const [user, setUser] = useKeyStorage(userStorage);
153
163
 
154
164
  ## API 参考
155
165
 
166
+ ### usePromiseState
167
+
168
+ ```typescript
169
+ function usePromiseState<R = unknown>(
170
+ options?: UsePromiseStateOptions<R>,
171
+ ): UsePromiseStateReturn<R>;
172
+ ```
173
+
174
+ 用于管理 promise 状态的 React hook,无执行逻辑。
175
+
176
+ **参数:**
177
+
178
+ - `options`: 配置选项
179
+ - `initialStatus`: 初始状态,默认为 IDLE
180
+ - `onSuccess`: 成功时调用的回调
181
+ - `onError`: 错误时调用的回调
182
+
183
+ **返回值:**
184
+
185
+ 包含以下属性的对象:
186
+
187
+ - `status`: 当前状态 (IDLE, LOADING, SUCCESS, ERROR)
188
+ - `loading`: 指示当前是否加载中
189
+ - `result`: 结果值
190
+ - `error`: 错误值
191
+ - `setLoading`: 设置状态为 LOADING
192
+ - `setSuccess`: 设置状态为 SUCCESS 并提供结果
193
+ - `setError`: 设置状态为 ERROR 并提供错误
194
+ - `setIdle`: 设置状态为 IDLE
195
+
196
+ ### useExecutePromise
197
+
198
+ ```typescript
199
+ function useExecutePromise<R = unknown>(): UseExecutePromiseReturn<R>;
200
+ ```
201
+
202
+ 用于管理异步操作的 React hook,具有适当的状态处理。
203
+
204
+ **返回值:**
205
+
206
+ 包含以下属性的对象:
207
+
208
+ - `status`: 当前状态
209
+ - `loading`: 指示当前是否加载中
210
+ - `result`: 结果值
211
+ - `error`: 错误值
212
+ - `execute`: 执行 promise 提供者的函数
213
+ - `reset`: 重置状态到初始值的函数
214
+
156
215
  ### useFetcher
157
216
 
158
217
  ```typescript
159
- function useFetcher<R>(
160
- request: FetchRequest,
161
- options?: UseFetcherOptions,
162
- ): UseFetcherResult<R>;
218
+ function useFetcher<R>(options?: UseFetcherOptions): UseFetcherReturn<R>;
163
219
  ```
164
220
 
165
- 提供数据获取功能并自动管理状态的 React hook
221
+ 用于管理异步获取操作的 React hook,具有适当的状态处理。
166
222
 
167
223
  **参数:**
168
224
 
169
- - `request`: 获取数据的请求配置
170
- - `options`: 获取数据操作的配置选项
171
- - `deps`: 获取数据操作的依赖项列表。提供时,当这些值中的任何一个发生变化时,hook 将重新获取数据。
172
- - `immediate`: 获取数据操作是否应在组件挂载时立即执行。默认为 `true`。
225
+ - `options`: 配置选项
173
226
  - `fetcher`: 要使用的自定义获取器实例。默认为默认获取器。
174
227
 
175
228
  **返回值:**
176
229
 
177
230
  包含以下属性的对象:
178
231
 
179
- - `loading`: 指示获取数据操作当前是否正在进行中
180
- - `exchange`: 代表正在进行的获取数据操作的 FetchExchange 对象
181
- - `result`: 获取数据操作返回的数据
182
- - `error`: 获取数据操作期间发生的任何错误
183
- - `execute`: 手动触发获取数据操作的函数
184
- - `cancel`: 取消正在进行的获取数据操作的函数
232
+ - `status`: 当前状态
233
+ - `loading`: 指示当前是否加载中
234
+ - `result`: 结果值
235
+ - `error`: 错误值
236
+ - `exchange`: FetchExchange 对象
237
+ - `execute`: 执行获取请求的函数
185
238
 
186
239
  ### useKeyStorage
187
240
 
@@ -7,15 +7,10 @@ export type PromiseSupplier<R> = () => Promise<R>;
7
7
  /**
8
8
  * Interface defining the return type of useExecutePromise hook
9
9
  * @template R - The type of the result value
10
- *
11
- * @example
12
- * ```typescript
13
- * const { loading, result, error, execute, reset } = useExecutePromise<string>();
14
- * ```
15
10
  */
16
11
  export interface UseExecutePromiseReturn<R> extends PromiseState<R> {
17
- /** Function to execute a promise supplier */
18
- execute: (provider: PromiseSupplier<R>) => Promise<R>;
12
+ /** Function to execute a promise supplier or promise */
13
+ execute: (input: PromiseSupplier<R> | Promise<R>) => Promise<R>;
19
14
  /** Function to reset the state to initial values */
20
15
  reset: () => void;
21
16
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useExecutePromise.d.ts","sourceRoot":"","sources":["../../src/core/useExecutePromise.ts"],"names":[],"mappings":"AAeA,OAAO,EAAmB,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAElE;;;GAGG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC;AAElD;;;;;;;;GAQG;AACH,MAAM,WAAW,uBAAuB,CAAC,CAAC,CAAE,SAAQ,YAAY,CAAC,CAAC,CAAC;IACjE,6CAA6C;IAC7C,OAAO,EAAE,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IACtD,oDAAoD;IACpD,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,GAAG,OAAO,KAAK,uBAAuB,CAAC,CAAC,CAAC,CAiD3E"}
1
+ {"version":3,"file":"useExecutePromise.d.ts","sourceRoot":"","sources":["../../src/core/useExecutePromise.ts"],"names":[],"mappings":"AAeA,OAAO,EAAmB,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAElE;;;GAGG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC;AAElD;;;GAGG;AACH,MAAM,WAAW,uBAAuB,CAAC,CAAC,CAAE,SAAQ,YAAY,CAAC,CAAC,CAAC;IACjE,wDAAwD;IACxD,OAAO,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAChE,oDAAoD;IACpD,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,GAAG,OAAO,KAAK,uBAAuB,CAAC,CAAC,CAAC,CAkD3E"}
package/dist/index.es.js CHANGED
@@ -1,7 +1,7 @@
1
- import { useRef as v, useCallback as c, useEffect as b, useState as d, useSyncExternalStore as S } from "react";
2
- import { fetcher as C, getFetcher as R } from "@ahoo-wang/fetcher";
1
+ import { useRef as v, useCallback as u, useEffect as b, useState as d, useSyncExternalStore as S } from "react";
2
+ import { fetcher as m, getFetcher as C } from "@ahoo-wang/fetcher";
3
3
  function g() {
4
- var t = v(!1), n = c(function() {
4
+ var t = v(!1), n = u(function() {
5
5
  return t.current;
6
6
  }, []);
7
7
  return b(function() {
@@ -10,118 +10,118 @@ function g() {
10
10
  };
11
11
  }, []), n;
12
12
  }
13
- var m = /* @__PURE__ */ ((t) => (t.IDLE = "idle", t.LOADING = "loading", t.SUCCESS = "success", t.ERROR = "error", t))(m || {});
13
+ var R = /* @__PURE__ */ ((t) => (t.IDLE = "idle", t.LOADING = "loading", t.SUCCESS = "success", t.ERROR = "error", t))(R || {});
14
14
  function x(t) {
15
- const [n, r] = d(
15
+ const [n, e] = d(
16
16
  t?.initialStatus ?? "idle"
17
17
  /* IDLE */
18
- ), [a, u] = d(void 0), [e, s] = d(void 0), o = g(), E = c(() => {
19
- o() && (r(
18
+ ), [a, s] = d(void 0), [o, r] = d(void 0), c = g(), E = u(() => {
19
+ c() && (e(
20
20
  "loading"
21
21
  /* LOADING */
22
- ), s(void 0));
23
- }, [o]), l = c(
24
- (f) => {
25
- o() && (u(f), r(
22
+ ), r(void 0));
23
+ }, [c]), f = u(
24
+ (l) => {
25
+ c() && (s(l), e(
26
26
  "success"
27
27
  /* SUCCESS */
28
- ), s(void 0), t?.onSuccess?.(f));
28
+ ), r(void 0), t?.onSuccess?.(l));
29
29
  },
30
- [o, t]
31
- ), i = c(
32
- (f) => {
33
- o() && (s(f), r(
30
+ [c, t]
31
+ ), i = u(
32
+ (l) => {
33
+ c() && (r(l), e(
34
34
  "error"
35
35
  /* ERROR */
36
- ), u(void 0), t?.onError?.(f));
36
+ ), s(void 0), t?.onError?.(l));
37
37
  },
38
- [o, t]
39
- ), h = c(() => {
40
- o() && (r(
38
+ [c, t]
39
+ ), h = u(() => {
40
+ c() && (e(
41
41
  "idle"
42
42
  /* IDLE */
43
- ), s(void 0), u(void 0));
44
- }, [o]);
43
+ ), r(void 0), s(void 0));
44
+ }, [c]);
45
45
  return {
46
46
  status: n,
47
47
  loading: n === "loading",
48
48
  result: a,
49
- error: e,
49
+ error: o,
50
50
  setLoading: E,
51
- setSuccess: l,
51
+ setSuccess: f,
52
52
  setError: i,
53
53
  setIdle: h
54
54
  };
55
55
  }
56
56
  function L() {
57
- const t = x(), n = g(), r = c(
58
- async (u) => {
57
+ const t = x(), n = g(), e = u(
58
+ async (s) => {
59
59
  if (!n())
60
60
  throw new Error("Component is unmounted");
61
61
  t.setLoading();
62
62
  try {
63
- const e = await u();
64
- return n() && t.setSuccess(e), e;
65
- } catch (e) {
66
- throw n() && t.setError(e), e;
63
+ const r = await (typeof s == "function" ? s() : s);
64
+ return n() && t.setSuccess(r), r;
65
+ } catch (o) {
66
+ throw n() && t.setError(o), o;
67
67
  }
68
68
  },
69
69
  [t, n]
70
- ), a = c(() => {
70
+ ), a = u(() => {
71
71
  n() && t.setIdle();
72
72
  }, [t, n]);
73
73
  return {
74
74
  loading: t.loading,
75
75
  result: t.result,
76
76
  error: t.error,
77
- execute: r,
77
+ execute: e,
78
78
  reset: a,
79
79
  status: t.status
80
80
  };
81
81
  }
82
82
  function I(t) {
83
- const n = c(
84
- (e) => t.addListener(e),
83
+ const n = u(
84
+ (o) => t.addListener(o),
85
85
  [t]
86
- ), r = c(() => t.get(), [t]), a = S(n, r, r), u = c(
87
- (e) => t.set(e),
86
+ ), e = u(() => t.get(), [t]), a = S(n, e, e), s = u(
87
+ (o) => t.set(o),
88
88
  [t]
89
89
  );
90
- return [a, u];
90
+ return [a, s];
91
91
  }
92
92
  function M(t) {
93
- const { fetcher: n = C } = t || {}, r = x(), [a, u] = d(
93
+ const { fetcher: n = m } = t || {}, e = x(), [a, s] = d(
94
94
  void 0
95
- ), e = g(), s = v(), o = R(n), E = c(
96
- async (l) => {
97
- s.current && s.current.abort(), s.current = l.abortController ?? new AbortController(), l.abortController = s.current, r.setLoading();
95
+ ), o = g(), r = v(), c = C(n), E = u(
96
+ async (f) => {
97
+ r.current && r.current.abort(), r.current = f.abortController ?? new AbortController(), f.abortController = r.current, e.setLoading();
98
98
  try {
99
- const i = await o.exchange(l, t);
100
- e() && u(i);
99
+ const i = await c.exchange(f, t);
100
+ o() && s(i);
101
101
  const h = await i.extractResult();
102
- e() && r.setSuccess(h);
102
+ o() && e.setSuccess(h);
103
103
  } catch (i) {
104
104
  if (i instanceof Error && i.name === "AbortError") {
105
- e() && r.setIdle();
105
+ o() && e.setIdle();
106
106
  return;
107
107
  }
108
- e() && r.setError(i);
108
+ o() && e.setError(i);
109
109
  } finally {
110
- s.current === l.abortController && (s.current = void 0);
110
+ r.current === f.abortController && (r.current = void 0);
111
111
  }
112
112
  },
113
- [o, e, t, r]
113
+ [c, o, t, e]
114
114
  );
115
115
  return b(() => () => {
116
- s.current?.abort(), s.current = void 0;
116
+ r.current?.abort(), r.current = void 0;
117
117
  }, []), {
118
- ...r,
118
+ ...e,
119
119
  exchange: a,
120
120
  execute: E
121
121
  };
122
122
  }
123
123
  export {
124
- m as PromiseStatus,
124
+ R as PromiseStatus,
125
125
  L as useExecutePromise,
126
126
  M as useFetcher,
127
127
  I as useKeyStorage,
@@ -1 +1 @@
1
- {"version":3,"file":"index.es.js","sources":["../../../node_modules/.pnpm/react-use@17.6.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-use/esm/useMountedState.js","../src/core/usePromiseState.ts","../src/core/useExecutePromise.ts","../src/storage/useKeyStorage.ts","../src/fetcher/useFetcher.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\nexport default function useMountedState() {\n var mountedRef = useRef(false);\n var get = useCallback(function () { return mountedRef.current; }, []);\n useEffect(function () {\n mountedRef.current = true;\n return function () {\n mountedRef.current = false;\n };\n }, []);\n return get;\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useCallback, useState } from 'react';\nimport { useMountedState } from 'react-use';\n\n/**\n * Enumeration of possible promise execution states\n */\nexport enum PromiseStatus {\n IDLE = 'idle',\n LOADING = 'loading',\n SUCCESS = 'success',\n ERROR = 'error',\n}\n\nexport interface PromiseState<R> {\n /** Current status of the promise */\n status: PromiseStatus;\n /** Indicates if currently loading */\n loading: boolean;\n /** The result value */\n result: R | undefined;\n /** The error value */\n error: unknown | undefined;\n}\n\n/**\n * Options for configuring usePromiseState behavior\n * @template R - The type of result\n *\n * @example\n * ```typescript\n * const options: UsePromiseStateOptions<string> = {\n * initialStatus: PromiseStatus.IDLE,\n * onSuccess: (result) => console.log('Success:', result),\n * onError: (error) => console.error('Error:', error),\n * };\n * ```\n */\nexport interface UsePromiseStateOptions<R> {\n /** Initial status, defaults to IDLE */\n initialStatus?: PromiseStatus;\n /** Callback invoked on success */\n onSuccess?: (result: R) => void;\n /** Callback invoked on error */\n onError?: (error: unknown) => void;\n}\n\n/**\n * Return type for usePromiseState hook\n * @template R - The type of result\n */\nexport interface UsePromiseStateReturn<R> extends PromiseState<R> {\n /** Set status to LOADING */\n setLoading: () => void;\n /** Set status to SUCCESS with result */\n setSuccess: (result: R) => void;\n /** Set status to ERROR with error */\n setError: (error: unknown) => void;\n /** Set status to IDLE */\n setIdle: () => void;\n}\n\n/**\n * A React hook for managing promise state without execution logic\n * @template R - The type of result\n * @param options - Configuration options\n * @returns State management object\n *\n * @example\n * ```typescript\n * import { usePromiseState, PromiseStatus } from '@ahoo-wang/fetcher-react';\n *\n * function MyComponent() {\n * const { status, loading, result, error, setSuccess, setError, setIdle } = usePromiseState<string>();\n *\n * const handleSuccess = () => setSuccess('Data loaded');\n * const handleError = () => setError(new Error('Failed to load'));\n *\n * return (\n * <div>\n * <button onClick={handleSuccess}>Set Success</button>\n * <button onClick={handleError}>Set Error</button>\n * <button onClick={setIdle}>Reset</button>\n * <p>Status: {status}</p>\n * {loading && <p>Loading...</p>}\n * {result && <p>Result: {result}</p>}\n * {error && <p>Error: {error.message}</p>}\n * </div>\n * );\n * }\n * ```\n */\nexport function usePromiseState<R = unknown>(\n options?: UsePromiseStateOptions<R>,\n): UsePromiseStateReturn<R> {\n const [status, setStatus] = useState<PromiseStatus>(\n options?.initialStatus ?? PromiseStatus.IDLE,\n );\n const [result, setResult] = useState<R | undefined>(undefined);\n const [error, setErrorState] = useState<unknown | undefined>(undefined);\n const isMounted = useMountedState();\n\n const setLoadingFn = useCallback(() => {\n if (isMounted()) {\n setStatus(PromiseStatus.LOADING);\n setErrorState(undefined);\n }\n }, [isMounted]);\n\n const setSuccessFn = useCallback(\n (result: R) => {\n if (isMounted()) {\n setResult(result);\n setStatus(PromiseStatus.SUCCESS);\n setErrorState(undefined);\n options?.onSuccess?.(result);\n }\n },\n [isMounted, options],\n );\n\n const setErrorFn = useCallback(\n (error: unknown) => {\n if (isMounted()) {\n setErrorState(error);\n setStatus(PromiseStatus.ERROR);\n setResult(undefined);\n options?.onError?.(error);\n }\n },\n [isMounted, options],\n );\n\n const setIdleFn = useCallback(() => {\n if (isMounted()) {\n setStatus(PromiseStatus.IDLE);\n setErrorState(undefined);\n setResult(undefined);\n }\n }, [isMounted]);\n\n return {\n status,\n loading: status === PromiseStatus.LOADING,\n result,\n error,\n setLoading: setLoadingFn,\n setSuccess: setSuccessFn,\n setError: setErrorFn,\n setIdle: setIdleFn,\n };\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useCallback } from 'react';\nimport { useMountedState } from 'react-use';\nimport { usePromiseState, PromiseState } from './usePromiseState';\n\n/**\n * Type definition for a function that returns a Promise\n * @template R - The type of value the promise will resolve to\n */\nexport type PromiseSupplier<R> = () => Promise<R>;\n\n/**\n * Interface defining the return type of useExecutePromise hook\n * @template R - The type of the result value\n *\n * @example\n * ```typescript\n * const { loading, result, error, execute, reset } = useExecutePromise<string>();\n * ```\n */\nexport interface UseExecutePromiseReturn<R> extends PromiseState<R> {\n /** Function to execute a promise supplier */\n execute: (provider: PromiseSupplier<R>) => Promise<R>;\n /** Function to reset the state to initial values */\n reset: () => void;\n}\n\n/**\n * A React hook for managing asynchronous operations with proper state handling\n * @template R - The type of the result value\n * @returns An object containing the current state and control functions\n *\n * @example\n * ```typescript\n * import { useExecutePromise } from '@ahoo-wang/fetcher-react';\n *\n * function MyComponent() {\n * const { loading, result, error, execute, reset } = useExecutePromise<string>();\n *\n * const fetchData = async () => {\n * const response = await fetch('/api/data');\n * return response.text();\n * };\n *\n * const handleFetch = () => {\n * execute(fetchData);\n * };\n *\n * const handleReset = () => {\n * reset();\n * };\n *\n * if (loading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error.message}</div>;\n * return (\n * <div>\n * <button onClick={handleFetch}>Fetch Data</button>\n * <button onClick={handleReset}>Reset</button>\n * {result && <p>{result}</p>}\n * </div>\n * );\n * }\n * ```\n */\nexport function useExecutePromise<R = unknown>(): UseExecutePromiseReturn<R> {\n const state = usePromiseState<R>();\n const isMounted = useMountedState();\n\n /**\n * Execute a promise supplier and manage its state\n * @param provider - A function that returns a Promise to be executed\n * @returns A Promise that resolves with the result of the executed promise\n */\n const execute = useCallback(\n async (provider: PromiseSupplier<R>): Promise<R> => {\n if (!isMounted()) {\n throw new Error('Component is unmounted');\n }\n state.setLoading();\n try {\n const data = await provider();\n\n if (isMounted()) {\n state.setSuccess(data);\n }\n return data;\n } catch (err) {\n if (isMounted()) {\n state.setError(err);\n }\n throw err;\n }\n },\n [state, isMounted],\n );\n\n /**\n * Reset the state to initial values\n */\n const reset = useCallback(() => {\n if (isMounted()) {\n state.setIdle();\n }\n }, [state, isMounted]);\n\n return {\n loading: state.loading,\n result: state.result,\n error: state.error,\n execute,\n reset,\n status: state.status,\n };\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useCallback, useSyncExternalStore } from 'react';\nimport { KeyStorage } from '@ahoo-wang/fetcher-storage';\n\n/**\n * A React hook that provides state management for a KeyStorage instance.\n * Subscribes to storage changes and returns the current value along with a setter function.\n *\n * @template T - The type of value stored in the key storage\n * @param keyStorage - The KeyStorage instance to subscribe to and manage\n * @returns A tuple containing the current stored value and a function to update it\n */\nexport function useKeyStorage<T>(\n keyStorage: KeyStorage<T>,\n): [T | null, (value: T) => void] {\n const subscribe = useCallback(\n (callback: () => void) => keyStorage.addListener(callback),\n [keyStorage],\n );\n const getSnapshot = useCallback(() => keyStorage.get(), [keyStorage]);\n const value = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n const setValue = useCallback(\n (value: T) => keyStorage.set(value),\n [keyStorage],\n );\n return [value, setValue];\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n fetcher as defaultFetcher,\n FetcherCapable,\n FetchExchange,\n FetchRequest,\n getFetcher,\n RequestOptions,\n} from '@ahoo-wang/fetcher';\nimport { useRef, useCallback, useEffect, useState } from 'react';\nimport { useMountedState } from 'react-use';\nimport {\n PromiseState,\n usePromiseState,\n} from '../core';\n\n/**\n * Configuration options for the useFetcher hook.\n * Extends RequestOptions and FetcherCapable interfaces.\n */\nexport interface UseFetcherOptions extends RequestOptions, FetcherCapable {\n}\n\nexport interface UseFetcherReturn<R> extends PromiseState<R> {\n /** The FetchExchange object representing the ongoing fetch operation */\n exchange?: FetchExchange;\n execute: (request: FetchRequest) => Promise<void>;\n}\n\n/**\n * A React hook for managing asynchronous operations with proper state handling\n * @param options - Configuration options for the fetcher\n * @returns An object containing the current state and control functions\n *\n * @example\n * ```typescript\n * import { useFetcher } from '@ahoo-wang/fetcher-react';\n *\n * function MyComponent() {\n * const { loading, result, error, execute } = useFetcher<string>();\n *\n * const handleFetch = () => {\n * execute({ url: '/api/data', method: 'GET' });\n * };\n *\n * if (loading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error.message}</div>;\n * return (\n * <div>\n * <button onClick={handleFetch}>Fetch Data</button>\n * {result && <p>{result}</p>}\n * </div>\n * );\n * }\n * ```\n */\nexport function useFetcher<R>(\n options?: UseFetcherOptions,\n): UseFetcherReturn<R> {\n const { fetcher = defaultFetcher } = options || {};\n const state = usePromiseState<R>();\n const [exchange, setExchange] = useState<FetchExchange | undefined>(\n undefined,\n );\n const isMounted = useMountedState();\n const abortControllerRef = useRef<AbortController | undefined>();\n\n const currentFetcher = getFetcher(fetcher);\n /**\n * Execute the fetch operation.\n * Cancels any ongoing fetch before starting a new one.\n */\n const execute = useCallback(\n async (request: FetchRequest) => {\n if (abortControllerRef.current) {\n abortControllerRef.current.abort();\n }\n abortControllerRef.current =\n request.abortController ?? new AbortController();\n request.abortController = abortControllerRef.current;\n state.setLoading();\n try {\n const exchange = await currentFetcher.exchange(request, options);\n if (isMounted()) {\n setExchange(exchange);\n }\n const result = await exchange.extractResult<R>();\n if (isMounted()) {\n state.setSuccess(result);\n }\n } catch (error) {\n if (error instanceof Error && error.name === 'AbortError') {\n if (isMounted()) {\n state.setIdle();\n }\n return;\n }\n if (isMounted()) {\n state.setError(error);\n }\n } finally {\n if (abortControllerRef.current === request.abortController) {\n abortControllerRef.current = undefined;\n }\n }\n },\n [currentFetcher, isMounted, options, state],\n );\n\n useEffect(() => {\n return () => {\n abortControllerRef.current?.abort();\n abortControllerRef.current = undefined;\n };\n }, []);\n return {\n ...state,\n exchange,\n execute,\n };\n}\n"],"names":["useMountedState","mountedRef","useRef","get","useCallback","useEffect","PromiseStatus","usePromiseState","options","status","setStatus","useState","result","setResult","error","setErrorState","isMounted","setLoadingFn","setSuccessFn","setErrorFn","setIdleFn","useExecutePromise","state","execute","provider","data","err","reset","useKeyStorage","keyStorage","subscribe","callback","getSnapshot","value","useSyncExternalStore","setValue","useFetcher","fetcher","defaultFetcher","exchange","setExchange","abortControllerRef","currentFetcher","getFetcher","request"],"mappings":";;AACe,SAASA,IAAkB;AACtC,MAAIC,IAAaC,EAAO,EAAK,GACzBC,IAAMC,EAAY,WAAY;AAAE,WAAOH,EAAW;AAAA,EAAS,GAAG,EAAE;AACpE,SAAAI,EAAU,WAAY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mB9B,KAAW,CAAA,GAC1Cc,IAAQf,EAAA,GACR,CAACgC,GAAUC,CAAW,IAAI7B;AAAA,IAC9B;AAAA,EAAA,GAEIK,IAAYhB,EAAA,GACZyC,IAAqBvC,EAAA,GAErBwC,IAAiBC,EAAWN,CAAO,GAKnCd,IAAUnB;AAAA,IACd,OAAOwC,MAA0B;AAC/B,MAAIH,EAAmB,WACrBA,EAAmB,QAAQ,MAAA,GAE7BA,EAAmB,UACjBG,EAAQ,mBAAmB,IAAI,gBAAA,GACjCA,EAAQ,kBAAkBH,EAAmB,SAC7CnB,EAAM,WAAA;AACN,UAAI;AACF,cAAMiB,IAAW,MAAMG,EAAe,SAASE,GAASpC,CAAO;AAC/D,QAAIQ,OACFwB,EAAYD,CAAQ;AAEtB,cAAM3B,IAAS,MAAM2B,EAAS,cAAA;AAC9B,QAAIvB,OACFM,EAAM,WAAWV,CAAM;AAAA,MAE3B,SAASE,GAAO;AACd,YAAIA,aAAiB,SAASA,EAAM,SAAS,cAAc;AACzD,UAAIE,OACFM,EAAM,QAAA;AAER;AAAA,QACF;AACA,QAAIN,OACFM,EAAM,SAASR,CAAK;AAAA,MAExB,UAAA;AACE,QAAI2B,EAAmB,YAAYG,EAAQ,oBACzCH,EAAmB,UAAU;AAAA,MAEjC;AAAA,IACF;AAAA,IACA,CAACC,GAAgB1B,GAAWR,GAASc,CAAK;AAAA,EAAA;AAG5C,SAAAjB,EAAU,MACD,MAAM;AACX,IAAAoC,EAAmB,SAAS,MAAA,GAC5BA,EAAmB,UAAU;AAAA,EAC/B,GACC,CAAA,CAAE,GACE;AAAA,IACL,GAAGnB;AAAA,IACH,UAAAiB;AAAA,IACA,SAAAhB;AAAA,EAAA;AAEJ;","x_google_ignoreList":[0]}
1
+ {"version":3,"file":"index.es.js","sources":["../../../node_modules/.pnpm/react-use@17.6.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-use/esm/useMountedState.js","../src/core/usePromiseState.ts","../src/core/useExecutePromise.ts","../src/storage/useKeyStorage.ts","../src/fetcher/useFetcher.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\nexport default function useMountedState() {\n var mountedRef = useRef(false);\n var get = useCallback(function () { return mountedRef.current; }, []);\n useEffect(function () {\n mountedRef.current = true;\n return function () {\n mountedRef.current = false;\n };\n }, []);\n return get;\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useCallback, useState } from 'react';\nimport { useMountedState } from 'react-use';\n\n/**\n * Enumeration of possible promise execution states\n */\nexport enum PromiseStatus {\n IDLE = 'idle',\n LOADING = 'loading',\n SUCCESS = 'success',\n ERROR = 'error',\n}\n\nexport interface PromiseState<R> {\n /** Current status of the promise */\n status: PromiseStatus;\n /** Indicates if currently loading */\n loading: boolean;\n /** The result value */\n result: R | undefined;\n /** The error value */\n error: unknown | undefined;\n}\n\n/**\n * Options for configuring usePromiseState behavior\n * @template R - The type of result\n *\n * @example\n * ```typescript\n * const options: UsePromiseStateOptions<string> = {\n * initialStatus: PromiseStatus.IDLE,\n * onSuccess: (result) => console.log('Success:', result),\n * onError: (error) => console.error('Error:', error),\n * };\n * ```\n */\nexport interface UsePromiseStateOptions<R> {\n /** Initial status, defaults to IDLE */\n initialStatus?: PromiseStatus;\n /** Callback invoked on success */\n onSuccess?: (result: R) => void;\n /** Callback invoked on error */\n onError?: (error: unknown) => void;\n}\n\n/**\n * Return type for usePromiseState hook\n * @template R - The type of result\n */\nexport interface UsePromiseStateReturn<R> extends PromiseState<R> {\n /** Set status to LOADING */\n setLoading: () => void;\n /** Set status to SUCCESS with result */\n setSuccess: (result: R) => void;\n /** Set status to ERROR with error */\n setError: (error: unknown) => void;\n /** Set status to IDLE */\n setIdle: () => void;\n}\n\n/**\n * A React hook for managing promise state without execution logic\n * @template R - The type of result\n * @param options - Configuration options\n * @returns State management object\n *\n * @example\n * ```typescript\n * import { usePromiseState, PromiseStatus } from '@ahoo-wang/fetcher-react';\n *\n * function MyComponent() {\n * const { status, loading, result, error, setSuccess, setError, setIdle } = usePromiseState<string>();\n *\n * const handleSuccess = () => setSuccess('Data loaded');\n * const handleError = () => setError(new Error('Failed to load'));\n *\n * return (\n * <div>\n * <button onClick={handleSuccess}>Set Success</button>\n * <button onClick={handleError}>Set Error</button>\n * <button onClick={setIdle}>Reset</button>\n * <p>Status: {status}</p>\n * {loading && <p>Loading...</p>}\n * {result && <p>Result: {result}</p>}\n * {error && <p>Error: {error.message}</p>}\n * </div>\n * );\n * }\n * ```\n */\nexport function usePromiseState<R = unknown>(\n options?: UsePromiseStateOptions<R>,\n): UsePromiseStateReturn<R> {\n const [status, setStatus] = useState<PromiseStatus>(\n options?.initialStatus ?? PromiseStatus.IDLE,\n );\n const [result, setResult] = useState<R | undefined>(undefined);\n const [error, setErrorState] = useState<unknown | undefined>(undefined);\n const isMounted = useMountedState();\n\n const setLoadingFn = useCallback(() => {\n if (isMounted()) {\n setStatus(PromiseStatus.LOADING);\n setErrorState(undefined);\n }\n }, [isMounted]);\n\n const setSuccessFn = useCallback(\n (result: R) => {\n if (isMounted()) {\n setResult(result);\n setStatus(PromiseStatus.SUCCESS);\n setErrorState(undefined);\n options?.onSuccess?.(result);\n }\n },\n [isMounted, options],\n );\n\n const setErrorFn = useCallback(\n (error: unknown) => {\n if (isMounted()) {\n setErrorState(error);\n setStatus(PromiseStatus.ERROR);\n setResult(undefined);\n options?.onError?.(error);\n }\n },\n [isMounted, options],\n );\n\n const setIdleFn = useCallback(() => {\n if (isMounted()) {\n setStatus(PromiseStatus.IDLE);\n setErrorState(undefined);\n setResult(undefined);\n }\n }, [isMounted]);\n\n return {\n status,\n loading: status === PromiseStatus.LOADING,\n result,\n error,\n setLoading: setLoadingFn,\n setSuccess: setSuccessFn,\n setError: setErrorFn,\n setIdle: setIdleFn,\n };\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useCallback } from 'react';\nimport { useMountedState } from 'react-use';\nimport { usePromiseState, PromiseState } from './usePromiseState';\n\n/**\n * Type definition for a function that returns a Promise\n * @template R - The type of value the promise will resolve to\n */\nexport type PromiseSupplier<R> = () => Promise<R>;\n\n/**\n * Interface defining the return type of useExecutePromise hook\n * @template R - The type of the result value\n */\nexport interface UseExecutePromiseReturn<R> extends PromiseState<R> {\n /** Function to execute a promise supplier or promise */\n execute: (input: PromiseSupplier<R> | Promise<R>) => Promise<R>;\n /** Function to reset the state to initial values */\n reset: () => void;\n}\n\n/**\n * A React hook for managing asynchronous operations with proper state handling\n * @template R - The type of the result value\n * @returns An object containing the current state and control functions\n *\n * @example\n * ```typescript\n * import { useExecutePromise } from '@ahoo-wang/fetcher-react';\n *\n * function MyComponent() {\n * const { loading, result, error, execute, reset } = useExecutePromise<string>();\n *\n * const fetchData = async () => {\n * const response = await fetch('/api/data');\n * return response.text();\n * };\n *\n * const handleFetch = () => {\n * execute(fetchData);\n * };\n *\n * const handleReset = () => {\n * reset();\n * };\n *\n * if (loading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error.message}</div>;\n * return (\n * <div>\n * <button onClick={handleFetch}>Fetch Data</button>\n * <button onClick={handleReset}>Reset</button>\n * {result && <p>{result}</p>}\n * </div>\n * );\n * }\n * ```\n */\nexport function useExecutePromise<R = unknown>(): UseExecutePromiseReturn<R> {\n const state = usePromiseState<R>();\n const isMounted = useMountedState();\n\n /**\n * Execute a promise supplier or promise and manage its state\n * @param input - A function that returns a Promise or a Promise to be executed\n * @returns A Promise that resolves with the result of the executed promise\n */\n const execute = useCallback(\n async (input: PromiseSupplier<R> | Promise<R>): Promise<R> => {\n if (!isMounted()) {\n throw new Error('Component is unmounted');\n }\n state.setLoading();\n try {\n const promise = typeof input === 'function' ? input() : input;\n const data = await promise;\n\n if (isMounted()) {\n state.setSuccess(data);\n }\n return data;\n } catch (err) {\n if (isMounted()) {\n state.setError(err);\n }\n throw err;\n }\n },\n [state, isMounted],\n );\n\n /**\n * Reset the state to initial values\n */\n const reset = useCallback(() => {\n if (isMounted()) {\n state.setIdle();\n }\n }, [state, isMounted]);\n\n return {\n loading: state.loading,\n result: state.result,\n error: state.error,\n execute,\n reset,\n status: state.status,\n };\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useCallback, useSyncExternalStore } from 'react';\nimport { KeyStorage } from '@ahoo-wang/fetcher-storage';\n\n/**\n * A React hook that provides state management for a KeyStorage instance.\n * Subscribes to storage changes and returns the current value along with a setter function.\n *\n * @template T - The type of value stored in the key storage\n * @param keyStorage - The KeyStorage instance to subscribe to and manage\n * @returns A tuple containing the current stored value and a function to update it\n */\nexport function useKeyStorage<T>(\n keyStorage: KeyStorage<T>,\n): [T | null, (value: T) => void] {\n const subscribe = useCallback(\n (callback: () => void) => keyStorage.addListener(callback),\n [keyStorage],\n );\n const getSnapshot = useCallback(() => keyStorage.get(), [keyStorage]);\n const value = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n const setValue = useCallback(\n (value: T) => keyStorage.set(value),\n [keyStorage],\n );\n return [value, setValue];\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n fetcher as defaultFetcher,\n FetcherCapable,\n FetchExchange,\n FetchRequest,\n getFetcher,\n RequestOptions,\n} from '@ahoo-wang/fetcher';\nimport { useRef, useCallback, useEffect, useState } from 'react';\nimport { useMountedState } from 'react-use';\nimport {\n PromiseState,\n usePromiseState,\n} from '../core';\n\n/**\n * Configuration options for the useFetcher hook.\n * Extends RequestOptions and FetcherCapable interfaces.\n */\nexport interface UseFetcherOptions extends RequestOptions, FetcherCapable {\n}\n\nexport interface UseFetcherReturn<R> extends PromiseState<R> {\n /** The FetchExchange object representing the ongoing fetch operation */\n exchange?: FetchExchange;\n execute: (request: FetchRequest) => Promise<void>;\n}\n\n/**\n * A React hook for managing asynchronous operations with proper state handling\n * @param options - Configuration options for the fetcher\n * @returns An object containing the current state and control functions\n *\n * @example\n * ```typescript\n * import { useFetcher } from '@ahoo-wang/fetcher-react';\n *\n * function MyComponent() {\n * const { loading, result, error, execute } = useFetcher<string>();\n *\n * const handleFetch = () => {\n * execute({ url: '/api/data', method: 'GET' });\n * };\n *\n * if (loading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error.message}</div>;\n * return (\n * <div>\n * <button onClick={handleFetch}>Fetch Data</button>\n * {result && <p>{result}</p>}\n * </div>\n * );\n * }\n * ```\n */\nexport function useFetcher<R>(\n options?: UseFetcherOptions,\n): UseFetcherReturn<R> {\n const { fetcher = defaultFetcher } = options || {};\n const state = usePromiseState<R>();\n const [exchange, setExchange] = useState<FetchExchange | undefined>(\n undefined,\n );\n const isMounted = useMountedState();\n const abortControllerRef = useRef<AbortController | undefined>();\n\n const currentFetcher = getFetcher(fetcher);\n /**\n * Execute the fetch operation.\n * Cancels any ongoing fetch before starting a new one.\n */\n const execute = useCallback(\n async (request: FetchRequest) => {\n if (abortControllerRef.current) {\n abortControllerRef.current.abort();\n }\n abortControllerRef.current =\n request.abortController ?? new AbortController();\n request.abortController = abortControllerRef.current;\n state.setLoading();\n try {\n const exchange = await currentFetcher.exchange(request, options);\n if (isMounted()) {\n setExchange(exchange);\n }\n const result = await exchange.extractResult<R>();\n if (isMounted()) {\n state.setSuccess(result);\n }\n } catch (error) {\n if (error instanceof Error && error.name === 'AbortError') {\n if (isMounted()) {\n state.setIdle();\n }\n return;\n }\n if (isMounted()) {\n state.setError(error);\n }\n } finally {\n if (abortControllerRef.current === request.abortController) {\n abortControllerRef.current = undefined;\n }\n }\n },\n [currentFetcher, isMounted, options, state],\n );\n\n useEffect(() => {\n return () => {\n abortControllerRef.current?.abort();\n abortControllerRef.current = undefined;\n };\n }, []);\n return {\n ...state,\n exchange,\n execute,\n };\n}\n"],"names":["useMountedState","mountedRef","useRef","get","useCallback","useEffect","PromiseStatus","usePromiseState","options","status","setStatus","useState","result","setResult","error","setErrorState","isMounted","setLoadingFn","setSuccessFn","setErrorFn","setIdleFn","useExecutePromise","state","execute","input","data","err","reset","useKeyStorage","keyStorage","subscribe","callback","getSnapshot","value","useSyncExternalStore","setValue","useFetcher","fetcher","defaultFetcher","exchange","setExchange","abortControllerRef","currentFetcher","getFetcher","request"],"mappings":";;AACe,SAASA,IAAkB;AACtC,MAAIC,IAAaC,EAAO,EAA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2 @@
1
- (function(u,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("react"),require("@ahoo-wang/fetcher")):typeof define=="function"&&define.amd?define(["exports","react","@ahoo-wang/fetcher"],t):(u=typeof globalThis<"u"?globalThis:u||self,t(u.FetcherReact={},u.React,u.Fetcher))})(this,(function(u,t,S){"use strict";function h(){var e=t.useRef(!1),s=t.useCallback(function(){return e.current},[]);return t.useEffect(function(){return e.current=!0,function(){e.current=!1}},[]),s}var g=(e=>(e.IDLE="idle",e.LOADING="loading",e.SUCCESS="success",e.ERROR="error",e))(g||{});function b(e){const[s,n]=t.useState(e?.initialStatus??"idle"),[l,i]=t.useState(void 0),[r,o]=t.useState(void 0),c=h(),C=t.useCallback(()=>{c()&&(n("loading"),o(void 0))},[c]),f=t.useCallback(d=>{c()&&(i(d),n("success"),o(void 0),e?.onSuccess?.(d))},[c,e]),a=t.useCallback(d=>{c()&&(o(d),n("error"),i(void 0),e?.onError?.(d))},[c,e]),E=t.useCallback(()=>{c()&&(n("idle"),o(void 0),i(void 0))},[c]);return{status:s,loading:s==="loading",result:l,error:r,setLoading:C,setSuccess:f,setError:a,setIdle:E}}function v(){const e=b(),s=h(),n=t.useCallback(async i=>{if(!s())throw new Error("Component is unmounted");e.setLoading();try{const r=await i();return s()&&e.setSuccess(r),r}catch(r){throw s()&&e.setError(r),r}},[e,s]),l=t.useCallback(()=>{s()&&e.setIdle()},[e,s]);return{loading:e.loading,result:e.result,error:e.error,execute:n,reset:l,status:e.status}}function F(e){const s=t.useCallback(r=>e.addListener(r),[e]),n=t.useCallback(()=>e.get(),[e]),l=t.useSyncExternalStore(s,n,n),i=t.useCallback(r=>e.set(r),[e]);return[l,i]}function m(e){const{fetcher:s=S.fetcher}=e||{},n=b(),[l,i]=t.useState(void 0),r=h(),o=t.useRef(),c=S.getFetcher(s),C=t.useCallback(async f=>{o.current&&o.current.abort(),o.current=f.abortController??new AbortController,f.abortController=o.current,n.setLoading();try{const a=await c.exchange(f,e);r()&&i(a);const E=await a.extractResult();r()&&n.setSuccess(E)}catch(a){if(a instanceof Error&&a.name==="AbortError"){r()&&n.setIdle();return}r()&&n.setError(a)}finally{o.current===f.abortController&&(o.current=void 0)}},[c,r,e,n]);return t.useEffect(()=>()=>{o.current?.abort(),o.current=void 0},[]),{...n,exchange:l,execute:C}}u.PromiseStatus=g,u.useExecutePromise=v,u.useFetcher=m,u.useKeyStorage=F,u.usePromiseState=b,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(u,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("react"),require("@ahoo-wang/fetcher")):typeof define=="function"&&define.amd?define(["exports","react","@ahoo-wang/fetcher"],t):(u=typeof globalThis<"u"?globalThis:u||self,t(u.FetcherReact={},u.React,u.Fetcher))})(this,(function(u,t,S){"use strict";function h(){var e=t.useRef(!1),s=t.useCallback(function(){return e.current},[]);return t.useEffect(function(){return e.current=!0,function(){e.current=!1}},[]),s}var g=(e=>(e.IDLE="idle",e.LOADING="loading",e.SUCCESS="success",e.ERROR="error",e))(g||{});function b(e){const[s,r]=t.useState(e?.initialStatus??"idle"),[l,c]=t.useState(void 0),[o,n]=t.useState(void 0),i=h(),C=t.useCallback(()=>{i()&&(r("loading"),n(void 0))},[i]),f=t.useCallback(d=>{i()&&(c(d),r("success"),n(void 0),e?.onSuccess?.(d))},[i,e]),a=t.useCallback(d=>{i()&&(n(d),r("error"),c(void 0),e?.onError?.(d))},[i,e]),E=t.useCallback(()=>{i()&&(r("idle"),n(void 0),c(void 0))},[i]);return{status:s,loading:s==="loading",result:l,error:o,setLoading:C,setSuccess:f,setError:a,setIdle:E}}function v(){const e=b(),s=h(),r=t.useCallback(async c=>{if(!s())throw new Error("Component is unmounted");e.setLoading();try{const n=await(typeof c=="function"?c():c);return s()&&e.setSuccess(n),n}catch(o){throw s()&&e.setError(o),o}},[e,s]),l=t.useCallback(()=>{s()&&e.setIdle()},[e,s]);return{loading:e.loading,result:e.result,error:e.error,execute:r,reset:l,status:e.status}}function m(e){const s=t.useCallback(o=>e.addListener(o),[e]),r=t.useCallback(()=>e.get(),[e]),l=t.useSyncExternalStore(s,r,r),c=t.useCallback(o=>e.set(o),[e]);return[l,c]}function F(e){const{fetcher:s=S.fetcher}=e||{},r=b(),[l,c]=t.useState(void 0),o=h(),n=t.useRef(),i=S.getFetcher(s),C=t.useCallback(async f=>{n.current&&n.current.abort(),n.current=f.abortController??new AbortController,f.abortController=n.current,r.setLoading();try{const a=await i.exchange(f,e);o()&&c(a);const E=await a.extractResult();o()&&r.setSuccess(E)}catch(a){if(a instanceof Error&&a.name==="AbortError"){o()&&r.setIdle();return}o()&&r.setError(a)}finally{n.current===f.abortController&&(n.current=void 0)}},[i,o,e,r]);return t.useEffect(()=>()=>{n.current?.abort(),n.current=void 0},[]),{...r,exchange:l,execute:C}}u.PromiseStatus=g,u.useExecutePromise=v,u.useFetcher=F,u.useKeyStorage=m,u.usePromiseState=b,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})}));
2
2
  //# sourceMappingURL=index.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.umd.js","sources":["../../../node_modules/.pnpm/react-use@17.6.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-use/esm/useMountedState.js","../src/core/usePromiseState.ts","../src/core/useExecutePromise.ts","../src/storage/useKeyStorage.ts","../src/fetcher/useFetcher.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\nexport default function useMountedState() {\n var mountedRef = useRef(false);\n var get = useCallback(function () { return mountedRef.current; }, []);\n useEffect(function () {\n mountedRef.current = true;\n return function () {\n mountedRef.current = false;\n };\n }, []);\n return get;\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useCallback, useState } from 'react';\nimport { useMountedState } from 'react-use';\n\n/**\n * Enumeration of possible promise execution states\n */\nexport enum PromiseStatus {\n IDLE = 'idle',\n LOADING = 'loading',\n SUCCESS = 'success',\n ERROR = 'error',\n}\n\nexport interface PromiseState<R> {\n /** Current status of the promise */\n status: PromiseStatus;\n /** Indicates if currently loading */\n loading: boolean;\n /** The result value */\n result: R | undefined;\n /** The error value */\n error: unknown | undefined;\n}\n\n/**\n * Options for configuring usePromiseState behavior\n * @template R - The type of result\n *\n * @example\n * ```typescript\n * const options: UsePromiseStateOptions<string> = {\n * initialStatus: PromiseStatus.IDLE,\n * onSuccess: (result) => console.log('Success:', result),\n * onError: (error) => console.error('Error:', error),\n * };\n * ```\n */\nexport interface UsePromiseStateOptions<R> {\n /** Initial status, defaults to IDLE */\n initialStatus?: PromiseStatus;\n /** Callback invoked on success */\n onSuccess?: (result: R) => void;\n /** Callback invoked on error */\n onError?: (error: unknown) => void;\n}\n\n/**\n * Return type for usePromiseState hook\n * @template R - The type of result\n */\nexport interface UsePromiseStateReturn<R> extends PromiseState<R> {\n /** Set status to LOADING */\n setLoading: () => void;\n /** Set status to SUCCESS with result */\n setSuccess: (result: R) => void;\n /** Set status to ERROR with error */\n setError: (error: unknown) => void;\n /** Set status to IDLE */\n setIdle: () => void;\n}\n\n/**\n * A React hook for managing promise state without execution logic\n * @template R - The type of result\n * @param options - Configuration options\n * @returns State management object\n *\n * @example\n * ```typescript\n * import { usePromiseState, PromiseStatus } from '@ahoo-wang/fetcher-react';\n *\n * function MyComponent() {\n * const { status, loading, result, error, setSuccess, setError, setIdle } = usePromiseState<string>();\n *\n * const handleSuccess = () => setSuccess('Data loaded');\n * const handleError = () => setError(new Error('Failed to load'));\n *\n * return (\n * <div>\n * <button onClick={handleSuccess}>Set Success</button>\n * <button onClick={handleError}>Set Error</button>\n * <button onClick={setIdle}>Reset</button>\n * <p>Status: {status}</p>\n * {loading && <p>Loading...</p>}\n * {result && <p>Result: {result}</p>}\n * {error && <p>Error: {error.message}</p>}\n * </div>\n * );\n * }\n * ```\n */\nexport function usePromiseState<R = unknown>(\n options?: UsePromiseStateOptions<R>,\n): UsePromiseStateReturn<R> {\n const [status, setStatus] = useState<PromiseStatus>(\n options?.initialStatus ?? PromiseStatus.IDLE,\n );\n const [result, setResult] = useState<R | undefined>(undefined);\n const [error, setErrorState] = useState<unknown | undefined>(undefined);\n const isMounted = useMountedState();\n\n const setLoadingFn = useCallback(() => {\n if (isMounted()) {\n setStatus(PromiseStatus.LOADING);\n setErrorState(undefined);\n }\n }, [isMounted]);\n\n const setSuccessFn = useCallback(\n (result: R) => {\n if (isMounted()) {\n setResult(result);\n setStatus(PromiseStatus.SUCCESS);\n setErrorState(undefined);\n options?.onSuccess?.(result);\n }\n },\n [isMounted, options],\n );\n\n const setErrorFn = useCallback(\n (error: unknown) => {\n if (isMounted()) {\n setErrorState(error);\n setStatus(PromiseStatus.ERROR);\n setResult(undefined);\n options?.onError?.(error);\n }\n },\n [isMounted, options],\n );\n\n const setIdleFn = useCallback(() => {\n if (isMounted()) {\n setStatus(PromiseStatus.IDLE);\n setErrorState(undefined);\n setResult(undefined);\n }\n }, [isMounted]);\n\n return {\n status,\n loading: status === PromiseStatus.LOADING,\n result,\n error,\n setLoading: setLoadingFn,\n setSuccess: setSuccessFn,\n setError: setErrorFn,\n setIdle: setIdleFn,\n };\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useCallback } from 'react';\nimport { useMountedState } from 'react-use';\nimport { usePromiseState, PromiseState } from './usePromiseState';\n\n/**\n * Type definition for a function that returns a Promise\n * @template R - The type of value the promise will resolve to\n */\nexport type PromiseSupplier<R> = () => Promise<R>;\n\n/**\n * Interface defining the return type of useExecutePromise hook\n * @template R - The type of the result value\n *\n * @example\n * ```typescript\n * const { loading, result, error, execute, reset } = useExecutePromise<string>();\n * ```\n */\nexport interface UseExecutePromiseReturn<R> extends PromiseState<R> {\n /** Function to execute a promise supplier */\n execute: (provider: PromiseSupplier<R>) => Promise<R>;\n /** Function to reset the state to initial values */\n reset: () => void;\n}\n\n/**\n * A React hook for managing asynchronous operations with proper state handling\n * @template R - The type of the result value\n * @returns An object containing the current state and control functions\n *\n * @example\n * ```typescript\n * import { useExecutePromise } from '@ahoo-wang/fetcher-react';\n *\n * function MyComponent() {\n * const { loading, result, error, execute, reset } = useExecutePromise<string>();\n *\n * const fetchData = async () => {\n * const response = await fetch('/api/data');\n * return response.text();\n * };\n *\n * const handleFetch = () => {\n * execute(fetchData);\n * };\n *\n * const handleReset = () => {\n * reset();\n * };\n *\n * if (loading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error.message}</div>;\n * return (\n * <div>\n * <button onClick={handleFetch}>Fetch Data</button>\n * <button onClick={handleReset}>Reset</button>\n * {result && <p>{result}</p>}\n * </div>\n * );\n * }\n * ```\n */\nexport function useExecutePromise<R = unknown>(): UseExecutePromiseReturn<R> {\n const state = usePromiseState<R>();\n const isMounted = useMountedState();\n\n /**\n * Execute a promise supplier and manage its state\n * @param provider - A function that returns a Promise to be executed\n * @returns A Promise that resolves with the result of the executed promise\n */\n const execute = useCallback(\n async (provider: PromiseSupplier<R>): Promise<R> => {\n if (!isMounted()) {\n throw new Error('Component is unmounted');\n }\n state.setLoading();\n try {\n const data = await provider();\n\n if (isMounted()) {\n state.setSuccess(data);\n }\n return data;\n } catch (err) {\n if (isMounted()) {\n state.setError(err);\n }\n throw err;\n }\n },\n [state, isMounted],\n );\n\n /**\n * Reset the state to initial values\n */\n const reset = useCallback(() => {\n if (isMounted()) {\n state.setIdle();\n }\n }, [state, isMounted]);\n\n return {\n loading: state.loading,\n result: state.result,\n error: state.error,\n execute,\n reset,\n status: state.status,\n };\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useCallback, useSyncExternalStore } from 'react';\nimport { KeyStorage } from '@ahoo-wang/fetcher-storage';\n\n/**\n * A React hook that provides state management for a KeyStorage instance.\n * Subscribes to storage changes and returns the current value along with a setter function.\n *\n * @template T - The type of value stored in the key storage\n * @param keyStorage - The KeyStorage instance to subscribe to and manage\n * @returns A tuple containing the current stored value and a function to update it\n */\nexport function useKeyStorage<T>(\n keyStorage: KeyStorage<T>,\n): [T | null, (value: T) => void] {\n const subscribe = useCallback(\n (callback: () => void) => keyStorage.addListener(callback),\n [keyStorage],\n );\n const getSnapshot = useCallback(() => keyStorage.get(), [keyStorage]);\n const value = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n const setValue = useCallback(\n (value: T) => keyStorage.set(value),\n [keyStorage],\n );\n return [value, setValue];\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n fetcher as defaultFetcher,\n FetcherCapable,\n FetchExchange,\n FetchRequest,\n getFetcher,\n RequestOptions,\n} from '@ahoo-wang/fetcher';\nimport { useRef, useCallback, useEffect, useState } from 'react';\nimport { useMountedState } from 'react-use';\nimport {\n PromiseState,\n usePromiseState,\n} from '../core';\n\n/**\n * Configuration options for the useFetcher hook.\n * Extends RequestOptions and FetcherCapable interfaces.\n */\nexport interface UseFetcherOptions extends RequestOptions, FetcherCapable {\n}\n\nexport interface UseFetcherReturn<R> extends PromiseState<R> {\n /** The FetchExchange object representing the ongoing fetch operation */\n exchange?: FetchExchange;\n execute: (request: FetchRequest) => Promise<void>;\n}\n\n/**\n * A React hook for managing asynchronous operations with proper state handling\n * @param options - Configuration options for the fetcher\n * @returns An object containing the current state and control functions\n *\n * @example\n * ```typescript\n * import { useFetcher } from '@ahoo-wang/fetcher-react';\n *\n * function MyComponent() {\n * const { loading, result, error, execute } = useFetcher<string>();\n *\n * const handleFetch = () => {\n * execute({ url: '/api/data', method: 'GET' });\n * };\n *\n * if (loading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error.message}</div>;\n * return (\n * <div>\n * <button onClick={handleFetch}>Fetch Data</button>\n * {result && <p>{result}</p>}\n * </div>\n * );\n * }\n * ```\n */\nexport function useFetcher<R>(\n options?: UseFetcherOptions,\n): UseFetcherReturn<R> {\n const { fetcher = defaultFetcher } = options || {};\n const state = usePromiseState<R>();\n const [exchange, setExchange] = useState<FetchExchange | undefined>(\n undefined,\n );\n const isMounted = useMountedState();\n const abortControllerRef = useRef<AbortController | undefined>();\n\n const currentFetcher = getFetcher(fetcher);\n /**\n * Execute the fetch operation.\n * Cancels any ongoing fetch before starting a new one.\n */\n const execute = useCallback(\n async (request: FetchRequest) => {\n if (abortControllerRef.current) {\n abortControllerRef.current.abort();\n }\n abortControllerRef.current =\n request.abortController ?? new AbortController();\n request.abortController = abortControllerRef.current;\n state.setLoading();\n try {\n const exchange = await currentFetcher.exchange(request, options);\n if (isMounted()) {\n setExchange(exchange);\n }\n const result = await exchange.extractResult<R>();\n if (isMounted()) {\n state.setSuccess(result);\n }\n } catch (error) {\n if (error instanceof Error && error.name === 'AbortError') {\n if (isMounted()) {\n state.setIdle();\n }\n return;\n }\n if (isMounted()) {\n state.setError(error);\n }\n } finally {\n if (abortControllerRef.current === request.abortController) {\n abortControllerRef.current = undefined;\n }\n }\n },\n [currentFetcher, isMounted, options, state],\n );\n\n useEffect(() => {\n return () => {\n abortControllerRef.current?.abort();\n abortControllerRef.current = undefined;\n };\n }, []);\n return {\n ...state,\n exchange,\n execute,\n };\n}\n"],"names":["useMountedState","mountedRef","useRef","get","useCallback","useEffect","PromiseStatus","usePromiseState","options","status","setStatus","useState","result","setResult","error","setErrorState","isMounted","setLoadingFn","setSuccessFn","setErrorFn","setIdleFn","useExecutePromise","state","execute","provider","data","err","reset","useKeyStorage","keyStorage","subscribe","callback","getSnapshot","value","useSyncExternalStore","setValue","useFetcher","fetcher","defaultFetcher","exchange","setExchange","abortControllerRef","currentFetcher","getFetcher","request"],"mappings":"uUACe,SAASA,GAAkB,CACtC,IAAIC,EAAaC,EAAAA,OAAO,EAAK,EACzBC,EAAMC,EAAAA,YAAY,UAAY,CAAE,OAAOH,EAAW,OAAS,EAAG,EAAE,EACpEI,OAAAA,EAAAA,UAAU,UAAY,CAClB,OAAAJ,EAAW,QAAU,GACd,UAAY,CACfA,EAAW,QAAU,EACzB,CACJ,EAAG,CAAA,CAAE,EACEE,CACX,CCQO,IAAKG,GAAAA,IACVA,EAAA,KAAO,OACPA,EAAA,QAAU,UACVA,EAAA,QAAU,UACVA,EAAA,MAAQ,QAJEA,IAAAA,GAAA,CAAA,CAAA,EAqFL,SAASC,EACdC,EAC0B,CAC1B,KAAM,CAACC,EAAQC,CAAS,EAAIC,EAAA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,CACrDE,KACFM,EAAM,QAAA,EAER,MACF,CACIN,KACFM,EAAM,SAASR,CAAK,CAExB,QAAA,CACM2B,EAAmB,UAAYG,EAAQ,kBACzCH,EAAmB,QAAU,OAEjC,CACF,EACA,CAACC,EAAgB1B,EAAWR,EAASc,CAAK,CAAA,EAG5CjB,OAAAA,EAAAA,UAAU,IACD,IAAM,CACXoC,EAAmB,SAAS,MAAA,EAC5BA,EAAmB,QAAU,MAC/B,EACC,CAAA,CAAE,EACE,CACL,GAAGnB,EACH,SAAAiB,EACA,QAAAhB,CAAA,CAEJ","x_google_ignoreList":[0]}
1
+ {"version":3,"file":"index.umd.js","sources":["../../../node_modules/.pnpm/react-use@17.6.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-use/esm/useMountedState.js","../src/core/usePromiseState.ts","../src/core/useExecutePromise.ts","../src/storage/useKeyStorage.ts","../src/fetcher/useFetcher.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\nexport default function useMountedState() {\n var mountedRef = useRef(false);\n var get = useCallback(function () { return mountedRef.current; }, []);\n useEffect(function () {\n mountedRef.current = true;\n return function () {\n mountedRef.current = false;\n };\n }, []);\n return get;\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useCallback, useState } from 'react';\nimport { useMountedState } from 'react-use';\n\n/**\n * Enumeration of possible promise execution states\n */\nexport enum PromiseStatus {\n IDLE = 'idle',\n LOADING = 'loading',\n SUCCESS = 'success',\n ERROR = 'error',\n}\n\nexport interface PromiseState<R> {\n /** Current status of the promise */\n status: PromiseStatus;\n /** Indicates if currently loading */\n loading: boolean;\n /** The result value */\n result: R | undefined;\n /** The error value */\n error: unknown | undefined;\n}\n\n/**\n * Options for configuring usePromiseState behavior\n * @template R - The type of result\n *\n * @example\n * ```typescript\n * const options: UsePromiseStateOptions<string> = {\n * initialStatus: PromiseStatus.IDLE,\n * onSuccess: (result) => console.log('Success:', result),\n * onError: (error) => console.error('Error:', error),\n * };\n * ```\n */\nexport interface UsePromiseStateOptions<R> {\n /** Initial status, defaults to IDLE */\n initialStatus?: PromiseStatus;\n /** Callback invoked on success */\n onSuccess?: (result: R) => void;\n /** Callback invoked on error */\n onError?: (error: unknown) => void;\n}\n\n/**\n * Return type for usePromiseState hook\n * @template R - The type of result\n */\nexport interface UsePromiseStateReturn<R> extends PromiseState<R> {\n /** Set status to LOADING */\n setLoading: () => void;\n /** Set status to SUCCESS with result */\n setSuccess: (result: R) => void;\n /** Set status to ERROR with error */\n setError: (error: unknown) => void;\n /** Set status to IDLE */\n setIdle: () => void;\n}\n\n/**\n * A React hook for managing promise state without execution logic\n * @template R - The type of result\n * @param options - Configuration options\n * @returns State management object\n *\n * @example\n * ```typescript\n * import { usePromiseState, PromiseStatus } from '@ahoo-wang/fetcher-react';\n *\n * function MyComponent() {\n * const { status, loading, result, error, setSuccess, setError, setIdle } = usePromiseState<string>();\n *\n * const handleSuccess = () => setSuccess('Data loaded');\n * const handleError = () => setError(new Error('Failed to load'));\n *\n * return (\n * <div>\n * <button onClick={handleSuccess}>Set Success</button>\n * <button onClick={handleError}>Set Error</button>\n * <button onClick={setIdle}>Reset</button>\n * <p>Status: {status}</p>\n * {loading && <p>Loading...</p>}\n * {result && <p>Result: {result}</p>}\n * {error && <p>Error: {error.message}</p>}\n * </div>\n * );\n * }\n * ```\n */\nexport function usePromiseState<R = unknown>(\n options?: UsePromiseStateOptions<R>,\n): UsePromiseStateReturn<R> {\n const [status, setStatus] = useState<PromiseStatus>(\n options?.initialStatus ?? PromiseStatus.IDLE,\n );\n const [result, setResult] = useState<R | undefined>(undefined);\n const [error, setErrorState] = useState<unknown | undefined>(undefined);\n const isMounted = useMountedState();\n\n const setLoadingFn = useCallback(() => {\n if (isMounted()) {\n setStatus(PromiseStatus.LOADING);\n setErrorState(undefined);\n }\n }, [isMounted]);\n\n const setSuccessFn = useCallback(\n (result: R) => {\n if (isMounted()) {\n setResult(result);\n setStatus(PromiseStatus.SUCCESS);\n setErrorState(undefined);\n options?.onSuccess?.(result);\n }\n },\n [isMounted, options],\n );\n\n const setErrorFn = useCallback(\n (error: unknown) => {\n if (isMounted()) {\n setErrorState(error);\n setStatus(PromiseStatus.ERROR);\n setResult(undefined);\n options?.onError?.(error);\n }\n },\n [isMounted, options],\n );\n\n const setIdleFn = useCallback(() => {\n if (isMounted()) {\n setStatus(PromiseStatus.IDLE);\n setErrorState(undefined);\n setResult(undefined);\n }\n }, [isMounted]);\n\n return {\n status,\n loading: status === PromiseStatus.LOADING,\n result,\n error,\n setLoading: setLoadingFn,\n setSuccess: setSuccessFn,\n setError: setErrorFn,\n setIdle: setIdleFn,\n };\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useCallback } from 'react';\nimport { useMountedState } from 'react-use';\nimport { usePromiseState, PromiseState } from './usePromiseState';\n\n/**\n * Type definition for a function that returns a Promise\n * @template R - The type of value the promise will resolve to\n */\nexport type PromiseSupplier<R> = () => Promise<R>;\n\n/**\n * Interface defining the return type of useExecutePromise hook\n * @template R - The type of the result value\n */\nexport interface UseExecutePromiseReturn<R> extends PromiseState<R> {\n /** Function to execute a promise supplier or promise */\n execute: (input: PromiseSupplier<R> | Promise<R>) => Promise<R>;\n /** Function to reset the state to initial values */\n reset: () => void;\n}\n\n/**\n * A React hook for managing asynchronous operations with proper state handling\n * @template R - The type of the result value\n * @returns An object containing the current state and control functions\n *\n * @example\n * ```typescript\n * import { useExecutePromise } from '@ahoo-wang/fetcher-react';\n *\n * function MyComponent() {\n * const { loading, result, error, execute, reset } = useExecutePromise<string>();\n *\n * const fetchData = async () => {\n * const response = await fetch('/api/data');\n * return response.text();\n * };\n *\n * const handleFetch = () => {\n * execute(fetchData);\n * };\n *\n * const handleReset = () => {\n * reset();\n * };\n *\n * if (loading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error.message}</div>;\n * return (\n * <div>\n * <button onClick={handleFetch}>Fetch Data</button>\n * <button onClick={handleReset}>Reset</button>\n * {result && <p>{result}</p>}\n * </div>\n * );\n * }\n * ```\n */\nexport function useExecutePromise<R = unknown>(): UseExecutePromiseReturn<R> {\n const state = usePromiseState<R>();\n const isMounted = useMountedState();\n\n /**\n * Execute a promise supplier or promise and manage its state\n * @param input - A function that returns a Promise or a Promise to be executed\n * @returns A Promise that resolves with the result of the executed promise\n */\n const execute = useCallback(\n async (input: PromiseSupplier<R> | Promise<R>): Promise<R> => {\n if (!isMounted()) {\n throw new Error('Component is unmounted');\n }\n state.setLoading();\n try {\n const promise = typeof input === 'function' ? input() : input;\n const data = await promise;\n\n if (isMounted()) {\n state.setSuccess(data);\n }\n return data;\n } catch (err) {\n if (isMounted()) {\n state.setError(err);\n }\n throw err;\n }\n },\n [state, isMounted],\n );\n\n /**\n * Reset the state to initial values\n */\n const reset = useCallback(() => {\n if (isMounted()) {\n state.setIdle();\n }\n }, [state, isMounted]);\n\n return {\n loading: state.loading,\n result: state.result,\n error: state.error,\n execute,\n reset,\n status: state.status,\n };\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useCallback, useSyncExternalStore } from 'react';\nimport { KeyStorage } from '@ahoo-wang/fetcher-storage';\n\n/**\n * A React hook that provides state management for a KeyStorage instance.\n * Subscribes to storage changes and returns the current value along with a setter function.\n *\n * @template T - The type of value stored in the key storage\n * @param keyStorage - The KeyStorage instance to subscribe to and manage\n * @returns A tuple containing the current stored value and a function to update it\n */\nexport function useKeyStorage<T>(\n keyStorage: KeyStorage<T>,\n): [T | null, (value: T) => void] {\n const subscribe = useCallback(\n (callback: () => void) => keyStorage.addListener(callback),\n [keyStorage],\n );\n const getSnapshot = useCallback(() => keyStorage.get(), [keyStorage]);\n const value = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n const setValue = useCallback(\n (value: T) => keyStorage.set(value),\n [keyStorage],\n );\n return [value, setValue];\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n fetcher as defaultFetcher,\n FetcherCapable,\n FetchExchange,\n FetchRequest,\n getFetcher,\n RequestOptions,\n} from '@ahoo-wang/fetcher';\nimport { useRef, useCallback, useEffect, useState } from 'react';\nimport { useMountedState } from 'react-use';\nimport {\n PromiseState,\n usePromiseState,\n} from '../core';\n\n/**\n * Configuration options for the useFetcher hook.\n * Extends RequestOptions and FetcherCapable interfaces.\n */\nexport interface UseFetcherOptions extends RequestOptions, FetcherCapable {\n}\n\nexport interface UseFetcherReturn<R> extends PromiseState<R> {\n /** The FetchExchange object representing the ongoing fetch operation */\n exchange?: FetchExchange;\n execute: (request: FetchRequest) => Promise<void>;\n}\n\n/**\n * A React hook for managing asynchronous operations with proper state handling\n * @param options - Configuration options for the fetcher\n * @returns An object containing the current state and control functions\n *\n * @example\n * ```typescript\n * import { useFetcher } from '@ahoo-wang/fetcher-react';\n *\n * function MyComponent() {\n * const { loading, result, error, execute } = useFetcher<string>();\n *\n * const handleFetch = () => {\n * execute({ url: '/api/data', method: 'GET' });\n * };\n *\n * if (loading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error.message}</div>;\n * return (\n * <div>\n * <button onClick={handleFetch}>Fetch Data</button>\n * {result && <p>{result}</p>}\n * </div>\n * );\n * }\n * ```\n */\nexport function useFetcher<R>(\n options?: UseFetcherOptions,\n): UseFetcherReturn<R> {\n const { fetcher = defaultFetcher } = options || {};\n const state = usePromiseState<R>();\n const [exchange, setExchange] = useState<FetchExchange | undefined>(\n undefined,\n );\n const isMounted = useMountedState();\n const abortControllerRef = useRef<AbortController | undefined>();\n\n const currentFetcher = getFetcher(fetcher);\n /**\n * Execute the fetch operation.\n * Cancels any ongoing fetch before starting a new one.\n */\n const execute = useCallback(\n async (request: FetchRequest) => {\n if (abortControllerRef.current) {\n abortControllerRef.current.abort();\n }\n abortControllerRef.current =\n request.abortController ?? new AbortController();\n request.abortController = abortControllerRef.current;\n state.setLoading();\n try {\n const exchange = await currentFetcher.exchange(request, options);\n if (isMounted()) {\n setExchange(exchange);\n }\n const result = await exchange.extractResult<R>();\n if (isMounted()) {\n state.setSuccess(result);\n }\n } catch (error) {\n if (error instanceof Error && error.name === 'AbortError') {\n if (isMounted()) {\n state.setIdle();\n }\n return;\n }\n if (isMounted()) {\n state.setError(error);\n }\n } finally {\n if (abortControllerRef.current === request.abortController) {\n abortControllerRef.current = undefined;\n }\n }\n },\n [currentFetcher, isMounted, options, state],\n );\n\n useEffect(() => {\n return () => {\n abortControllerRef.current?.abort();\n abortControllerRef.current = undefined;\n };\n }, []);\n return {\n ...state,\n exchange,\n execute,\n };\n}\n"],"names":["useMountedState","mountedRef","useRef","get","useCallback","useEffect","PromiseStatus","usePromiseState","options","status","setStatus","useState","result","setResult","error","setErrorState","isMounted","setLoadingFn","setSuccessFn","setErrorFn","setIdleFn","useExecutePromise","state","execute","input","data","err","reset","useKeyStorage","keyStorage","subscribe","callback","getSnapshot","value","useSyncExternalStore","setValue","useFetcher","fetcher","defaultFetcher","exchange","setExchange","abortControllerRef","currentFetcher","getFetcher","request"],"mappings":"uUACe,SAASA,GAAkB,CACtC,IAAIC,EAAaC,EAAAA,OAAO,EAAK,EACzBC,EAAMC,EAAAA,YAAY,UAAY,CAAE,OAAOH,EAAW,OAAS,EAAG,EAAE,EACpEI,OAAAA,EAAAA,UAAU,UAAY,CAClB,OAAAJ,EAAW,QAAU,GACd,UAAY,CACfA,EAAW,QAAU,EACzB,CACJ,EAAG,CAAA,CAAE,EACEE,CACX,CCQO,IAAKG,GAAAA,IACVA,EAAA,KAAO,OACPA,EAAA,QAAU,UACVA,EAAA,QAAU,UACVA,EAAA,MAAQ,QAJEA,IAAAA,GAAA,CAAA,CAAA,EAqFL,SAASC,EACdC,EAC0B,CAC1B,KAAM,CAACC,EAAQC,CAAS,EAAIC,EAAAA,SAC1BH,GAAS,eAAiB,MAAA,EAEtB,CAACI,EAAQC,CAAS,EAAIF,EAAAA,SAAwB,MAAS,EACvD,CAACG,EAAOC,CAAa,EAAIJ,EAAAA,SAA8B,MAAS,EAChEK,EAAYhB,EAAA,EAEZiB,EAAeb,EAAAA,YAAY,IAAM,CACjCY,MACFN,EAAU,SAAA,EACVK,EAAc,MAAS,EAE3B,EAAG,CAACC,CAAS,CAAC,EAERE,EAAed,EAAAA,YAClBQ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,MAC/B,EACC,CAAA,CAAE,EACE,CACL,GAAGnB,EACH,SAAAiB,EACA,QAAAhB,CAAA,CAEJ","x_google_ignoreList":[0]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ahoo-wang/fetcher-react",
3
- "version": "2.5.6",
3
+ "version": "2.5.8",
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",