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 +12 -9
- package/build/atomaric.umd.cjs +1 -1
- package/package.json +1 -1
- package/types/model.d.ts +1 -0
package/build/atomaric.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
class
|
|
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
|
|
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
|
-
|
|
37
|
+
h as Atom,
|
|
35
38
|
v as atom,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
45
|
+
c as useAtomValue
|
|
43
46
|
};
|
package/build/atomaric.umd.cjs
CHANGED
|
@@ -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
|
|
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
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;
|