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.
- package/dist/use-storage-state.js +57 -60
- package/dist/use-url-state.js +2 -1
- package/package.json +1 -1
|
@@ -1,78 +1,75 @@
|
|
|
1
|
-
import { useRef as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
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
|
|
13
|
-
import { i as
|
|
14
|
-
import
|
|
15
|
-
const
|
|
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
|
-
} :
|
|
18
|
+
} : U(r) ? {
|
|
19
19
|
__type: "Set",
|
|
20
20
|
value: Array.from(r)
|
|
21
|
-
} : r,
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
27
|
-
if (!
|
|
43
|
+
B(() => {
|
|
44
|
+
if (!I.browser())
|
|
28
45
|
return;
|
|
29
46
|
const {
|
|
30
|
-
storage: f =
|
|
47
|
+
storage: f = u,
|
|
31
48
|
onError: t,
|
|
32
|
-
omitKeys:
|
|
49
|
+
omitKeys: n,
|
|
33
50
|
pickKeys: e
|
|
34
|
-
} =
|
|
35
|
-
if (
|
|
51
|
+
} = a.current, c = f === "local" ? localStorage : sessionStorage;
|
|
52
|
+
if (c)
|
|
36
53
|
try {
|
|
37
|
-
let o =
|
|
38
|
-
|
|
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
|
-
}, [
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
69
|
-
const { storage: f =
|
|
70
|
-
t == null || t.removeItem(
|
|
71
|
-
}, [
|
|
72
|
-
return [
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
72
|
+
$ as default,
|
|
73
|
+
C as jsonReplacer,
|
|
74
|
+
L as jsonReviver
|
|
78
75
|
};
|
package/dist/use-url-state.js
CHANGED
|
@@ -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
|
-
|
|
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