atomaric 0.0.1 → 0.0.2

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,6 +1,6 @@
1
- class c {
1
+ class h {
2
2
  constructor(s, o) {
3
- if (this.subscribers = /* @__PURE__ */ new Set(), this.save = () => {
3
+ if (this._defaultValue = s, this.subscribers = /* @__PURE__ */ new Set(), this.save = () => {
4
4
  }, this.invokeSubscriber = (e) => e(this.value), this.get = () => this.value, this.toggle = () => this.set(!this.value), this.inkrement = (e) => this.set(this.value + e), this.subscribe = (e) => (this.subscribers.add(e), () => {
5
5
  this.subscribers.delete(e);
6
6
  }), this.set = (e, r) => {
@@ -25,19 +25,22 @@ class c {
25
25
  }), typeof s != "number" && (this.inkrement = () => {
26
26
  });
27
27
  }
28
+ get defaultValue() {
29
+ return this._defaultValue;
30
+ }
28
31
  }
29
32
  let n = () => {
30
33
  throw "you meed pass react useSyncExternalStore hook func in registerReactUseSyncExternalStoreHookFunc() before all ";
31
34
  };
32
- const b = (t) => n = t, h = (t) => n(t.subscribe, t.get), u = (t) => t.set, a = (t) => t.get, l = (t) => t.toggle, S = (t) => t.inkrement, g = (t) => [h(t), u(t)], v = (t, s) => new c(t, s);
35
+ const a = (t) => n = t, c = (t) => n(t.subscribe, t.get), u = (t) => t.set, b = (t) => t.get, l = (t) => t.toggle, g = (t) => t.inkrement, S = (t) => [c(t), u(t)], v = (t, s) => new h(t, s);
33
36
  export {
34
- c as Atom,
37
+ h as Atom,
35
38
  v as atom,
36
- b as registerReactUseSyncExternalStoreHookFunc,
37
- g as useAtom,
38
- a as useAtomGet,
39
- S as useAtomInkrement,
39
+ a as registerReactUseSyncExternalStoreHookFunc,
40
+ S as useAtom,
41
+ b as useAtomGet,
42
+ g as useAtomInkrement,
40
43
  u as useAtomSet,
41
44
  l as useAtomToggle,
42
- h as useAtomValue
45
+ c as useAtomValue
43
46
  };
@@ -1 +1 @@
1
- (function(s,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(s=typeof globalThis<"u"?globalThis:s||self,o(s.atomaric={}))})(this,function(s){"use strict";class o{constructor(i,a){if(this.subscribers=new Set,this.save=()=>{},this.invokeSubscriber=t=>t(this.value),this.get=()=>this.value,this.toggle=()=>this.set(!this.value),this.inkrement=t=>this.set(this.value+t),this.subscribe=t=>(this.subscribers.add(t),()=>{this.subscribers.delete(t)}),this.set=(t,r)=>{const n=typeof t=="function"?t(this.value):t;n===this.value||n===void 0||typeof n=="number"&&isNaN(n)||(this.value=n,this.subscribers.forEach(this.invokeSubscriber,this),r!==!0&&this.save(n))},a!==void 0){const t=`atom/${a}`;this.value=t in localStorage?JSON.parse(localStorage[t]):i,this.save=r=>{if(r===i){this.reset();return}localStorage[t]=JSON.stringify(r)},this.reset=()=>{delete localStorage[t],this.set(i,!0)}}else this.value=i,this.reset=()=>{this.set(i,!0),this.subscribers.forEach(this.invokeSubscriber,this)};typeof i!="boolean"&&(this.toggle=()=>{}),typeof i!="number"&&(this.inkrement=()=>{})}}let c=()=>{throw"you meed pass react useSyncExternalStore hook func in registerReactUseSyncExternalStoreHookFunc() before all "};const l=e=>c=e,u=e=>c(e.subscribe,e.get),h=e=>e.set,m=e=>e.get,b=e=>e.toggle,S=e=>e.inkrement,g=e=>[u(e),h(e)],f=(e,i)=>new o(e,i);s.Atom=o,s.atom=f,s.registerReactUseSyncExternalStoreHookFunc=l,s.useAtom=g,s.useAtomGet=m,s.useAtomInkrement=S,s.useAtomSet=h,s.useAtomToggle=b,s.useAtomValue=u,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
1
+ (function(s,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(s=typeof globalThis<"u"?globalThis:s||self,o(s.atomaric={}))})(this,function(s){"use strict";class o{constructor(i,a){if(this._defaultValue=i,this.subscribers=new Set,this.save=()=>{},this.invokeSubscriber=t=>t(this.value),this.get=()=>this.value,this.toggle=()=>this.set(!this.value),this.inkrement=t=>this.set(this.value+t),this.subscribe=t=>(this.subscribers.add(t),()=>{this.subscribers.delete(t)}),this.set=(t,r)=>{const n=typeof t=="function"?t(this.value):t;n===this.value||n===void 0||typeof n=="number"&&isNaN(n)||(this.value=n,this.subscribers.forEach(this.invokeSubscriber,this),r!==!0&&this.save(n))},a!==void 0){const t=`atom/${a}`;this.value=t in localStorage?JSON.parse(localStorage[t]):i,this.save=r=>{if(r===i){this.reset();return}localStorage[t]=JSON.stringify(r)},this.reset=()=>{delete localStorage[t],this.set(i,!0)}}else this.value=i,this.reset=()=>{this.set(i,!0),this.subscribers.forEach(this.invokeSubscriber,this)};typeof i!="boolean"&&(this.toggle=()=>{}),typeof i!="number"&&(this.inkrement=()=>{})}get defaultValue(){return this._defaultValue}}let u=()=>{throw"you meed pass react useSyncExternalStore hook func in registerReactUseSyncExternalStoreHookFunc() before all "};const l=e=>u=e,c=e=>u(e.subscribe,e.get),h=e=>e.set,m=e=>e.get,b=e=>e.toggle,f=e=>e.inkrement,g=e=>[c(e),h(e)],S=(e,i)=>new o(e,i);s.Atom=o,s.atom=S,s.registerReactUseSyncExternalStoreHookFunc=l,s.useAtom=g,s.useAtomGet=m,s.useAtomInkrement=f,s.useAtomSet=h,s.useAtomToggle=b,s.useAtomValue=c,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.1",
4
+ "version": "0.0.2",
5
5
  "type": "module",
6
6
  "main": "./build/atomaric.umd.cjs",
7
7
  "module": "./build/atomaric.js",
package/types/model.d.ts CHANGED
@@ -3,6 +3,7 @@ type Sunscriber<Value> = (value: Value) => void;
3
3
  export class Atom<Value> {
4
4
  constructor(defaultValue: Value, storeKey: `${string}${string}:${string}${string}` | undefined);
5
5
 
6
+ readonly defaultValue: Value;
6
7
  readonly get: () => Value;
7
8
  readonly reset: () => void;
8
9
  readonly toggle: () => void;