@cripty2001/utils 0.0.14 → 0.0.16
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/react-whispr.d.ts +14 -0
- package/dist/react-whispr.js +25 -0
- package/package.json +4 -4
package/dist/react-whispr.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Whispr } from "@cripty2001/whispr";
|
|
2
|
+
import { Dispatcher } from "./Dispatcher";
|
|
2
3
|
/**
|
|
3
4
|
* Convert a Whispr value into a reactive react value, usable in function components with the standard react reactive system.
|
|
4
5
|
* If the value is not a Whispr, it is returned as is, thus allowing for progressive migration and adoption
|
|
@@ -26,3 +27,16 @@ export declare function useWhisprValue<I, O = I>(w: Whispr<I>, computer?: (data:
|
|
|
26
27
|
export declare function useWhispr<T>(data: T | Whispr<T>): Whispr<T>;
|
|
27
28
|
export declare function useCurrentTimestamp(): number;
|
|
28
29
|
export declare function useDebounced<T>(value: T): T;
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* Wraps an async function into a reactable data.
|
|
33
|
+
*
|
|
34
|
+
* @param f The async function to call. It should return a promise that resolves to the data. It is not reactive
|
|
35
|
+
* @param data The data to give to f. It must be stable, as anything in the dependency array of the useEffect and similars in the react ecosystem.
|
|
36
|
+
* @param debouce Debounce time in ms. Default to 200ms. The async function will not be called if this time has not passed since the useAsync first invocation or value change. If another change happens during the wait, the first function call is never executed
|
|
37
|
+
* @returns The dispatcher
|
|
38
|
+
*
|
|
39
|
+
* @type I Input for the async function.
|
|
40
|
+
* @type O Output for the async function
|
|
41
|
+
*/
|
|
42
|
+
export declare function useAsync<I, O>(f: (input: I, setProgress: (p: number) => void, signal: AbortSignal) => Promise<O>, data: I, debouce?: number): Dispatcher<I, O>;
|
package/dist/react-whispr.js
CHANGED
|
@@ -4,9 +4,11 @@ exports.useWhisprValue = useWhisprValue;
|
|
|
4
4
|
exports.useWhispr = useWhispr;
|
|
5
5
|
exports.useCurrentTimestamp = useCurrentTimestamp;
|
|
6
6
|
exports.useDebounced = useDebounced;
|
|
7
|
+
exports.useAsync = useAsync;
|
|
7
8
|
const whispr_1 = require("@cripty2001/whispr");
|
|
8
9
|
const react_1 = require("react");
|
|
9
10
|
const lodash_1 = require("lodash");
|
|
11
|
+
const Dispatcher_1 = require("./Dispatcher");
|
|
10
12
|
/**
|
|
11
13
|
* Convert a Whispr value into a reactive react value, usable in function components with the standard react reactive system.
|
|
12
14
|
* If the value is not a Whispr, it is returned as is, thus allowing for progressive migration and adoption
|
|
@@ -71,3 +73,26 @@ function useDebounced(value) {
|
|
|
71
73
|
}, [value]);
|
|
72
74
|
return debounced;
|
|
73
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
*
|
|
78
|
+
* Wraps an async function into a reactable data.
|
|
79
|
+
*
|
|
80
|
+
* @param f The async function to call. It should return a promise that resolves to the data. It is not reactive
|
|
81
|
+
* @param data The data to give to f. It must be stable, as anything in the dependency array of the useEffect and similars in the react ecosystem.
|
|
82
|
+
* @param debouce Debounce time in ms. Default to 200ms. The async function will not be called if this time has not passed since the useAsync first invocation or value change. If another change happens during the wait, the first function call is never executed
|
|
83
|
+
* @returns The dispatcher
|
|
84
|
+
*
|
|
85
|
+
* @type I Input for the async function.
|
|
86
|
+
* @type O Output for the async function
|
|
87
|
+
*/
|
|
88
|
+
function useAsync(f, data, debouce = 200) {
|
|
89
|
+
// Initing reactive input
|
|
90
|
+
const [input, setInput] = whispr_1.Whispr.create(data);
|
|
91
|
+
(0, react_1.useEffect)(() => {
|
|
92
|
+
setInput(data);
|
|
93
|
+
}, [data, setInput]);
|
|
94
|
+
// Initing dispatcher
|
|
95
|
+
const dispatcher = (0, react_1.useRef)(new Dispatcher_1.Dispatcher(input, f, debouce)).current;
|
|
96
|
+
// Returning dispatcher
|
|
97
|
+
return dispatcher;
|
|
98
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cripty2001/utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
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": {
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@types/react": "^19
|
|
26
|
-
"react": "^19
|
|
25
|
+
"@types/react": "^19",
|
|
26
|
+
"react": "^19",
|
|
27
27
|
"typescript": "^5.9.3"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"lodash": "^4.17.21"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"react": "^19
|
|
35
|
+
"react": "^19"
|
|
36
36
|
},
|
|
37
37
|
"peerDependenciesMeta": {
|
|
38
38
|
"react": {
|