@cripty2001/utils 0.0.144 → 0.0.146

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.
@@ -30,8 +30,9 @@ export declare function useWhispr<T>(data: T | Whispr<T>): Whispr<T>;
30
30
  * Subscribe a callback to a Whispr inside a react component, properly handling unsubscription on unmount.
31
31
  * @param w The whispr to subscribe to
32
32
  * @param cb The callback to call on value change
33
+ * @param unsafe If true, the callback will be allowed to throw errors, that will then bubble up
33
34
  */
34
- export declare function useOnWhispr<T>(w: Whispr<T>, cb: (value: T) => void): void;
35
+ export declare function useOnWhispr<T>(w: Whispr<T>, unsafe: boolean | undefined, cb: (value: T) => void): void;
35
36
  /**
36
37
  * Return a reactive current timestamp (ms), updated at the given interval.
37
38
  * @returns The current timestamp
@@ -109,11 +110,9 @@ export declare function useAsync<I, O>(f: (input: I, setProgress: (p: number) =>
109
110
  export declare function useAsyncEffect<I>(f: (input: I, setProgress: (p: number) => void, signal: AbortSignal) => Promise<void>, data: I, debounce?: number): void;
110
111
  /**
111
112
  * Format a timestamp into a relative time string (e.g. "5 minutes ago", "in 2 hours"), using the browser locale.
112
- * The refreshed time is reactive.
113
- * @param refresh The refresh interval, in milliseconds. Default to 1000ms.
114
113
  * @returns A callback (reactive, will change on refresh) that formats a given timestamp into a relative time string.
115
114
  */
116
- export declare function useRelTime(refresh?: number): (ts: Date | number) => string;
115
+ export declare function useRelTime(): (ts: Date | number) => string;
117
116
  /**
118
117
  * React shorthand for the Searcher
119
118
  * @param data The data to search on
@@ -66,10 +66,11 @@ function useWhispr(data) {
66
66
  * Subscribe a callback to a Whispr inside a react component, properly handling unsubscription on unmount.
67
67
  * @param w The whispr to subscribe to
68
68
  * @param cb The callback to call on value change
69
+ * @param unsafe If true, the callback will be allowed to throw errors, that will then bubble up
69
70
  */
70
- function useOnWhispr(w, cb) {
71
+ function useOnWhispr(w, unsafe = false, cb) {
71
72
  (0, react_1.useEffect)(() => {
72
- const unsub = w.subscribe(cb);
73
+ const unsub = w.subscribe(cb, undefined, unsafe);
73
74
  return () => unsub();
74
75
  }, [w, cb]);
75
76
  }
@@ -205,7 +206,7 @@ function useAsync(f, data, debouce = 200) {
205
206
  */
206
207
  function useAsyncEffect(f, data, debounce = 200) {
207
208
  const dispatcher = useAsync(f, data, debounce);
208
- useOnWhispr(dispatcher.data, (data) => {
209
+ useOnWhispr(dispatcher.data, true, (data) => {
209
210
  if (!data.loading && !data.ok) {
210
211
  throw data.error;
211
212
  }
@@ -213,12 +214,10 @@ function useAsyncEffect(f, data, debounce = 200) {
213
214
  }
214
215
  /**
215
216
  * Format a timestamp into a relative time string (e.g. "5 minutes ago", "in 2 hours"), using the browser locale.
216
- * The refreshed time is reactive.
217
- * @param refresh The refresh interval, in milliseconds. Default to 1000ms.
218
217
  * @returns A callback (reactive, will change on refresh) that formats a given timestamp into a relative time string.
219
218
  */
220
- function useRelTime(refresh = 1000) {
221
- const currTs = useCurrentTimestamp(refresh);
219
+ function useRelTime() {
220
+ const currTs = useCurrentTimestamp(1000);
222
221
  const rtf = (0, react_1.useRef)(new Intl.RelativeTimeFormat(navigator.language, { numeric: "auto" })).current;
223
222
  const getFormat = (_diff) => {
224
223
  const diff = Math.abs(_diff);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cripty2001/utils",
3
- "version": "0.0.144",
3
+ "version": "0.0.146",
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": {
@@ -22,7 +22,7 @@
22
22
  "dist"
23
23
  ],
24
24
  "dependencies": {
25
- "@cripty2001/whispr": "^0.2.1",
25
+ "@cripty2001/whispr": "^0.2.3",
26
26
  "lodash": "^4.17.21"
27
27
  },
28
28
  "devDependencies": {