use-good-hooks 1.0.18 → 1.0.20

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.
@@ -9,65 +9,67 @@ import d from "lodash/omit";
9
9
  import K from "lodash/omitBy";
10
10
  import R from "lodash/pick";
11
11
  import w from "lodash/pickBy";
12
- import a from "lodash/size";
12
+ import u from "lodash/size";
13
13
  import { i as A } from "./is-BPZNFd2v.mjs";
14
14
  import U from "./use-debounce.js";
15
- const h = 500, y = "local", j = (m, r) => I(r) ? {
15
+ const h = 500, S = "local", j = (m, r) => I(r) ? {
16
16
  __type: "Map",
17
17
  value: Array.from(r.entries())
18
18
  } : O(r) ? {
19
19
  __type: "Set",
20
20
  value: Array.from(r)
21
21
  } : r, C = (m, r) => r && r.__type === "Map" ? new Map(r.value) : r && r.__type === "Set" ? new Set(r.value) : r, Z = (m, r, D) => {
22
- const p = _(D || {}), S = _(!1), [l, u] = k(r), g = U(
23
- l,
22
+ const p = _(D || {}), a = _(!1), [g, y] = k(r), l = U(
23
+ g,
24
24
  p.current.debounce ?? h
25
25
  );
26
26
  E(() => {
27
- if (!A.browser() || !S.current)
27
+ if (!A.browser() || !a.current)
28
28
  return;
29
29
  const {
30
- storage: f = y,
30
+ storage: f = S,
31
31
  onError: t,
32
32
  omitKeys: s,
33
- pickKeys: o
33
+ pickKeys: e
34
34
  } = p.current, n = f === "local" ? localStorage : sessionStorage;
35
35
  if (n)
36
36
  try {
37
- let e = g;
38
- s && (a(s) || i(s)) && (e = i(s) ? K(e, s) : d(e, s)), o && (a(o) || i(o)) && (e = i(o) ? w(e, o) : R(e, o)), n.setItem(m, b.stringify(e, j));
39
- } catch (e) {
40
- t && t(e);
37
+ let o = l;
38
+ s && (u(s) || i(s)) && (o = i(s) ? K(o, s) : d(o, s)), e && (u(e) || i(e)) && (o = i(e) ? w(o, e) : R(o, e)), n.setItem(m, b.stringify(o, j));
39
+ } catch (o) {
40
+ t && t(o);
41
41
  }
42
- }, [m, g]), E(() => {
42
+ }, [m, l]), E(() => {
43
+ if (a.current)
44
+ return;
43
45
  const {
44
- storage: f = y,
46
+ storage: f = S,
45
47
  omitKeys: t,
46
48
  onError: s,
47
- pickKeys: o
49
+ pickKeys: e
48
50
  } = p.current;
49
51
  try {
50
- const n = f === "local" ? localStorage : sessionStorage, e = n == null ? void 0 : n.getItem(m);
51
- if (e) {
52
- let c = b.parse(e, C);
53
- t && (a(t) || i(t)) && (c = i(t) ? K(c, t) : d(c, t)), o && (a(o) || i(o)) && (c = i(o) ? w(c, o) : R(c, o)), u(
52
+ const n = f === "local" ? localStorage : sessionStorage, o = n == null ? void 0 : n.getItem(m);
53
+ if (o) {
54
+ let c = b.parse(o, C);
55
+ t && (u(t) || i(t)) && (c = i(t) ? K(c, t) : d(c, t)), e && (u(e) || i(e)) && (c = i(e) ? w(c, e) : R(c, e)), y(
54
56
  F(c) ? r : T({}, r, c)
55
57
  );
56
58
  }
57
59
  } catch (n) {
58
60
  s && s(n);
59
61
  } finally {
60
- S.current = !0;
62
+ a.current = !0;
61
63
  }
62
64
  }, []);
63
65
  const M = B(() => {
64
66
  if (!A.browser())
65
67
  return;
66
- u(r);
67
- const { storage: f = y } = p.current, t = f === "local" ? localStorage : sessionStorage;
68
+ y(r);
69
+ const { storage: f = S } = p.current, t = f === "local" ? localStorage : sessionStorage;
68
70
  t == null || t.removeItem(m);
69
71
  }, [m, r]);
70
- return [l, u, { removeKey: M }];
72
+ return [a.current ? g : r, y, { removeKey: M }];
71
73
  };
72
74
  export {
73
75
  Z as default,
package/package.json CHANGED
@@ -49,5 +49,5 @@
49
49
  "test": "vitest",
50
50
  "test:coverage": "vitest --coverage"
51
51
  },
52
- "version": "1.0.18"
52
+ "version": "1.0.20"
53
53
  }