@ahoo-wang/fetcher-react 2.6.6 → 2.6.9

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.
@@ -1,4 +1,12 @@
1
1
  import { PromiseState, UsePromiseStateOptions } from './usePromiseState';
2
+ export interface UseExecutePromiseOptions<R, E = unknown> extends UsePromiseStateOptions<R, E> {
3
+ /**
4
+ * Whether to propagate errors thrown by the promise.
5
+ * If true, the execute function will throw errors.
6
+ * If false (default), the execute function will return the error as the result instead of throwing.
7
+ */
8
+ propagateError?: boolean;
9
+ }
2
10
  /**
3
11
  * Type definition for a function that returns a Promise
4
12
  * @template R - The type of value the promise will resolve to
@@ -9,14 +17,19 @@ export type PromiseSupplier<R> = () => Promise<R>;
9
17
  * @template R - The type of the result value
10
18
  */
11
19
  export interface UseExecutePromiseReturn<R, E = unknown> extends PromiseState<R, E> {
12
- /** Function to execute a promise supplier or promise */
13
- execute: (input: PromiseSupplier<R> | Promise<R>) => Promise<R>;
20
+ /**
21
+ * Function to execute a promise supplier or promise.
22
+ * Returns a promise that resolves to the result on success, or the error if propagateError is false.
23
+ */
24
+ execute: (input: PromiseSupplier<R> | Promise<R>) => Promise<R | E>;
14
25
  /** Function to reset the state to initial values */
15
26
  reset: () => void;
16
27
  }
17
28
  /**
18
29
  * A React hook for managing asynchronous operations with proper state handling
19
30
  * @template R - The type of the result value
31
+ * @template E - The type of the error value
32
+ * @param options - Configuration options for the hook
20
33
  * @returns An object containing the current state and control functions
21
34
  *
22
35
  * @example
@@ -49,7 +62,15 @@ export interface UseExecutePromiseReturn<R, E = unknown> extends PromiseState<R,
49
62
  * </div>
50
63
  * );
51
64
  * }
65
+ *
66
+ * // Example with propagateError set to true
67
+ * const { execute } = useExecutePromise<string>({ propagateError: true });
68
+ * try {
69
+ * await execute(fetchData);
70
+ * } catch (err) {
71
+ * console.error('Error occurred:', err);
72
+ * }
52
73
  * ```
53
74
  */
54
- export declare function useExecutePromise<R = unknown, E = unknown>(options?: UsePromiseStateOptions<R, E>): UseExecutePromiseReturn<R, E>;
75
+ export declare function useExecutePromise<R = unknown, E = unknown>(options?: UseExecutePromiseOptions<R, E>): UseExecutePromiseReturn<R, E>;
55
76
  //# sourceMappingURL=useExecutePromise.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useExecutePromise.d.ts","sourceRoot":"","sources":["../../src/core/useExecutePromise.ts"],"names":[],"mappings":"AAeA,OAAO,EAEL,YAAY,EACZ,sBAAsB,EACvB,MAAM,mBAAmB,CAAC;AAG3B;;;GAGG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC;AAElD;;;GAGG;AACH,MAAM,WAAW,uBAAuB,CAAC,CAAC,EAAE,CAAC,GAAG,OAAO,CACrD,SAAQ,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC;IAC1B,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,EAAE,CAAC,GAAG,OAAO,EACxD,OAAO,CAAC,EAAE,sBAAsB,CAAC,CAAC,EAAE,CAAC,CAAC,GACrC,uBAAuB,CAAC,CAAC,EAAE,CAAC,CAAC,CAuD/B"}
1
+ {"version":3,"file":"useExecutePromise.d.ts","sourceRoot":"","sources":["../../src/core/useExecutePromise.ts"],"names":[],"mappings":"AAeA,OAAO,EAEL,YAAY,EACZ,sBAAsB,EACvB,MAAM,mBAAmB,CAAC;AAG3B,MAAM,WAAW,wBAAwB,CAAC,CAAC,EAAE,CAAC,GAAG,OAAO,CACtD,SAAQ,sBAAsB,CAAC,CAAC,EAAE,CAAC,CAAC;IACpC;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;GAGG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC;AAElD;;;GAGG;AACH,MAAM,WAAW,uBAAuB,CAAC,CAAC,EAAE,CAAC,GAAG,OAAO,CACrD,SAAQ,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC;IAC1B;;;OAGG;IACH,OAAO,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACpE,oDAAoD;IACpD,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,EACxD,OAAO,CAAC,EAAE,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAAC,GACvC,uBAAuB,CAAC,CAAC,EAAE,CAAC,CAAC,CA0D/B"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './core';
2
2
  export * from './storage';
3
3
  export * from './fetcher';
4
+ export * from './wow';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,OAAO,CAAC"}