atomaric 0.0.25 → 0.0.26

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
@@ -56,7 +56,7 @@ const x = (t, e, c) => {
56
56
  const f = typeof c == "object" && c != null && "do" in c ? c.do(
57
57
  (n, r) => e.set(n, r),
58
58
  () => e.get(),
59
- void 0,
59
+ e,
60
60
  (n, r, g) => e.setDeferred(n, r, g)
61
61
  ) : null, d = {};
62
62
  return f && Object.keys(f).forEach((n) => Object.defineProperty(d, n, { get: () => f[n] })), u && Object.keys(u).forEach(
@@ -66,13 +66,13 @@ const x = (t, e, c) => {
66
66
  class F {
67
67
  constructor(e, c) {
68
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;
69
+ let r = e, g, C = () => {
70
+ }, h = () => f(), v = () => {
71
+ const s = x(e, A, c);
72
+ return v = () => s, s;
73
73
  };
74
- const I = new Proxy(this, {
75
- get: (s, l) => l === "do" ? C() : s[l],
74
+ const A = new Proxy(this, {
75
+ get: (s, l) => l === "do" ? v() : s[l],
76
76
  set: P
77
77
  }), S = (s, l) => {
78
78
  const a = typeof s == "function" ? s(h()) : s;
@@ -82,7 +82,7 @@ class F {
82
82
  E.postMessage({ key: i, value: f() });
83
83
  } catch {
84
84
  }
85
- l !== !0 && v(a);
85
+ l !== !0 && C(a);
86
86
  }
87
87
  };
88
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), () => {
@@ -93,37 +93,37 @@ class F {
93
93
  T && g === void 0 && S(s, a), clearTimeout(g), g = setTimeout(() => {
94
94
  S(s, a), g = void 0;
95
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) => {
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
98
  if (s instanceof Set) return JSON.stringify(Array.from(s));
99
99
  throw console.error(s), "The value is not Set instance";
100
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;
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
102
  const i = `atom/${b}`;
103
103
  let N = !0;
104
104
  if (h = () => {
105
105
  if (h = () => f(), N) {
106
106
  N = !1;
107
107
  try {
108
- u(i in o ? A(o[i]) : e);
108
+ u(i in o ? _(o[i]) : e);
109
109
  } catch {
110
110
  console.warn("Invalid json value", o[i]);
111
111
  }
112
112
  }
113
113
  return f();
114
- }, v = (s) => {
114
+ }, C = (s) => {
115
115
  if (s === e) {
116
116
  this.reset();
117
117
  return;
118
118
  }
119
- o[i] = _(s);
119
+ o[i] = p(s);
120
120
  }, this.reset = () => {
121
121
  delete o[i], S(e, !0);
122
- }, m && w[i] !== void 0 && console.warn("Duplicate Atom key", b), D)
123
- if (j) {
122
+ }, D && w[i] !== void 0 && console.warn("Duplicate Atom key", b), j)
123
+ if (m) {
124
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()));
125
+ I[i] = this, w[i] = () => {
126
+ clearTimeout(l), l = setTimeout(() => s = !1, 10), !s && (s = !0, o[i] = p(f()));
127
127
  };
128
128
  } else
129
129
  w[i] = (s) => {
@@ -132,23 +132,23 @@ class F {
132
132
  return;
133
133
  }
134
134
  try {
135
- S(A(s.newValue));
135
+ S(_(s.newValue));
136
136
  } catch {
137
137
  console.warn("Invalid json value", s.newValue);
138
138
  }
139
139
  };
140
- return I;
140
+ return A;
141
141
  }
142
142
  }
143
143
  let E;
144
144
  try {
145
145
  E = new BroadcastChannel("updateHere"), E.addEventListener("message", (t) => {
146
146
  var e;
147
- (e = p[t.data.key]) == null || e.set(t.data.value, !0);
147
+ (e = I[t.data.key]) == null || e.set(t.data.value, !0);
148
148
  });
149
149
  } catch {
150
150
  }
151
- const o = window.localStorage, w = {}, p = {}, P = (t, e) => {
151
+ const o = window.localStorage, w = {}, I = {}, P = (t, e) => {
152
152
  throw `${e} is readonly property`;
153
153
  };
154
154
  window.addEventListener("storage", (t) => {
@@ -157,10 +157,10 @@ window.addEventListener("storage", (t) => {
157
157
  });
158
158
  const H = o.setItem.bind(o), L = o.removeItem.bind(o);
159
159
  o.setItem = (t, e) => {
160
- p[t] === void 0 && H.call(o, t, e);
160
+ I[t] === void 0 && H.call(o, t, e);
161
161
  };
162
162
  o.removeItem = (t) => {
163
- p[t] === void 0 && L.call(o, t);
163
+ I[t] === void 0 && L.call(o, t);
164
164
  };
165
165
  let k = () => {
166
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,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"})});
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"})});
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.25",
4
+ "version": "0.0.26",
5
5
  "type": "module",
6
6
  "main": "./build/atomaric.umd.cjs",
7
7
  "module": "./build/atomaric.js",
package/types/model.d.ts CHANGED
@@ -49,7 +49,9 @@ export type UpdateAction<Value> = {
49
49
  };
50
50
 
51
51
  export type NumberActions<Value> = {
52
- /** pass the 2 to increment on 2, pass the -2 to decrement on 2 */
52
+ /** pass the 2 to increment on 2, pass the -2 to decrement on 2
53
+ * **default: 1**
54
+ */
53
55
  increment: (delta?: number) => void;
54
56
  };
55
57