@cripty2001/utils 0.0.256 → 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.
@@ -26,16 +26,23 @@ 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
- constructor(value: Whispr<I>, f: DispatcherFunction<I, O>, DEBOUNCE_INTERVAL?: number);
45
+ static create<I, O>(value: Whispr<I>, f: DispatcherFunction<I, O>, DEBOUNCE_INTERVAL?: number): [Dispatcher<I, O>, () => Promise<void>];
39
46
  /**
40
47
  * Re-execute the dispatcher, ignoring both the debounce interval and the input deduplication
41
48
  */
@@ -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
- * Create a new dispatcher
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,27 @@ 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
+ }
61
75
  /**
62
76
  * Re-execute the dispatcher, ignoring both the debounce interval and the input deduplication
63
77
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cripty2001/utils",
3
- "version": "0.0.256",
3
+ "version": "0.0.257",
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": {