@cripty2001/utils 0.0.255 → 0.0.256

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.
@@ -36,6 +36,10 @@ export declare class Dispatcher<I, O> {
36
36
  * @remarks Data updating flag is set in a synchronous way. This means that in the event your DEBOUNCE_INTERVAL is near infinity, you still get the data set to updating true immediately when you update the value. It just wait like this forever
37
37
  */
38
38
  constructor(value: Whispr<I>, f: DispatcherFunction<I, O>, DEBOUNCE_INTERVAL?: number);
39
+ /**
40
+ * Re-execute the dispatcher, ignoring both the debounce interval and the input deduplication
41
+ */
42
+ refresh(): void;
39
43
  private reset;
40
44
  private dispatch;
41
45
  }
@@ -58,6 +58,12 @@ class Dispatcher {
58
58
  return response.data;
59
59
  });
60
60
  }
61
+ /**
62
+ * Re-execute the dispatcher, ignoring both the debounce interval and the input deduplication
63
+ */
64
+ refresh() {
65
+ this.dispatch(this.value.value);
66
+ }
61
67
  reset() {
62
68
  // Aborting previous request
63
69
  this.state.value.controller.abort();
@@ -244,27 +244,20 @@ function useAsync(data, debouce, interval, f) {
244
244
  setInput(data); // Debouncing already handled by dispatcher
245
245
  }
246
246
  }, [data, setInput]);
247
- // Initing refresh bundle
248
- const timer = useSafeRef(() => interval !== null ?
249
- (0, _1.getClock)(interval) :
250
- whispr_1.Whispr.create(0)[0]);
251
- const [refresh, setRefresh] = useSafeRef(() => whispr_1.Whispr.create(Math.random()));
252
- const bundle = useSafeRef(() => whispr_1.Whispr.from({
253
- input,
254
- timer,
255
- refresh
256
- }, ({ input, timer, refresh }) => ({
257
- data: input,
258
- timer,
259
- refresh
260
- })));
261
247
  // Initing dispatcher
262
- const dispatcher = useSafeRef(() => new Dispatcher_1.Dispatcher(bundle, (i, p, s) => f(i.data, p, s), debouce));
248
+ const dispatcher = useSafeRef(() => new Dispatcher_1.Dispatcher(input, (i, p, s) => f(i, p, s), debouce));
249
+ // Starting refresher
250
+ const clock = useClock(interval ?
251
+ interval :
252
+ Number.MAX_SAFE_INTEGER);
253
+ (0, react_1.useEffect)(() => {
254
+ dispatcher.refresh();
255
+ }, [clock, dispatcher]);
263
256
  // Returning dispatcher and refresh function
264
257
  return [
265
258
  dispatcher,
266
259
  () => {
267
- setRefresh(Math.random());
260
+ dispatcher.refresh();
268
261
  }
269
262
  ];
270
263
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cripty2001/utils",
3
- "version": "0.0.255",
3
+ "version": "0.0.256",
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": {