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