atomaric 0.0.0 → 0.0.1

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/README.md CHANGED
@@ -7,12 +7,12 @@ npm install atomaric
7
7
  ### usage
8
8
 
9
9
  ```ts
10
- import { microb, useMicrobValue } from 'atomaric';
10
+ import { atom, useAtomValue } from 'atomaric';
11
11
 
12
- const nameMicrob = microb('World');
12
+ const nameAtom = atom('World');
13
13
 
14
14
  function App() {
15
- const [name, setIsOpen] = useMicrobValue(nameMicrob);
15
+ const [name, setIsOpen] = useAtomValue(nameAtom);
16
16
 
17
17
  return <div onClick={() => setIsOpen(isOpen => (name === 'World' ? 'Man' : 'World'))}>Hello, {name}</div>;
18
18
  }
package/build/atomaric.js CHANGED
@@ -1,43 +1,43 @@
1
- class n {
2
- constructor(t, o) {
1
+ class c {
2
+ constructor(s, o) {
3
3
  if (this.subscribers = /* @__PURE__ */ new Set(), this.save = () => {
4
- }, this.invokeSubscriber = (s) => s(this.value), this.get = () => this.value, this.toggle = () => this.set(!this.value), this.inkrement = (s) => this.set(this.value + s), this.subscribe = (s) => (this.subscribers.add(s), () => {
5
- this.subscribers.delete(s);
6
- }), this.set = (s, r) => {
7
- const i = typeof s == "function" ? s(this.value) : s;
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
+ this.subscribers.delete(e);
6
+ }), this.set = (e, r) => {
7
+ const i = typeof e == "function" ? e(this.value) : e;
8
8
  i === this.value || i === void 0 || typeof i == "number" && isNaN(i) || (this.value = i, this.subscribers.forEach(this.invokeSubscriber, this), r !== !0 && this.save(i));
9
9
  }, o !== void 0) {
10
- const s = `microb/${o}`;
11
- this.value = s in localStorage ? JSON.parse(localStorage[s]) : t, this.save = (r) => {
12
- if (r === t) {
10
+ const e = `atom/${o}`;
11
+ this.value = e in localStorage ? JSON.parse(localStorage[e]) : s, this.save = (r) => {
12
+ if (r === s) {
13
13
  this.reset();
14
14
  return;
15
15
  }
16
- localStorage[s] = JSON.stringify(r);
16
+ localStorage[e] = JSON.stringify(r);
17
17
  }, this.reset = () => {
18
- delete localStorage[s], this.set(t, !0);
18
+ delete localStorage[e], this.set(s, !0);
19
19
  };
20
20
  } else
21
- this.value = t, this.reset = () => {
22
- this.set(t, !0), this.subscribers.forEach(this.invokeSubscriber, this);
21
+ this.value = s, this.reset = () => {
22
+ this.set(s, !0), this.subscribers.forEach(this.invokeSubscriber, this);
23
23
  };
24
- typeof t != "boolean" && (this.toggle = () => {
25
- }), typeof t != "number" && (this.inkrement = () => {
24
+ typeof s != "boolean" && (this.toggle = () => {
25
+ }), typeof s != "number" && (this.inkrement = () => {
26
26
  });
27
27
  }
28
28
  }
29
- let c = () => {
29
+ let n = () => {
30
30
  throw "you meed pass react useSyncExternalStore hook func in registerReactUseSyncExternalStoreHookFunc() before all ";
31
31
  };
32
- const u = (e) => c = e, h = (e) => c(e.subscribe, e.get), b = (e) => e.set, a = (e) => e.get, l = (e) => e.toggle, S = (e) => e.inkrement, g = (e) => [h(e), b(e)], v = (e, t) => new n(e, t);
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);
33
33
  export {
34
- n as Microb,
35
- v as microb,
36
- u as registerReactUseSyncExternalStoreHookFunc,
37
- g as useMicrob,
38
- a as useMicrobGet,
39
- S as useMicrobInkrement,
40
- b as useMicrobSet,
41
- l as useMicrobToggle,
42
- h as useMicrobValue
34
+ c as Atom,
35
+ v as atom,
36
+ b as registerReactUseSyncExternalStoreHookFunc,
37
+ g as useAtom,
38
+ a as useAtomGet,
39
+ S as useAtomInkrement,
40
+ u as useAtomSet,
41
+ l as useAtomToggle,
42
+ h as useAtomValue
43
43
  };
@@ -1 +1 @@
1
- (function(s,r){typeof exports=="object"&&typeof module<"u"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(s=typeof globalThis<"u"?globalThis:s||self,r(s.atomaric={}))})(this,function(s){"use strict";class r{constructor(i,b){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,n)=>{const o=typeof t=="function"?t(this.value):t;o===this.value||o===void 0||typeof o=="number"&&isNaN(o)||(this.value=o,this.subscribers.forEach(this.invokeSubscriber,this),n!==!0&&this.save(o))},b!==void 0){const t=`microb/${b}`;this.value=t in localStorage?JSON.parse(localStorage[t]):i,this.save=n=>{if(n===i){this.reset();return}localStorage[t]=JSON.stringify(n)},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 a=e=>c=e,u=e=>c(e.subscribe,e.get),h=e=>e.set,l=e=>e.get,S=e=>e.toggle,g=e=>e.inkrement,f=e=>[u(e),h(e)],v=(e,i)=>new r(e,i);s.Microb=r,s.microb=v,s.registerReactUseSyncExternalStoreHookFunc=a,s.useMicrob=f,s.useMicrobGet=l,s.useMicrobInkrement=g,s.useMicrobSet=h,s.useMicrobToggle=S,s.useMicrobValue=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.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"})});
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.0",
4
+ "version": "0.0.1",
5
5
  "type": "module",
6
6
  "main": "./build/atomaric.umd.cjs",
7
7
  "module": "./build/atomaric.js",
package/types/model.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  type Sunscriber<Value> = (value: Value) => void;
2
2
 
3
- export class Microb<Value> {
3
+ export class Atom<Value> {
4
4
  constructor(defaultValue: Value, storeKey: `${string}${string}:${string}${string}` | undefined);
5
5
 
6
6
  readonly get: () => Value;
@@ -11,14 +11,14 @@ export class Microb<Value> {
11
11
  readonly set: (value: Value | ((prev: Value) => Value), isPreventSave?: boolean) => void;
12
12
  }
13
13
 
14
- export function useMicrobValue<Value>(microb: Microb<Value>): Value;
15
- export function useMicrobSet<Value>(microb: Microb<Value>): (typeof microb)['set'];
16
- export function useMicrobGet<Value>(microb: Microb<Value>): (typeof microb)['get'];
17
- export function useMicrobToggle(microb: Microb<boolean>): (typeof microb)['toggle'];
18
- export function useMicrobInkrement(microb: Microb<number>): (typeof microb)['inkrement'];
14
+ export function useAtomValue<Value>(atom: Atom<Value>): Value;
15
+ export function useAtomSet<Value>(atom: Atom<Value>): (typeof atom)['set'];
16
+ export function useAtomGet<Value>(atom: Atom<Value>): (typeof atom)['get'];
17
+ export function useAtomToggle(atom: Atom<boolean>): (typeof atom)['toggle'];
18
+ export function useAtomInkrement(atom: Atom<number>): (typeof atom)['inkrement'];
19
19
 
20
- export function useMicrob<Value>(microb: Microb<Value>): [Value, (typeof microb)['set']];
20
+ export function useAtom<Value>(atom: Atom<Value>): [Value, (typeof atom)['set']];
21
21
 
22
- export function microb<Value>(value: Value, storeKey?: `${string}${string}:${string}${string}`): Microb<Value>;
22
+ export function atom<Value>(value: Value, storeKey?: `${string}${string}:${string}${string}`): Atom<Value>;
23
23
 
24
24
  export function registerReactUseSyncExternalStoreHookFunc(hook: typeof useSyncExternalStore): void;