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