@cripty2001/utils 0.0.256 → 0.0.258
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 +8 -1
- package/dist/Dispatcher.js +22 -8
- package/package.json +1 -1
package/dist/Dispatcher.d.ts
CHANGED
|
@@ -25,18 +25,25 @@ export declare class Dispatcher<I, O> {
|
|
|
25
25
|
private readonly f;
|
|
26
26
|
private value;
|
|
27
27
|
private lastValue;
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated Use static constructor instead
|
|
30
|
+
*/
|
|
31
|
+
constructor(value: Whispr<I>, f: DispatcherFunction<I, O>, DEBOUNCE_INTERVAL?: number);
|
|
28
32
|
/**
|
|
29
33
|
* Create a new dispatcher
|
|
30
34
|
* @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
35
|
* @param f The async function to call. It should return a promise that resolves to the data.
|
|
32
36
|
* @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
37
|
*
|
|
38
|
+
* @returns A tuple containing the dispatcher and a function to refresh it
|
|
39
|
+
*
|
|
34
40
|
* @remarks If the debounce interval is 0, the function will be called synchronously, as a Whispr listener would do.
|
|
35
41
|
* @remarks The value is deep checked for equality. The function will be called only if the value changed deeply
|
|
36
42
|
* @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
43
|
*/
|
|
38
|
-
|
|
44
|
+
static create<I, O>(value: Whispr<I>, f: DispatcherFunction<I, O>, DEBOUNCE_INTERVAL?: number): [Dispatcher<I, O>, () => Promise<void>];
|
|
39
45
|
/**
|
|
46
|
+
* @deprecated Use static constructor instead
|
|
40
47
|
* Re-execute the dispatcher, ignoring both the debounce interval and the input deduplication
|
|
41
48
|
*/
|
|
42
49
|
refresh(): void;
|
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
|
|
@@ -59,6 +52,27 @@ class Dispatcher {
|
|
|
59
52
|
});
|
|
60
53
|
}
|
|
61
54
|
/**
|
|
55
|
+
* Create a new dispatcher
|
|
56
|
+
* @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
|
|
57
|
+
* @param f The async function to call. It should return a promise that resolves to the data.
|
|
58
|
+
* @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.
|
|
59
|
+
*
|
|
60
|
+
* @returns A tuple containing the dispatcher and a function to refresh it
|
|
61
|
+
*
|
|
62
|
+
* @remarks If the debounce interval is 0, the function will be called synchronously, as a Whispr listener would do.
|
|
63
|
+
* @remarks The value is deep checked for equality. The function will be called only if the value changed deeply
|
|
64
|
+
* @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
|
|
65
|
+
*/
|
|
66
|
+
static create(value, f, DEBOUNCE_INTERVAL = 200) {
|
|
67
|
+
const d = new Dispatcher(value, f, DEBOUNCE_INTERVAL);
|
|
68
|
+
const refresh = async () => {
|
|
69
|
+
d.refresh();
|
|
70
|
+
await d.data.wait(d => d.output.loading === false);
|
|
71
|
+
};
|
|
72
|
+
return [d, refresh];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* @deprecated Use static constructor instead
|
|
62
76
|
* Re-execute the dispatcher, ignoring both the debounce interval and the input deduplication
|
|
63
77
|
*/
|
|
64
78
|
refresh() {
|
package/package.json
CHANGED