@cripty2001/utils 0.0.141 → 0.0.143
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 +5 -11
- package/package.json +1 -1
package/dist/react-whispr.d.ts
CHANGED
|
@@ -80,7 +80,7 @@ export declare function useRelTime(refresh?: number): (ts: Date | number) => str
|
|
|
80
80
|
*/
|
|
81
81
|
export declare function useSearcher<T>(data: SearcherData<T>[], q: string): SearcherData<T>[];
|
|
82
82
|
/**
|
|
83
|
-
* A react ref hook with safe
|
|
83
|
+
* A react ref hook with safe lazy initialization, ready for safe side effects.
|
|
84
84
|
* @remarks The initialization function will only be called once, and the result will be stored in the ref.
|
|
85
85
|
* @param value The value to initialize the ref with. If a function is provided, it will be called to initialize the ref.
|
|
86
86
|
* @returns
|
package/dist/react-whispr.js
CHANGED
|
@@ -149,18 +149,14 @@ function useSynced(def, value, setValue) {
|
|
|
149
149
|
*/
|
|
150
150
|
function useAsync(f, data, debouce = 200) {
|
|
151
151
|
// Initing reactive input
|
|
152
|
-
const
|
|
153
|
-
if (!whisprRef.current) {
|
|
154
|
-
whisprRef.current = whispr_1.Whispr.create(data ?? (0, _1.getRandomId)());
|
|
155
|
-
}
|
|
156
|
-
const [input, setInput] = whisprRef.current;
|
|
152
|
+
const [input, setInput] = useSafeRef(() => whispr_1.Whispr.create(data ?? (0, _1.getRandomId)()));
|
|
157
153
|
if (data !== null) {
|
|
158
154
|
(0, react_1.useEffect)(() => {
|
|
159
155
|
setInput(data); // Debouncing already handled by dispatcher
|
|
160
156
|
}, [data, setInput]);
|
|
161
157
|
}
|
|
162
158
|
// Initing dispatcher
|
|
163
|
-
const dispatcher = (
|
|
159
|
+
const dispatcher = useSafeRef(() => new Dispatcher_1.Dispatcher(input, f, debouce));
|
|
164
160
|
// Returning dispatcher
|
|
165
161
|
return dispatcher;
|
|
166
162
|
}
|
|
@@ -236,17 +232,15 @@ function useSearcher(data, q) {
|
|
|
236
232
|
return useWhisprValue(searcher);
|
|
237
233
|
}
|
|
238
234
|
/**
|
|
239
|
-
* A react ref hook with safe
|
|
235
|
+
* A react ref hook with safe lazy initialization, ready for safe side effects.
|
|
240
236
|
* @remarks The initialization function will only be called once, and the result will be stored in the ref.
|
|
241
237
|
* @param value The value to initialize the ref with. If a function is provided, it will be called to initialize the ref.
|
|
242
238
|
* @returns
|
|
243
239
|
*/
|
|
244
240
|
function useSafeRef(value) {
|
|
245
241
|
const ref = (0, react_1.useRef)(null);
|
|
246
|
-
(
|
|
247
|
-
if (ref.current !== null)
|
|
248
|
-
return;
|
|
242
|
+
if (ref.current === null) {
|
|
249
243
|
ref.current = value();
|
|
250
|
-
}
|
|
244
|
+
}
|
|
251
245
|
return ref.current;
|
|
252
246
|
}
|
package/package.json
CHANGED