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.
- package/dist/use-storage-state.js +24 -22
- package/package.json +1 -1
|
@@ -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
|
|
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,
|
|
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 || {}),
|
|
23
|
-
|
|
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() || !
|
|
27
|
+
if (!A.browser() || !a.current)
|
|
28
28
|
return;
|
|
29
29
|
const {
|
|
30
|
-
storage: f =
|
|
30
|
+
storage: f = S,
|
|
31
31
|
onError: t,
|
|
32
32
|
omitKeys: s,
|
|
33
|
-
pickKeys:
|
|
33
|
+
pickKeys: e
|
|
34
34
|
} = p.current, n = f === "local" ? localStorage : sessionStorage;
|
|
35
35
|
if (n)
|
|
36
36
|
try {
|
|
37
|
-
let
|
|
38
|
-
s && (
|
|
39
|
-
} catch (
|
|
40
|
-
t && t(
|
|
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,
|
|
42
|
+
}, [m, l]), E(() => {
|
|
43
|
+
if (a.current)
|
|
44
|
+
return;
|
|
43
45
|
const {
|
|
44
|
-
storage: f =
|
|
46
|
+
storage: f = S,
|
|
45
47
|
omitKeys: t,
|
|
46
48
|
onError: s,
|
|
47
|
-
pickKeys:
|
|
49
|
+
pickKeys: e
|
|
48
50
|
} = p.current;
|
|
49
51
|
try {
|
|
50
|
-
const n = f === "local" ? localStorage : sessionStorage,
|
|
51
|
-
if (
|
|
52
|
-
let c = b.parse(
|
|
53
|
-
t && (
|
|
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
|
-
|
|
62
|
+
a.current = !0;
|
|
61
63
|
}
|
|
62
64
|
}, []);
|
|
63
65
|
const M = B(() => {
|
|
64
66
|
if (!A.browser())
|
|
65
67
|
return;
|
|
66
|
-
|
|
67
|
-
const { storage: f =
|
|
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 [
|
|
72
|
+
return [a.current ? g : r, y, { removeKey: M }];
|
|
71
73
|
};
|
|
72
74
|
export {
|
|
73
75
|
Z as default,
|
package/package.json
CHANGED