@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 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
- setInterval(() => {
208
- setCurrentTsMs(Date.now());
209
- }, 200);
210
- exports.CURRENT_TS_MS = currentTsMs;
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;
@@ -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 [input, setInput] = (0, react_1.useRef)(whispr_1.Whispr.create(data ?? (0, _1.getRandomId)())).current;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cripty2001/utils",
3
- "version": "0.0.138",
3
+ "version": "0.0.140",
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": {