atomaric 0.0.10 → 0.0.12
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 +137 -85
- package/build/atomaric.umd.cjs +1 -1
- package/package.json +1 -1
- package/types/model.d.ts +38 -13
package/build/atomaric.js
CHANGED
|
@@ -1,76 +1,122 @@
|
|
|
1
|
-
class
|
|
1
|
+
class C {
|
|
2
|
+
constructor(s) {
|
|
3
|
+
this.value = s;
|
|
4
|
+
}
|
|
5
|
+
getValue() {
|
|
6
|
+
return this.value;
|
|
7
|
+
}
|
|
8
|
+
setValue(s) {
|
|
9
|
+
this.value = s;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
class T extends C {
|
|
2
13
|
constructor(s, n) {
|
|
3
|
-
|
|
4
|
-
}, this.invokeSubscriber = (e) => e(this.
|
|
14
|
+
super(s), this._defaultValue = s, this.subscribers = /* @__PURE__ */ new Set(), this.save = () => {
|
|
15
|
+
}, this.invokeSubscriber = (e) => e(this.get()), this.do = {}, this.get = () => super.getValue(), this.subscribe = (e) => (this.subscribers.add(e), () => {
|
|
5
16
|
this.subscribers.delete(e);
|
|
6
|
-
}), this.set = (e,
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
}, this.setDeferred = (e,
|
|
10
|
-
|
|
11
|
-
this.set(e,
|
|
12
|
-
},
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
17
|
+
}), this.set = (e, i) => {
|
|
18
|
+
const l = typeof e == "function" ? e(this.get()) : e;
|
|
19
|
+
l === this.get() || l === void 0 || typeof l == "number" && isNaN(l) || (super.setValue(l), this.subscribers.forEach(this.invokeSubscriber, this), i !== !0 && this.save(l));
|
|
20
|
+
}, this.setDeferred = (e, i = 500, l, k = !0) => {
|
|
21
|
+
k && this.debounceTimeout === void 0 && this.set(e, l), clearTimeout(this.debounceTimeout), this.debounceTimeout = setTimeout(() => {
|
|
22
|
+
this.set(e, l), delete this.debounceTimeout;
|
|
23
|
+
}, i);
|
|
24
|
+
};
|
|
25
|
+
const c = (e, i) => i;
|
|
26
|
+
let h = null;
|
|
27
|
+
typeof s == "number" && (h = c(s, {
|
|
28
|
+
increment: (e) => {
|
|
29
|
+
this.set(+this.get() + (e ?? 0));
|
|
30
|
+
}
|
|
31
|
+
})), typeof s == "boolean" && (h = c(s, {
|
|
32
|
+
toggle: () => {
|
|
33
|
+
this.set(!this.get());
|
|
34
|
+
}
|
|
35
|
+
})), Array.isArray(s) && (h = c(s, {
|
|
36
|
+
push: (e) => {
|
|
37
|
+
this.set([...this.get(), e]);
|
|
38
|
+
},
|
|
39
|
+
unshift: (e) => {
|
|
40
|
+
this.set([e, ...this.get()]);
|
|
41
|
+
},
|
|
42
|
+
update: (e) => {
|
|
43
|
+
const i = [...this.get()];
|
|
44
|
+
e(i), this.set(i);
|
|
45
|
+
},
|
|
46
|
+
filter: (e) => {
|
|
47
|
+
this.set(this.get().filter(e ?? U));
|
|
48
|
+
}
|
|
49
|
+
})), s instanceof Set && (h = c(s, {
|
|
50
|
+
add: (e) => {
|
|
51
|
+
const i = new Set(this.get());
|
|
52
|
+
i.add(e), this.set(i);
|
|
53
|
+
},
|
|
54
|
+
delete: (e) => {
|
|
55
|
+
const i = new Set(this.get());
|
|
56
|
+
i.delete(e), this.set(i);
|
|
57
|
+
},
|
|
58
|
+
clear: () => {
|
|
59
|
+
this.set(/* @__PURE__ */ new Set());
|
|
60
|
+
},
|
|
61
|
+
update: (e) => {
|
|
62
|
+
const i = new Set(this.get());
|
|
63
|
+
e(i), this.set(i);
|
|
64
|
+
}
|
|
65
|
+
}));
|
|
66
|
+
const E = typeof n == "object" && "do" in n ? n.do(
|
|
67
|
+
() => this.get(),
|
|
68
|
+
(e, i) => this.set(e, i)
|
|
69
|
+
) : {};
|
|
70
|
+
if (this.do = {
|
|
71
|
+
...E,
|
|
72
|
+
...h
|
|
73
|
+
}, this.reset = () => {
|
|
33
74
|
this.set(s, !0), this.subscribers.forEach(this.invokeSubscriber, this);
|
|
34
75
|
}, n == null) return;
|
|
35
|
-
let
|
|
76
|
+
let d = null, m = !0, S = !0, b = !1, g = s instanceof Set ? (e) => new Set(JSON.parse(e)) : (e) => JSON.parse(e), f = s instanceof Set ? (e) => {
|
|
36
77
|
if (e instanceof Set) return JSON.stringify(Array.from(e));
|
|
37
78
|
throw console.error(e), "The value is not Set instance";
|
|
38
79
|
} : (e) => JSON.stringify(e);
|
|
39
|
-
if (typeof n == "string" ?
|
|
40
|
-
const
|
|
41
|
-
let
|
|
80
|
+
if (typeof n == "string" ? d = n : "storeKey" in n && (m = n.warnOnDuplicateStoreKey ?? !0, S = n.listenStorageChanges ?? !0, d = n.storeKey, g = n.parseValue ?? g, f = n.stringifyValue ?? f, b = n.unchangable ?? b), d === null) return;
|
|
81
|
+
const o = `atom/${d}`;
|
|
82
|
+
let v = !0;
|
|
42
83
|
if (this.get = () => {
|
|
43
|
-
if (this.get = () =>
|
|
44
|
-
|
|
84
|
+
if (this.get = () => super.getValue(), v) {
|
|
85
|
+
v = !1;
|
|
45
86
|
try {
|
|
46
|
-
|
|
87
|
+
super.setValue(o in r ? g(r[o]) : s);
|
|
47
88
|
} catch {
|
|
48
|
-
console.warn("Invalid json value",
|
|
89
|
+
console.warn("Invalid json value", r[o]);
|
|
49
90
|
}
|
|
50
91
|
}
|
|
51
|
-
return
|
|
92
|
+
return super.getValue();
|
|
52
93
|
}, this.save = (e) => {
|
|
53
94
|
if (e === s) {
|
|
54
95
|
this.reset();
|
|
55
96
|
return;
|
|
56
97
|
}
|
|
57
|
-
|
|
98
|
+
r[o] = f(e), I(o);
|
|
58
99
|
}, this.reset = () => {
|
|
59
|
-
delete
|
|
60
|
-
},
|
|
61
|
-
if (
|
|
62
|
-
let e = !1;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
100
|
+
delete r[o], this.set(s, !0);
|
|
101
|
+
}, m && u[o] !== void 0 && console.warn("Duplicate Atom key", d), u[o] = {}, S)
|
|
102
|
+
if (b) {
|
|
103
|
+
let e, i = !1;
|
|
104
|
+
u[o].updateUnchangable = () => {
|
|
105
|
+
try {
|
|
106
|
+
this.set(g(r[o]), !0);
|
|
107
|
+
} catch {
|
|
108
|
+
}
|
|
109
|
+
}, a[o] = () => {
|
|
110
|
+
i || (i = !0, r[o] = f(this.get()), clearTimeout(e), e = setTimeout(() => i = !1, 100));
|
|
111
|
+
}, N();
|
|
66
112
|
} else
|
|
67
|
-
|
|
113
|
+
u[o].updatable = (e) => {
|
|
68
114
|
if (e.newValue === null) {
|
|
69
115
|
this.reset();
|
|
70
116
|
return;
|
|
71
117
|
}
|
|
72
118
|
try {
|
|
73
|
-
this.set(
|
|
119
|
+
this.set(g(e.newValue));
|
|
74
120
|
} catch {
|
|
75
121
|
console.warn("Invalid json value", e.newValue);
|
|
76
122
|
}
|
|
@@ -80,61 +126,67 @@ class v {
|
|
|
80
126
|
return this._defaultValue;
|
|
81
127
|
}
|
|
82
128
|
}
|
|
83
|
-
const
|
|
129
|
+
const r = window.localStorage, u = {}, a = {};
|
|
84
130
|
window.addEventListener("storage", (t) => {
|
|
85
|
-
var s, n,
|
|
86
|
-
t.key
|
|
131
|
+
var s, n, c;
|
|
132
|
+
t.key === null || t.newValue === t.oldValue || ((s = a[t.key]) == null || s.call(a), (c = (n = u[t.key]) == null ? void 0 : n.updatable) == null || c.call(n, t));
|
|
87
133
|
});
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
var n;
|
|
91
|
-
(
|
|
134
|
+
const A = new BroadcastChannel("unchangableChanged");
|
|
135
|
+
A.addEventListener("message", (t) => {
|
|
136
|
+
var s, n;
|
|
137
|
+
(n = (s = u[t.data]) == null ? void 0 : s.updateUnchangable) == null || n.call(s);
|
|
138
|
+
});
|
|
139
|
+
const I = (t) => {
|
|
140
|
+
A.postMessage(t);
|
|
141
|
+
}, D = r.setItem.bind(r), L = r.removeItem.bind(r), j = r.clear.bind(r);
|
|
142
|
+
r.setItem = (t, s) => {
|
|
143
|
+
a[t] === void 0 && D.call(r, t, s);
|
|
144
|
+
};
|
|
145
|
+
r.removeItem = (t) => {
|
|
146
|
+
a[t] === void 0 && L.call(r, t);
|
|
92
147
|
};
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
((s = a[t]) == null ? void 0 : s.unchangable) === void 0 && I.call(i, t);
|
|
148
|
+
r.clear = () => {
|
|
149
|
+
j(), w();
|
|
96
150
|
};
|
|
97
|
-
|
|
151
|
+
let p = r.length;
|
|
152
|
+
const w = () => {
|
|
153
|
+
p !== r.length && (p = r.length, Object.keys(a).forEach((t) => {
|
|
154
|
+
t in r || (I(t), a[t]());
|
|
155
|
+
}));
|
|
156
|
+
}, N = /* @__PURE__ */ (() => {
|
|
98
157
|
let t = !1;
|
|
99
158
|
return () => {
|
|
100
159
|
if (t) return;
|
|
101
160
|
t = !0;
|
|
102
161
|
let s;
|
|
103
162
|
const n = () => {
|
|
104
|
-
|
|
105
|
-
const c = () => {
|
|
106
|
-
r !== i.length && (r = i.length, Object.keys(a).forEach((b) => {
|
|
107
|
-
var u, f;
|
|
108
|
-
b in i || (f = (u = a[b]) == null ? void 0 : u.unchangable) == null || f.call(u);
|
|
109
|
-
}));
|
|
110
|
-
};
|
|
111
|
-
c(), s = setInterval(c, 100);
|
|
163
|
+
clearInterval(s), s = setInterval(w, 0), w();
|
|
112
164
|
};
|
|
113
|
-
window.addEventListener("focus", () => clearInterval(s)), window.addEventListener("blur", n);
|
|
165
|
+
n(), window.addEventListener("focus", () => clearInterval(s), !0), window.addEventListener("focus", () => clearInterval(s), !1), window.addEventListener("click", () => clearInterval(s), !1), window.addEventListener("click", () => clearInterval(s), !0), window.addEventListener("blur", n, !0);
|
|
114
166
|
};
|
|
115
167
|
})();
|
|
116
168
|
(() => {
|
|
117
169
|
const t = (n) => {
|
|
118
|
-
var
|
|
119
|
-
n in
|
|
120
|
-
}, s = () => Object.keys(
|
|
170
|
+
var c;
|
|
171
|
+
n in r || (c = a[n]) == null || c.call(a);
|
|
172
|
+
}, s = () => Object.keys(u).forEach(t);
|
|
121
173
|
Object.defineProperty(window, "localStorage", {
|
|
122
|
-
get: () => (Promise.resolve().then(s),
|
|
174
|
+
get: () => (Promise.resolve().then(s), r)
|
|
123
175
|
});
|
|
124
176
|
})();
|
|
125
|
-
|
|
177
|
+
const U = (t) => t;
|
|
178
|
+
let y = () => {
|
|
126
179
|
throw "call configureAtomaric() before all!";
|
|
127
180
|
};
|
|
128
|
-
const
|
|
181
|
+
const J = (t) => y = t.useSyncExternalStore, V = (t) => y(t.subscribe, t.get), x = (t) => t.set, B = (t) => t.setDeferred, G = (t) => t.get, M = (t) => t.do, P = (t) => [V(t), x(t)], R = (t, s) => new T(t, s);
|
|
129
182
|
export {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
y as useAtomValue
|
|
183
|
+
T as Atom,
|
|
184
|
+
R as atom,
|
|
185
|
+
J as configureAtomaric,
|
|
186
|
+
P as useAtom,
|
|
187
|
+
M as useAtomDo,
|
|
188
|
+
G as useAtomGet,
|
|
189
|
+
x as useAtomSet,
|
|
190
|
+
B as useAtomSetDeferred,
|
|
191
|
+
V as useAtomValue
|
|
140
192
|
};
|
package/build/atomaric.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(o,
|
|
1
|
+
(function(o,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(o=typeof globalThis<"u"?globalThis:o||self,d(o.atomaric={}))})(this,function(o){"use strict";class d{constructor(s){this.value=s}getValue(){return this.value}setValue(s){this.value=s}}class v extends d{constructor(s,n){super(s),this._defaultValue=s,this.subscribers=new Set,this.save=()=>{},this.invokeSubscriber=e=>e(this.get()),this.do={},this.get=()=>super.getValue(),this.subscribe=e=>(this.subscribers.add(e),()=>{this.subscribers.delete(e)}),this.set=(e,r)=>{const l=typeof e=="function"?e(this.get()):e;l===this.get()||l===void 0||typeof l=="number"&&isNaN(l)||(super.setValue(l),this.subscribers.forEach(this.invokeSubscriber,this),r!==!0&&this.save(l))},this.setDeferred=(e,r=500,l,$=!0)=>{$&&this.debounceTimeout===void 0&&this.set(e,l),clearTimeout(this.debounceTimeout),this.debounceTimeout=setTimeout(()=>{this.set(e,l),delete this.debounceTimeout},r)};const u=(e,r)=>r;let f=null;typeof s=="number"&&(f=u(s,{increment:e=>{this.set(+this.get()+(e??0))}})),typeof s=="boolean"&&(f=u(s,{toggle:()=>{this.set(!this.get())}})),Array.isArray(s)&&(f=u(s,{push:e=>{this.set([...this.get(),e])},unshift:e=>{this.set([e,...this.get()])},update:e=>{const r=[...this.get()];e(r),this.set(r)},filter:e=>{this.set(this.get().filter(e??U))}})),s instanceof Set&&(f=u(s,{add:e=>{const r=new Set(this.get());r.add(e),this.set(r)},delete:e=>{const r=new Set(this.get());r.delete(e),this.set(r)},clear:()=>{this.set(new Set)},update:e=>{const r=new Set(this.get());e(r),this.set(r)}}));const W=typeof n=="object"&&"do"in n?n.do(()=>this.get(),(e,r)=>this.set(e,r)):{};if(this.do={...W,...f},this.reset=()=>{this.set(s,!0),this.subscribers.forEach(this.invokeSubscriber,this)},n==null)return;let g=null,D=!0,k=!0,w=!1,m=s instanceof Set?e=>new Set(JSON.parse(e)):e=>JSON.parse(e),b=s instanceof Set?e=>{if(e instanceof Set)return JSON.stringify(Array.from(e));throw console.error(e),"The value is not Set instance"}:e=>JSON.stringify(e);if(typeof n=="string"?g=n:"storeKey"in n&&(D=n.warnOnDuplicateStoreKey??!0,k=n.listenStorageChanges??!0,g=n.storeKey,m=n.parseValue??m,b=n.stringifyValue??b,w=n.unchangable??w),g===null)return;const a=`atom/${g}`;let C=!0;if(this.get=()=>{if(this.get=()=>super.getValue(),C){C=!1;try{super.setValue(a in i?m(i[a]):s)}catch{console.warn("Invalid json value",i[a])}}return super.getValue()},this.save=e=>{if(e===s){this.reset();return}i[a]=b(e),p(a)},this.reset=()=>{delete i[a],this.set(s,!0)},D&&h[a]!==void 0&&console.warn("Duplicate Atom key",g),h[a]={},k)if(w){let e,r=!1;h[a].updateUnchangable=()=>{try{this.set(m(i[a]),!0)}catch{}},c[a]=()=>{r||(r=!0,i[a]=b(this.get()),clearTimeout(e),e=setTimeout(()=>r=!1,100))},N()}else h[a].updatable=e=>{if(e.newValue===null){this.reset();return}try{this.set(m(e.newValue))}catch{console.warn("Invalid json value",e.newValue)}}}get defaultValue(){return this._defaultValue}}const i=window.localStorage,h={},c={};window.addEventListener("storage",t=>{var s,n,u;t.key===null||t.newValue===t.oldValue||((s=c[t.key])==null||s.call(c),(u=(n=h[t.key])==null?void 0:n.updatable)==null||u.call(n,t))});const A=new BroadcastChannel("unchangableChanged");A.addEventListener("message",t=>{var s,n;(n=(s=h[t.data])==null?void 0:s.updateUnchangable)==null||n.call(s)});const p=t=>{A.postMessage(t)},j=i.setItem.bind(i),L=i.removeItem.bind(i),V=i.clear.bind(i);i.setItem=(t,s)=>{c[t]===void 0&&j.call(i,t,s)},i.removeItem=t=>{c[t]===void 0&&L.call(i,t)},i.clear=()=>{V(),S()};let y=i.length;const S=()=>{y!==i.length&&(y=i.length,Object.keys(c).forEach(t=>{t in i||(p(t),c[t]())}))},N=(()=>{let t=!1;return()=>{if(t)return;t=!0;let s;const n=()=>{clearInterval(s),s=setInterval(S,0),S()};n(),window.addEventListener("focus",()=>clearInterval(s),!0),window.addEventListener("focus",()=>clearInterval(s),!1),window.addEventListener("click",()=>clearInterval(s),!1),window.addEventListener("click",()=>clearInterval(s),!0),window.addEventListener("blur",n,!0)}})();(()=>{const t=n=>{var u;n in i||(u=c[n])==null||u.call(c)},s=()=>Object.keys(h).forEach(t);Object.defineProperty(window,"localStorage",{get:()=>(Promise.resolve().then(s),i)})})();const U=t=>t;let I=()=>{throw"call configureAtomaric() before all!"};const J=t=>I=t.useSyncExternalStore,E=t=>I(t.subscribe,t.get),T=t=>t.set,G=t=>t.setDeferred,M=t=>t.get,P=t=>t.do,B=t=>[E(t),T(t)],R=(t,s)=>new v(t,s);o.Atom=v,o.atom=R,o.configureAtomaric=J,o.useAtom=B,o.useAtomDo=P,o.useAtomGet=M,o.useAtomSet=T,o.useAtomSetDeferred=G,o.useAtomValue=E,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
package/types/model.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ type Sunscriber<Value> = (value: Value) => void;
|
|
|
2
2
|
|
|
3
3
|
export type AtomStoreKey = `${string}${string}:${string}${string}`;
|
|
4
4
|
|
|
5
|
-
export type AtomOptions<Value, Actions extends Record<string, Function
|
|
5
|
+
export type AtomOptions<Value, Actions extends Record<string, Function> = {}> = {
|
|
6
6
|
/** **default: true** */
|
|
7
7
|
warnOnDuplicateStoreKey?: boolean;
|
|
8
8
|
/** will update value if localStorage value is changed
|
|
@@ -23,7 +23,7 @@ export type AtomOptions<Value, Actions extends Record<string, Function>> = {
|
|
|
23
23
|
storeKey: AtomStoreKey;
|
|
24
24
|
}
|
|
25
25
|
| {
|
|
26
|
-
do: (get: () => Value, set: (value: Value) => void) => Actions;
|
|
26
|
+
do: (get: () => Value, set: (value: Value, isPreventSave?: boolean) => void) => Actions;
|
|
27
27
|
}
|
|
28
28
|
);
|
|
29
29
|
|
|
@@ -37,13 +37,41 @@ export type AtomSetDeferredMethod<Value> = (
|
|
|
37
37
|
|
|
38
38
|
export type AtomSubscribeMethod<Value> = (subscriber: Sunscriber<Value>) => () => void;
|
|
39
39
|
|
|
40
|
-
export type
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
export type UpdateAction<Value> = {
|
|
41
|
+
update: (updater: (value: Value) => void) => void;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type NumberActions<Value> = {
|
|
45
|
+
increment: (delta?: number) => void;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export type BooleanActions<Value> = {
|
|
49
|
+
toggle: () => void;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export type SetActions<Value> = UpdateAction<Value> & {
|
|
53
|
+
add: (value: Value) => void;
|
|
54
|
+
delete: (value: Value) => void;
|
|
43
55
|
clear: () => void;
|
|
44
56
|
};
|
|
45
57
|
|
|
46
|
-
export
|
|
58
|
+
export type ArrayActions<Value> = UpdateAction<Value[]> & {
|
|
59
|
+
push: (value: Value) => void;
|
|
60
|
+
unshift: (value: Value) => void;
|
|
61
|
+
filter: (filter?: (value: Value, index: number, array: Value[]) => any) => void;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export type DefaultActions<Value> = Value extends Set<infer V>
|
|
65
|
+
? SetActions<V>
|
|
66
|
+
: Value extends boolean
|
|
67
|
+
? BooleanActions<Value>
|
|
68
|
+
: Value extends (infer Val)[]
|
|
69
|
+
? ArrayActions<Val>
|
|
70
|
+
: Value extends number
|
|
71
|
+
? NumberActions<Value>
|
|
72
|
+
: {};
|
|
73
|
+
|
|
74
|
+
export class Atom<Value, Actions extends Record<string, Function> = {}> {
|
|
47
75
|
constructor(defaultValue: Value, storeKeyOrOptions: AtomStoreKey | undefined | AtomOptions<Value, Actions>);
|
|
48
76
|
|
|
49
77
|
readonly defaultValue: Value;
|
|
@@ -51,26 +79,23 @@ export class Atom<Value, Actions extends Record<string, Function>> {
|
|
|
51
79
|
readonly set: AtomSetMethod<Value>;
|
|
52
80
|
readonly setDeferred: AtomSetDeferredMethod<Value>;
|
|
53
81
|
readonly reset: () => void;
|
|
54
|
-
readonly toggle: () => void;
|
|
55
|
-
readonly inkrement: (delta: number) => void;
|
|
56
82
|
readonly subscribe: AtomSubscribeMethod<Value>;
|
|
57
|
-
do: Actions &
|
|
83
|
+
do: Actions & DefaultActions<Value>;
|
|
58
84
|
}
|
|
59
85
|
|
|
60
86
|
export function useAtomValue<Value>(atom: Atom<Value>): Value;
|
|
61
87
|
export function useAtomSet<Value>(atom: Atom<Value>): (typeof atom)['set'];
|
|
62
88
|
export function useAtomSetDeferred<Value>(atom: Atom<Value>): (typeof atom)['setDeferred'];
|
|
63
89
|
export function useAtomGet<Value>(atom: Atom<Value>): (typeof atom)['get'];
|
|
64
|
-
export function
|
|
65
|
-
export function useAtomInkrement(atom: Atom<number>): (typeof atom)['inkrement'];
|
|
90
|
+
export function useAtomDo<Value>(atom: Atom<Value>): (typeof atom)['do'];
|
|
66
91
|
|
|
67
92
|
export function useAtom<Value>(atom: Atom<Value>): [Value, (typeof atom)['set']];
|
|
68
93
|
|
|
69
|
-
export type StoreKeyOrOptions<Value, Actions extends Record<string, Function
|
|
94
|
+
export type StoreKeyOrOptions<Value, Actions extends Record<string, Function> = {}> =
|
|
70
95
|
| `${string}${string}:${string}${string}`
|
|
71
96
|
| AtomOptions<Value, Actions>;
|
|
72
97
|
|
|
73
|
-
export function atom<Value, Actions extends Record<string, Function
|
|
98
|
+
export function atom<Value, Actions extends Record<string, Function> = {}>(
|
|
74
99
|
value: Value,
|
|
75
100
|
storeKeyOrOptions?: StoreKeyOrOptions<Value, Actions>,
|
|
76
101
|
): Atom<Value, Actions>;
|