use-good-hooks 1.0.20 → 1.0.21

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