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 +3 -3
- package/build/atomaric.js +26 -26
- package/build/atomaric.umd.cjs +1 -1
- package/package.json +1 -1
- package/types/model.d.ts +8 -8
package/README.md
CHANGED
|
@@ -7,12 +7,12 @@ npm install atomaric
|
|
|
7
7
|
### usage
|
|
8
8
|
|
|
9
9
|
```ts
|
|
10
|
-
import {
|
|
10
|
+
import { atom, useAtomValue } from 'atomaric';
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const nameAtom = atom('World');
|
|
13
13
|
|
|
14
14
|
function App() {
|
|
15
|
-
const [name, setIsOpen] =
|
|
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
|
|
2
|
-
constructor(
|
|
1
|
+
class c {
|
|
2
|
+
constructor(s, o) {
|
|
3
3
|
if (this.subscribers = /* @__PURE__ */ new Set(), this.save = () => {
|
|
4
|
-
}, this.invokeSubscriber = (
|
|
5
|
-
this.subscribers.delete(
|
|
6
|
-
}), this.set = (
|
|
7
|
-
const i = typeof
|
|
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
|
|
11
|
-
this.value =
|
|
12
|
-
if (r ===
|
|
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[
|
|
16
|
+
localStorage[e] = JSON.stringify(r);
|
|
17
17
|
}, this.reset = () => {
|
|
18
|
-
delete localStorage[
|
|
18
|
+
delete localStorage[e], this.set(s, !0);
|
|
19
19
|
};
|
|
20
20
|
} else
|
|
21
|
-
this.value =
|
|
22
|
-
this.set(
|
|
21
|
+
this.value = s, this.reset = () => {
|
|
22
|
+
this.set(s, !0), this.subscribers.forEach(this.invokeSubscriber, this);
|
|
23
23
|
};
|
|
24
|
-
typeof
|
|
25
|
-
}), typeof
|
|
24
|
+
typeof s != "boolean" && (this.toggle = () => {
|
|
25
|
+
}), typeof s != "number" && (this.inkrement = () => {
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
let
|
|
29
|
+
let n = () => {
|
|
30
30
|
throw "you meed pass react useSyncExternalStore hook func in registerReactUseSyncExternalStoreHookFunc() before all ";
|
|
31
31
|
};
|
|
32
|
-
const
|
|
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
|
-
|
|
35
|
-
v as
|
|
36
|
-
|
|
37
|
-
g as
|
|
38
|
-
a as
|
|
39
|
-
S as
|
|
40
|
-
|
|
41
|
-
l as
|
|
42
|
-
h as
|
|
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
|
};
|
package/build/atomaric.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(s,
|
|
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
package/types/model.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
type Sunscriber<Value> = (value: Value) => void;
|
|
2
2
|
|
|
3
|
-
export class
|
|
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
|
|
15
|
-
export function
|
|
16
|
-
export function
|
|
17
|
-
export function
|
|
18
|
-
export function
|
|
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
|
|
20
|
+
export function useAtom<Value>(atom: Atom<Value>): [Value, (typeof atom)['set']];
|
|
21
21
|
|
|
22
|
-
export function
|
|
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;
|