use-good-hooks 1.0.21 → 1.0.23
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 +44 -42
- package/package.json +2 -2
|
@@ -3,70 +3,72 @@ import O from "lodash/isEmpty";
|
|
|
3
3
|
import m from "lodash/isFunction";
|
|
4
4
|
import T from "lodash/isMap";
|
|
5
5
|
import U from "lodash/isSet";
|
|
6
|
-
import
|
|
6
|
+
import E from "use-json";
|
|
7
7
|
import h from "lodash/merge";
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import { i as
|
|
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
14
|
import j from "./use-debounce.js";
|
|
15
|
-
const k = 500,
|
|
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, L = (
|
|
22
|
-
const
|
|
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;
|
|
23
25
|
const {
|
|
24
|
-
storage: f =
|
|
25
|
-
omitKeys:
|
|
26
|
+
storage: f = S,
|
|
27
|
+
omitKeys: e,
|
|
26
28
|
onError: n,
|
|
27
|
-
pickKeys:
|
|
28
|
-
} =
|
|
29
|
+
pickKeys: o
|
|
30
|
+
} = p.current, i = f === "local" ? localStorage : sessionStorage;
|
|
29
31
|
try {
|
|
30
|
-
const
|
|
31
|
-
if (
|
|
32
|
-
let s =
|
|
33
|
-
return
|
|
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);
|
|
34
36
|
}
|
|
35
|
-
} catch (
|
|
36
|
-
n && n(
|
|
37
|
+
} catch (t) {
|
|
38
|
+
n && n(t);
|
|
37
39
|
}
|
|
38
40
|
return r;
|
|
39
|
-
}, [
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
}, [g, y] = M(R), l = j(
|
|
42
|
+
g,
|
|
43
|
+
p.current.debounce ?? k
|
|
42
44
|
);
|
|
43
45
|
B(() => {
|
|
44
|
-
if (!
|
|
46
|
+
if (!u.browser())
|
|
45
47
|
return;
|
|
46
48
|
const {
|
|
47
|
-
storage: f =
|
|
48
|
-
onError:
|
|
49
|
+
storage: f = S,
|
|
50
|
+
onError: e,
|
|
49
51
|
omitKeys: n,
|
|
50
|
-
pickKeys:
|
|
51
|
-
} =
|
|
52
|
-
if (
|
|
52
|
+
pickKeys: o
|
|
53
|
+
} = p.current, i = f === "local" ? localStorage : sessionStorage;
|
|
54
|
+
if (i)
|
|
53
55
|
try {
|
|
54
|
-
let
|
|
55
|
-
n && (
|
|
56
|
-
const s =
|
|
57
|
-
s !==
|
|
58
|
-
} catch (
|
|
59
|
-
|
|
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);
|
|
60
62
|
}
|
|
61
|
-
}, [
|
|
63
|
+
}, [c, l]);
|
|
62
64
|
const A = F(() => {
|
|
63
|
-
if (!
|
|
65
|
+
if (!u.browser())
|
|
64
66
|
return;
|
|
65
|
-
|
|
66
|
-
const { storage: f =
|
|
67
|
-
|
|
68
|
-
}, [
|
|
69
|
-
return [
|
|
67
|
+
y(r);
|
|
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 }];
|
|
70
72
|
};
|
|
71
73
|
export {
|
|
72
74
|
$ as default,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "use-good-hooks",
|
|
3
3
|
"dependencies": {
|
|
4
|
-
"use-json": "^1.0.
|
|
4
|
+
"use-json": "^1.0.1",
|
|
5
5
|
"use-qs": "^1.0.4"
|
|
6
6
|
},
|
|
7
7
|
"devDependencies": {
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"test": "vitest",
|
|
50
50
|
"test:coverage": "vitest --coverage"
|
|
51
51
|
},
|
|
52
|
-
"version": "1.0.
|
|
52
|
+
"version": "1.0.23"
|
|
53
53
|
}
|