atomaric 0.0.28 → 0.0.29

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,18 +1,18 @@
1
- const P = (n, e, c) => {
2
- let u = null;
3
- typeof n == "number" ? u = p(
1
+ const P = (n, e, l) => {
2
+ let i = null;
3
+ typeof n == "number" ? i = y(
4
4
  {
5
5
  increment: (s) => {
6
6
  e.set(+e.get() + (s ?? 0));
7
7
  }
8
8
  }
9
- ) : typeof n == "boolean" ? u = p(
9
+ ) : typeof n == "boolean" ? i = y(
10
10
  {
11
11
  toggle: () => {
12
12
  e.set(!e.get());
13
13
  }
14
14
  }
15
- ) : Array.isArray(n) ? u = p(
15
+ ) : Array.isArray(n) ? i = y(
16
16
  {
17
17
  push: (...s) => {
18
18
  e.set(e.get().concat(s));
@@ -28,7 +28,7 @@ const P = (n, e, c) => {
28
28
  e.set(e.get().filter(s ?? V));
29
29
  }
30
30
  }
31
- ) : n instanceof Set ? u = p(
31
+ ) : n instanceof Set ? i = y(
32
32
  {
33
33
  add: (s) => {
34
34
  e.set(new Set(e.get()).add(s));
@@ -49,7 +49,7 @@ const P = (n, e, c) => {
49
49
  s(r), e.set(r);
50
50
  }
51
51
  }
52
- ) : n instanceof Object && (u = p(
52
+ ) : n instanceof Object && (i = y(
53
53
  {
54
54
  setPartial: (s) => e.set((r) => ({
55
55
  ...r,
@@ -57,95 +57,95 @@ const P = (n, e, c) => {
57
57
  }))
58
58
  }
59
59
  ));
60
- const f = typeof c == "object" && c != null && "do" in c ? c.do(
60
+ const f = typeof l == "object" && l != null && "do" in l ? l.do(
61
61
  (s, r) => e.set(s, r),
62
62
  () => e.get(),
63
63
  e,
64
64
  (s, r, w) => e.setDeferred(s, r, w)
65
65
  ) : null, d = {};
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] })
66
+ return f && Object.keys(f).forEach((s) => Object.defineProperty(d, s, { get: () => f[s] })), i && Object.keys(i).forEach(
67
+ (s) => Object.defineProperty(d, s, { get: () => i[s] })
68
68
  ), d;
69
- }, V = (n) => n, p = (n, e) => n;
69
+ }, V = (n) => n, y = (n, e) => n;
70
70
  class H {
71
- constructor(e, c) {
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;
71
+ constructor(e, l) {
72
+ const i = (t) => r = t, f = () => r, d = /* @__PURE__ */ new Set(), s = (t) => t(S());
73
+ let r = e, w, C = () => {
74
+ }, S = () => f(), g = null, $ = () => {
75
+ const t = P(e, _, l);
76
+ return $ = () => t, t;
77
77
  };
78
78
  const _ = new Proxy(this, {
79
- get: (t, l) => l === "do" ? k() : t[l],
79
+ get: (t, o) => o === "do" ? $() : t[o],
80
80
  set: L
81
- }), b = (t, l) => {
81
+ }), b = (t, o) => {
82
82
  const a = typeof t == "function" ? t(S()) : t;
83
83
  if (!(a === S() || a === void 0 || typeof a == "number" && isNaN(a))) {
84
- u(a), d.forEach(s, this);
84
+ i(a), d.forEach(s, this);
85
85
  try {
86
- C.postMessage({ key: i, value: f() });
86
+ T.postMessage({ key: u, value: f() });
87
87
  } catch {
88
88
  }
89
- l !== !0 && $(a);
89
+ o !== !0 && C(a);
90
90
  }
91
91
  };
92
- this.set = (t, l) => b(t, l), this.get = () => S(), this.initialValue = e, this.isInitialValue = () => e === f(), this.subscribe = (t) => (d.add(t), () => {
92
+ this.set = (t, o) => b(t, o), this.get = () => S(), this.initialValue = e, this.isInitialValue = () => e === f(), this.subscribe = (t) => (d.add(t), () => {
93
93
  d.delete(t);
94
94
  }), this.reset = () => {
95
95
  b(e, !0), d.forEach(s, this);
96
96
  };
97
- const J = (t, l) => {
98
- b(t, l), w = void 0;
97
+ const J = (t, o) => {
98
+ b(t, o), w = void 0;
99
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) => {
100
+ if (this.setDeferred = (t, o = 500, a, k = !0) => {
101
+ k && w === void 0 && b(t, a), clearTimeout(w), w = setTimeout(J, o, t, a);
102
+ }, l == null) return _;
103
+ let h = null, p = null, I = !0, x = !0, j = !1, E = e instanceof Set ? (t) => new Set(t) : (t) => t, m = e instanceof Set ? (t) => {
104
104
  if (t instanceof Set) return Array.from(t);
105
105
  throw console.error(t), "The value is not Set instance";
106
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;
107
+ if (typeof l == "string")
108
+ h = l;
109
+ else if ("storeKey" in l)
110
+ I = l.warnOnDuplicateStoreKey ?? I, x = l.listenStorageChanges ?? x, h = l.storeKey, E = l.unzipValue ?? E, m = l.zipValue ?? m, j = l.unchangable ?? j, p = l.exp ?? p;
111
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}`;
116
- let N = !0;
117
- if (o[`atom/${h}`] && (this.set(T(`[${o[`atom/${h}`]}]`)), delete o[`atom/${h}`]), S = () => {
118
- if (S = f, N) {
119
- N = !1;
112
+ const v = p === null || !(p() instanceof Date) ? (t) => JSON.stringify([m(t)]) : (t) => (g ?? (g = {}), g.exp = p().getTime(), JSON.stringify([m(t), g])), N = (t) => {
113
+ const o = JSON.parse(t);
114
+ return g = o[1], g != null && g.exp != null && g.exp < Date.now() ? (this.reset(), e) : E(o[0]);
115
+ }, u = `atom\\${h}`;
116
+ let z = !0;
117
+ if (c[`atom/${h}`] && (c[u] || (c[u] = `[${c[`atom/${h}`]}]`), delete c[`atom/${h}`]), S = () => {
118
+ if (S = f, z) {
119
+ z = !1;
120
120
  try {
121
- u(i in o ? T(o[i]) : e);
121
+ i(u in c ? N(c[u]) : e);
122
122
  } catch {
123
- console.warn("Invalid json value", o[i]);
123
+ console.warn("Invalid json value", c[u]);
124
124
  }
125
125
  }
126
126
  return f();
127
- }, $ = (t) => {
127
+ }, C = (t) => {
128
128
  if (t === e) {
129
129
  this.reset();
130
130
  return;
131
131
  }
132
- o[i] = v(t);
132
+ c[u] = v(t);
133
133
  }, this.reset = () => {
134
- delete o[i], b(e, !0);
135
- }, I && A[i] !== void 0 && console.warn("Duplicate Atom key", h), x)
134
+ delete c[u], b(e, !0);
135
+ }, I && A[u] !== void 0 && console.warn("Duplicate Atom key", h), x)
136
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()));
137
+ let t = !1, o;
138
+ D[u] = this, A[u] = () => {
139
+ clearTimeout(o), o = setTimeout(() => t = !1, 10), !t && (t = !0, c[u] = v(f()));
140
140
  };
141
141
  } else
142
- A[i] = (t) => {
142
+ A[u] = (t) => {
143
143
  if (t.newValue === null) {
144
144
  this.reset();
145
145
  return;
146
146
  }
147
147
  try {
148
- b(T(t.newValue));
148
+ b(N(t.newValue));
149
149
  } catch {
150
150
  console.warn("Invalid json value", t.newValue);
151
151
  }
@@ -153,27 +153,27 @@ class H {
153
153
  return _;
154
154
  }
155
155
  }
156
- let C;
156
+ let T;
157
157
  try {
158
- C = new BroadcastChannel("updateHere"), C.addEventListener("message", (n) => {
158
+ T = new BroadcastChannel("updateHere"), T.addEventListener("message", (n) => {
159
159
  var e;
160
160
  (e = D[n.data.key]) == null || e.set(n.data.value, !0);
161
161
  });
162
162
  } catch {
163
163
  }
164
- const o = window.localStorage, A = {}, D = {}, L = (n, e) => {
164
+ const c = window.localStorage, A = {}, D = {}, L = (n, e) => {
165
165
  throw `${e} is readonly property`;
166
166
  };
167
167
  window.addEventListener("storage", (n) => {
168
168
  var e;
169
169
  n.key === null || n.newValue === n.oldValue || (e = A[n.key]) == null || e.call(A, n);
170
170
  });
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);
171
+ const B = c.setItem.bind(c), G = c.removeItem.bind(c);
172
+ c.setItem = (n, e) => {
173
+ D[n] === void 0 && B.call(c, n, e);
174
174
  };
175
- o.removeItem = (n) => {
176
- D[n] === void 0 && G.call(o, n);
175
+ c.removeItem = (n) => {
176
+ D[n] === void 0 && G.call(c, n);
177
177
  };
178
178
  let F = () => {
179
179
  throw "call configureAtomaric() before all!";
@@ -1 +1 @@
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"})});
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,o)=>{let f=null;typeof n=="number"?f=p({increment:s=>{e.set(+e.get()+(s??0))}}):typeof n=="boolean"?f=p({toggle:()=>{e.set(!e.get())}}):Array.isArray(n)?f=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?f=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&&(f=p({setPartial:s=>e.set(r=>({...r,...typeof s=="function"?s(e.get()):s}))}));const d=typeof o=="object"&&o!=null&&"do"in o?o.do((s,r)=>e.set(s,r),()=>e.get(),e,(s,r,A)=>e.setDeferred(s,r,A)):null,g={};return d&&Object.keys(d).forEach(s=>Object.defineProperty(g,s,{get:()=>d[s]})),f&&Object.keys(f).forEach(s=>Object.defineProperty(g,s,{get:()=>f[s]})),g},L=n=>n,p=(n,e)=>n;class N{constructor(e,o){const f=t=>r=t,d=()=>r,g=new Set,s=t=>t(b());let r=e,A,k=()=>{},b=()=>d(),h=null,x=()=>{const t=y(e,I,o);return x=()=>t,t};const I=new Proxy(this,{get:(t,l)=>l==="do"?x():t[l],set:M}),m=(t,l)=>{const a=typeof t=="function"?t(b()):t;if(!(a===b()||a===void 0||typeof a=="number"&&isNaN(a))){f(a),g.forEach(s,this);try{j.postMessage({key:i,value:d()})}catch{}l!==!0&&k(a)}};this.set=(t,l)=>m(t,l),this.get=()=>b(),this.initialValue=e,this.isInitialValue=()=>e===d(),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,a,H=!0)=>{H&&A===void 0&&m(t,a),clearTimeout(A),A=setTimeout(Z,l,t,a)},o==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 o=="string")S=o;else if("storeKey"in o)E=o.warnOnDuplicateStoreKey??E,C=o.listenStorageChanges??C,S=o.storeKey,$=o.unzipValue??$,T=o.zipValue??T,v=o.unchangable??v,_=o.exp??_;else return I;const F=_===null||!(_()instanceof Date)?t=>JSON.stringify([T(t)]):t=>(h??(h={}),h.exp=_().getTime(),JSON.stringify([T(t),h])),J=t=>{const l=JSON.parse(t);return h=l[1],h!=null&&h.exp!=null&&h.exp<Date.now()?(this.reset(),e):$(l[0])},i=`atom\\${S}`;let G=!0;if(c[`atom/${S}`]&&(c[i]||(c[i]=`[${c[`atom/${S}`]}]`),delete c[`atom/${S}`]),b=()=>{if(b=d,G){G=!1;try{f(i in c?J(c[i]):e)}catch{console.warn("Invalid json value",c[i])}}return d()},k=t=>{if(t===e){this.reset();return}c[i]=F(t)},this.reset=()=>{delete c[i],m(e,!0)},E&&w[i]!==void 0&&console.warn("Duplicate Atom key",S),C)if(v){let t=!1,l;D[i]=this,w[i]=()=>{clearTimeout(l),l=setTimeout(()=>t=!1,10),!t&&(t=!0,c[i]=F(d()))}}else w[i]=t=>{if(t.newValue===null){this.reset();return}try{m(J(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 c=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=c.setItem.bind(c),U=c.removeItem.bind(c);c.setItem=(n,e)=>{D[n]===void 0&&B.call(c,n,e)},c.removeItem=n=>{D[n]===void 0&&U.call(c,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.28",
4
+ "version": "0.0.29",
5
5
  "type": "module",
6
6
  "main": "./build/atomaric.umd.cjs",
7
7
  "module": "./build/atomaric.js",
@@ -23,7 +23,7 @@
23
23
  "manager"
24
24
  ],
25
25
  "scripts": {
26
- "dev": "vite --port 8378 --host",
26
+ "start": "vite --port 8378 --host",
27
27
  "build": "tsc && vite build",
28
28
  "preview": "vite preview"
29
29
  },