@cripty2001/utils 0.0.255 → 0.0.257
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/Dispatcher.d.ts +12 -1
- package/dist/Dispatcher.js +28 -8
- package/dist/react-whispr.js +9 -16
- package/package.json +1 -1
package/dist/Dispatcher.d.ts
CHANGED
|
@@ -26,16 +26,27 @@ export declare class Dispatcher<I, O> {
|
|
|
26
26
|
private value;
|
|
27
27
|
private lastValue;
|
|
28
28
|
/**
|
|
29
|
+
* @deprecated Use static constructor instead
|
|
30
|
+
*/
|
|
31
|
+
constructor(value: Whispr<I>, f: DispatcherFunction<I, O>, DEBOUNCE_INTERVAL?: number);
|
|
32
|
+
/**
|
|
33
|
+
* @deprecated Use static constructor instead
|
|
29
34
|
* Create a new dispatcher
|
|
30
35
|
* @param value The whispr value that will trigger f call when changed. Using this pattern instead of exposing a dispatch method allow to return the full dispatcher to anyone, without having to worry about them messing it
|
|
31
36
|
* @param f The async function to call. It should return a promise that resolves to the data.
|
|
32
37
|
* @param DEBOUNCE_INTERVAL The debounce interval in milliseconds. Default to 200ms. The function will not be called if this time has not passed since the last call. If another change happens during the wait, the first function call will be aborted.
|
|
33
38
|
*
|
|
39
|
+
* @returns A tuple containing the dispatcher and a function to refresh it
|
|
40
|
+
*
|
|
34
41
|
* @remarks If the debounce interval is 0, the function will be called synchronously, as a Whispr listener would do.
|
|
35
42
|
* @remarks The value is deep checked for equality. The function will be called only if the value changed deeply
|
|
36
43
|
* @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
44
|
*/
|
|
38
|
-
|
|
45
|
+
static create<I, O>(value: Whispr<I>, f: DispatcherFunction<I, O>, DEBOUNCE_INTERVAL?: number): [Dispatcher<I, O>, () => Promise<void>];
|
|
46
|
+
/**
|
|
47
|
+
* Re-execute the dispatcher, ignoring both the debounce interval and the input deduplication
|
|
48
|
+
*/
|
|
49
|
+
refresh(): void;
|
|
39
50
|
private reset;
|
|
40
51
|
private dispatch;
|
|
41
52
|
}
|
package/dist/Dispatcher.js
CHANGED
|
@@ -14,14 +14,7 @@ class Dispatcher {
|
|
|
14
14
|
value; // Value is a whispr that we are subscribed to. We must keep a reference to it to avoid the subscription being automatically canceled
|
|
15
15
|
lastValue = null; // Last value, to avoid useless dispatches
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
18
|
-
* @param value The whispr value that will trigger f call when changed. Using this pattern instead of exposing a dispatch method allow to return the full dispatcher to anyone, without having to worry about them messing it
|
|
19
|
-
* @param f The async function to call. It should return a promise that resolves to the data.
|
|
20
|
-
* @param DEBOUNCE_INTERVAL The debounce interval in milliseconds. Default to 200ms. The function will not be called if this time has not passed since the last call. If another change happens during the wait, the first function call will be aborted.
|
|
21
|
-
*
|
|
22
|
-
* @remarks If the debounce interval is 0, the function will be called synchronously, as a Whispr listener would do.
|
|
23
|
-
* @remarks The value is deep checked for equality. The function will be called only if the value changed deeply
|
|
24
|
-
* @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
|
|
17
|
+
* @deprecated Use static constructor instead
|
|
25
18
|
*/
|
|
26
19
|
constructor(value, f, DEBOUNCE_INTERVAL = 200) {
|
|
27
20
|
// Initing state
|
|
@@ -58,6 +51,33 @@ class Dispatcher {
|
|
|
58
51
|
return response.data;
|
|
59
52
|
});
|
|
60
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* @deprecated Use static constructor instead
|
|
56
|
+
* Create a new dispatcher
|
|
57
|
+
* @param value The whispr value that will trigger f call when changed. Using this pattern instead of exposing a dispatch method allow to return the full dispatcher to anyone, without having to worry about them messing it
|
|
58
|
+
* @param f The async function to call. It should return a promise that resolves to the data.
|
|
59
|
+
* @param DEBOUNCE_INTERVAL The debounce interval in milliseconds. Default to 200ms. The function will not be called if this time has not passed since the last call. If another change happens during the wait, the first function call will be aborted.
|
|
60
|
+
*
|
|
61
|
+
* @returns A tuple containing the dispatcher and a function to refresh it
|
|
62
|
+
*
|
|
63
|
+
* @remarks If the debounce interval is 0, the function will be called synchronously, as a Whispr listener would do.
|
|
64
|
+
* @remarks The value is deep checked for equality. The function will be called only if the value changed deeply
|
|
65
|
+
* @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
|
|
66
|
+
*/
|
|
67
|
+
static create(value, f, DEBOUNCE_INTERVAL = 200) {
|
|
68
|
+
const d = new Dispatcher(value, f, DEBOUNCE_INTERVAL);
|
|
69
|
+
const refresh = async () => {
|
|
70
|
+
d.refresh();
|
|
71
|
+
await d.data.wait(d => d.output.loading === false);
|
|
72
|
+
};
|
|
73
|
+
return [d, refresh];
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Re-execute the dispatcher, ignoring both the debounce interval and the input deduplication
|
|
77
|
+
*/
|
|
78
|
+
refresh() {
|
|
79
|
+
this.dispatch(this.value.value);
|
|
80
|
+
}
|
|
61
81
|
reset() {
|
|
62
82
|
// Aborting previous request
|
|
63
83
|
this.state.value.controller.abort();
|
package/dist/react-whispr.js
CHANGED
|
@@ -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(
|
|
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
|
-
|
|
260
|
+
dispatcher.refresh();
|
|
268
261
|
}
|
|
269
262
|
];
|
|
270
263
|
}
|
package/package.json
CHANGED