atomaric 0.0.65 → 0.0.67
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/build/atomaric.js +276 -279
- package/build/atomaric.umd.cjs +1 -1
- package/package.json +1 -1
- package/types/index.d.ts +24 -67
package/build/atomaric.js
CHANGED
|
@@ -1,363 +1,360 @@
|
|
|
1
|
-
let
|
|
1
|
+
let k = () => {
|
|
2
2
|
throw "call configureAtomaric() before all!";
|
|
3
3
|
};
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
}, ne = (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
const L = {}, Ae = (t) => {
|
|
5
|
+
L.useSyncExternalStore = k = t.useSyncExternalStore, L.keyPathSeparator = t.keyPathSeparator, L.securifyKeyLevel = t.securifyKeyLevel, L.securifyValueLevel = t.securifyValueLevel;
|
|
6
|
+
}, ne = (t) => k(t.subscribe, t.get), oe = (t) => t.set, Se = (t) => t.setDeferred, xe = (t) => t.get, be = (t) => t.do, De = (t) => [ne(t), oe(t)], $e = (t, e) => new de(t, e);
|
|
7
|
+
class E {
|
|
8
|
+
constructor(e) {
|
|
9
|
+
if (e)
|
|
10
|
+
return new Proxy(this, {
|
|
11
|
+
get: (n, s) => s in this ? n[s] : e[s]
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const ce = (t, e) => {
|
|
16
|
+
const n = (s, o, i) => new Proxy(s, {
|
|
17
|
+
get: (u, f, y) => {
|
|
18
|
+
const d = i === 0 && e.get != null ? e.get(u, f, y) : u[f];
|
|
19
|
+
return typeof d == "object" && d !== null ? n(
|
|
20
|
+
Array.isArray(d) ? d.slice(0) : { ...d },
|
|
21
|
+
o.concat(Array.isArray(u) ? +f : f),
|
|
22
|
+
i + 1
|
|
23
|
+
) : d;
|
|
15
24
|
},
|
|
16
|
-
set: (
|
|
25
|
+
set: (u, f, y) => (e.onSet(u, o, f, y, u[f]) && (u[f] = y), !0)
|
|
17
26
|
});
|
|
18
|
-
return
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
n.set(!n.get());
|
|
36
|
-
}
|
|
37
|
-
})
|
|
38
|
-
);
|
|
39
|
-
else if (Array.isArray(e))
|
|
40
|
-
l = q(
|
|
41
|
-
t,
|
|
42
|
-
(n) => ({
|
|
43
|
-
push: (...s) => {
|
|
44
|
-
n.set(n.get().concat(s));
|
|
45
|
-
},
|
|
46
|
-
unshift: (...s) => {
|
|
47
|
-
n.set(s.concat(n.get()));
|
|
48
|
-
},
|
|
49
|
-
update: (s) => {
|
|
50
|
-
const i = n.get(), u = Z(i, s);
|
|
51
|
-
u !== i && n.set(u);
|
|
52
|
-
},
|
|
53
|
-
filter: (s) => {
|
|
54
|
-
n.set(n.get().filter(s ?? ue));
|
|
55
|
-
},
|
|
56
|
-
add: (s) => {
|
|
57
|
-
n.get().includes(s) || n.set(n.get().concat([s]));
|
|
58
|
-
},
|
|
59
|
-
remove: (s) => {
|
|
60
|
-
const i = n.get().indexOf(s);
|
|
61
|
-
if (i < 0) return;
|
|
62
|
-
const u = n.get().slice(0);
|
|
63
|
-
u.splice(i, 1), n.set(u);
|
|
64
|
-
},
|
|
65
|
-
toggle: (s, i) => {
|
|
66
|
-
const u = n.get().slice(), d = u.indexOf(s);
|
|
67
|
-
d < 0 ? i ? u.unshift(s) : u.push(s) : u.splice(d, 1), n.set(u);
|
|
68
|
-
}
|
|
69
|
-
})
|
|
70
|
-
);
|
|
71
|
-
else if (e instanceof Set)
|
|
72
|
-
l = q(
|
|
73
|
-
t,
|
|
74
|
-
(n) => ({
|
|
75
|
-
add: (s) => {
|
|
76
|
-
n.set(new Set(n.get()).add(s));
|
|
77
|
-
},
|
|
78
|
-
delete: (s) => {
|
|
79
|
-
const i = new Set(n.get());
|
|
80
|
-
i.delete(s), n.set(i);
|
|
81
|
-
},
|
|
82
|
-
toggle: (s) => {
|
|
83
|
-
const i = new Set(n.get());
|
|
84
|
-
i.has(s) ? i.delete(s) : i.add(s), n.set(i);
|
|
85
|
-
},
|
|
86
|
-
clear: () => {
|
|
87
|
-
n.set(/* @__PURE__ */ new Set());
|
|
27
|
+
return n(t, [], 0);
|
|
28
|
+
};
|
|
29
|
+
class O extends E {
|
|
30
|
+
constructor() {
|
|
31
|
+
super(...arguments), this.updateValue = (e, n) => {
|
|
32
|
+
const s = Array.isArray(e) ? e.slice(0) : { ...e };
|
|
33
|
+
let o = !1;
|
|
34
|
+
const i = ce(e, {
|
|
35
|
+
onSet: (u, f, y, d, g) => {
|
|
36
|
+
if (d === g) return !0;
|
|
37
|
+
let A = s;
|
|
38
|
+
o = !0;
|
|
39
|
+
for (const l of f) {
|
|
40
|
+
const h = A[l];
|
|
41
|
+
A = A[l] = Array.isArray(h) ? h.slice(0) : { ...h };
|
|
42
|
+
}
|
|
43
|
+
return A[y] = d, !0;
|
|
88
44
|
}
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
45
|
+
});
|
|
46
|
+
return n(i), o ? s : e;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
class ie extends O {
|
|
51
|
+
constructor(e, n) {
|
|
52
|
+
super(n), this.atom = e, this.push = (...s) => {
|
|
53
|
+
this.atom.set(this.atom.get().concat(s));
|
|
54
|
+
}, this.unshift = (...s) => {
|
|
55
|
+
this.atom.set(s.concat(this.atom.get()));
|
|
56
|
+
}, this.update = (s) => {
|
|
57
|
+
const o = this.atom.get(), i = this.updateValue(o, s);
|
|
58
|
+
i !== o && this.atom.set(i);
|
|
59
|
+
}, this.filter = (s) => {
|
|
60
|
+
this.atom.set(this.atom.get().filter(s ?? ae));
|
|
61
|
+
}, this.add = (s) => {
|
|
62
|
+
this.atom.get().includes(s) || this.atom.set(this.atom.get().concat([s]));
|
|
63
|
+
}, this.remove = (s) => {
|
|
64
|
+
const o = this.atom.get().indexOf(s);
|
|
65
|
+
if (o < 0) return;
|
|
66
|
+
const i = this.atom.get().slice(0);
|
|
67
|
+
i.splice(o, 1), this.atom.set(i);
|
|
68
|
+
}, this.toggle = (s, o) => {
|
|
69
|
+
const i = this.atom.get().slice(), u = i.indexOf(s);
|
|
70
|
+
u < 0 ? o ? i.unshift(s) : i.push(s) : i.splice(u, 1), this.atom.set(i);
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const ae = (t) => t;
|
|
75
|
+
class ue extends E {
|
|
76
|
+
constructor(e, n) {
|
|
77
|
+
super(n), this.atom = e, this.toggle = () => {
|
|
78
|
+
this.atom.set(!this.atom.get());
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
class le extends E {
|
|
83
|
+
constructor(e, n) {
|
|
84
|
+
super(n), this.atom = e, this.increment = (s) => {
|
|
85
|
+
this.atom.set(+this.atom.get() + (s ?? 1));
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
class fe extends O {
|
|
90
|
+
constructor(e, n) {
|
|
91
|
+
super(n), this.atom = e, this.setPartial = (s) => this.atom.set((o) => ({
|
|
92
|
+
...o,
|
|
93
|
+
...typeof s == "function" ? s(this.atom.get()) : s
|
|
94
|
+
})), this.update = (s) => {
|
|
95
|
+
const o = this.atom.get(), i = this.updateValue(o, s);
|
|
96
|
+
i !== o && this.atom.set(i);
|
|
97
|
+
}, this.setDeepPartial = (s, o, i, u = L.keyPathSeparator || ".") => {
|
|
98
|
+
if (!u) return;
|
|
99
|
+
if (s.includes(u)) {
|
|
100
|
+
let d = s.split(u);
|
|
101
|
+
const g = d[d.length - 1];
|
|
102
|
+
d = d.slice(0, -1);
|
|
103
|
+
const A = { ...this.atom.get() };
|
|
104
|
+
let l = A, h = i;
|
|
105
|
+
for (const p of d) {
|
|
106
|
+
h = h == null ? void 0 : h[Array.isArray(h) ? "0" : p];
|
|
107
|
+
const x = l[Z(l, p)] ?? (Array.isArray(h) ? [] : {});
|
|
108
|
+
if (x == null || typeof x != "object") {
|
|
109
|
+
if (i == null) throw "Incorrect path for setDeepPartial";
|
|
110
|
+
const S = typeof o == "function" ? o(void 0) : o;
|
|
111
|
+
this.atom.get()[s] !== S && this.setPartial({ [s]: S });
|
|
125
112
|
return;
|
|
126
113
|
}
|
|
127
|
-
|
|
128
|
-
A !== h && s.do.setPartial({ [i]: A });
|
|
114
|
+
l = l[Z(l, p)] = Array.isArray(x) ? [...x] : { ...x };
|
|
129
115
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const g = typeof c == "object" && c != null && "do" in c ? c.do(
|
|
134
|
-
(n, s) => t.set(n, s),
|
|
135
|
-
() => t.get(),
|
|
136
|
-
t,
|
|
137
|
-
(n, s, i) => t.setDeferred(n, s, i)
|
|
138
|
-
) : null, S = {};
|
|
139
|
-
return g && Object.keys(g).forEach((n) => Object.defineProperty(S, n, { get: () => g[n] })), l && Object.keys(l).forEach(
|
|
140
|
-
(n) => Object.defineProperty(S, n, { get: () => l[n] })
|
|
141
|
-
), S;
|
|
142
|
-
}, ue = (e) => e, q = (e, t, c) => t(e), Z = (e, t) => {
|
|
143
|
-
const c = Array.isArray(e) ? e.slice(0) : { ...e };
|
|
144
|
-
let l = !1;
|
|
145
|
-
const g = ie(e, {
|
|
146
|
-
onSet: (S, n, s, i, u) => {
|
|
147
|
-
if (i === u) return !0;
|
|
148
|
-
let d = c;
|
|
149
|
-
l = !0;
|
|
150
|
-
for (const b of n) {
|
|
151
|
-
const h = d[b];
|
|
152
|
-
d = d[b] = Array.isArray(h) ? h.slice(0) : { ...h };
|
|
116
|
+
const z = l[g];
|
|
117
|
+
l[g] = typeof o == "function" ? o(l[g]) : o, z !== l[g] && this.atom.set(A);
|
|
118
|
+
return;
|
|
153
119
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
120
|
+
const f = this.atom.get()[s], y = typeof o == "function" ? o(f) : o;
|
|
121
|
+
y !== f && this.setPartial({ [s]: y });
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const Z = (t, e) => Array.isArray(t) ? `${+e}` : e;
|
|
126
|
+
class he extends E {
|
|
127
|
+
constructor(e, n) {
|
|
128
|
+
super(n), this.atom = e, this.add = (s) => {
|
|
129
|
+
this.atom.set(new Set(this.atom.get()).add(s));
|
|
130
|
+
}, this.delete = (s) => {
|
|
131
|
+
const o = new Set(this.atom.get());
|
|
132
|
+
o.delete(s), this.atom.set(o);
|
|
133
|
+
}, this.toggle = (s) => {
|
|
134
|
+
const o = new Set(this.atom.get());
|
|
135
|
+
o.has(s) ? o.delete(s) : o.add(s), this.atom.set(o);
|
|
136
|
+
}, this.clear = () => {
|
|
137
|
+
this.atom.set(/* @__PURE__ */ new Set());
|
|
138
|
+
}, this.atom = e;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const me = (t, e, n) => {
|
|
142
|
+
const s = typeof n == "object" && n != null && "do" in n ? n.do(
|
|
143
|
+
(i, u) => e.set(i, u),
|
|
144
|
+
() => e.get(),
|
|
145
|
+
e,
|
|
146
|
+
(i, u, f) => e.setDeferred(i, u, f)
|
|
147
|
+
) : null, o = {};
|
|
148
|
+
return s && Object.keys(s).forEach((i) => Object.defineProperty(o, i, { get: () => s[i] })), typeof t == "number" ? new le(e, s) : typeof t == "boolean" ? new ue(e, s) : Array.isArray(t) ? new ie(e, s) : t instanceof Set ? new he(e, s) : t instanceof Object ? new fe(e, s) : new E(s);
|
|
149
|
+
};
|
|
150
|
+
class de {
|
|
151
|
+
constructor(e, n) {
|
|
152
|
+
e = typeof e == "function" ? e() : e;
|
|
153
|
+
const s = (r) => d = r, o = () => d, i = /* @__PURE__ */ new Set(), u = (r) => r(l());
|
|
154
|
+
let f = !0, y = !1, d = e, g, A = () => {
|
|
155
|
+
}, l = () => o(), h = null, z = () => {
|
|
156
|
+
const r = me(e, p, n);
|
|
157
|
+
return z = () => r, r;
|
|
166
158
|
};
|
|
167
|
-
const
|
|
168
|
-
get: (r,
|
|
169
|
-
set:
|
|
170
|
-
}),
|
|
171
|
-
|
|
159
|
+
const p = new Proxy(this, {
|
|
160
|
+
get: (r, m) => m === "do" ? z() : r[m],
|
|
161
|
+
set: ye
|
|
162
|
+
}), x = () => {
|
|
163
|
+
f = !0, y !== !0 && A(l()), y = !1;
|
|
172
164
|
try {
|
|
173
|
-
|
|
165
|
+
W.postMessage({ key: a, value: o() });
|
|
174
166
|
} catch {
|
|
175
167
|
}
|
|
176
|
-
},
|
|
177
|
-
const
|
|
178
|
-
|
|
168
|
+
}, S = (r, m) => {
|
|
169
|
+
const D = typeof r == "function" ? r(l()) : r;
|
|
170
|
+
D !== l() && (s(D), y = m, f && (f = !1, i.forEach(u), queueMicrotask(x)));
|
|
179
171
|
};
|
|
180
|
-
this.set = (r,
|
|
181
|
-
|
|
172
|
+
this.set = (r, m) => S(r, m), this.get = () => l(), this.initialValue = e, this.isInitialValue = () => e === o(), this.subscribe = (r) => (i.add(r), () => {
|
|
173
|
+
i.delete(r);
|
|
182
174
|
}), this.reset = () => {
|
|
183
|
-
|
|
175
|
+
S(e, !0);
|
|
184
176
|
};
|
|
185
|
-
const
|
|
186
|
-
|
|
177
|
+
const re = (r, m) => {
|
|
178
|
+
S(r, m), g = void 0;
|
|
187
179
|
};
|
|
188
|
-
if (this.setDeferred = (r,
|
|
189
|
-
|
|
190
|
-
},
|
|
191
|
-
let
|
|
180
|
+
if (this.setDeferred = (r, m = 500, D, $ = !0) => {
|
|
181
|
+
$ && g === void 0 && S(r, D), clearTimeout(g), g = setTimeout(re, m, r, D);
|
|
182
|
+
}, n == null) return p;
|
|
183
|
+
let w = null, j = null, M = !0, v = !0, B = !1, b = 0, T = 0, Q = -1, V = e instanceof Set ? (r) => new Set(r) : (r) => r, C = e instanceof Set ? (r) => {
|
|
192
184
|
if (r instanceof Set) return Array.from(r);
|
|
193
185
|
throw console.error(r), "The value is not Set instance";
|
|
194
186
|
} : (r) => r;
|
|
195
|
-
if (typeof
|
|
196
|
-
|
|
197
|
-
else if ("storeKey" in
|
|
198
|
-
|
|
199
|
-
else return
|
|
200
|
-
const
|
|
201
|
-
if (
|
|
202
|
-
const r = `${
|
|
203
|
-
r in
|
|
187
|
+
if (typeof n == "string")
|
|
188
|
+
w = n;
|
|
189
|
+
else if ("storeKey" in n)
|
|
190
|
+
M = n.warnOnDuplicateStoreKey ?? M, v = n.listenStorageChanges ?? v, w = n.storeKey, V = n.unzipValue ?? V, C = n.zipValue ?? C, B = n.unchangable ?? B, b = n.securifyKeyLevel ?? L.securifyKeyLevel ?? b, T = n.securifyValueLevel ?? L.securifyValueLevel ?? T, j = n.exp ?? j;
|
|
191
|
+
else return p;
|
|
192
|
+
const F = b ? I(w, b) : w, a = `${T ? H : P}${F}`;
|
|
193
|
+
if (b) {
|
|
194
|
+
const r = `${P}${w}`;
|
|
195
|
+
r in c && (c[a] = c[r], delete c[r]);
|
|
204
196
|
} else {
|
|
205
|
-
const r = `${
|
|
206
|
-
r in
|
|
197
|
+
const r = `${P}${I(w, b)}`;
|
|
198
|
+
r in c && (c[a] = c[r], delete c[r]);
|
|
207
199
|
}
|
|
208
|
-
const
|
|
209
|
-
if (
|
|
210
|
-
const r = `${
|
|
211
|
-
if (
|
|
200
|
+
const N = j === null || !(j(p, a in c) instanceof Date) ? (r) => I([C(r)], 0) : (r) => (h ?? (h = {}), h.exp = j(p, a in c).getTime(), h.exp - Date.now() < 24 * 60 * 60 * 1e3 && (clearTimeout(Q), clearTimeout(ee[a]), Q = setTimeout(() => this.reset(), h.exp - Date.now())), h.exp = Math.trunc(h.exp / 1e3), I([C(r), h], 0));
|
|
201
|
+
if (T) {
|
|
202
|
+
const r = `${P}${F}`, m = C, D = V;
|
|
203
|
+
if (C = ($) => {
|
|
212
204
|
try {
|
|
213
|
-
return
|
|
205
|
+
return I([m($)], T);
|
|
214
206
|
} catch {
|
|
215
|
-
return delete
|
|
207
|
+
return delete c[a], "";
|
|
216
208
|
}
|
|
217
|
-
}, r in
|
|
218
|
-
const
|
|
209
|
+
}, r in c) {
|
|
210
|
+
const $ = `${P}${I(w, b)}`;
|
|
219
211
|
try {
|
|
220
|
-
|
|
212
|
+
c[$] = N(V(R(c[r], 0)[0])), delete c[r];
|
|
221
213
|
} catch {
|
|
222
214
|
}
|
|
223
215
|
}
|
|
224
|
-
|
|
216
|
+
V = ($) => {
|
|
225
217
|
try {
|
|
226
|
-
return
|
|
218
|
+
return D(R($, T)[0]);
|
|
227
219
|
} catch {
|
|
228
|
-
return delete
|
|
220
|
+
return delete c[a], "";
|
|
229
221
|
}
|
|
230
222
|
};
|
|
231
|
-
} else delete
|
|
223
|
+
} else delete c[`${H}${F}`];
|
|
232
224
|
const K = (r) => {
|
|
233
|
-
const
|
|
234
|
-
return
|
|
225
|
+
const m = R(r, 0);
|
|
226
|
+
return h = m[1], V(m[0]);
|
|
235
227
|
};
|
|
236
228
|
let X = !0;
|
|
237
|
-
if (
|
|
238
|
-
if (
|
|
229
|
+
if (J[a] = p, c[`atom/${w}`] && (c[a] || (c[a] = `[${c[`atom/${w}`]}]`), delete c[`atom/${w}`]), l = () => {
|
|
230
|
+
if (l = o, X) {
|
|
239
231
|
X = !1;
|
|
240
232
|
try {
|
|
241
|
-
|
|
233
|
+
s(a in c ? K(c[a]) : e);
|
|
242
234
|
} catch {
|
|
243
|
-
console.warn("Invalid json value",
|
|
235
|
+
console.warn("Invalid json value", c[a]);
|
|
244
236
|
}
|
|
245
237
|
}
|
|
246
|
-
return
|
|
247
|
-
},
|
|
248
|
-
if (r ===
|
|
238
|
+
return o();
|
|
239
|
+
}, A = (r) => {
|
|
240
|
+
if (r === e) {
|
|
249
241
|
this.reset();
|
|
250
242
|
return;
|
|
251
243
|
}
|
|
252
|
-
|
|
244
|
+
c[a] = N(r);
|
|
253
245
|
}, this.reset = () => {
|
|
254
|
-
delete
|
|
255
|
-
},
|
|
256
|
-
if (
|
|
257
|
-
let r = !1,
|
|
258
|
-
|
|
259
|
-
clearTimeout(
|
|
246
|
+
delete c[a], S(e, !0);
|
|
247
|
+
}, M && _[a] !== void 0 && console.warn("Duplicate Atom key", w), v)
|
|
248
|
+
if (B) {
|
|
249
|
+
let r = !1, m;
|
|
250
|
+
q[a] = this, _[a] = () => {
|
|
251
|
+
clearTimeout(m), m = setTimeout(() => r = !1, 10), !r && (r = !0, c[a] = N(o()));
|
|
260
252
|
};
|
|
261
253
|
} else
|
|
262
|
-
|
|
254
|
+
_[a] = (r) => {
|
|
263
255
|
if (r.newValue === null) {
|
|
264
256
|
this.reset();
|
|
265
257
|
return;
|
|
266
258
|
}
|
|
267
259
|
try {
|
|
268
|
-
|
|
260
|
+
S(K(r.newValue));
|
|
269
261
|
} catch {
|
|
270
262
|
console.warn("Invalid json value", r.newValue);
|
|
271
263
|
}
|
|
272
264
|
};
|
|
273
|
-
return
|
|
265
|
+
return p;
|
|
274
266
|
}
|
|
275
267
|
}
|
|
276
|
-
let
|
|
268
|
+
let W;
|
|
277
269
|
try {
|
|
278
|
-
|
|
279
|
-
var
|
|
280
|
-
(
|
|
270
|
+
W = new BroadcastChannel("updateHere"), W.addEventListener("message", (t) => {
|
|
271
|
+
var e;
|
|
272
|
+
(e = q[t.data.key]) == null || e.set(t.data.value, !0);
|
|
281
273
|
});
|
|
282
274
|
} catch {
|
|
283
275
|
}
|
|
284
|
-
const
|
|
285
|
-
throw `${
|
|
276
|
+
const c = localStorage, _ = {}, q = {}, ye = (t, e) => {
|
|
277
|
+
throw `${e} is readonly property`;
|
|
286
278
|
};
|
|
287
|
-
window.addEventListener("storage", (
|
|
288
|
-
var
|
|
289
|
-
|
|
279
|
+
window.addEventListener("storage", (t) => {
|
|
280
|
+
var e;
|
|
281
|
+
t.key === null || t.newValue === t.oldValue || (e = _[t.key]) == null || e.call(_, t);
|
|
290
282
|
});
|
|
291
|
-
const
|
|
292
|
-
|
|
293
|
-
|
|
283
|
+
const ge = c.setItem.bind(c), pe = c.removeItem.bind(c);
|
|
284
|
+
c.setItem = (t, e) => {
|
|
285
|
+
q[t] === void 0 && ge.call(c, t, e);
|
|
294
286
|
};
|
|
295
|
-
|
|
296
|
-
|
|
287
|
+
c.removeItem = (t) => {
|
|
288
|
+
q[t] === void 0 && pe.call(c, t);
|
|
297
289
|
};
|
|
298
|
-
const
|
|
299
|
-
for (let
|
|
300
|
-
if (
|
|
301
|
-
const
|
|
302
|
-
|
|
290
|
+
const we = /"exp":\s*(\d+)/, P = "atom\\", H = "atom`s\\", J = {}, ee = {}, te = /[a-z]/gi, U = 5, G = {};
|
|
291
|
+
for (let t = 54; t < 80; t++) {
|
|
292
|
+
if (t === 68 || t === 72 || t === 55) continue;
|
|
293
|
+
const e = String.fromCharCode(t + 43).toUpperCase(), n = String.fromCharCode(t + 43).toLowerCase();
|
|
294
|
+
G[e] = n, G[n] = e;
|
|
303
295
|
}
|
|
304
|
-
const se = (
|
|
305
|
-
const
|
|
306
|
-
(
|
|
307
|
-
(
|
|
308
|
-
(
|
|
309
|
-
const
|
|
310
|
-
return `${
|
|
296
|
+
const se = (t) => G[t] ?? t, I = /* @__PURE__ */ (() => {
|
|
297
|
+
const t = [
|
|
298
|
+
(e) => JSON.stringify(e),
|
|
299
|
+
(e) => btoa(encodeURI(t[0](e))),
|
|
300
|
+
(e) => {
|
|
301
|
+
const n = t[1](e);
|
|
302
|
+
return `${n.slice(0, U)}${n.slice(U).replace(te, se)}`;
|
|
311
303
|
},
|
|
312
|
-
(
|
|
304
|
+
(e) => btoa(t[2](e))
|
|
313
305
|
];
|
|
314
|
-
return (
|
|
306
|
+
return (e, n) => {
|
|
315
307
|
try {
|
|
316
|
-
return
|
|
317
|
-
} catch (
|
|
318
|
-
if (
|
|
319
|
-
return
|
|
308
|
+
return t[n](e);
|
|
309
|
+
} catch (s) {
|
|
310
|
+
if (n === 0) throw s;
|
|
311
|
+
return t[0](e);
|
|
320
312
|
}
|
|
321
313
|
};
|
|
322
|
-
})(),
|
|
323
|
-
const
|
|
324
|
-
(
|
|
325
|
-
(
|
|
326
|
-
(
|
|
327
|
-
`${
|
|
314
|
+
})(), R = /* @__PURE__ */ (() => {
|
|
315
|
+
const t = [
|
|
316
|
+
(e) => JSON.parse(e),
|
|
317
|
+
(e) => t[0](decodeURI(atob(e))),
|
|
318
|
+
(e) => t[1](
|
|
319
|
+
`${e.slice(0, U)}${e.slice(U).replace(te, se)}`
|
|
328
320
|
),
|
|
329
|
-
(
|
|
321
|
+
(e) => t[2](atob(e))
|
|
330
322
|
];
|
|
331
|
-
return (
|
|
323
|
+
return (e, n) => {
|
|
332
324
|
try {
|
|
333
|
-
return
|
|
334
|
-
} catch (
|
|
335
|
-
if (
|
|
336
|
-
return
|
|
325
|
+
return t[n](e);
|
|
326
|
+
} catch (s) {
|
|
327
|
+
if (n === 0) throw s;
|
|
328
|
+
return t[0](e);
|
|
337
329
|
}
|
|
338
330
|
};
|
|
339
331
|
})();
|
|
340
332
|
setTimeout(() => {
|
|
341
|
-
Object.keys(
|
|
342
|
-
var
|
|
343
|
-
if (typeof
|
|
344
|
-
const
|
|
345
|
-
if (!
|
|
346
|
-
const
|
|
347
|
-
!Array.isArray(
|
|
348
|
-
|
|
349
|
-
},
|
|
333
|
+
Object.keys(c).forEach((t) => {
|
|
334
|
+
var s;
|
|
335
|
+
if (typeof c[t] != "string" || !t.startsWith(P) && !t.startsWith(H)) return;
|
|
336
|
+
const e = +((s = c[t].match(we)) == null ? void 0 : s[1]);
|
|
337
|
+
if (!e || e * 1e3 - Date.now() > 24 * 60 * 60 * 1e3) return;
|
|
338
|
+
const n = R(c[t], 0);
|
|
339
|
+
!Array.isArray(n) || n[1] == null || !("exp" in n[1]) || n[1].exp !== e || (ee[t] = setTimeout(() => {
|
|
340
|
+
J[t] ? J[t].reset() : delete c[t];
|
|
341
|
+
}, e * 1e3 - Date.now()));
|
|
350
342
|
});
|
|
351
343
|
}, 1e3);
|
|
352
344
|
export {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
345
|
+
de as Atom,
|
|
346
|
+
ie as AtomArrayDoActions,
|
|
347
|
+
ue as AtomBooleanDoActions,
|
|
348
|
+
le as AtomNumberDoActions,
|
|
349
|
+
fe as AtomObjectDoActions,
|
|
350
|
+
he as AtomSetDoActions,
|
|
351
|
+
$e as atom,
|
|
352
|
+
Ae as configureAtomaric,
|
|
353
|
+
L as configuredOptions,
|
|
354
|
+
De as useAtom,
|
|
355
|
+
be as useAtomDo,
|
|
356
|
+
xe as useAtomGet,
|
|
357
|
+
oe as useAtomSet,
|
|
358
|
+
Se as useAtomSetDeferred,
|
|
362
359
|
ne as useAtomValue
|
|
363
360
|
};
|
package/build/atomaric.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(l,j){typeof exports=="object"&&typeof module<"u"?j(exports):typeof define=="function"&&define.amd?define(["exports"],j):(l=typeof globalThis<"u"?globalThis:l||self,j(l.atomaric={}))})(this,function(l){"use strict";let j=()=>{throw"call configureAtomaric() before all!"};const D={},he=t=>{D.useSyncExternalStore=j=t.useSyncExternalStore,D.keyPathSeparator=t.keyPathSeparator,D.securifyKeyLevel=t.securifyKeyLevel,D.securifyValueLevel=t.securifyValueLevel},X=t=>j(t.subscribe,t.get),Y=t=>t.set,me=t=>t.setDeferred,de=t=>t.get,Ae=t=>t.do,ye=t=>[X(t),Y(t)],ge=(t,e)=>new ne(t,e);class z{constructor(e){if(e)return new Proxy(this,{get:(n,s)=>s in this?n[s]:e[s]})}}const we=(t,e)=>{const n=(s,o,c)=>new Proxy(s,{get:(a,h,y)=>{const A=c===0&&e.get!=null?e.get(a,h,y):a[h];return typeof A=="object"&&A!==null?n(Array.isArray(A)?A.slice(0):{...A},o.concat(Array.isArray(a)?+h:h),c+1):A},set:(a,h,y)=>(e.onSet(a,o,h,y,a[h])&&(a[h]=y),!0)});return n(t,[],0)};class Z extends z{constructor(){super(...arguments),this.updateValue=(e,n)=>{const s=Array.isArray(e)?e.slice(0):{...e};let o=!1;const c=we(e,{onSet:(a,h,y,A,g)=>{if(A===g)return!0;let S=s;o=!0;for(const f of h){const m=S[f];S=S[f]=Array.isArray(m)?m.slice(0):{...m}}return S[y]=A,!0}});return n(c),o?s:e}}}class k extends Z{constructor(e,n){super(n),this.atom=e,this.push=(...s)=>{this.atom.set(this.atom.get().concat(s))},this.unshift=(...s)=>{this.atom.set(s.concat(this.atom.get()))},this.update=s=>{const o=this.atom.get(),c=this.updateValue(o,s);c!==o&&this.atom.set(c)},this.filter=s=>{this.atom.set(this.atom.get().filter(s??pe))},this.add=s=>{this.atom.get().includes(s)||this.atom.set(this.atom.get().concat([s]))},this.remove=s=>{const o=this.atom.get().indexOf(s);if(o<0)return;const c=this.atom.get().slice(0);c.splice(o,1),this.atom.set(c)},this.toggle=(s,o)=>{const c=this.atom.get().slice(),a=c.indexOf(s);a<0?o?c.unshift(s):c.push(s):c.splice(a,1),this.atom.set(c)}}}const pe=t=>t;class O extends z{constructor(e,n){super(n),this.atom=e,this.toggle=()=>{this.atom.set(!this.atom.get())}}}class ee extends z{constructor(e,n){super(n),this.atom=e,this.increment=s=>{this.atom.set(+this.atom.get()+(s??1))}}}class te extends Z{constructor(e,n){super(n),this.atom=e,this.setPartial=s=>this.atom.set(o=>({...o,...typeof s=="function"?s(this.atom.get()):s})),this.update=s=>{const o=this.atom.get(),c=this.updateValue(o,s);c!==o&&this.atom.set(c)},this.setDeepPartial=(s,o,c,a=D.keyPathSeparator||".")=>{if(!a)return;if(s.includes(a)){let A=s.split(a);const g=A[A.length-1];A=A.slice(0,-1);const S={...this.atom.get()};let f=S,m=c;for(const w of A){m=m==null?void 0:m[Array.isArray(m)?"0":w];const x=f[se(f,w)]??(Array.isArray(m)?[]:{});if(x==null||typeof x!="object"){if(c==null)throw"Incorrect path for setDeepPartial";const b=typeof o=="function"?o(void 0):o;this.atom.get()[s]!==b&&this.setPartial({[s]:b});return}f=f[se(f,w)]=Array.isArray(x)?[...x]:{...x}}const v=f[g];f[g]=typeof o=="function"?o(f[g]):o,v!==f[g]&&this.atom.set(S);return}const h=this.atom.get()[s],y=typeof o=="function"?o(h):o;y!==h&&this.setPartial({[s]:y})}}}const se=(t,e)=>Array.isArray(t)?`${+e}`:e;class re extends z{constructor(e,n){super(n),this.atom=e,this.add=s=>{this.atom.set(new Set(this.atom.get()).add(s))},this.delete=s=>{const o=new Set(this.atom.get());o.delete(s),this.atom.set(o)},this.toggle=s=>{const o=new Set(this.atom.get());o.has(s)?o.delete(s):o.add(s),this.atom.set(o)},this.clear=()=>{this.atom.set(new Set)},this.atom=e}}const Se=(t,e,n)=>{const s=typeof n=="object"&&n!=null&&"do"in n?n.do((c,a)=>e.set(c,a),()=>e.get(),e,(c,a,h)=>e.setDeferred(c,a,h)):null,o={};return s&&Object.keys(s).forEach(c=>Object.defineProperty(o,c,{get:()=>s[c]})),typeof t=="number"?new ee(e,s):typeof t=="boolean"?new O(e,s):Array.isArray(t)?new k(e,s):t instanceof Set?new re(e,s):t instanceof Object?new te(e,s):new z(s)};class ne{constructor(e,n){e=typeof e=="function"?e():e;const s=r=>A=r,o=()=>A,c=new Set,a=r=>r(f());let h=!0,y=!1,A=e,g,S=()=>{},f=()=>o(),m=null,v=()=>{const r=Se(e,w,n);return v=()=>r,r};const w=new Proxy(this,{get:(r,d)=>d==="do"?v():r[d],set:be}),x=()=>{h=!0,y!==!0&&S(f()),y=!1;try{B.postMessage({key:u,value:o()})}catch{}},b=(r,d)=>{const T=typeof r=="function"?r(f()):r;T!==f()&&(s(T),y=d,h&&(h=!1,c.forEach(a),queueMicrotask(x)))};this.set=(r,d)=>b(r,d),this.get=()=>f(),this.initialValue=e,this.isInitialValue=()=>e===o(),this.subscribe=r=>(c.add(r),()=>{c.delete(r)}),this.reset=()=>{b(e,!0)};const Te=(r,d)=>{b(r,d),g=void 0};if(this.setDeferred=(r,d=500,T,V=!0)=>{V&&g===void 0&&b(r,T),clearTimeout(g),g=setTimeout(Te,d,r,T)},n==null)return w;let p=null,R=null,G=!0,H=!0,J=!1,$=0,I=0,ue=-1,_=e instanceof Set?r=>new Set(r):r=>r,E=e instanceof Set?r=>{if(r instanceof Set)return Array.from(r);throw console.error(r),"The value is not Set instance"}:r=>r;if(typeof n=="string")p=n;else if("storeKey"in n)G=n.warnOnDuplicateStoreKey??G,H=n.listenStorageChanges??H,p=n.storeKey,_=n.unzipValue??_,E=n.zipValue??E,J=n.unchangable??J,$=n.securifyKeyLevel??D.securifyKeyLevel??$,I=n.securifyValueLevel??D.securifyValueLevel??I,R=n.exp??R;else return w;const Q=$?C(p,$):p,u=`${I?N:P}${Q}`;if($){const r=`${P}${p}`;r in i&&(i[u]=i[r],delete i[r])}else{const r=`${P}${C(p,$)}`;r in i&&(i[u]=i[r],delete i[r])}const K=R===null||!(R(w,u in i)instanceof Date)?r=>C([E(r)],0):r=>(m??(m={}),m.exp=R(w,u in i).getTime(),m.exp-Date.now()<24*60*60*1e3&&(clearTimeout(ue),clearTimeout(oe[u]),ue=setTimeout(()=>this.reset(),m.exp-Date.now())),m.exp=Math.trunc(m.exp/1e3),C([E(r),m],0));if(I){const r=`${P}${Q}`,d=E,T=_;if(E=V=>{try{return C([d(V)],I)}catch{return delete i[u],""}},r in i){const V=`${P}${C(p,$)}`;try{i[V]=K(_(q(i[r],0)[0])),delete i[r]}catch{}}_=V=>{try{return T(q(V,I)[0])}catch{return delete i[u],""}}}else delete i[`${N}${Q}`];const ae=r=>{const d=q(r,0);return m=d[1],_(d[0])};let le=!0;if(F[u]=w,i[`atom/${p}`]&&(i[u]||(i[u]=`[${i[`atom/${p}`]}]`),delete i[`atom/${p}`]),f=()=>{if(f=o,le){le=!1;try{s(u in i?ae(i[u]):e)}catch{console.warn("Invalid json value",i[u])}}return o()},S=r=>{if(r===e){this.reset();return}i[u]=K(r)},this.reset=()=>{delete i[u],b(e,!0)},G&&L[u]!==void 0&&console.warn("Duplicate Atom key",p),H)if(J){let r=!1,d;M[u]=this,L[u]=()=>{clearTimeout(d),d=setTimeout(()=>r=!1,10),!r&&(r=!0,i[u]=K(o()))}}else L[u]=r=>{if(r.newValue===null){this.reset();return}try{b(ae(r.newValue))}catch{console.warn("Invalid json value",r.newValue)}};return w}}let B;try{B=new BroadcastChannel("updateHere"),B.addEventListener("message",t=>{var e;(e=M[t.data.key])==null||e.set(t.data.value,!0)})}catch{}const i=localStorage,L={},M={},be=(t,e)=>{throw`${e} is readonly property`};window.addEventListener("storage",t=>{var e;t.key===null||t.newValue===t.oldValue||(e=L[t.key])==null||e.call(L,t)});const De=i.setItem.bind(i),xe=i.removeItem.bind(i);i.setItem=(t,e)=>{M[t]===void 0&&De.call(i,t,e)},i.removeItem=t=>{M[t]===void 0&&xe.call(i,t)};const $e=/"exp":\s*(\d+)/,P="atom\\",N="atom`s\\",F={},oe={},ie=/[a-z]/gi,U=5,W={};for(let t=54;t<80;t++){if(t===68||t===72||t===55)continue;const e=String.fromCharCode(t+43).toUpperCase(),n=String.fromCharCode(t+43).toLowerCase();W[e]=n,W[n]=e}const ce=t=>W[t]??t,C=(()=>{const t=[e=>JSON.stringify(e),e=>btoa(encodeURI(t[0](e))),e=>{const n=t[1](e);return`${n.slice(0,U)}${n.slice(U).replace(ie,ce)}`},e=>btoa(t[2](e))];return(e,n)=>{try{return t[n](e)}catch(s){if(n===0)throw s;return t[0](e)}}})(),q=(()=>{const t=[e=>JSON.parse(e),e=>t[0](decodeURI(atob(e))),e=>t[1](`${e.slice(0,U)}${e.slice(U).replace(ie,ce)}`),e=>t[2](atob(e))];return(e,n)=>{try{return t[n](e)}catch(s){if(n===0)throw s;return t[0](e)}}})();setTimeout(()=>{Object.keys(i).forEach(t=>{var s;if(typeof i[t]!="string"||!t.startsWith(P)&&!t.startsWith(N))return;const e=+((s=i[t].match($e))==null?void 0:s[1]);if(!e||e*1e3-Date.now()>24*60*60*1e3)return;const n=q(i[t],0);!Array.isArray(n)||n[1]==null||!("exp"in n[1])||n[1].exp!==e||(oe[t]=setTimeout(()=>{F[t]?F[t].reset():delete i[t]},e*1e3-Date.now()))})},1e3),l.Atom=ne,l.AtomArrayDoActions=k,l.AtomBooleanDoActions=O,l.AtomNumberDoActions=ee,l.AtomObjectDoActions=te,l.AtomSetDoActions=re,l.atom=ge,l.configureAtomaric=he,l.configuredOptions=D,l.useAtom=ye,l.useAtomDo=Ae,l.useAtomGet=de,l.useAtomSet=Y,l.useAtomSetDeferred=me,l.useAtomValue=X,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { useSyncExternalStore } from 'react';
|
|
2
|
+
import { AtomArrayDoActions } from '../src/do.classes/Array';
|
|
3
|
+
import { AtomBooleanDoActions } from '../src/do.classes/Boolean';
|
|
4
|
+
import { AtomNumberDoActions } from '../src/do.classes/Number';
|
|
5
|
+
import { AtomObjectDoActions } from '../src/do.classes/Object';
|
|
6
|
+
import { AtomSetDoActions } from '../src/do.classes/Set';
|
|
2
7
|
import { Path, PathValue, PathValueDonor } from './paths';
|
|
3
8
|
|
|
4
9
|
export type AtomSecureLevel = 0 | 1 | 2 | 3;
|
|
5
10
|
|
|
6
11
|
export interface Register {}
|
|
7
12
|
|
|
8
|
-
export type
|
|
13
|
+
export type ObjectActionsSetDeepPartialSeparator = Register extends {
|
|
9
14
|
keyPathSeparator: infer Separator extends string;
|
|
10
15
|
}
|
|
11
16
|
? Separator
|
|
@@ -60,79 +65,31 @@ export type AtomSetDeferredMethod<Value> = (
|
|
|
60
65
|
|
|
61
66
|
export type AtomSubscribeMethod<Value> = (subscriber: Sunscriber<Value>) => () => void;
|
|
62
67
|
|
|
63
|
-
export type
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
export type ObjectActions<Value> = UpdateAction<Value> & {
|
|
76
|
-
/** pass partial object to update some field values */
|
|
77
|
-
setPartial: (value: Partial<Value> | ((value: Value) => Partial<Value>)) => void;
|
|
78
|
-
/** pass partial value to update some deep values by flat path */
|
|
79
|
-
setDeepPartial: <
|
|
80
|
-
ValuePath extends Path<Value, Sep>,
|
|
81
|
-
Val extends PathValue<Value, Sep, ValuePath>,
|
|
82
|
-
Sep extends string = ObjectActionsSetDeepPartial,
|
|
83
|
-
>(
|
|
84
|
-
path: ValuePath,
|
|
85
|
-
value: Val | ((value: Val) => Val),
|
|
86
|
-
donor: PathValueDonor<Value, Sep, ValuePath> | null,
|
|
87
|
-
separator?: Sep,
|
|
88
|
-
) => void;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
export type BooleanActions = {
|
|
92
|
-
/** toggle current value between true/false */
|
|
93
|
-
toggle: () => void;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
export type SetActions<Value> = {
|
|
97
|
-
/** like the Set.prototype.add() method */
|
|
98
|
-
add: (value: Value) => void;
|
|
99
|
-
/** like the Set.prototype.delete() method */
|
|
100
|
-
delete: (value: Value) => void;
|
|
101
|
-
/** will add value if it doesn't exist, otherwise delete */
|
|
102
|
-
toggle: (value: Value) => void;
|
|
103
|
-
/** like the Set.prototype.clear() method */
|
|
104
|
-
clear: () => void;
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
export type ArrayActions<Value> = UpdateAction<Value[]> & {
|
|
108
|
-
/** like the Array.prototype.push() method */
|
|
109
|
-
push: (...values: Value[]) => void;
|
|
110
|
-
/** like the Array.prototype.unshift() method */
|
|
111
|
-
unshift: (...values: Value[]) => void;
|
|
112
|
-
/** like the Array.prototype.filter() method, but callback is optional - (it) => !!it */
|
|
113
|
-
filter: (filter?: (value: Value, index: number, array: Value[]) => any) => void;
|
|
114
|
-
/** will add value if it doesn't exist, otherwise delete */
|
|
115
|
-
toggle: (value: Value, isAddInStart?: boolean) => void;
|
|
116
|
-
/** will add value if not exists */
|
|
117
|
-
add: (value: Value) => void;
|
|
118
|
-
/** will delete value from array */
|
|
119
|
-
remove: (value: Value) => void;
|
|
120
|
-
};
|
|
68
|
+
export type ObjectActionsSetDeepPartialDoAction<Value> = <
|
|
69
|
+
ValuePath extends Path<Value, Sep>,
|
|
70
|
+
Val extends PathValue<Value, Sep, ValuePath>,
|
|
71
|
+
Sep extends string = ObjectActionsSetDeepPartialSeparator,
|
|
72
|
+
>(
|
|
73
|
+
path: ValuePath,
|
|
74
|
+
value: Val | ((value: Val) => Val),
|
|
75
|
+
donor: PathValueDonor<Value, Sep, ValuePath> | null,
|
|
76
|
+
separator?: Sep,
|
|
77
|
+
) => void;
|
|
121
78
|
|
|
122
79
|
export type DefaultActions<Value> = Value extends Set<infer Val>
|
|
123
|
-
?
|
|
80
|
+
? AtomSetDoActions<Val>
|
|
124
81
|
: Value extends boolean
|
|
125
|
-
?
|
|
82
|
+
? AtomBooleanDoActions
|
|
126
83
|
: Value extends (infer Val)[]
|
|
127
|
-
?
|
|
84
|
+
? AtomArrayDoActions<Val>
|
|
128
85
|
: Value extends number
|
|
129
|
-
?
|
|
86
|
+
? AtomNumberDoActions
|
|
130
87
|
: Value extends object
|
|
131
|
-
?
|
|
88
|
+
? AtomObjectDoActions<Value>
|
|
132
89
|
: {};
|
|
133
90
|
|
|
134
91
|
declare class Atom<Value, Actions extends Record<string, Function> = {}> {
|
|
135
|
-
constructor(initialValue: Value, storeKeyOrOptions: StoreKeyOrOptions<Value, Actions> | undefined);
|
|
92
|
+
constructor(initialValue: Value | (() => Value), storeKeyOrOptions: StoreKeyOrOptions<Value, Actions> | undefined);
|
|
136
93
|
|
|
137
94
|
/** initial value */
|
|
138
95
|
readonly initialValue: Value;
|
|
@@ -171,14 +128,14 @@ export type StoreKeyOrOptions<Value, Actions extends Record<string, Function> =
|
|
|
171
128
|
| AtomOptions<Value, Actions>;
|
|
172
129
|
|
|
173
130
|
export function atom<Value, Actions extends Record<string, Function> = {}>(
|
|
174
|
-
value: Value,
|
|
131
|
+
value: Value | (() => Value),
|
|
175
132
|
storeKeyOrOptions?: StoreKeyOrOptions<Value, Actions>,
|
|
176
133
|
): Atom<Value, Actions>;
|
|
177
134
|
|
|
178
135
|
/** invoke this function before all atom usages */
|
|
179
136
|
export function configureAtomaric(options: {
|
|
180
137
|
useSyncExternalStore: typeof useSyncExternalStore;
|
|
181
|
-
keyPathSeparator:
|
|
138
|
+
keyPathSeparator: ObjectActionsSetDeepPartialSeparator;
|
|
182
139
|
securifyKeyLevel?: AtomSecureLevel;
|
|
183
140
|
securifyValueLevel?: AtomSecureLevel;
|
|
184
141
|
}): void;
|