@cripty2001/utils 0.0.138 → 0.0.140
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/index.d.ts +1 -1
- package/dist/index.js +10 -4
- package/dist/react-whispr.js +6 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -83,6 +83,6 @@ export declare function randBetween(min: number, max: number): number;
|
|
|
83
83
|
* @returns The environment variable value, or the default value if provided
|
|
84
84
|
*/
|
|
85
85
|
export declare function getEnv(key: string, defaultValue?: string): string;
|
|
86
|
-
export declare const CURRENT_TS_MS: Whispr<number>;
|
|
86
|
+
export declare const CURRENT_TS_MS: () => Whispr<number>;
|
|
87
87
|
export declare function timediff2HumanReadable(diffMs: number): string;
|
|
88
88
|
export declare function fn2promise<T>(fn: () => T | Promise<T>): Promise<T>;
|
package/dist/index.js
CHANGED
|
@@ -204,10 +204,16 @@ function getEnv(key, defaultValue) {
|
|
|
204
204
|
return value;
|
|
205
205
|
}
|
|
206
206
|
const [currentTsMs, setCurrentTsMs] = whispr_1.Whispr.create(Date.now());
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
207
|
+
const currentTsMsInterval = null;
|
|
208
|
+
const CURRENT_TS_MS = () => {
|
|
209
|
+
if (currentTsMsInterval === null) {
|
|
210
|
+
setInterval(() => {
|
|
211
|
+
setCurrentTsMs(Date.now());
|
|
212
|
+
}, 200);
|
|
213
|
+
}
|
|
214
|
+
return currentTsMs;
|
|
215
|
+
};
|
|
216
|
+
exports.CURRENT_TS_MS = CURRENT_TS_MS;
|
|
211
217
|
function timediff2HumanReadable(diffMs) {
|
|
212
218
|
const { unit, diff } = (() => {
|
|
213
219
|
let toReturn = diffMs;
|
package/dist/react-whispr.js
CHANGED
|
@@ -76,7 +76,7 @@ function useOnWhispr(w, cb) {
|
|
|
76
76
|
* @returns The current timestamp
|
|
77
77
|
*/
|
|
78
78
|
function useCurrentTimestamp(refresh = 1000) {
|
|
79
|
-
return useWhisprValue(_1.CURRENT_TS_MS);
|
|
79
|
+
return useWhisprValue((0, _1.CURRENT_TS_MS)());
|
|
80
80
|
}
|
|
81
81
|
/**
|
|
82
82
|
* Debounce a reactive value, deep checking for equality, and stopping updates until the value changes.
|
|
@@ -148,7 +148,11 @@ function useSynced(def, value, setValue) {
|
|
|
148
148
|
*/
|
|
149
149
|
function useAsync(f, data, debouce = 200) {
|
|
150
150
|
// Initing reactive input
|
|
151
|
-
const
|
|
151
|
+
const whisprRef = (0, react_1.useRef)(null);
|
|
152
|
+
if (!whisprRef.current) {
|
|
153
|
+
whisprRef.current = whispr_1.Whispr.create(data ?? (0, _1.getRandomId)());
|
|
154
|
+
}
|
|
155
|
+
const [input, setInput] = whisprRef.current;
|
|
152
156
|
if (data !== null) {
|
|
153
157
|
(0, react_1.useEffect)(() => {
|
|
154
158
|
setInput(data); // Debouncing already handled by dispatcher
|
package/package.json
CHANGED