@cripty2001/utils 0.0.27 → 0.0.28
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 +6 -0
- package/dist/react-whispr.js +12 -0
- package/package.json +1 -1
package/dist/react-whispr.d.ts
CHANGED
|
@@ -25,6 +25,12 @@ export declare function useWhisprValue<I, O = I>(w: Whispr<I>, computer?: (data:
|
|
|
25
25
|
* @remarks The returned whispr has already been ref-fed, so it can be directly used without worrying about react recreating it or similar bad things
|
|
26
26
|
*/
|
|
27
27
|
export declare function useWhispr<T>(data: T | Whispr<T>): Whispr<T>;
|
|
28
|
+
/**
|
|
29
|
+
* Subscribe a callback to a Whispr inside a react component, properly handling unsubscription on unmount.
|
|
30
|
+
* @param w The whispr to subscribe to
|
|
31
|
+
* @param cb The callback to call on value change
|
|
32
|
+
*/
|
|
33
|
+
export declare function useOnWhispr<T>(w: Whispr<T>, cb: (value: T) => void): void;
|
|
28
34
|
export declare function useCurrentTimestamp(refresh?: number): number;
|
|
29
35
|
export declare function useDebounced<T>(value: T): T;
|
|
30
36
|
/**
|
package/dist/react-whispr.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useWhisprValue = useWhisprValue;
|
|
4
4
|
exports.useWhispr = useWhispr;
|
|
5
|
+
exports.useOnWhispr = useOnWhispr;
|
|
5
6
|
exports.useCurrentTimestamp = useCurrentTimestamp;
|
|
6
7
|
exports.useDebounced = useDebounced;
|
|
7
8
|
exports.useAsync = useAsync;
|
|
@@ -54,6 +55,17 @@ function useWhispr(data) {
|
|
|
54
55
|
return data;
|
|
55
56
|
return w;
|
|
56
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Subscribe a callback to a Whispr inside a react component, properly handling unsubscription on unmount.
|
|
60
|
+
* @param w The whispr to subscribe to
|
|
61
|
+
* @param cb The callback to call on value change
|
|
62
|
+
*/
|
|
63
|
+
function useOnWhispr(w, cb) {
|
|
64
|
+
(0, react_1.useEffect)(() => {
|
|
65
|
+
const unsub = w.subscribe(cb);
|
|
66
|
+
return () => unsub();
|
|
67
|
+
}, [w, cb]);
|
|
68
|
+
}
|
|
57
69
|
function useCurrentTimestamp(refresh = 1000) {
|
|
58
70
|
const [currTs, setCurrTs] = (0, react_1.useState)(Date.now());
|
|
59
71
|
(0, react_1.useEffect)(() => {
|
package/package.json
CHANGED