@cripty2001/utils 0.0.136 → 0.0.137
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 +1 -1
- package/dist/react-whispr.js +7 -5
- package/package.json +1 -1
package/dist/react-whispr.d.ts
CHANGED
|
@@ -56,7 +56,7 @@ export declare function useSynced<T extends any>(def: T, value: T | undefined, s
|
|
|
56
56
|
* Wraps an async function into a reactable data.
|
|
57
57
|
*
|
|
58
58
|
* @param f The async function to call. It should return a promise that resolves to the data. It is not reactive
|
|
59
|
-
* @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.
|
|
59
|
+
* @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. If null, this function will act like an useEffect with an empty dependency array.
|
|
60
60
|
* @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
|
|
61
61
|
* @returns The dispatcher
|
|
62
62
|
*
|
package/dist/react-whispr.js
CHANGED
|
@@ -139,7 +139,7 @@ function useSynced(def, value, setValue) {
|
|
|
139
139
|
* Wraps an async function into a reactable data.
|
|
140
140
|
*
|
|
141
141
|
* @param f The async function to call. It should return a promise that resolves to the data. It is not reactive
|
|
142
|
-
* @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.
|
|
142
|
+
* @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. If null, this function will act like an useEffect with an empty dependency array.
|
|
143
143
|
* @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
|
|
144
144
|
* @returns The dispatcher
|
|
145
145
|
*
|
|
@@ -148,10 +148,12 @@ function useSynced(def, value, setValue) {
|
|
|
148
148
|
*/
|
|
149
149
|
function useAsync(f, data, debouce = 200) {
|
|
150
150
|
// Initing reactive input
|
|
151
|
-
const [input, setInput] = (0, react_1.useRef)(whispr_1.Whispr.create(data)).current;
|
|
152
|
-
(
|
|
153
|
-
|
|
154
|
-
|
|
151
|
+
const [input, setInput] = (0, react_1.useRef)(whispr_1.Whispr.create(data ?? (0, _1.getRandomId)())).current;
|
|
152
|
+
if (data !== null) {
|
|
153
|
+
(0, react_1.useEffect)(() => {
|
|
154
|
+
setInput(data); // Debouncing already handled by dispatcher
|
|
155
|
+
}, [data, setInput]);
|
|
156
|
+
}
|
|
155
157
|
// Initing dispatcher
|
|
156
158
|
const dispatcher = (0, react_1.useRef)(new Dispatcher_1.Dispatcher(input, f, debouce)).current;
|
|
157
159
|
// Returning dispatcher
|
package/package.json
CHANGED