atomaric 0.0.14 → 0.0.15

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,129 +1,134 @@
1
1
  class C {
2
- constructor(n, o) {
3
- let A = n, g, b = () => {
2
+ constructor(s, o) {
3
+ let _ = s, g, p = () => {
4
4
  };
5
- const _ = (t) => A = t, y = () => A;
6
- this.get = () => y();
7
- let p = () => {
8
- const t = (s, i) => i;
9
- let c = null;
10
- typeof n == "number" && (c = t(n, {
11
- increment: (s) => {
12
- r(+this.get() + (s ?? 0));
5
+ const D = (e) => _ = e, m = () => _;
6
+ this.get = () => m();
7
+ let N = () => {
8
+ let e = null;
9
+ typeof s == "number" ? e = w(
10
+ {
11
+ increment: (n) => {
12
+ i(+this.get() + (n ?? 0));
13
+ }
13
14
  }
14
- })), typeof n == "boolean" && (c = t(n, {
15
- toggle: () => {
16
- r(!this.get());
15
+ ) : typeof s == "boolean" ? e = w(
16
+ {
17
+ toggle: () => {
18
+ i(!this.get());
19
+ }
17
20
  }
18
- })), Array.isArray(n) && (c = t(n, {
19
- push: (...s) => {
20
- r([this.get()].flat().concat(s));
21
- },
22
- unshift: (...s) => {
23
- r(s.concat(this.get()));
24
- },
25
- update: (s) => {
26
- const i = [...this.get()];
27
- s(i), r(i);
28
- },
29
- filter: (s) => {
30
- r(this.get().filter(s ?? I));
21
+ ) : Array.isArray(s) ? e = w(
22
+ {
23
+ push: (...n) => {
24
+ i([this.get()].flat().concat(n));
25
+ },
26
+ unshift: (...n) => {
27
+ i(n.concat(this.get()));
28
+ },
29
+ update: (n) => {
30
+ const r = [...this.get()];
31
+ n(r), i(r);
32
+ },
33
+ filter: (n) => {
34
+ i(this.get().filter(n ?? I));
35
+ }
31
36
  }
32
- })), n instanceof Set && (c = t(n, {
33
- add: (s) => {
34
- const i = new Set(this.get());
35
- i.add(s), r(i);
36
- },
37
- delete: (s) => {
38
- const i = new Set(this.get());
39
- i.delete(s), r(i);
40
- },
41
- clear: () => {
42
- r(/* @__PURE__ */ new Set());
43
- },
44
- update: (s) => {
45
- const i = new Set(this.get());
46
- s(i), r(i);
37
+ ) : s instanceof Set && (e = w(
38
+ {
39
+ add: (n) => {
40
+ const r = new Set(this.get());
41
+ r.add(n), i(r);
42
+ },
43
+ delete: (n) => {
44
+ const r = new Set(this.get());
45
+ r.delete(n), i(r);
46
+ },
47
+ clear: () => {
48
+ i(/* @__PURE__ */ new Set());
49
+ },
50
+ update: (n) => {
51
+ const r = new Set(this.get());
52
+ n(r), i(r);
53
+ }
47
54
  }
48
- }));
49
- const d = {
50
- ...typeof o == "object" && "do" in o ? o.do(
51
- () => this.get(),
52
- (s, i) => r(s, i)
53
- ) : {},
54
- ...c
55
- };
56
- return p = () => d, d;
55
+ ));
56
+ const c = { ...typeof o == "object" && o != null && "do" in o ? o.do(
57
+ () => this.get(),
58
+ (n, r) => i(n, r)
59
+ ) : {}, ...e };
60
+ return N = () => c, c;
57
61
  };
58
- Object.defineProperty(this, "do", { get: () => p() }), Object.defineProperty(this, "defaultValue", { get: () => n });
59
- const S = /* @__PURE__ */ new Set(), D = (t) => t(this.get());
60
- this.subscribe = (t) => (S.add(t), () => (S.delete(t), void 0));
61
- const r = (t, c) => {
62
- const l = typeof t == "function" ? t(this.get()) : t;
63
- l === this.get() || l === void 0 || typeof l == "number" && isNaN(l) || (_(l), S.forEach(D, this), c !== !0 && b(l));
62
+ Object.defineProperty(this, "do", { get: () => N() }), Object.defineProperty(this, "defaultValue", { get: () => s });
63
+ const S = /* @__PURE__ */ new Set(), j = (e) => e(this.get());
64
+ this.subscribe = (e) => (S.add(e), () => (S.delete(e), void 0));
65
+ const i = (e, a) => {
66
+ const c = typeof e == "function" ? e(this.get()) : e;
67
+ c === this.get() || c === void 0 || typeof c == "number" && isNaN(c) || (D(c), S.forEach(j, this), a !== !0 && p(c));
64
68
  };
65
- if (this.set = (t, c) => r(t, c), this.reset = () => {
66
- r(n, !0), S.forEach(D, this);
67
- }, this.setDeferred = (t, c = 500, l, d = !0) => {
68
- d && g === void 0 && r(t, l), clearTimeout(g), g = setTimeout(() => {
69
- r(t, l), g = void 0;
70
- }, c);
69
+ if (this.set = (e, a) => i(e, a), this.reset = () => {
70
+ i(s, !0), S.forEach(j, this);
71
+ }, this.setDeferred = (e, a = 500, c, n = !0) => {
72
+ n && g === void 0 && i(e, c), clearTimeout(g), g = setTimeout(() => {
73
+ i(e, c), g = void 0;
74
+ }, a);
71
75
  }, o == null) return;
72
- let u = null, N = !0, j = !0, w = n instanceof Set ? (t) => new Set(JSON.parse(t)) : (t) => JSON.parse(t), m = n instanceof Set ? (t) => {
73
- if (t instanceof Set) return JSON.stringify(Array.from(t));
74
- throw console.error(t), "The value is not Set instance";
75
- } : (t) => JSON.stringify(t);
76
- if (typeof o == "string" ? u = o : "storeKey" in o && (N = o.warnOnDuplicateStoreKey ?? !0, j = o.listenStorageChanges ?? !0, u = o.storeKey, w = o.parseValue ?? w, m = o.stringifyValue ?? m), u === null) return;
77
- const a = `atom/${u}`;
76
+ let u = null, y = !0, A = !0, d = s instanceof Set ? (e) => new Set(JSON.parse(e)) : (e) => JSON.parse(e), b = s instanceof Set ? (e) => {
77
+ if (e instanceof Set) return JSON.stringify(Array.from(e));
78
+ throw console.error(e), "The value is not Set instance";
79
+ } : (e) => JSON.stringify(e);
80
+ if (typeof o == "string" ? u = o : "storeKey" in o && (y = o.warnOnDuplicateStoreKey ?? y, A = o.listenStorageChanges ?? A, u = o.storeKey, d = o.parseValue ?? d, b = o.stringifyValue ?? b), u === null) return;
81
+ const l = `atom/${u}`;
78
82
  let k = !0;
79
83
  this.get = () => {
80
- if (this.get = () => y(), k) {
84
+ if (this.get = () => m(), k) {
81
85
  k = !1;
82
86
  try {
83
- _(a in h ? w(h[a]) : n);
87
+ D(l in f ? d(f[l]) : s);
84
88
  } catch {
85
- console.warn("Invalid json value", h[a]);
89
+ console.warn("Invalid json value", f[l]);
86
90
  }
87
91
  }
88
- return y();
89
- }, b = (t) => {
90
- if (t === n) {
92
+ return m();
93
+ }, p = (e) => {
94
+ if (e === s) {
91
95
  this.reset();
92
96
  return;
93
97
  }
94
- h[a] = m(t);
98
+ f[l] = b(e);
95
99
  }, this.reset = () => {
96
- delete h[a], r(n, !0);
97
- }, N && f[a] !== void 0 && console.warn("Duplicate Atom key", u), j && (f[a] = (t) => {
98
- if (t.newValue === null) {
100
+ delete f[l], i(s, !0);
101
+ }, y && h[l] !== void 0 && console.warn("Duplicate Atom key", u), A && (h[l] = (e) => {
102
+ if (e.newValue === null) {
99
103
  this.reset();
100
104
  return;
101
105
  }
102
106
  try {
103
- r(w(t.newValue));
107
+ i(d(e.newValue));
104
108
  } catch {
105
- console.warn("Invalid json value", t.newValue);
109
+ console.warn("Invalid json value", e.newValue);
106
110
  }
107
111
  });
108
112
  }
109
113
  }
110
- const h = window.localStorage, f = {}, I = (e) => e;
111
- window.addEventListener("storage", (e) => {
112
- var n;
113
- e.key === null || e.newValue === e.oldValue || (n = f[e.key]) == null || n.call(f, e);
114
+ const f = window.localStorage, h = {}, I = (t) => t;
115
+ window.addEventListener("storage", (t) => {
116
+ var s;
117
+ t.key === null || t.newValue === t.oldValue || (s = h[t.key]) == null || s.call(h, t);
114
118
  });
119
+ const w = (t, s) => t;
115
120
  let E = () => {
116
121
  throw "call configureAtomaric() before all!";
117
122
  };
118
- const x = (e) => E = e.useSyncExternalStore, J = (e) => E(e.subscribe, e.get), T = (e) => e.set, v = (e) => e.setDeferred, F = (e) => e.get, G = (e) => e.do, L = (e) => [J(e), T(e)], P = (e, n) => new C(e, n);
123
+ const x = (t) => E = t.useSyncExternalStore, J = (t) => E(t.subscribe, t.get), T = (t) => t.set, V = (t) => t.setDeferred, v = (t) => t.get, F = (t) => t.do, G = (t) => [J(t), T(t)], L = (t, s) => new C(t, s);
119
124
  export {
120
125
  C as Atom,
121
- P as atom,
126
+ L as atom,
122
127
  x as configureAtomaric,
123
- L as useAtom,
124
- G as useAtomDo,
125
- F as useAtomGet,
128
+ G as useAtom,
129
+ F as useAtomDo,
130
+ v as useAtomGet,
126
131
  T as useAtomSet,
127
- v as useAtomSetDeferred,
132
+ V as useAtomSetDeferred,
128
133
  J as useAtomValue
129
134
  };
@@ -1 +1 @@
1
- (function(r,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(r=typeof globalThis<"u"?globalThis:r||self,f(r.atomaric={}))})(this,function(r){"use strict";class f{constructor(n,c){let T=n,S,p=()=>{};const N=e=>T=e,y=()=>T;this.get=()=>y();let k=()=>{const e=(i,s)=>s;let u=null;typeof n=="number"&&(u=e(n,{increment:i=>{o(+this.get()+(i??0))}})),typeof n=="boolean"&&(u=e(n,{toggle:()=>{o(!this.get())}})),Array.isArray(n)&&(u=e(n,{push:(...i)=>{o([this.get()].flat().concat(i))},unshift:(...i)=>{o(i.concat(this.get()))},update:i=>{const s=[...this.get()];i(s),o(s)},filter:i=>{o(this.get().filter(i??v))}})),n instanceof Set&&(u=e(n,{add:i=>{const s=new Set(this.get());s.add(i),o(s)},delete:i=>{const s=new Set(this.get());s.delete(i),o(s)},clear:()=>{o(new Set)},update:i=>{const s=new Set(this.get());i(s),o(s)}}));const A={...typeof c=="object"&&"do"in c?c.do(()=>this.get(),(i,s)=>o(i,s)):{},...u};return k=()=>A,A};Object.defineProperty(this,"do",{get:()=>k()}),Object.defineProperty(this,"defaultValue",{get:()=>n});const m=new Set,E=e=>e(this.get());this.subscribe=e=>(m.add(e),()=>(m.delete(e),void 0));const o=(e,u)=>{const l=typeof e=="function"?e(this.get()):e;l===this.get()||l===void 0||typeof l=="number"&&isNaN(l)||(N(l),m.forEach(E,this),u!==!0&&p(l))};if(this.set=(e,u)=>o(e,u),this.reset=()=>{o(n,!0),m.forEach(E,this)},this.setDeferred=(e,u=500,l,A=!0)=>{A&&S===void 0&&o(e,l),clearTimeout(S),S=setTimeout(()=>{o(e,l),S=void 0},u)},c==null)return;let d=null,C=!0,I=!0,w=n instanceof Set?e=>new Set(JSON.parse(e)):e=>JSON.parse(e),b=n 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 c=="string"?d=c:"storeKey"in c&&(C=c.warnOnDuplicateStoreKey??!0,I=c.listenStorageChanges??!0,d=c.storeKey,w=c.parseValue??w,b=c.stringifyValue??b),d===null)return;const a=`atom/${d}`;let J=!0;this.get=()=>{if(this.get=()=>y(),J){J=!1;try{N(a in h?w(h[a]):n)}catch{console.warn("Invalid json value",h[a])}}return y()},p=e=>{if(e===n){this.reset();return}h[a]=b(e)},this.reset=()=>{delete h[a],o(n,!0)},C&&g[a]!==void 0&&console.warn("Duplicate Atom key",d),I&&(g[a]=e=>{if(e.newValue===null){this.reset();return}try{o(w(e.newValue))}catch{console.warn("Invalid json value",e.newValue)}})}}const h=window.localStorage,g={},v=t=>t;window.addEventListener("storage",t=>{var n;t.key===null||t.newValue===t.oldValue||(n=g[t.key])==null||n.call(g,t)});let _=()=>{throw"call configureAtomaric() before all!"};const G=t=>_=t.useSyncExternalStore,D=t=>_(t.subscribe,t.get),j=t=>t.set,P=t=>t.setDeferred,F=t=>t.get,L=t=>t.do,M=t=>[D(t),j(t)],$=(t,n)=>new f(t,n);r.Atom=f,r.atom=$,r.configureAtomaric=G,r.useAtom=M,r.useAtomDo=L,r.useAtomGet=F,r.useAtomSet=j,r.useAtomSetDeferred=P,r.useAtomValue=D,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
1
+ (function(s,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(s=typeof globalThis<"u"?globalThis:s||self,f(s.atomaric={}))})(this,function(s){"use strict";class f{constructor(i,r){let k=i,m,p=()=>{};const E=e=>k=e,y=()=>k;this.get=()=>y();let C=()=>{let e=null;typeof i=="number"?e=S({increment:n=>{o(+this.get()+(n??0))}}):typeof i=="boolean"?e=S({toggle:()=>{o(!this.get())}}):Array.isArray(i)?e=S({push:(...n)=>{o([this.get()].flat().concat(n))},unshift:(...n)=>{o(n.concat(this.get()))},update:n=>{const c=[...this.get()];n(c),o(c)},filter:n=>{o(this.get().filter(n??V))}}):i instanceof Set&&(e=S({add:n=>{const c=new Set(this.get());c.add(n),o(c)},delete:n=>{const c=new Set(this.get());c.delete(n),o(c)},clear:()=>{o(new Set)},update:n=>{const c=new Set(this.get());n(c),o(c)}}));const l={...typeof r=="object"&&r!=null&&"do"in r?r.do(()=>this.get(),(n,c)=>o(n,c)):{},...e};return C=()=>l,l};Object.defineProperty(this,"do",{get:()=>C()}),Object.defineProperty(this,"defaultValue",{get:()=>i});const w=new Set,I=e=>e(this.get());this.subscribe=e=>(w.add(e),()=>(w.delete(e),void 0));const o=(e,a)=>{const l=typeof e=="function"?e(this.get()):e;l===this.get()||l===void 0||typeof l=="number"&&isNaN(l)||(E(l),w.forEach(I,this),a!==!0&&p(l))};if(this.set=(e,a)=>o(e,a),this.reset=()=>{o(i,!0),w.forEach(I,this)},this.setDeferred=(e,a=500,l,n=!0)=>{n&&m===void 0&&o(e,l),clearTimeout(m),m=setTimeout(()=>{o(e,l),m=void 0},a)},r==null)return;let d=null,b=!0,_=!0,A=i instanceof Set?e=>new Set(JSON.parse(e)):e=>JSON.parse(e),D=i 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 r=="string"?d=r:"storeKey"in r&&(b=r.warnOnDuplicateStoreKey??b,_=r.listenStorageChanges??_,d=r.storeKey,A=r.parseValue??A,D=r.stringifyValue??D),d===null)return;const u=`atom/${d}`;let J=!0;this.get=()=>{if(this.get=()=>y(),J){J=!1;try{E(u in h?A(h[u]):i)}catch{console.warn("Invalid json value",h[u])}}return y()},p=e=>{if(e===i){this.reset();return}h[u]=D(e)},this.reset=()=>{delete h[u],o(i,!0)},b&&g[u]!==void 0&&console.warn("Duplicate Atom key",d),_&&(g[u]=e=>{if(e.newValue===null){this.reset();return}try{o(A(e.newValue))}catch{console.warn("Invalid json value",e.newValue)}})}}const h=window.localStorage,g={},V=t=>t;window.addEventListener("storage",t=>{var i;t.key===null||t.newValue===t.oldValue||(i=g[t.key])==null||i.call(g,t)});const S=(t,i)=>t;let j=()=>{throw"call configureAtomaric() before all!"};const v=t=>j=t.useSyncExternalStore,T=t=>j(t.subscribe,t.get),N=t=>t.set,G=t=>t.setDeferred,P=t=>t.get,F=t=>t.do,L=t=>[T(t),N(t)],M=(t,i)=>new f(t,i);s.Atom=f,s.atom=M,s.configureAtomaric=v,s.useAtom=L,s.useAtomDo=F,s.useAtomGet=P,s.useAtomSet=N,s.useAtomSetDeferred=G,s.useAtomValue=T,Object.defineProperty(s,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.14",
4
+ "version": "0.0.15",
5
5
  "type": "module",
6
6
  "main": "./build/atomaric.umd.cjs",
7
7
  "module": "./build/atomaric.js",