@cripty2001/utils 0.0.249 → 0.0.251

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.
@@ -95,9 +95,9 @@ export declare function useAsync<I, O>(f: (input: I, setProgress: (p: number) =>
95
95
  * @param interval The interval to re-execute the async function. If null, the async function will not be re-executed.
96
96
  * @param f @see useAsync
97
97
  *
98
- * @returns @see useAsync
98
+ * @returns [@see useAsync, A function to trigger a manual refresh]
99
99
  */
100
- export declare function useAsyncPeriodic<I, O>(data: I, interval: number, f: (input: I, setProgress: (p: number) => void, signal: AbortSignal) => Promise<O>): Dispatcher<any, O>;
100
+ export declare function useAsyncPeriodic<I, O>(data: I, interval: number, f: (input: I, setProgress: (p: number) => void, signal: AbortSignal) => Promise<O>): [Dispatcher<any, O>, () => void];
101
101
  /**
102
102
  * Async version of useEffect with debouncing. Executes an async function as a side effect when data changes.
103
103
  *
@@ -204,17 +204,25 @@ function useAsync(f, data, debouce = 200) {
204
204
  * @param interval The interval to re-execute the async function. If null, the async function will not be re-executed.
205
205
  * @param f @see useAsync
206
206
  *
207
- * @returns @see useAsync
207
+ * @returns [@see useAsync, A function to trigger a manual refresh]
208
208
  */
209
209
  function useAsyncPeriodic(data, interval, f) {
210
210
  const timer = useClock(interval);
211
+ const [refresh, setRefresh] = (0, react_1.useState)(Math.random());
211
212
  const bundle = (0, react_1.useMemo)(() => {
212
213
  return {
213
214
  data,
214
- timer
215
+ timer,
216
+ refresh
215
217
  };
216
- }, [data, timer]);
217
- return useAsync((i, p, s) => f(i.data, p, s), bundle);
218
+ }, [data, timer, refresh]);
219
+ const dispatcher = useSafeRef(() => useAsync((i, p, s) => f(i.data, p, s), bundle));
220
+ return [
221
+ dispatcher,
222
+ () => {
223
+ setRefresh(Math.random());
224
+ }
225
+ ];
218
226
  }
219
227
  /**
220
228
  * Async version of useEffect with debouncing. Executes an async function as a side effect when data changes.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cripty2001/utils",
3
- "version": "0.0.249",
3
+ "version": "0.0.251",
4
4
  "description": "Internal Set of utils. If you need them use them, otherwise go to the next package ;)",
5
5
  "homepage": "https://github.com/cripty2001/utils#readme",
6
6
  "bugs": {