atomaric 0.0.23 → 0.0.25

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 CHANGED
@@ -1,139 +1,140 @@
1
- const x = (t, e, i) => {
2
- let l = null;
3
- typeof t == "number" ? l = y(
1
+ const x = (t, e, c) => {
2
+ let u = null;
3
+ typeof t == "number" ? u = y(
4
4
  {
5
- increment: (s) => {
6
- e.set(+e.get() + (s ?? 0));
5
+ increment: (n) => {
6
+ e.set(+e.get() + (n ?? 0));
7
7
  }
8
8
  }
9
- ) : typeof t == "boolean" ? l = y(
9
+ ) : typeof t == "boolean" ? u = y(
10
10
  {
11
11
  toggle: () => {
12
12
  e.set(!e.get());
13
13
  }
14
14
  }
15
- ) : Array.isArray(t) ? l = y(
15
+ ) : Array.isArray(t) ? u = y(
16
16
  {
17
- push: (...s) => {
18
- e.set(e.get().concat(s));
17
+ push: (...n) => {
18
+ e.set(e.get().concat(n));
19
19
  },
20
- unshift: (...s) => {
21
- e.set(s.concat(e.get()));
20
+ unshift: (...n) => {
21
+ e.set(n.concat(e.get()));
22
22
  },
23
- update: (s) => {
23
+ update: (n) => {
24
24
  const r = e.get().slice();
25
- s(r), e.set(r);
25
+ n(r), e.set(r);
26
26
  },
27
- filter: (s) => {
28
- e.set(e.get().filter(s ?? J));
27
+ filter: (n) => {
28
+ e.set(e.get().filter(n ?? J));
29
29
  }
30
30
  }
31
- ) : t instanceof Set ? l = y(
31
+ ) : t instanceof Set ? u = y(
32
32
  {
33
- add: (s) => {
34
- e.set(new Set(e.get()).add(s));
33
+ add: (n) => {
34
+ e.set(new Set(e.get()).add(n));
35
35
  },
36
- delete: (s) => {
36
+ delete: (n) => {
37
37
  const r = new Set(e.get());
38
- r.delete(s), e.set(r);
38
+ r.delete(n), e.set(r);
39
39
  },
40
40
  clear: () => {
41
41
  e.set(/* @__PURE__ */ new Set());
42
42
  },
43
- update: (s) => {
43
+ update: (n) => {
44
44
  const r = new Set(e.get());
45
- s(r), e.set(r);
45
+ n(r), e.set(r);
46
46
  }
47
47
  }
48
- ) : t instanceof Object && (l = y(
48
+ ) : t instanceof Object && (u = y(
49
49
  {
50
- setPartial: (s) => e.set((r) => ({
50
+ setPartial: (n) => e.set((r) => ({
51
51
  ...r,
52
- ...typeof s == "function" ? s(e.get()) : s
52
+ ...typeof n == "function" ? n(e.get()) : n
53
53
  }))
54
54
  }
55
55
  ));
56
- const a = typeof i == "object" && i != null && "do" in i ? i.do(
57
- (s, r) => e.set(s, r),
56
+ const f = typeof c == "object" && c != null && "do" in c ? c.do(
57
+ (n, r) => e.set(n, r),
58
58
  () => e.get(),
59
- (s, r, d) => e.setDeferred(s, r, d)
60
- ) : null, g = {};
61
- return a && Object.keys(a).forEach((s) => Object.defineProperty(g, s, { get: () => a[s] })), l && Object.keys(l).forEach(
62
- (s) => Object.defineProperty(g, s, { get: () => l[s] })
63
- ), g;
59
+ void 0,
60
+ (n, r, g) => e.setDeferred(n, r, g)
61
+ ) : null, d = {};
62
+ return f && Object.keys(f).forEach((n) => Object.defineProperty(d, n, { get: () => f[n] })), u && Object.keys(u).forEach(
63
+ (n) => Object.defineProperty(d, n, { get: () => u[n] })
64
+ ), d;
64
65
  }, J = (t) => t, y = (t, e) => t;
65
66
  class F {
66
- constructor(e, i) {
67
- const l = (n) => r = n, a = () => r, g = /* @__PURE__ */ new Set(), s = (n) => n(h());
68
- let r = e, d, C = () => {
69
- }, h = () => a(), v = () => {
70
- const n = x(e, this, i);
71
- return v = () => n, n;
67
+ constructor(e, c) {
68
+ const u = (s) => r = s, f = () => r, d = /* @__PURE__ */ new Set(), n = (s) => s(h());
69
+ let r = e, g, v = () => {
70
+ }, h = () => f(), C = () => {
71
+ const s = x(e, this, c);
72
+ return C = () => s, s;
72
73
  };
73
74
  const I = new Proxy(this, {
74
- get: (n, o) => o === "do" ? v() : n[o],
75
+ get: (s, l) => l === "do" ? C() : s[l],
75
76
  set: P
76
- }), S = (n, o) => {
77
- const f = typeof n == "function" ? n(h()) : n;
78
- if (!(f === h() || f === void 0 || typeof f == "number" && isNaN(f))) {
79
- l(f), g.forEach(s, this);
77
+ }), S = (s, l) => {
78
+ const a = typeof s == "function" ? s(h()) : s;
79
+ if (!(a === h() || a === void 0 || typeof a == "number" && isNaN(a))) {
80
+ u(a), d.forEach(n, this);
80
81
  try {
81
- E.postMessage({ key: u, value: a() });
82
+ E.postMessage({ key: i, value: f() });
82
83
  } catch {
83
84
  }
84
- o !== !0 && C(f);
85
+ l !== !0 && v(a);
85
86
  }
86
87
  };
87
- if (this.set = (n, o) => S(n, o), this.get = () => h(), this.defaultValue = e, this.subscribe = (n) => (g.add(n), () => {
88
- g.delete(n);
88
+ if (this.set = (s, l) => S(s, l), this.get = () => h(), this.initialValue = e, this.isInitialValue = () => e === f(), this.subscribe = (s) => (d.add(s), () => {
89
+ d.delete(s);
89
90
  }), this.reset = () => {
90
- S(e, !0), g.forEach(s, this);
91
- }, this.setDeferred = (n, o = 500, f, T = !0) => {
92
- T && d === void 0 && S(n, f), clearTimeout(d), d = setTimeout(() => {
93
- S(n, f), d = void 0;
94
- }, o);
95
- }, i == null) return I;
96
- let b = null, m = !0, D = !0, j = !1, A = e instanceof Set ? (n) => new Set(JSON.parse(n)) : (n) => JSON.parse(n), _ = e instanceof Set ? (n) => {
97
- if (n instanceof Set) return JSON.stringify(Array.from(n));
98
- throw console.error(n), "The value is not Set instance";
99
- } : (n) => JSON.stringify(n);
100
- if (typeof i == "string" ? b = i : "storeKey" in i && (m = i.warnOnDuplicateStoreKey ?? m, D = i.listenStorageChanges ?? D, b = i.storeKey, A = i.parseValue ?? A, _ = i.stringifyValue ?? _, j = i.unchangable ?? j), b === null) return I;
101
- const u = `atom/${b}`;
91
+ S(e, !0), d.forEach(n, this);
92
+ }, this.setDeferred = (s, l = 500, a, T = !0) => {
93
+ T && g === void 0 && S(s, a), clearTimeout(g), g = setTimeout(() => {
94
+ S(s, a), g = void 0;
95
+ }, l);
96
+ }, c == null) return I;
97
+ let b = null, m = !0, D = !0, j = !1, A = e instanceof Set ? (s) => new Set(JSON.parse(s)) : (s) => JSON.parse(s), _ = e instanceof Set ? (s) => {
98
+ if (s instanceof Set) return JSON.stringify(Array.from(s));
99
+ throw console.error(s), "The value is not Set instance";
100
+ } : (s) => JSON.stringify(s);
101
+ if (typeof c == "string" ? b = c : "storeKey" in c && (m = c.warnOnDuplicateStoreKey ?? m, D = c.listenStorageChanges ?? D, b = c.storeKey, A = c.parseValue ?? A, _ = c.stringifyValue ?? _, j = c.unchangable ?? j), b === null) return I;
102
+ const i = `atom/${b}`;
102
103
  let N = !0;
103
104
  if (h = () => {
104
- if (h = () => a(), N) {
105
+ if (h = () => f(), N) {
105
106
  N = !1;
106
107
  try {
107
- l(u in c ? A(c[u]) : e);
108
+ u(i in o ? A(o[i]) : e);
108
109
  } catch {
109
- console.warn("Invalid json value", c[u]);
110
+ console.warn("Invalid json value", o[i]);
110
111
  }
111
112
  }
112
- return a();
113
- }, C = (n) => {
114
- if (n === e) {
113
+ return f();
114
+ }, v = (s) => {
115
+ if (s === e) {
115
116
  this.reset();
116
117
  return;
117
118
  }
118
- c[u] = _(n);
119
+ o[i] = _(s);
119
120
  }, this.reset = () => {
120
- delete c[u], S(e, !0);
121
- }, m && w[u] !== void 0 && console.warn("Duplicate Atom key", b), D)
121
+ delete o[i], S(e, !0);
122
+ }, m && w[i] !== void 0 && console.warn("Duplicate Atom key", b), D)
122
123
  if (j) {
123
- let n = !1, o;
124
- p[u] = this, w[u] = () => {
125
- clearTimeout(o), o = setTimeout(() => n = !1, 10), !n && (n = !0, c[u] = _(a()));
124
+ let s = !1, l;
125
+ p[i] = this, w[i] = () => {
126
+ clearTimeout(l), l = setTimeout(() => s = !1, 10), !s && (s = !0, o[i] = _(f()));
126
127
  };
127
128
  } else
128
- w[u] = (n) => {
129
- if (n.newValue === null) {
129
+ w[i] = (s) => {
130
+ if (s.newValue === null) {
130
131
  this.reset();
131
132
  return;
132
133
  }
133
134
  try {
134
- S(A(n.newValue));
135
+ S(A(s.newValue));
135
136
  } catch {
136
- console.warn("Invalid json value", n.newValue);
137
+ console.warn("Invalid json value", s.newValue);
137
138
  }
138
139
  };
139
140
  return I;
@@ -147,19 +148,19 @@ try {
147
148
  });
148
149
  } catch {
149
150
  }
150
- const c = window.localStorage, w = {}, p = {}, P = (t, e) => {
151
+ const o = window.localStorage, w = {}, p = {}, P = (t, e) => {
151
152
  throw `${e} is readonly property`;
152
153
  };
153
154
  window.addEventListener("storage", (t) => {
154
155
  var e;
155
156
  t.key === null || t.newValue === t.oldValue || (e = w[t.key]) == null || e.call(w, t);
156
157
  });
157
- const H = c.setItem.bind(c), L = c.removeItem.bind(c);
158
- c.setItem = (t, e) => {
159
- p[t] === void 0 && H.call(c, t, e);
158
+ const H = o.setItem.bind(o), L = o.removeItem.bind(o);
159
+ o.setItem = (t, e) => {
160
+ p[t] === void 0 && H.call(o, t, e);
160
161
  };
161
- c.removeItem = (t) => {
162
- p[t] === void 0 && L.call(c, t);
162
+ o.removeItem = (t) => {
163
+ p[t] === void 0 && L.call(o, t);
163
164
  };
164
165
  let k = () => {
165
166
  throw "call configureAtomaric() before all!";
@@ -1 +1 @@
1
- (function(c,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(c=typeof globalThis<"u"?globalThis:c||self,b(c.atomaric={}))})(this,function(c){"use strict";const b=(t,e,i)=>{let u=null;typeof t=="number"?u=y({increment:s=>{e.set(+e.get()+(s??0))}}):typeof t=="boolean"?u=y({toggle:()=>{e.set(!e.get())}}):Array.isArray(t)?u=y({push:(...s)=>{e.set(e.get().concat(s))},unshift:(...s)=>{e.set(s.concat(e.get()))},update:s=>{const r=e.get().slice();s(r),e.set(r)},filter:s=>{e.set(e.get().filter(s??H))}}):t instanceof Set?u=y({add:s=>{e.set(new Set(e.get()).add(s))},delete:s=>{const r=new Set(e.get());r.delete(s),e.set(r)},clear:()=>{e.set(new Set)},update:s=>{const r=new Set(e.get());s(r),e.set(r)}}):t instanceof Object&&(u=y({setPartial:s=>e.set(r=>({...r,...typeof s=="function"?s(e.get()):s}))}));const a=typeof i=="object"&&i!=null&&"do"in i?i.do((s,r)=>e.set(s,r),()=>e.get(),(s,r,S)=>e.setDeferred(s,r,S)):null,g={};return a&&Object.keys(a).forEach(s=>Object.defineProperty(g,s,{get:()=>a[s]})),u&&Object.keys(u).forEach(s=>Object.defineProperty(g,s,{get:()=>u[s]})),g},H=t=>t,y=(t,e)=>t;class C{constructor(e,i){const u=n=>r=n,a=()=>r,g=new Set,s=n=>n(w());let r=e,S,P=()=>{},w=()=>a(),F=()=>{const n=b(e,this,i);return F=()=>n,n};const p=new Proxy(this,{get:(n,l)=>l==="do"?F():n[l],set:L}),A=(n,l)=>{const d=typeof n=="function"?n(w()):n;if(!(d===w()||d===void 0||typeof d=="number"&&isNaN(d))){u(d),g.forEach(s,this);try{I.postMessage({key:f,value:a()})}catch{}l!==!0&&P(d)}};if(this.set=(n,l)=>A(n,l),this.get=()=>w(),this.defaultValue=e,this.subscribe=n=>(g.add(n),()=>{g.delete(n)}),this.reset=()=>{A(e,!0),g.forEach(s,this)},this.setDeferred=(n,l=500,d,G=!0)=>{G&&S===void 0&&A(n,d),clearTimeout(S),S=setTimeout(()=>{A(n,d),S=void 0},l)},i==null)return p;let m=null,T=!0,E=!0,v=!1,D=e instanceof Set?n=>new Set(JSON.parse(n)):n=>JSON.parse(n),j=e instanceof Set?n=>{if(n instanceof Set)return JSON.stringify(Array.from(n));throw console.error(n),"The value is not Set instance"}:n=>JSON.stringify(n);if(typeof i=="string"?m=i:"storeKey"in i&&(T=i.warnOnDuplicateStoreKey??T,E=i.listenStorageChanges??E,m=i.storeKey,D=i.parseValue??D,j=i.stringifyValue??j,v=i.unchangable??v),m===null)return p;const f=`atom/${m}`;let V=!0;if(w=()=>{if(w=()=>a(),V){V=!1;try{u(f in o?D(o[f]):e)}catch{console.warn("Invalid json value",o[f])}}return a()},P=n=>{if(n===e){this.reset();return}o[f]=j(n)},this.reset=()=>{delete o[f],A(e,!0)},T&&h[f]!==void 0&&console.warn("Duplicate Atom key",m),E)if(v){let n=!1,l;_[f]=this,h[f]=()=>{clearTimeout(l),l=setTimeout(()=>n=!1,10),!n&&(n=!0,o[f]=j(a()))}}else h[f]=n=>{if(n.newValue===null){this.reset();return}try{A(D(n.newValue))}catch{console.warn("Invalid json value",n.newValue)}};return p}}let I;try{I=new BroadcastChannel("updateHere"),I.addEventListener("message",t=>{var e;(e=_[t.data.key])==null||e.set(t.data.value,!0)})}catch{}const o=window.localStorage,h={},_={},L=(t,e)=>{throw`${e} is readonly property`};window.addEventListener("storage",t=>{var e;t.key===null||t.newValue===t.oldValue||(e=h[t.key])==null||e.call(h,t)});const M=o.setItem.bind(o),$=o.removeItem.bind(o);o.setItem=(t,e)=>{_[t]===void 0&&M.call(o,t,e)},o.removeItem=t=>{_[t]===void 0&&$.call(o,t)};let N=()=>{throw"call configureAtomaric() before all!"};const B=t=>N=t.useSyncExternalStore,k=t=>N(t.subscribe,t.get),J=t=>t.set,U=t=>t.setDeferred,q=t=>t.get,z=t=>t.do,Q=t=>[k(t),J(t)],R=(t,e)=>new C(t,e);c.Atom=C,c.atom=R,c.configureAtomaric=B,c.useAtom=Q,c.useAtomDo=z,c.useAtomGet=q,c.useAtomSet=J,c.useAtomSetDeferred=U,c.useAtomValue=k,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
1
+ (function(c,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(c=typeof globalThis<"u"?globalThis:c||self,b(c.atomaric={}))})(this,function(c){"use strict";const b=(t,e,o)=>{let i=null;typeof t=="number"?i=y({increment:s=>{e.set(+e.get()+(s??0))}}):typeof t=="boolean"?i=y({toggle:()=>{e.set(!e.get())}}):Array.isArray(t)?i=y({push:(...s)=>{e.set(e.get().concat(s))},unshift:(...s)=>{e.set(s.concat(e.get()))},update:s=>{const r=e.get().slice();s(r),e.set(r)},filter:s=>{e.set(e.get().filter(s??H))}}):t instanceof Set?i=y({add:s=>{e.set(new Set(e.get()).add(s))},delete:s=>{const r=new Set(e.get());r.delete(s),e.set(r)},clear:()=>{e.set(new Set)},update:s=>{const r=new Set(e.get());s(r),e.set(r)}}):t instanceof Object&&(i=y({setPartial:s=>e.set(r=>({...r,...typeof s=="function"?s(e.get()):s}))}));const a=typeof o=="object"&&o!=null&&"do"in o?o.do((s,r)=>e.set(s,r),()=>e.get(),void 0,(s,r,S)=>e.setDeferred(s,r,S)):null,g={};return a&&Object.keys(a).forEach(s=>Object.defineProperty(g,s,{get:()=>a[s]})),i&&Object.keys(i).forEach(s=>Object.defineProperty(g,s,{get:()=>i[s]})),g},H=t=>t,y=(t,e)=>t;class C{constructor(e,o){const i=n=>r=n,a=()=>r,g=new Set,s=n=>n(w());let r=e,S,P=()=>{},w=()=>a(),F=()=>{const n=b(e,this,o);return F=()=>n,n};const p=new Proxy(this,{get:(n,u)=>u==="do"?F():n[u],set:L}),A=(n,u)=>{const d=typeof n=="function"?n(w()):n;if(!(d===w()||d===void 0||typeof d=="number"&&isNaN(d))){i(d),g.forEach(s,this);try{j.postMessage({key:f,value:a()})}catch{}u!==!0&&P(d)}};if(this.set=(n,u)=>A(n,u),this.get=()=>w(),this.initialValue=e,this.isInitialValue=()=>e===a(),this.subscribe=n=>(g.add(n),()=>{g.delete(n)}),this.reset=()=>{A(e,!0),g.forEach(s,this)},this.setDeferred=(n,u=500,d,G=!0)=>{G&&S===void 0&&A(n,d),clearTimeout(S),S=setTimeout(()=>{A(n,d),S=void 0},u)},o==null)return p;let m=null,T=!0,v=!0,E=!1,D=e instanceof Set?n=>new Set(JSON.parse(n)):n=>JSON.parse(n),I=e instanceof Set?n=>{if(n instanceof Set)return JSON.stringify(Array.from(n));throw console.error(n),"The value is not Set instance"}:n=>JSON.stringify(n);if(typeof o=="string"?m=o:"storeKey"in o&&(T=o.warnOnDuplicateStoreKey??T,v=o.listenStorageChanges??v,m=o.storeKey,D=o.parseValue??D,I=o.stringifyValue??I,E=o.unchangable??E),m===null)return p;const f=`atom/${m}`;let V=!0;if(w=()=>{if(w=()=>a(),V){V=!1;try{i(f in l?D(l[f]):e)}catch{console.warn("Invalid json value",l[f])}}return a()},P=n=>{if(n===e){this.reset();return}l[f]=I(n)},this.reset=()=>{delete l[f],A(e,!0)},T&&h[f]!==void 0&&console.warn("Duplicate Atom key",m),v)if(E){let n=!1,u;_[f]=this,h[f]=()=>{clearTimeout(u),u=setTimeout(()=>n=!1,10),!n&&(n=!0,l[f]=I(a()))}}else h[f]=n=>{if(n.newValue===null){this.reset();return}try{A(D(n.newValue))}catch{console.warn("Invalid json value",n.newValue)}};return p}}let j;try{j=new BroadcastChannel("updateHere"),j.addEventListener("message",t=>{var e;(e=_[t.data.key])==null||e.set(t.data.value,!0)})}catch{}const l=window.localStorage,h={},_={},L=(t,e)=>{throw`${e} is readonly property`};window.addEventListener("storage",t=>{var e;t.key===null||t.newValue===t.oldValue||(e=h[t.key])==null||e.call(h,t)});const M=l.setItem.bind(l),$=l.removeItem.bind(l);l.setItem=(t,e)=>{_[t]===void 0&&M.call(l,t,e)},l.removeItem=t=>{_[t]===void 0&&$.call(l,t)};let N=()=>{throw"call configureAtomaric() before all!"};const B=t=>N=t.useSyncExternalStore,k=t=>N(t.subscribe,t.get),J=t=>t.set,U=t=>t.setDeferred,q=t=>t.get,z=t=>t.do,Q=t=>[k(t),J(t)],R=(t,e)=>new C(t,e);c.Atom=C,c.atom=R,c.configureAtomaric=B,c.useAtom=Q,c.useAtomDo=z,c.useAtomGet=q,c.useAtomSet=J,c.useAtomSetDeferred=U,c.useAtomValue=k,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "atomaric",
3
3
  "description": "Manage your project state",
4
- "version": "0.0.23",
4
+ "version": "0.0.25",
5
5
  "type": "module",
6
6
  "main": "./build/atomaric.umd.cjs",
7
7
  "module": "./build/atomaric.js",
package/types/model.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { useSyncExternalStore } from 'react';
2
+
1
3
  type Sunscriber<Value> = (value: Value) => void;
2
4
 
3
5
  export type AtomStoreKey = `${string}${string}:${string}${string}`;
@@ -25,6 +27,7 @@ export type AtomOptions<Value, Actions extends Record<string, Function> = {}> =
25
27
  do: (
26
28
  set: (value: Value | ((value: Value) => Value), isPreventSave?: boolean) => void,
27
29
  get: () => Value,
30
+ self: Atom<Value>,
28
31
  setDeferred: (value: Value | ((value: Value) => Value), debounceMs?: number, isPreventSave?: boolean) => void,
29
32
  ) => Actions;
30
33
  }
@@ -41,37 +44,47 @@ export type AtomSetDeferredMethod<Value> = (
41
44
  export type AtomSubscribeMethod<Value> = (subscriber: Sunscriber<Value>) => () => void;
42
45
 
43
46
  export type UpdateAction<Value> = {
47
+ /** transform current taken value */
44
48
  update: (updater: (value: Value) => void) => void;
45
49
  };
46
50
 
47
51
  export type NumberActions<Value> = {
52
+ /** pass the 2 to increment on 2, pass the -2 to decrement on 2 */
48
53
  increment: (delta?: number) => void;
49
54
  };
50
55
 
51
56
  export type ObjectActions<Value> = {
57
+ /** pass partial object to update some fields */
52
58
  setPartial: (value: Partial<Value> | ((value: Value) => Partial<Value>)) => void;
53
59
  };
54
60
 
55
- export type BooleanActions<Value> = {
61
+ export type BooleanActions = {
62
+ /** toggle current value between true/false */
56
63
  toggle: () => void;
57
64
  };
58
65
 
59
66
  export type SetActions<Value> = UpdateAction<Value> & {
67
+ /** like the Set.prototype.add() method */
60
68
  add: (value: Value) => void;
69
+ /** like the Set.prototype.delete() method */
61
70
  delete: (value: Value) => void;
71
+ /** like the Set.prototype.clear() method */
62
72
  clear: () => void;
63
73
  };
64
74
 
65
75
  export type ArrayActions<Value> = UpdateAction<Value[]> & {
76
+ /** like the Array.prototype.push() method */
66
77
  push: (...values: Value[]) => void;
78
+ /** like the Array.prototype.unshift() method */
67
79
  unshift: (...values: Value[]) => void;
80
+ /** like the Array.prototype.filter() method, but callback is optional - (it) => !!it */
68
81
  filter: (filter?: (value: Value, index: number, array: Value[]) => any) => void;
69
82
  };
70
83
 
71
84
  export type DefaultActions<Value> = Value extends Set<infer Val>
72
85
  ? SetActions<Val>
73
86
  : Value extends boolean
74
- ? BooleanActions<Value>
87
+ ? BooleanActions
75
88
  : Value extends (infer Val)[]
76
89
  ? ArrayActions<Val>
77
90
  : Value extends number
@@ -80,19 +93,25 @@ export type DefaultActions<Value> = Value extends Set<infer Val>
80
93
  ? ObjectActions<Value>
81
94
  : {};
82
95
 
83
- export class Atom<Value, Actions extends Record<string, Function> = {}> {
84
- constructor(defaultValue: Value, storeKeyOrOptions: StoreKeyOrOptions<Value, Actions> | undefined);
96
+ declare class Atom<Value, Actions extends Record<string, Function> = {}> {
97
+ constructor(initialValue: Value, storeKeyOrOptions: StoreKeyOrOptions<Value, Actions> | undefined);
85
98
 
86
- readonly defaultValue: Value;
99
+ /** initial value */
100
+ readonly initialValue: Value;
101
+ /** get current value */
87
102
  readonly get: () => Value;
103
+ /** set current value */
88
104
  readonly set: AtomSetMethod<Value>;
105
+ /** set current value with debounce */
89
106
  readonly setDeferred: AtomSetDeferredMethod<Value>;
90
- /** set default (initial) value as current */
107
+ /** set current value as default (initial) */
91
108
  readonly reset: () => void;
92
109
  /** subscribe on value changes */
93
110
  readonly subscribe: AtomSubscribeMethod<Value>;
94
111
  /** your custom actions */
95
112
  readonly do: Actions & DefaultActions<Value>;
113
+ /** check is current value not changed */
114
+ readonly isInitialValue: () => boolean;
96
115
  }
97
116
 
98
117
  export function useAtom<Value>(atom: Atom<Value>): [Value, AtomSetMethod<Value>];
@@ -118,4 +137,5 @@ export function atom<Value, Actions extends Record<string, Function> = {}>(
118
137
  storeKeyOrOptions?: StoreKeyOrOptions<Value, Actions>,
119
138
  ): Atom<Value, Actions>;
120
139
 
140
+ /** invoke this function before all atom usages */
121
141
  export function configureAtomaric(options: { useSyncExternalStore: typeof useSyncExternalStore }): void;