@cripty2001/utils 0.0.145 → 0.0.147

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.
@@ -110,11 +110,9 @@ export declare function useAsync<I, O>(f: (input: I, setProgress: (p: number) =>
110
110
  export declare function useAsyncEffect<I>(f: (input: I, setProgress: (p: number) => void, signal: AbortSignal) => Promise<void>, data: I, debounce?: number): void;
111
111
  /**
112
112
  * Format a timestamp into a relative time string (e.g. "5 minutes ago", "in 2 hours"), using the browser locale.
113
- * The refreshed time is reactive.
114
- * @param refresh The refresh interval, in milliseconds. Default to 1000ms.
115
113
  * @returns A callback (reactive, will change on refresh) that formats a given timestamp into a relative time string.
116
114
  */
117
- export declare function useRelTime(refresh?: number): (ts: Date | number) => string;
115
+ export declare function useRelTime(): (ts: Date | number) => string;
118
116
  /**
119
117
  * React shorthand for the Searcher
120
118
  * @param data The data to search on
@@ -36,11 +36,18 @@ const Searcher_1 = require("./Searcher");
36
36
  function useWhisprValue(w, computer = (d) => d) {
37
37
  const value_w = (0, react_1.useRef)(whispr_1.Whispr.from({ w }, ({ w }) => computer(w))).current;
38
38
  const [value, setValue] = (0, react_1.useState)(value_w.value);
39
- value_w.subscribe((newValue) => {
40
- if ((0, lodash_1.isEqual)(newValue, value))
41
- return;
42
- setValue(newValue);
43
- }, false); // Already got the initial value, and this will call syncronously generate a react warning as called on an not yet mounted component
39
+ const valueRef = (0, react_1.useRef)(value);
40
+ (0, react_1.useEffect)(() => {
41
+ valueRef.current = value;
42
+ }, [value]);
43
+ (0, react_1.useEffect)(() => {
44
+ const unsub = value_w.subscribe((newValue) => {
45
+ if ((0, lodash_1.isEqual)(newValue, valueRef.current))
46
+ return;
47
+ setValue(newValue);
48
+ }, false);
49
+ return () => unsub();
50
+ }, [value_w]);
44
51
  return value;
45
52
  }
46
53
  /**
@@ -214,12 +221,10 @@ function useAsyncEffect(f, data, debounce = 200) {
214
221
  }
215
222
  /**
216
223
  * Format a timestamp into a relative time string (e.g. "5 minutes ago", "in 2 hours"), using the browser locale.
217
- * The refreshed time is reactive.
218
- * @param refresh The refresh interval, in milliseconds. Default to 1000ms.
219
224
  * @returns A callback (reactive, will change on refresh) that formats a given timestamp into a relative time string.
220
225
  */
221
- function useRelTime(refresh = 1000) {
222
- const currTs = useCurrentTimestamp(refresh);
226
+ function useRelTime() {
227
+ const currTs = useCurrentTimestamp(1000);
223
228
  const rtf = (0, react_1.useRef)(new Intl.RelativeTimeFormat(navigator.language, { numeric: "auto" })).current;
224
229
  const getFormat = (_diff) => {
225
230
  const diff = Math.abs(_diff);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cripty2001/utils",
3
- "version": "0.0.145",
3
+ "version": "0.0.147",
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": {