@cripty2001/utils 0.0.218 → 0.0.219
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 +27 -0
- package/dist/react-whispr.js +1 -0
- package/package.json +1 -1
package/dist/react-whispr.d.ts
CHANGED
|
@@ -205,3 +205,30 @@ export declare function useAsyncInput<C extends Record<string, JSONEncodable>, R
|
|
|
205
205
|
setValue: (updater: (draft: C) => C | void) => void,
|
|
206
206
|
result: R | null
|
|
207
207
|
];
|
|
208
|
+
/**
|
|
209
|
+
* Creates a Whispr from an external (non-reactive) data source.
|
|
210
|
+
*
|
|
211
|
+
* Unlike `Whispr.from`, which derives state from other Whisprs, this function
|
|
212
|
+
* bridges an arbitrary data generator into Whispr's reactive system — useful
|
|
213
|
+
* when your source of truth lives outside the Whispr graph (e.g. a DOM API,
|
|
214
|
+
* a global store, or a plain function).
|
|
215
|
+
*
|
|
216
|
+
* @param getData - A function that returns the current value of the external source.
|
|
217
|
+
* Called once immediately to seed the Whispr, then on every refresh.
|
|
218
|
+
* @param interval - If provided, the Whispr will automatically re-poll `getData`
|
|
219
|
+
* every `interval` milliseconds. Pass `null` to disable auto-refresh.
|
|
220
|
+
* @returns A tuple of:
|
|
221
|
+
* - The resulting `Whispr<T>`, seeded with the initial value from `getData`.
|
|
222
|
+
* - A `refresh` function that manually re-reads `getData` and pushes the new
|
|
223
|
+
* value into the Whispr. Hook this wherever you have a hint that the
|
|
224
|
+
* external source may have changed.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* const [windowSize, refreshSize] = whisprFromExternal(
|
|
228
|
+
* () => ({ width: window.innerWidth, height: window.innerHeight }),
|
|
229
|
+
* null,
|
|
230
|
+
* );
|
|
231
|
+
*
|
|
232
|
+
* window.addEventListener("resize", refreshSize);
|
|
233
|
+
*/
|
|
234
|
+
export declare function whisprFromExternal<T>(getData: () => T, interval: number | null): [Whispr<T>, () => void];
|
package/dist/react-whispr.js
CHANGED
|
@@ -13,6 +13,7 @@ exports.useRelTime = useRelTime;
|
|
|
13
13
|
exports.useSearcher = useSearcher;
|
|
14
14
|
exports.useSafeRef = useSafeRef;
|
|
15
15
|
exports.useAsyncInput = useAsyncInput;
|
|
16
|
+
exports.whisprFromExternal = whisprFromExternal;
|
|
16
17
|
const whispr_1 = require("@cripty2001/whispr");
|
|
17
18
|
const react_1 = require("react");
|
|
18
19
|
const lodash_1 = require("lodash");
|
package/package.json
CHANGED