atomaric 0.0.26 → 0.0.28

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