@cripty2001/utils 0.0.218 → 0.0.220

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.
@@ -205,3 +205,34 @@ 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 An object with:
221
+ * - `data`: The resulting `Whispr<T>`, seeded with the initial value from `getData`.
222
+ * - `refresh`: A 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 { data: windowSize, refresh: refreshSize } = whisprFromExternal(
228
+ * () => ({ width: window.innerWidth, height: window.innerHeight }),
229
+ * null,
230
+ * );
231
+ *
232
+ * window.addEventListener("resize", refreshSize);
233
+ */
234
+ export type WhisprFromExternalResult<T> = {
235
+ data: Whispr<T>;
236
+ refresh: () => void;
237
+ };
238
+ export declare function whisprFromExternal<T>(getData: () => T, interval: number | null): WhisprFromExternalResult<T>;
@@ -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");
@@ -438,32 +439,6 @@ function useAsyncInput(value, setValue, handler, setPending = () => { }) {
438
439
  result,
439
440
  ];
440
441
  }
441
- /**
442
- * Creates a Whispr from an external (non-reactive) data source.
443
- *
444
- * Unlike `Whispr.from`, which derives state from other Whisprs, this function
445
- * bridges an arbitrary data generator into Whispr's reactive system — useful
446
- * when your source of truth lives outside the Whispr graph (e.g. a DOM API,
447
- * a global store, or a plain function).
448
- *
449
- * @param getData - A function that returns the current value of the external source.
450
- * Called once immediately to seed the Whispr, then on every refresh.
451
- * @param interval - If provided, the Whispr will automatically re-poll `getData`
452
- * every `interval` milliseconds. Pass `null` to disable auto-refresh.
453
- * @returns A tuple of:
454
- * - The resulting `Whispr<T>`, seeded with the initial value from `getData`.
455
- * - A `refresh` function that manually re-reads `getData` and pushes the new
456
- * value into the Whispr. Hook this wherever you have a hint that the
457
- * external source may have changed.
458
- *
459
- * @example
460
- * const [windowSize, refreshSize] = whisprFromExternal(
461
- * () => ({ width: window.innerWidth, height: window.innerHeight }),
462
- * null,
463
- * );
464
- *
465
- * window.addEventListener("resize", refreshSize);
466
- */
467
442
  function whisprFromExternal(getData, interval) {
468
443
  const intervalRef = (() => {
469
444
  return interval !== null ?
@@ -478,5 +453,8 @@ function whisprFromExternal(getData, interval) {
478
453
  }
479
454
  };
480
455
  const [value, setValue] = whispr_1.Whispr.create(getData(), cleanup);
481
- return [value, () => setValue(getData())];
456
+ return {
457
+ data: value,
458
+ refresh: () => setValue(getData()),
459
+ };
482
460
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cripty2001/utils",
3
- "version": "0.0.218",
3
+ "version": "0.0.220",
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": {