@cripty2001/utils 0.0.164 → 0.0.166

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.
@@ -37,11 +37,13 @@ const Searcher_1 = require("./Searcher");
37
37
  function useWhisprValue(w, computer = (d) => d) {
38
38
  const value_w = (0, react_1.useRef)(whispr_1.Whispr.from({ w }, ({ w }) => computer(w))).current;
39
39
  const [value, setValue] = (0, react_1.useState)(value_w.value);
40
- value_w.subscribe((newValue) => {
41
- if ((0, lodash_1.isEqual)(newValue, value))
42
- return;
43
- setValue(newValue);
44
- }, false); // Already got the initial value, and this will call syncronously generate a react warning as called on an not yet mounted component
40
+ (0, react_1.useEffect)(() => {
41
+ return value_w.subscribe((newValue) => {
42
+ if ((0, lodash_1.isEqual)(newValue, value))
43
+ return;
44
+ setValue(newValue);
45
+ });
46
+ }, [value_w]);
45
47
  return value;
46
48
  }
47
49
  /**
@@ -361,19 +363,6 @@ function useAsyncInput(value, setValue, handler) {
361
363
  setMeta(value._meta);
362
364
  }
363
365
  }, [value, meta, setMeta]);
364
- // // React has always random problems with stale closures, expecially in async environment.
365
- // // On the other side, the watched param of useAsync is always perfect
366
- // // We aren't taking any risks, here
367
- // type AsyncPack = {
368
- // c: C,
369
- // ts: number,
370
- // }
371
- // const asyncPack: AsyncPack = useMemo(() => {
372
- // return {
373
- // c: meta.config,
374
- // ts: meta.ts,
375
- // }
376
- // }, [meta]);
377
366
  const result_d = useAsync(async ({ config, ts }) => {
378
367
  const r = await handler(config);
379
368
  return {
@@ -391,7 +380,7 @@ function useAsyncInput(value, setValue, handler) {
391
380
  if (result._meta.ts <= value._meta.ts)
392
381
  return;
393
382
  setValue(result);
394
- }, [result, setValue]);
383
+ }, [result, value, setValue]);
395
384
  const returnedSetValue = (0, react_1.useCallback)((updater) => {
396
385
  const cloned = structuredClone(meta.config);
397
386
  const new_data = updater(cloned);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cripty2001/utils",
3
- "version": "0.0.164",
3
+ "version": "0.0.166",
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": {