@cripty2001/utils 0.0.245 → 0.0.246
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/dist/react-whispr.d.ts +13 -2
- package/dist/react-whispr.js +22 -1
- package/package.json +1 -1
package/dist/react-whispr.d.ts
CHANGED
|
@@ -66,7 +66,7 @@ export declare function useSynced<T extends any>(def: T, value: T | undefined, s
|
|
|
66
66
|
*
|
|
67
67
|
* @param f The async function to call. It should return a promise that resolves to the data. It is not reactive.
|
|
68
68
|
* @param data The data to give to f. It must be stable, as anything in the dependency array of the useEffect and similars in the react ecosystem. If null, this function will act like an useEffect with an empty dependency array.
|
|
69
|
-
* @param debouce Debounce time in ms. Default to 200ms. The async function will not be called if this time has not passed since the useAsync first invocation or value change. If another change happens during the wait, the first function call is never executed.
|
|
69
|
+
* @param debouce Debounce time in ms. Default to 200ms. The async function will not be called if this time has not passed since the useAsync first invocation or value change. If another change happens during the wait, the first function call is never executed. Not reactive
|
|
70
70
|
* @returns A Dispatcher object containing:
|
|
71
71
|
* - `data`: A Whispr<DispatcherStatePayload<O>> that contains the loading state, progress, and either the result data or error
|
|
72
72
|
* - `filtered`: A Whispr<O | null> that contains the result data when successful, or null when loading or on error
|
|
@@ -87,7 +87,18 @@ export declare function useSynced<T extends any>(def: T, value: T | undefined, s
|
|
|
87
87
|
* console.error('Error:', state.error);
|
|
88
88
|
* }
|
|
89
89
|
*/
|
|
90
|
-
export declare function useAsync<I, O>(f: (input: I, setProgress: (p: number) => void, signal: AbortSignal) => Promise<O>, data: I, debouce?: number): Dispatcher<
|
|
90
|
+
export declare function useAsync<I, O>(f: (input: I, setProgress: (p: number) => void, signal: AbortSignal) => Promise<O>, data: I, debouce?: number): Dispatcher<any, O>;
|
|
91
|
+
/**
|
|
92
|
+
* Like useAsync, but it also automatically re-execute the async function periodically
|
|
93
|
+
*
|
|
94
|
+
* @param f @see useAsync
|
|
95
|
+
* @param data @see useAsync
|
|
96
|
+
* @param interval The interval to re-execute the async function. If null, the async function will not be re-executed.
|
|
97
|
+
* @param debounce @see useAsync
|
|
98
|
+
*
|
|
99
|
+
* @returns @see useAsync
|
|
100
|
+
*/
|
|
101
|
+
export declare function useAsyncPeriodic<I, O>(f: (input: I, setProgress: (p: number) => void, signal: AbortSignal) => Promise<O>, data: I, interval: number, debounce?: number): Dispatcher<any, O>;
|
|
91
102
|
/**
|
|
92
103
|
* Async version of useEffect with debouncing. Executes an async function as a side effect when data changes.
|
|
93
104
|
*
|
package/dist/react-whispr.js
CHANGED
|
@@ -8,6 +8,7 @@ exports.useClock = useClock;
|
|
|
8
8
|
exports.useDebounced = useDebounced;
|
|
9
9
|
exports.useSynced = useSynced;
|
|
10
10
|
exports.useAsync = useAsync;
|
|
11
|
+
exports.useAsyncPeriodic = useAsyncPeriodic;
|
|
11
12
|
exports.useAsyncEffect = useAsyncEffect;
|
|
12
13
|
exports.useRelTime = useRelTime;
|
|
13
14
|
exports.useSearcher = useSearcher;
|
|
@@ -162,7 +163,7 @@ function useSynced(def, value, setValue) {
|
|
|
162
163
|
*
|
|
163
164
|
* @param f The async function to call. It should return a promise that resolves to the data. It is not reactive.
|
|
164
165
|
* @param data The data to give to f. It must be stable, as anything in the dependency array of the useEffect and similars in the react ecosystem. If null, this function will act like an useEffect with an empty dependency array.
|
|
165
|
-
* @param debouce Debounce time in ms. Default to 200ms. The async function will not be called if this time has not passed since the useAsync first invocation or value change. If another change happens during the wait, the first function call is never executed.
|
|
166
|
+
* @param debouce Debounce time in ms. Default to 200ms. The async function will not be called if this time has not passed since the useAsync first invocation or value change. If another change happens during the wait, the first function call is never executed. Not reactive
|
|
166
167
|
* @returns A Dispatcher object containing:
|
|
167
168
|
* - `data`: A Whispr<DispatcherStatePayload<O>> that contains the loading state, progress, and either the result data or error
|
|
168
169
|
* - `filtered`: A Whispr<O | null> that contains the result data when successful, or null when loading or on error
|
|
@@ -196,6 +197,26 @@ function useAsync(f, data, debouce = 200) {
|
|
|
196
197
|
// Returning dispatcher
|
|
197
198
|
return dispatcher;
|
|
198
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* Like useAsync, but it also automatically re-execute the async function periodically
|
|
202
|
+
*
|
|
203
|
+
* @param f @see useAsync
|
|
204
|
+
* @param data @see useAsync
|
|
205
|
+
* @param interval The interval to re-execute the async function. If null, the async function will not be re-executed.
|
|
206
|
+
* @param debounce @see useAsync
|
|
207
|
+
*
|
|
208
|
+
* @returns @see useAsync
|
|
209
|
+
*/
|
|
210
|
+
function useAsyncPeriodic(f, data, interval, debounce) {
|
|
211
|
+
const timer = useClock(interval);
|
|
212
|
+
const bundle = (0, react_1.useMemo)(() => {
|
|
213
|
+
return {
|
|
214
|
+
data,
|
|
215
|
+
interval
|
|
216
|
+
};
|
|
217
|
+
}, [data, timer, debounce]);
|
|
218
|
+
return useAsync((i, p, s) => f(i.data, p, s), bundle, debounce);
|
|
219
|
+
}
|
|
199
220
|
/**
|
|
200
221
|
* Async version of useEffect with debouncing. Executes an async function as a side effect when data changes.
|
|
201
222
|
*
|
package/package.json
CHANGED