Comparing version 2.9.0 to 2.9.1
@@ -1,3 +0,4 @@ | ||
import babel, { PluginObj } from '@babel/core'; | ||
import babel from '@babel/core'; | ||
import type { PluginObj } from '@babel/core'; | ||
import type { PluginOptions } from './utils'; | ||
export default function debugLabelPlugin({ types: t }: typeof babel, options?: PluginOptions): PluginObj; |
@@ -1,3 +0,4 @@ | ||
import babel, { PluginObj } from '@babel/core'; | ||
import babel from '@babel/core'; | ||
import type { PluginObj } from '@babel/core'; | ||
import type { PluginOptions } from './utils'; | ||
export default function reactRefreshPlugin({ types: t }: typeof babel, options?: PluginOptions): PluginObj; |
import babel from '@babel/core'; | ||
import { PluginOptions } from './utils'; | ||
import type { PluginOptions } from './utils'; | ||
export default function jotaiPreset(_: typeof babel, options?: PluginOptions): { | ||
plugins: babel.PluginItem[]; | ||
}; |
@@ -6,3 +6,3 @@ { | ||
"type": "commonjs", | ||
"version": "2.9.0", | ||
"version": "2.9.1", | ||
"main": "./index.js", | ||
@@ -9,0 +9,0 @@ "types": "./index.d.ts", |
@@ -52,3 +52,3 @@ 'use client'; | ||
if (t) return (t = t.call(r)).next.bind(t); | ||
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e ) { | ||
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) { | ||
t && (r = t); | ||
@@ -55,0 +55,0 @@ var o = 0; |
@@ -1,6 +0,6 @@ | ||
System.register(['@babel/template'], (function (exports) { | ||
System.register(['@babel/core', '@babel/template'], (function (exports) { | ||
'use strict'; | ||
var _templateBuilder; | ||
return { | ||
setters: [function (module) { | ||
setters: [null, function (module) { | ||
_templateBuilder = module.default; | ||
@@ -7,0 +7,0 @@ }], |
@@ -1,4 +0,4 @@ | ||
System.register(["@babel/template"],function(l){"use strict";var r;return{setters:[function(a){r=a.default}],execute:function(){l("default",u);function a(t,i,e=[]){const n=[...c,...e];if(t.isIdentifier(i)&&n.includes(i.name))return!0;if(t.isMemberExpression(i)){const{property:o}=i;if(t.isIdentifier(o)&&n.includes(o.name))return!0}return!1}const c=["atom","atomFamily","atomWithDefault","atomWithObservable","atomWithReducer","atomWithReset","atomWithStorage","freezeAtom","loadable","selectAtom","splitAtom","unwrap","atomWithMachine","atomWithImmer","atomWithProxy","atomWithQuery","atomWithMutation","atomWithSubscription","atomWithStore","atomWithHash","atomWithLocation","focusAtom","atomWithValidate","validateAtoms","atomWithCache","atomWithRecoilValue"],d=r.default||r;function u({types:t},i){return{visitor:{ExportDefaultDeclaration(e,n){const{node:o}=e;if(t.isCallExpression(o.declaration)&&a(t,o.declaration.callee,i==null?void 0:i.customAtomNames)){const m=(n.filename||"unknown").replace(/\.\w+$/,"");let s=m.split("/").pop();s==="index"&&(s=m.slice(0,-6).split("/").pop()||"unknown");const f=d(` | ||
System.register(["@babel/core","@babel/template"],function(m){"use strict";var r;return{setters:[null,function(a){r=a.default}],execute:function(){m("default",u);function a(t,i,e=[]){const n=[...c,...e];if(t.isIdentifier(i)&&n.includes(i.name))return!0;if(t.isMemberExpression(i)){const{property:o}=i;if(t.isIdentifier(o)&&n.includes(o.name))return!0}return!1}const c=["atom","atomFamily","atomWithDefault","atomWithObservable","atomWithReducer","atomWithReset","atomWithStorage","freezeAtom","loadable","selectAtom","splitAtom","unwrap","atomWithMachine","atomWithImmer","atomWithProxy","atomWithQuery","atomWithMutation","atomWithSubscription","atomWithStore","atomWithHash","atomWithLocation","focusAtom","atomWithValidate","validateAtoms","atomWithCache","atomWithRecoilValue"],d=r.default||r;function u({types:t},i){return{visitor:{ExportDefaultDeclaration(e,n){const{node:o}=e;if(t.isCallExpression(o.declaration)&&a(t,o.declaration.callee,i==null?void 0:i.customAtomNames)){const l=(n.filename||"unknown").replace(/\.\w+$/,"");let s=l.split("/").pop();s==="index"&&(s=l.slice(0,-6).split("/").pop()||"unknown");const f=d(` | ||
const %%atomIdentifier%% = %%atom%%; | ||
export default %%atomIdentifier%% | ||
`)({atomIdentifier:t.identifier(s),atom:o.declaration});e.replaceWithMultiple(f)}},VariableDeclarator(e){t.isIdentifier(e.node.id)&&t.isCallExpression(e.node.init)&&a(t,e.node.init.callee,i==null?void 0:i.customAtomNames)&&e.parentPath.insertAfter(t.expressionStatement(t.assignmentExpression("=",t.memberExpression(t.identifier(e.node.id.name),t.identifier("debugLabel")),t.stringLiteral(e.node.id.name))))}}}}}}}); |
@@ -1,6 +0,6 @@ | ||
System.register(['@babel/template'], (function (exports) { | ||
System.register(['@babel/core', '@babel/template'], (function (exports) { | ||
'use strict'; | ||
var _templateBuilder; | ||
return { | ||
setters: [function (module) { | ||
setters: [null, function (module) { | ||
_templateBuilder = module.default; | ||
@@ -7,0 +7,0 @@ }], |
@@ -1,2 +0,2 @@ | ||
System.register(["@babel/template"],function(c){"use strict";var m;return{setters:[function(n){m=n.default}],execute:function(){c("default",u);function n(e,a,t=[]){const o=[...h,...t];if(e.isIdentifier(a)&&o.includes(a.name))return!0;if(e.isMemberExpression(a)){const{property:i}=a;if(e.isIdentifier(i)&&o.includes(i.name))return!0}return!1}const h=["atom","atomFamily","atomWithDefault","atomWithObservable","atomWithReducer","atomWithReset","atomWithStorage","freezeAtom","loadable","selectAtom","splitAtom","unwrap","atomWithMachine","atomWithImmer","atomWithProxy","atomWithQuery","atomWithMutation","atomWithSubscription","atomWithStore","atomWithHash","atomWithLocation","focusAtom","atomWithValidate","validateAtoms","atomWithCache","atomWithRecoilValue"],s=m.default||m;function u({types:e},a){return{pre({opts:t}){if(!t.filename)throw new Error("Filename must be available")},visitor:{Program:{exit(t){const o=s(` | ||
System.register(["@babel/core","@babel/template"],function(c){"use strict";var m;return{setters:[null,function(n){m=n.default}],execute:function(){c("default",u);function n(e,a,t=[]){const o=[...h,...t];if(e.isIdentifier(a)&&o.includes(a.name))return!0;if(e.isMemberExpression(a)){const{property:i}=a;if(e.isIdentifier(i)&&o.includes(i.name))return!0}return!1}const h=["atom","atomFamily","atomWithDefault","atomWithObservable","atomWithReducer","atomWithReset","atomWithStorage","freezeAtom","loadable","selectAtom","splitAtom","unwrap","atomWithMachine","atomWithImmer","atomWithProxy","atomWithQuery","atomWithMutation","atomWithSubscription","atomWithStore","atomWithHash","atomWithLocation","focusAtom","atomWithValidate","validateAtoms","atomWithCache","atomWithRecoilValue"],l=m.default||m;function u({types:e},a){return{pre({opts:t}){if(!t.filename)throw new Error("Filename must be available")},visitor:{Program:{exit(t){const o=l(` | ||
globalThis.jotaiAtomCache = globalThis.jotaiAtomCache || { | ||
@@ -11,2 +11,2 @@ cache: new Map(), | ||
}, | ||
}`)();t.unshiftContainer("body",o)}},ExportDefaultDeclaration(t,o){const{node:i}=t;if(e.isCallExpression(i.declaration)&&n(e,i.declaration.callee,a==null?void 0:a.customAtomNames)){const r=`${o.filename||"unknown"}/defaultExport`,l=s("export default globalThis.jotaiAtomCache.get(%%atomKey%%, %%atom%%)")({atomKey:e.stringLiteral(r),atom:i.declaration});t.replaceWith(l)}},VariableDeclarator(t,o){var i,r;if(e.isIdentifier(t.node.id)&&e.isCallExpression(t.node.init)&&n(e,t.node.init.callee,a==null?void 0:a.customAtomNames)&&((i=t.parentPath.parentPath)!=null&&i.isProgram()||(r=t.parentPath.parentPath)!=null&&r.isExportNamedDeclaration())){const l=`${o.filename||"unknown"}/${t.node.id.name}`,d=s("const %%atomIdentifier%% = globalThis.jotaiAtomCache.get(%%atomKey%%, %%atom%%)")({atomIdentifier:e.identifier(t.node.id.name),atomKey:e.stringLiteral(l),atom:t.node.init});t.parentPath.replaceWith(d)}}}}}}}}); | ||
}`)();t.unshiftContainer("body",o)}},ExportDefaultDeclaration(t,o){const{node:i}=t;if(e.isCallExpression(i.declaration)&&n(e,i.declaration.callee,a==null?void 0:a.customAtomNames)){const r=`${o.filename||"unknown"}/defaultExport`,s=l("export default globalThis.jotaiAtomCache.get(%%atomKey%%, %%atom%%)")({atomKey:e.stringLiteral(r),atom:i.declaration});t.replaceWith(s)}},VariableDeclarator(t,o){var i,r;if(e.isIdentifier(t.node.id)&&e.isCallExpression(t.node.init)&&n(e,t.node.init.callee,a==null?void 0:a.customAtomNames)&&((i=t.parentPath.parentPath)!=null&&i.isProgram()||(r=t.parentPath.parentPath)!=null&&r.isExportNamedDeclaration())){const s=`${o.filename||"unknown"}/${t.node.id.name}`,d=l("const %%atomIdentifier%% = globalThis.jotaiAtomCache.get(%%atomKey%%, %%atom%%)")({atomIdentifier:e.identifier(t.node.id.name),atomKey:e.stringLiteral(s),atom:t.node.init});t.parentPath.replaceWith(d)}}}}}}}}); |
@@ -1,6 +0,6 @@ | ||
System.register(['@babel/template'], (function (exports) { | ||
System.register(['@babel/core', '@babel/template'], (function (exports) { | ||
'use strict'; | ||
var _templateBuilder; | ||
return { | ||
setters: [function (module) { | ||
setters: [null, function (module) { | ||
_templateBuilder = module.default; | ||
@@ -7,0 +7,0 @@ }], |
@@ -1,2 +0,2 @@ | ||
System.register(["@babel/template"],function(d){"use strict";var s;return{setters:[function(l){s=l.default}],execute:function(){d("default",b);function l(e,i,t=[]){const o=[...u,...t];if(e.isIdentifier(i)&&o.includes(i.name))return!0;if(e.isMemberExpression(i)){const{property:a}=i;if(e.isIdentifier(a)&&o.includes(a.name))return!0}return!1}const u=["atom","atomFamily","atomWithDefault","atomWithObservable","atomWithReducer","atomWithReset","atomWithStorage","freezeAtom","loadable","selectAtom","splitAtom","unwrap","atomWithMachine","atomWithImmer","atomWithProxy","atomWithQuery","atomWithMutation","atomWithSubscription","atomWithStore","atomWithHash","atomWithLocation","focusAtom","atomWithValidate","validateAtoms","atomWithCache","atomWithRecoilValue"],f=s.default||s;function h({types:e},i){return{visitor:{ExportDefaultDeclaration(t,o){const{node:a}=t;if(e.isCallExpression(a.declaration)&&l(e,a.declaration.callee,i==null?void 0:i.customAtomNames)){const n=(o.filename||"unknown").replace(/\.\w+$/,"");let r=n.split("/").pop();r==="index"&&(r=n.slice(0,-6).split("/").pop()||"unknown");const c=f(` | ||
System.register(["@babel/core","@babel/template"],function(d){"use strict";var s;return{setters:[null,function(l){s=l.default}],execute:function(){d("default",b);function l(e,i,t=[]){const o=[...u,...t];if(e.isIdentifier(i)&&o.includes(i.name))return!0;if(e.isMemberExpression(i)){const{property:a}=i;if(e.isIdentifier(a)&&o.includes(a.name))return!0}return!1}const u=["atom","atomFamily","atomWithDefault","atomWithObservable","atomWithReducer","atomWithReset","atomWithStorage","freezeAtom","loadable","selectAtom","splitAtom","unwrap","atomWithMachine","atomWithImmer","atomWithProxy","atomWithQuery","atomWithMutation","atomWithSubscription","atomWithStore","atomWithHash","atomWithLocation","focusAtom","atomWithValidate","validateAtoms","atomWithCache","atomWithRecoilValue"],f=s.default||s;function h({types:e},i){return{visitor:{ExportDefaultDeclaration(t,o){const{node:a}=t;if(e.isCallExpression(a.declaration)&&l(e,a.declaration.callee,i==null?void 0:i.customAtomNames)){const n=(o.filename||"unknown").replace(/\.\w+$/,"");let r=n.split("/").pop();r==="index"&&(r=n.slice(0,-6).split("/").pop()||"unknown");const c=f(` | ||
const %%atomIdentifier%% = %%atom%%; | ||
@@ -3,0 +3,0 @@ export default %%atomIdentifier%% |
@@ -12,3 +12,5 @@ System.register([], (function (exports) { | ||
const config = { | ||
toString: () => key | ||
toString() { | ||
return this.debugLabel ? key + ":" + this.debugLabel : key; | ||
} | ||
}; | ||
@@ -412,5 +414,5 @@ if (typeof read === "function") { | ||
if (!atomState.d.has(a)) { | ||
atomState.m.d.delete(a); | ||
const aMounted = unmountAtom(pending, a); | ||
aMounted == null ? void 0 : aMounted.t.delete(atom); | ||
atomState.m.d.delete(a); | ||
} | ||
@@ -453,3 +455,6 @@ } | ||
const atomState = getAtomState(atom); | ||
if (atomState.m && !atomState.m.l.size && !Array.from(atomState.m.t).some((a) => getAtomState(a).m)) { | ||
if (atomState.m && !atomState.m.l.size && !Array.from(atomState.m.t).some((a) => { | ||
var _a; | ||
return (_a = getAtomState(a).m) == null ? void 0 : _a.d.has(atom); | ||
})) { | ||
const onUnmount = atomState.m.u; | ||
@@ -489,7 +494,9 @@ if (onUnmount) { | ||
}; | ||
const store = { | ||
get: readAtom, | ||
set: writeAtom, | ||
sub: subscribeAtom | ||
}; | ||
{ | ||
const store = { | ||
get: readAtom, | ||
set: writeAtom, | ||
sub: subscribeAtom, | ||
const devStore = { | ||
// store dev methods (these are tentative and subject to change without notice) | ||
@@ -502,9 +509,9 @@ dev4_get_internal_weak_map: () => atomStateMap, | ||
if (hasInitialValue(atom)) { | ||
const aState = getAtomState(atom); | ||
const hasPrevValue = "v" in aState; | ||
const prevValue = aState.v; | ||
setAtomStateValueOrPromise(atom, aState, value); | ||
mountDependencies(pending, atom, aState); | ||
if (!hasPrevValue || !Object.is(prevValue, aState.v)) { | ||
addPendingAtom(pending, atom, aState); | ||
const atomState = getAtomState(atom); | ||
const hasPrevValue = "v" in atomState; | ||
const prevValue = atomState.v; | ||
setAtomStateValueOrPromise(atom, atomState, value); | ||
mountDependencies(pending, atom, atomState); | ||
if (!hasPrevValue || !Object.is(prevValue, atomState.v)) { | ||
addPendingAtom(pending, atom, atomState); | ||
recomputeDependents(pending, atom); | ||
@@ -517,4 +524,5 @@ } | ||
}; | ||
return store; | ||
Object.assign(store, devStore); | ||
} | ||
return store; | ||
}); | ||
@@ -521,0 +529,0 @@ let defaultStore; |
@@ -1,1 +0,1 @@ | ||
System.register([],function(_){"use strict";return{execute:function(){_("atom",N);let L=0;function N(t,s){const f=`atom${++L}`,m={toString:()=>f};return typeof t=="function"?m.read=t:(m.init=t,m.read=P,m.write=R),s&&(m.write=s),m}function P(t){return t(this)}function R(t,s,f){return s(this,typeof f=="function"?f(t(this)):f)}const B=(t,s)=>t.unstable_is?t.unstable_is(s):s===t,F=t=>"init"in t,G=t=>!!t.write,M=Symbol(""),C="pending",T="fulfilled",U="rejected",$=t=>typeof t=="object"&&t!==null&&M in t,D=new WeakMap,x=(t,s,f)=>{if(!D.has(t)){let m;const w=new Promise((j,q)=>{let y=t;const z=v=>p=>{y===v&&(w.status=T,w.value=p,j(p),f())},g=v=>p=>{y===v&&(w.status=U,w.reason=p,q(p),f())};t.then(z(t),g(t)),m=(v,p)=>{v&&(D.set(v,w),y=v,v.then(z(v),g(v)),s(),s=p)}});w.status=C,w[M]=m,D.set(t,w)}return D.get(t)},Q=t=>typeof(t==null?void 0:t.then)=="function",H=t=>"v"in t||"e"in t,O=t=>{if("e"in t)throw t.e;return t.v},W=t=>{const s=t.v;return $(s)&&s.status===C?s:null},I=(t,s,f)=>{f.p.has(t)||(f.p.add(t),s.then(()=>{f.p.delete(t)},()=>{f.p.delete(t)}))},E=()=>[new Map,new Map,new Set],J=(t,s,f)=>{t[0].has(s)||t[0].set(s,new Set),t[1].set(s,f)},X=(t,s,f)=>{const m=t[0].get(s);m&&m.add(f)},Y=(t,s)=>t[0].get(s),K=(t,s)=>{t[2].add(s)},b=t=>{for(;t[1].size||t[2].size;){t[0].clear();const s=new Set(t[1].values());t[1].clear();const f=new Set(t[2]);t[2].clear(),s.forEach(m=>{var w;return(w=m.m)==null?void 0:w.l.forEach(j=>j())}),f.forEach(m=>m())}},Z=_("createStore",()=>{const t=new WeakMap,s=r=>{let e=t.get(r);return e||(e={d:new Map,p:new Set,n:0},t.set(r,e)),e},f=(r,e,n,o=()=>{},i=()=>{})=>{const a="v"in e,u=e.v,h=W(e);if(Q(n))if(h)h!==n&&(h[M](n,o),++e.n);else{const l=x(n,o,i);if(l.status===C)for(const c of e.d.keys()){const d=s(c);I(r,l,d)}e.v=l,delete e.e}else h&&h[M](Promise.resolve(n),o),e.v=n,delete e.e;(!a||!Object.is(u,e.v))&&++e.n},m=(r,e,n,o)=>{var i;const a=s(e);a.d.set(n,o.n);const u=W(a);u&&I(e,u,o),(i=o.m)==null||i.t.add(e),r&&X(r,n,e)},w=(r,e,n)=>{const o=s(e);if(!(n!=null&&n(e))&&H(o)&&(o.m||Array.from(o.d).every(([c,d])=>w(r,c,n).n===d)))return o;o.d.clear();let i=!0;const a=c=>{if(B(e,c)){const S=s(c);if(!H(S))if(F(c))f(c,S,c.init);else throw new Error("no atom init");return O(S)}const d=w(r,c,n);if(i)m(r,e,c,d);else{const S=E();m(S,e,c,d),g(S,e,o),b(S)}return O(d)};let u,h;const l={get signal(){return u||(u=new AbortController),u.signal},get setSelf(){return!h&&G(e)&&(h=(...c)=>{if(!i)return z(e,...c)}),h}};try{const c=e.read(a,l);return f(e,o,c,()=>u==null?void 0:u.abort(),()=>{if(o.m){const d=E();g(d,e,o),b(d)}}),o}catch(c){return delete o.v,o.e=c,++o.n,o}finally{i=!1}},j=r=>O(w(void 0,r)),q=(r,e)=>{const n=l=>{var c,d;const S=s(l),k=new Set((c=S.m)==null?void 0:c.t);for(const A of S.p)k.add(A);return(d=Y(r,l))==null||d.forEach(A=>{k.add(A)}),k},o=[],i=new Set,a=l=>{if(!i.has(l)){i.add(l);for(const c of n(l))l!==c&&a(c);o.push(l)}};a(e);const u=new Set([e]),h=l=>i.has(l);for(let l=o.length-1;l>=0;--l){const c=o[l],d=s(c),S=d.n;let k=!1;for(const A of d.d.keys())if(A!==c&&u.has(A)){k=!0;break}k&&(w(r,c,h),g(r,c,d),S!==d.n&&(J(r,c,d),u.add(c))),i.delete(c)}},y=(r,e,...n)=>{const o=a=>O(w(r,a)),i=(a,...u)=>{let h;if(B(e,a)){if(!F(a))throw new Error("atom not writable");const l=s(a),c="v"in l,d=l.v,S=u[0];f(a,l,S),g(r,a,l),(!c||!Object.is(d,l.v))&&(J(r,a,l),q(r,a))}else h=y(r,a,...u);return b(r),h};return e.write(o,i,...n)},z=(r,...e)=>{const n=E(),o=y(n,r,...e);return b(n),o},g=(r,e,n)=>{if(n.m&&!W(n)){for(const o of n.d.keys())n.m.d.has(o)||(v(r,o).t.add(e),n.m.d.add(o));for(const o of n.m.d||[])if(!n.d.has(o)){const i=p(r,o);i==null||i.t.delete(e),n.m.d.delete(o)}}},v=(r,e)=>{const n=s(e);if(!n.m){w(r,e);for(const o of n.d.keys())v(r,o).t.add(e);if(n.m={l:new Set,d:new Set(n.d.keys()),t:new Set},G(e)&&e.onMount){const o=n.m,{onMount:i}=e;K(r,()=>{const a=i((...u)=>y(r,e,...u));a&&(o.u=a)})}}return n.m},p=(r,e)=>{const n=s(e);if(n.m&&!n.m.l.size&&!Array.from(n.m.t).some(o=>s(o).m)){const o=n.m.u;o&&K(r,o),delete n.m;for(const a of n.d.keys()){const u=p(r,a);u==null||u.t.delete(e)}const i=W(n);i&&i[M](void 0,()=>{});return}return n.m};return{get:j,set:z,sub:(r,e)=>{const n=E(),o=v(n,r);b(n);const i=o.l;return i.add(e),()=>{i.delete(e);const a=E();p(a,r),b(a)}}}});let V;const tt=_("getDefaultStore",()=>(V||(V=Z()),V))}}}); | ||
System.register([],function(W){"use strict";return{execute:function(){W("atom",L);let K=0;function L(t,s){const f=`atom${++K}`,m={toString(){return f}};return typeof t=="function"?m.read=t:(m.init=t,m.read=N,m.write=R),s&&(m.write=s),m}function N(t){return t(this)}function R(t,s,f){return s(this,typeof f=="function"?f(t(this)):f)}const q=(t,s)=>t.unstable_is?t.unstable_is(s):s===t,B=t=>"init"in t,F=t=>!!t.write,M=Symbol(""),_="pending",T="fulfilled",U="rejected",$=t=>typeof t=="object"&&t!==null&&M in t,D=new WeakMap,x=(t,s,f)=>{if(!D.has(t)){let m;const w=new Promise((j,V)=>{let y=t;const z=h=>p=>{y===h&&(w.status=T,w.value=p,j(p),f())},g=h=>p=>{y===h&&(w.status=U,w.reason=p,V(p),f())};t.then(z(t),g(t)),m=(h,p)=>{h&&(D.set(h,w),y=h,h.then(z(h),g(h)),s(),s=p)}});w.status=_,w[M]=m,D.set(t,w)}return D.get(t)},Q=t=>typeof(t==null?void 0:t.then)=="function",G=t=>"v"in t||"e"in t,O=t=>{if("e"in t)throw t.e;return t.v},P=t=>{const s=t.v;return $(s)&&s.status===_?s:null},H=(t,s,f)=>{f.p.has(t)||(f.p.add(t),s.then(()=>{f.p.delete(t)},()=>{f.p.delete(t)}))},E=()=>[new Map,new Map,new Set],I=(t,s,f)=>{t[0].has(s)||t[0].set(s,new Set),t[1].set(s,f)},X=(t,s,f)=>{const m=t[0].get(s);m&&m.add(f)},Y=(t,s)=>t[0].get(s),J=(t,s)=>{t[2].add(s)},b=t=>{for(;t[1].size||t[2].size;){t[0].clear();const s=new Set(t[1].values());t[1].clear();const f=new Set(t[2]);t[2].clear(),s.forEach(m=>{var w;return(w=m.m)==null?void 0:w.l.forEach(j=>j())}),f.forEach(m=>m())}},Z=W("createStore",()=>{const t=new WeakMap,s=r=>{let e=t.get(r);return e||(e={d:new Map,p:new Set,n:0},t.set(r,e)),e},f=(r,e,n,o=()=>{},c=()=>{})=>{const l="v"in e,u=e.v,v=P(e);if(Q(n))if(v)v!==n&&(v[M](n,o),++e.n);else{const a=x(n,o,c);if(a.status===_)for(const i of e.d.keys()){const d=s(i);H(r,a,d)}e.v=a,delete e.e}else v&&v[M](Promise.resolve(n),o),e.v=n,delete e.e;(!l||!Object.is(u,e.v))&&++e.n},m=(r,e,n,o)=>{var c;const l=s(e);l.d.set(n,o.n);const u=P(l);u&&H(e,u,o),(c=o.m)==null||c.t.add(e),r&&X(r,n,e)},w=(r,e,n)=>{const o=s(e);if(!(n!=null&&n(e))&&G(o)&&(o.m||Array.from(o.d).every(([i,d])=>w(r,i,n).n===d)))return o;o.d.clear();let c=!0;const l=i=>{if(q(e,i)){const S=s(i);if(!G(S))if(B(i))f(i,S,i.init);else throw new Error("no atom init");return O(S)}const d=w(r,i,n);if(c)m(r,e,i,d);else{const S=E();m(S,e,i,d),g(S,e,o),b(S)}return O(d)};let u,v;const a={get signal(){return u||(u=new AbortController),u.signal},get setSelf(){return!v&&F(e)&&(v=(...i)=>{if(!c)return z(e,...i)}),v}};try{const i=e.read(l,a);return f(e,o,i,()=>u==null?void 0:u.abort(),()=>{if(o.m){const d=E();g(d,e,o),b(d)}}),o}catch(i){return delete o.v,o.e=i,++o.n,o}finally{c=!1}},j=r=>O(w(void 0,r)),V=(r,e)=>{const n=a=>{var i,d;const S=s(a),k=new Set((i=S.m)==null?void 0:i.t);for(const A of S.p)k.add(A);return(d=Y(r,a))==null||d.forEach(A=>{k.add(A)}),k},o=[],c=new Set,l=a=>{if(!c.has(a)){c.add(a);for(const i of n(a))a!==i&&l(i);o.push(a)}};l(e);const u=new Set([e]),v=a=>c.has(a);for(let a=o.length-1;a>=0;--a){const i=o[a],d=s(i),S=d.n;let k=!1;for(const A of d.d.keys())if(A!==i&&u.has(A)){k=!0;break}k&&(w(r,i,v),g(r,i,d),S!==d.n&&(I(r,i,d),u.add(i))),c.delete(i)}},y=(r,e,...n)=>{const o=l=>O(w(r,l)),c=(l,...u)=>{let v;if(q(e,l)){if(!B(l))throw new Error("atom not writable");const a=s(l),i="v"in a,d=a.v,S=u[0];f(l,a,S),g(r,l,a),(!i||!Object.is(d,a.v))&&(I(r,l,a),V(r,l))}else v=y(r,l,...u);return b(r),v};return e.write(o,c,...n)},z=(r,...e)=>{const n=E(),o=y(n,r,...e);return b(n),o},g=(r,e,n)=>{if(n.m&&!P(n)){for(const o of n.d.keys())n.m.d.has(o)||(h(r,o).t.add(e),n.m.d.add(o));for(const o of n.m.d||[])if(!n.d.has(o)){n.m.d.delete(o);const c=p(r,o);c==null||c.t.delete(e)}}},h=(r,e)=>{const n=s(e);if(!n.m){w(r,e);for(const o of n.d.keys())h(r,o).t.add(e);if(n.m={l:new Set,d:new Set(n.d.keys()),t:new Set},F(e)&&e.onMount){const o=n.m,{onMount:c}=e;J(r,()=>{const l=c((...u)=>y(r,e,...u));l&&(o.u=l)})}}return n.m},p=(r,e)=>{const n=s(e);if(n.m&&!n.m.l.size&&!Array.from(n.m.t).some(o=>{var c;return(c=s(o).m)==null?void 0:c.d.has(e)})){const o=n.m.u;o&&J(r,o),delete n.m;for(const l of n.d.keys()){const u=p(r,l);u==null||u.t.delete(e)}const c=P(n);c&&c[M](void 0,()=>{});return}return n.m};return{get:j,set:z,sub:(r,e)=>{const n=E(),o=h(n,r);b(n);const c=o.l;return c.add(e),()=>{c.delete(e);const l=E();p(l,r),b(l)}}}});let C;const tt=W("getDefaultStore",()=>(C||(C=Z()),C))}}}); |
@@ -1,4 +0,5 @@ | ||
import babel, { PluginObj } from '@babel/core'; | ||
import babel from '@babel/core'; | ||
import type { PluginObj } from '@babel/core'; | ||
import type { PluginOptions } from './utils'; | ||
export default function debugLabelPlugin({ types: t }: typeof babel, options?: PluginOptions): PluginObj; | ||
declare type Awaited<T> = T extends Promise<infer V> ? V : T; |
@@ -1,4 +0,5 @@ | ||
import babel, { PluginObj } from '@babel/core'; | ||
import babel from '@babel/core'; | ||
import type { PluginObj } from '@babel/core'; | ||
import type { PluginOptions } from './utils'; | ||
export default function reactRefreshPlugin({ types: t }: typeof babel, options?: PluginOptions): PluginObj; | ||
declare type Awaited<T> = T extends Promise<infer V> ? V : T; |
import babel from '@babel/core'; | ||
import { PluginOptions } from './utils'; | ||
import type { PluginOptions } from './utils'; | ||
export default function jotaiPreset(_: typeof babel, options?: PluginOptions): { | ||
@@ -4,0 +4,0 @@ plugins: babel.PluginItem[]; |
@@ -1,4 +0,5 @@ | ||
import babel, { PluginObj } from '@babel/core'; | ||
import babel from '@babel/core'; | ||
import type { PluginObj } from '@babel/core'; | ||
import type { PluginOptions } from './utils'; | ||
export default function debugLabelPlugin({ types: t }: typeof babel, options?: PluginOptions): PluginObj; | ||
declare type Awaited<T> = T extends Promise<infer V> ? V : T; |
@@ -1,4 +0,5 @@ | ||
import babel, { PluginObj } from '@babel/core'; | ||
import babel from '@babel/core'; | ||
import type { PluginObj } from '@babel/core'; | ||
import type { PluginOptions } from './utils'; | ||
export default function reactRefreshPlugin({ types: t }: typeof babel, options?: PluginOptions): PluginObj; | ||
declare type Awaited<T> = T extends Promise<infer V> ? V : T; |
import babel from '@babel/core'; | ||
import { PluginOptions } from './utils'; | ||
import type { PluginOptions } from './utils'; | ||
export default function jotaiPreset(_: typeof babel, options?: PluginOptions): { | ||
@@ -4,0 +4,0 @@ plugins: babel.PluginItem[]; |
@@ -40,4 +40,5 @@ type Getter = <Value>(atom: Atom<Value>) => Value; | ||
export declare function atom<Value, Args extends unknown[], Result>(initialValue: Value, write: Write<Args, Result>): WritableAtom<Value, Args, Result> & WithInitialValue<Value>; | ||
export declare function atom<Value>(): PrimitiveAtom<Value | undefined> & WithInitialValue<Value | undefined>; | ||
export declare function atom<Value>(initialValue: Value): PrimitiveAtom<Value> & WithInitialValue<Value>; | ||
export {}; | ||
declare type Awaited<T> = T extends Promise<infer V> ? V : T; |
@@ -1,3 +0,3 @@ | ||
import { PrimitiveAtom } from 'jotai/vanilla'; | ||
import type { PrimitiveAtom } from 'jotai/vanilla'; | ||
export declare function atomWithLazy<Value>(makeInitial: () => Value): PrimitiveAtom<Value>; | ||
declare type Awaited<T> = T extends Promise<infer V> ? V : T; |
@@ -40,4 +40,5 @@ type Getter = <Value>(atom: Atom<Value>) => Value; | ||
export declare function atom<Value, Args extends unknown[], Result>(initialValue: Value, write: Write<Args, Result>): WritableAtom<Value, Args, Result> & WithInitialValue<Value>; | ||
export declare function atom<Value>(): PrimitiveAtom<Value | undefined> & WithInitialValue<Value | undefined>; | ||
export declare function atom<Value>(initialValue: Value): PrimitiveAtom<Value> & WithInitialValue<Value>; | ||
export {}; | ||
declare type Awaited<T> = T extends Promise<infer V> ? V : T; |
@@ -1,3 +0,3 @@ | ||
import { PrimitiveAtom } from 'jotai/vanilla'; | ||
import type { PrimitiveAtom } from 'jotai/vanilla'; | ||
export declare function atomWithLazy<Value>(makeInitial: () => Value): PrimitiveAtom<Value>; | ||
declare type Awaited<T> = T extends Promise<infer V> ? V : T; |
@@ -51,3 +51,3 @@ 'use client'; | ||
if (t) return (t = t.call(r)).next.bind(t); | ||
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e ) { | ||
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) { | ||
t && (r = t); | ||
@@ -54,0 +54,0 @@ var o = 0; |
@@ -12,3 +12,3 @@ (function (global, factory) { | ||
toString: function toString() { | ||
return key; | ||
return this.debugLabel ? key + ':' + this.debugLabel : key; | ||
} | ||
@@ -43,3 +43,3 @@ }; | ||
if (t) return (t = t.call(r)).next.bind(t); | ||
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e ) { | ||
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) { | ||
t && (r = t); | ||
@@ -221,3 +221,3 @@ var o = 0; | ||
} | ||
var hasPrevValue = ('v' in atomState); | ||
var hasPrevValue = 'v' in atomState; | ||
var prevValue = atomState.v; | ||
@@ -434,3 +434,3 @@ var pendingPromise = getPendingContinuablePromise(atomState); | ||
var aState = getAtomState(a); | ||
var hasPrevValue = ('v' in aState); | ||
var hasPrevValue = 'v' in aState; | ||
var prevValue = aState.v; | ||
@@ -478,5 +478,5 @@ var v = args[0]; | ||
if (!atomState.d.has(_a)) { | ||
atomState.m.d.delete(_a); | ||
var _aMounted = unmountAtom(pending, _a); | ||
_aMounted == null || _aMounted.t.delete(atom); | ||
atomState.m.d.delete(_a); | ||
} | ||
@@ -524,3 +524,4 @@ } | ||
if (atomState.m && !atomState.m.l.size && !Array.from(atomState.m.t).some(function (a) { | ||
return getAtomState(a).m; | ||
var _getAtomState$m; | ||
return (_getAtomState$m = getAtomState(a).m) == null ? void 0 : _getAtomState$m.d.has(atom); | ||
})) { | ||
@@ -561,7 +562,9 @@ var onUnmount = atomState.m.u; | ||
}; | ||
var store = { | ||
get: readAtom, | ||
set: writeAtom, | ||
sub: subscribeAtom | ||
}; | ||
{ | ||
var store = { | ||
get: readAtom, | ||
set: writeAtom, | ||
sub: subscribeAtom, | ||
var devStore = { | ||
dev4_get_internal_weak_map: function dev4_get_internal_weak_map() { | ||
@@ -580,9 +583,9 @@ return atomStateMap; | ||
if (hasInitialValue(atom)) { | ||
var aState = getAtomState(atom); | ||
var hasPrevValue = ('v' in aState); | ||
var prevValue = aState.v; | ||
setAtomStateValueOrPromise(atom, aState, value); | ||
mountDependencies(pending, atom, aState); | ||
if (!hasPrevValue || !Object.is(prevValue, aState.v)) { | ||
addPendingAtom(pending, atom, aState); | ||
var atomState = getAtomState(atom); | ||
var hasPrevValue = 'v' in atomState; | ||
var prevValue = atomState.v; | ||
setAtomStateValueOrPromise(atom, atomState, value); | ||
mountDependencies(pending, atom, atomState); | ||
if (!hasPrevValue || !Object.is(prevValue, atomState.v)) { | ||
addPendingAtom(pending, atom, atomState); | ||
recomputeDependents(pending, atom); | ||
@@ -595,4 +598,5 @@ } | ||
}; | ||
return store; | ||
Object.assign(store, devStore); | ||
} | ||
return store; | ||
}; | ||
@@ -599,0 +603,0 @@ var defaultStore; |
@@ -1,1 +0,1 @@ | ||
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((n="undefined"!=typeof globalThis?globalThis:n||self).jotaiVanilla={})}(this,(function(n){"use strict";var e=0;function t(n){return n(this)}function r(n,e,t){return e(this,"function"==typeof t?t(n(this)):t)}function o(n,e){(null==e||e>n.length)&&(e=n.length);for(var t=0,r=Array(e);t<e;t++)r[t]=n[t];return r}function a(n,e){var t="undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(t)return(t=t.call(n)).next.bind(t);if(Array.isArray(n)||(t=function(n,e){if(n){if("string"==typeof n)return o(n,e);var t={}.toString.call(n).slice(8,-1);return"Object"===t&&n.constructor&&(t=n.constructor.name),"Map"===t||"Set"===t?Array.from(n):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?o(n,e):void 0}}(n))||e){t&&(n=t);var r=0;return function(){return r>=n.length?{done:!0}:{done:!1,value:n[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,u=function(n,e){return n.unstable_is?n.unstable_is(e):e===n},f=function(n){return"init"in n},c=function(n){return!!n.write},l=Symbol(""),v="pending",d=new WeakMap,s=function(n){return"v"in n||"e"in n},m=function(n){if("e"in n)throw n.e;return n.v},y=function(n){var e,t=n.v;return"object"==typeof(e=t)&&null!==e&&l in e&&t.status===v?t:null},p=function(n,e,t){t.p.has(n)||(t.p.add(n),e.then((function(){t.p.delete(n)}),(function(){t.p.delete(n)})))},h=function(){return[new Map,new Map,new Set]},w=function(n,e,t){n[0].has(e)||n[0].set(e,new Set),n[1].set(e,t)},g=function(n,e){n[2].add(e)},b=function(n){for(;n[1].size||n[2].size;){n[0].clear();var e=new Set(n[1].values());n[1].clear();var t=new Set(n[2]);n[2].clear(),e.forEach((function(n){var e;return null==(e=n.m)?void 0:e.l.forEach((function(n){return n()}))})),t.forEach((function(n){return n()}))}},S=function(){var n=new WeakMap,e=function(e){var t=n.get(e);return t||(t={d:new Map,p:new Set,n:0},n.set(e,t)),t},t=function(n,t,r,o,i){void 0===o&&(o=function(){}),void 0===i&&(i=function(){});var u,f="v"in t,c=t.v,s=y(t);if("function"==typeof(null==(u=r)?void 0:u.then))if(s)s!==r&&(s[l](r,o),++t.n);else{var m=function(n,e,t){if(!d.has(n)){var r,o=new Promise((function(a,i){var u=n,f=function(n){return function(e){u===n&&(o.status="fulfilled",o.value=e,a(e),t())}},c=function(n){return function(e){u===n&&(o.status="rejected",o.reason=e,i(e),t())}};n.then(f(n),c(n)),r=function(n,t){n&&(d.set(n,o),u=n,n.then(f(n),c(n)),e(),e=t)}}));o.status=v,o[l]=r,d.set(n,o)}return d.get(n)}(r,o,i);if(m.status===v)for(var h,w=a(t.d.keys());!(h=w()).done;){var g=h.value,b=e(g);p(n,m,b)}t.v=m,delete t.e}else s&&s[l](Promise.resolve(r),o),t.v=r,delete t.e;f&&Object.is(c,t.v)||++t.n},r=function(n,t,r,o){var a,i=e(t);i.d.set(r,o.n);var u=y(i);u&&p(t,u,o),null==(a=o.m)||a.t.add(t),n&&function(n,e,t){var r=n[0].get(e);r&&r.add(t)}(n,r,t)},o=function n(o,a,i){var l=e(a);if((null==i||!i(a))&&s(l)){if(l.m)return l;if(Array.from(l.d).every((function(e){var t=e[0],r=e[1];return n(o,t,i).n===r})))return l}l.d.clear();var v,d,y=!0,p={get signal(){return v||(v=new AbortController),v.signal},get setSelf(){return!d&&c(a)&&(d=function(){if(!y){for(var n=arguments.length,e=new Array(n),t=0;t<n;t++)e[t]=arguments[t];return A.apply(void 0,[a].concat(e))}}),d}};try{var w=a.read((function(c){if(u(a,c)){var v=e(c);if(!s(v)){if(!f(c))throw new Error("no atom init");t(c,v,c.init)}return m(v)}var d=n(o,c,i);if(y)r(o,a,c,d);else{var p=h();r(p,a,c,d),k(p,a,l),b(p)}return m(d)}),p);return t(a,l,w,(function(){var n;return null==(n=v)?void 0:n.abort()}),(function(){if(l.m){var n=h();k(n,a,l),b(n)}})),l}catch(n){return delete l.v,l.e=n,++l.n,l}finally{y=!1}},i=function(n,t){var r=[],i=new Set;!function t(o){if(!i.has(o)){i.add(o);for(var u,f=a(function(t){for(var r,o,i,u=e(t),f=new Set(null==(r=u.m)?void 0:r.t),c=a(u.p);!(i=c()).done;){var l=i.value;f.add(l)}return null==(o=function(n,e){return n[0].get(e)}(n,t))||o.forEach((function(n){f.add(n)})),f}(o));!(u=f()).done;){var c=u.value;o!==c&&t(c)}r.push(o)}}(t);for(var u=new Set([t]),f=function(n){return i.has(n)},c=r.length-1;c>=0;--c){for(var l,v=r[c],d=e(v),s=d.n,m=!1,y=a(d.d.keys());!(l=y()).done;){var p=l.value;if(p!==v&&u.has(p)){m=!0;break}}m&&(o(n,v,f),k(n,v,d),s!==d.n&&(w(n,v,d),u.add(v))),i.delete(v)}},S=function n(r,a){for(var c=arguments.length,l=new Array(c>2?c-2:0),v=2;v<c;v++)l[v-2]=arguments[v];var d=a.write.apply(a,[function(n){return m(o(r,n))},function(o){for(var c,l=arguments.length,v=new Array(l>1?l-1:0),d=1;d<l;d++)v[d-1]=arguments[d];if(u(a,o)){if(!f(o))throw new Error("atom not writable");var s=e(o),m="v"in s,y=s.v,p=v[0];t(o,s,p),k(r,o,s),m&&Object.is(y,s.v)||(w(r,o,s),i(r,o))}else c=n.apply(void 0,[r,o].concat(v));return b(r),c}].concat(l));return d},A=function(n){for(var e=h(),t=arguments.length,r=new Array(t>1?t-1:0),o=1;o<t;o++)r[o-1]=arguments[o];var a=S.apply(void 0,[e,n].concat(r));return b(e),a},k=function(n,e,t){if(t.m&&!y(t)){for(var r,o=a(t.d.keys());!(r=o()).done;){var i=r.value;if(!t.m.d.has(i))j(n,i).t.add(e),t.m.d.add(i)}for(var u,f=a(t.m.d||[]);!(u=f()).done;){var c=u.value;if(!t.d.has(c)){var l=M(n,c);null==l||l.t.delete(e),t.m.d.delete(c)}}}},j=function n(t,r){var i=e(r);if(!i.m){o(t,r);for(var u,f=a(i.d.keys());!(u=f()).done;){var l=u.value;n(t,l).t.add(r)}if(i.m={l:new Set,d:new Set(i.d.keys()),t:new Set},c(r)&&r.onMount){var v=i.m,d=r.onMount;g(t,(function(){var n=d((function(){for(var n=arguments.length,e=new Array(n),o=0;o<n;o++)e[o]=arguments[o];return S.apply(void 0,[t,r].concat(e))}));n&&(v.u=n)}))}}return i.m},M=function n(t,r){var o=e(r);if(!o.m||o.m.l.size||Array.from(o.m.t).some((function(n){return e(n).m})))return o.m;var i=o.m.u;i&&g(t,i),delete o.m;for(var u,f=a(o.d.keys());!(u=f()).done;){var c=n(t,u.value);null==c||c.t.delete(r)}var v=y(o);v&&v[l](void 0,(function(){}))};return{get:function(n){return m(o(void 0,n))},set:A,sub:function(n,e){var t=h(),r=j(t,n);b(t);var o=r.l;return o.add(e),function(){o.delete(e);var t=h();M(t,n),b(t)}}}};n.atom=function(n,o){var a="atom"+ ++e,i={toString:function(){return a}};return"function"==typeof n?i.read=n:(i.init=n,i.read=t,i.write=r),o&&(i.write=o),i},n.createStore=S,n.getDefaultStore=function(){return i||(i=S()),i}})); | ||
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((n="undefined"!=typeof globalThis?globalThis:n||self).jotaiVanilla={})}(this,(function(n){"use strict";var e=0;function t(n){return n(this)}function r(n,e,t){return e(this,"function"==typeof t?t(n(this)):t)}function o(n,e){(null==e||e>n.length)&&(e=n.length);for(var t=0,r=Array(e);t<e;t++)r[t]=n[t];return r}function a(n,e){var t="undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(t)return(t=t.call(n)).next.bind(t);if(Array.isArray(n)||(t=function(n,e){if(n){if("string"==typeof n)return o(n,e);var t={}.toString.call(n).slice(8,-1);return"Object"===t&&n.constructor&&(t=n.constructor.name),"Map"===t||"Set"===t?Array.from(n):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?o(n,e):void 0}}(n))||e){t&&(n=t);var r=0;return function(){return r>=n.length?{done:!0}:{done:!1,value:n[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,u=function(n,e){return n.unstable_is?n.unstable_is(e):e===n},f=function(n){return"init"in n},l=function(n){return!!n.write},c=Symbol(""),v="pending",d=new WeakMap,s=function(n){return"v"in n||"e"in n},m=function(n){if("e"in n)throw n.e;return n.v},y=function(n){var e,t=n.v;return"object"==typeof(e=t)&&null!==e&&c in e&&t.status===v?t:null},h=function(n,e,t){t.p.has(n)||(t.p.add(n),e.then((function(){t.p.delete(n)}),(function(){t.p.delete(n)})))},p=function(){return[new Map,new Map,new Set]},w=function(n,e,t){n[0].has(e)||n[0].set(e,new Set),n[1].set(e,t)},g=function(n,e){n[2].add(e)},b=function(n){for(;n[1].size||n[2].size;){n[0].clear();var e=new Set(n[1].values());n[1].clear();var t=new Set(n[2]);n[2].clear(),e.forEach((function(n){var e;return null==(e=n.m)?void 0:e.l.forEach((function(n){return n()}))})),t.forEach((function(n){return n()}))}},S=function(){var n=new WeakMap,e=function(e){var t=n.get(e);return t||(t={d:new Map,p:new Set,n:0},n.set(e,t)),t},t=function(n,t,r,o,i){void 0===o&&(o=function(){}),void 0===i&&(i=function(){});var u,f="v"in t,l=t.v,s=y(t);if("function"==typeof(null==(u=r)?void 0:u.then))if(s)s!==r&&(s[c](r,o),++t.n);else{var m=function(n,e,t){if(!d.has(n)){var r,o=new Promise((function(a,i){var u=n,f=function(n){return function(e){u===n&&(o.status="fulfilled",o.value=e,a(e),t())}},l=function(n){return function(e){u===n&&(o.status="rejected",o.reason=e,i(e),t())}};n.then(f(n),l(n)),r=function(n,t){n&&(d.set(n,o),u=n,n.then(f(n),l(n)),e(),e=t)}}));o.status=v,o[c]=r,d.set(n,o)}return d.get(n)}(r,o,i);if(m.status===v)for(var p,w=a(t.d.keys());!(p=w()).done;){var g=p.value,b=e(g);h(n,m,b)}t.v=m,delete t.e}else s&&s[c](Promise.resolve(r),o),t.v=r,delete t.e;f&&Object.is(l,t.v)||++t.n},r=function(n,t,r,o){var a,i=e(t);i.d.set(r,o.n);var u=y(i);u&&h(t,u,o),null==(a=o.m)||a.t.add(t),n&&function(n,e,t){var r=n[0].get(e);r&&r.add(t)}(n,r,t)},o=function n(o,a,i){var c=e(a);if((null==i||!i(a))&&s(c)){if(c.m)return c;if(Array.from(c.d).every((function(e){var t=e[0],r=e[1];return n(o,t,i).n===r})))return c}c.d.clear();var v,d,y=!0,h={get signal(){return v||(v=new AbortController),v.signal},get setSelf(){return!d&&l(a)&&(d=function(){if(!y){for(var n=arguments.length,e=new Array(n),t=0;t<n;t++)e[t]=arguments[t];return A.apply(void 0,[a].concat(e))}}),d}};try{var w=a.read((function(l){if(u(a,l)){var v=e(l);if(!s(v)){if(!f(l))throw new Error("no atom init");t(l,v,l.init)}return m(v)}var d=n(o,l,i);if(y)r(o,a,l,d);else{var h=p();r(h,a,l,d),k(h,a,c),b(h)}return m(d)}),h);return t(a,c,w,(function(){var n;return null==(n=v)?void 0:n.abort()}),(function(){if(c.m){var n=p();k(n,a,c),b(n)}})),c}catch(n){return delete c.v,c.e=n,++c.n,c}finally{y=!1}},i=function(n,t){var r=[],i=new Set;!function t(o){if(!i.has(o)){i.add(o);for(var u,f=a(function(t){for(var r,o,i,u=e(t),f=new Set(null==(r=u.m)?void 0:r.t),l=a(u.p);!(i=l()).done;){var c=i.value;f.add(c)}return null==(o=function(n,e){return n[0].get(e)}(n,t))||o.forEach((function(n){f.add(n)})),f}(o));!(u=f()).done;){var l=u.value;o!==l&&t(l)}r.push(o)}}(t);for(var u=new Set([t]),f=function(n){return i.has(n)},l=r.length-1;l>=0;--l){for(var c,v=r[l],d=e(v),s=d.n,m=!1,y=a(d.d.keys());!(c=y()).done;){var h=c.value;if(h!==v&&u.has(h)){m=!0;break}}m&&(o(n,v,f),k(n,v,d),s!==d.n&&(w(n,v,d),u.add(v))),i.delete(v)}},S=function n(r,a){for(var l=arguments.length,c=new Array(l>2?l-2:0),v=2;v<l;v++)c[v-2]=arguments[v];var d=a.write.apply(a,[function(n){return m(o(r,n))},function(o){for(var l,c=arguments.length,v=new Array(c>1?c-1:0),d=1;d<c;d++)v[d-1]=arguments[d];if(u(a,o)){if(!f(o))throw new Error("atom not writable");var s=e(o),m="v"in s,y=s.v,h=v[0];t(o,s,h),k(r,o,s),m&&Object.is(y,s.v)||(w(r,o,s),i(r,o))}else l=n.apply(void 0,[r,o].concat(v));return b(r),l}].concat(c));return d},A=function(n){for(var e=p(),t=arguments.length,r=new Array(t>1?t-1:0),o=1;o<t;o++)r[o-1]=arguments[o];var a=S.apply(void 0,[e,n].concat(r));return b(e),a},k=function(n,e,t){if(t.m&&!y(t)){for(var r,o=a(t.d.keys());!(r=o()).done;){var i=r.value;if(!t.m.d.has(i))j(n,i).t.add(e),t.m.d.add(i)}for(var u,f=a(t.m.d||[]);!(u=f()).done;){var l=u.value;if(!t.d.has(l)){t.m.d.delete(l);var c=M(n,l);null==c||c.t.delete(e)}}}},j=function n(t,r){var i=e(r);if(!i.m){o(t,r);for(var u,f=a(i.d.keys());!(u=f()).done;){var c=u.value;n(t,c).t.add(r)}if(i.m={l:new Set,d:new Set(i.d.keys()),t:new Set},l(r)&&r.onMount){var v=i.m,d=r.onMount;g(t,(function(){var n=d((function(){for(var n=arguments.length,e=new Array(n),o=0;o<n;o++)e[o]=arguments[o];return S.apply(void 0,[t,r].concat(e))}));n&&(v.u=n)}))}}return i.m},M=function n(t,r){var o=e(r);if(!o.m||o.m.l.size||Array.from(o.m.t).some((function(n){var t;return null==(t=e(n).m)?void 0:t.d.has(r)})))return o.m;var i=o.m.u;i&&g(t,i),delete o.m;for(var u,f=a(o.d.keys());!(u=f()).done;){var l=n(t,u.value);null==l||l.t.delete(r)}var v=y(o);v&&v[c](void 0,(function(){}))},E={get:function(n){return m(o(void 0,n))},set:A,sub:function(n,e){var t=p(),r=j(t,n);b(t);var o=r.l;return o.add(e),function(){o.delete(e);var t=p();M(t,n),b(t)}}};return E};n.atom=function(n,o){var a="atom"+ ++e,i={toString:function(){return a}};return"function"==typeof n?i.read=n:(i.init=n,i.read=t,i.write=r),o&&(i.write=o),i},n.createStore=S,n.getDefaultStore=function(){return i||(i=S()),i}})); |
@@ -31,3 +31,3 @@ (function (global, factory) { | ||
if (t) return (t = t.call(r)).next.bind(t); | ||
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e ) { | ||
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) { | ||
t && (r = t); | ||
@@ -34,0 +34,0 @@ var o = 0; |
@@ -8,3 +8,3 @@ 'use strict'; | ||
toString: function toString() { | ||
return key; | ||
return process.env.NODE_ENV !== 'production' && this.debugLabel ? key + ':' + this.debugLabel : key; | ||
} | ||
@@ -39,3 +39,3 @@ }; | ||
if (t) return (t = t.call(r)).next.bind(t); | ||
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e ) { | ||
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) { | ||
t && (r = t); | ||
@@ -217,3 +217,3 @@ var o = 0; | ||
} | ||
var hasPrevValue = ('v' in atomState); | ||
var hasPrevValue = 'v' in atomState; | ||
var prevValue = atomState.v; | ||
@@ -430,3 +430,3 @@ var pendingPromise = getPendingContinuablePromise(atomState); | ||
var aState = getAtomState(a); | ||
var hasPrevValue = ('v' in aState); | ||
var hasPrevValue = 'v' in aState; | ||
var prevValue = aState.v; | ||
@@ -474,5 +474,5 @@ var v = args[0]; | ||
if (!atomState.d.has(_a)) { | ||
atomState.m.d.delete(_a); | ||
var _aMounted = unmountAtom(pending, _a); | ||
_aMounted == null || _aMounted.t.delete(atom); | ||
atomState.m.d.delete(_a); | ||
} | ||
@@ -520,3 +520,4 @@ } | ||
if (atomState.m && !atomState.m.l.size && !Array.from(atomState.m.t).some(function (a) { | ||
return getAtomState(a).m; | ||
var _getAtomState$m; | ||
return (_getAtomState$m = getAtomState(a).m) == null ? void 0 : _getAtomState$m.d.has(atom); | ||
})) { | ||
@@ -557,7 +558,9 @@ var onUnmount = atomState.m.u; | ||
}; | ||
var store = { | ||
get: readAtom, | ||
set: writeAtom, | ||
sub: subscribeAtom | ||
}; | ||
if (process.env.NODE_ENV !== 'production') { | ||
var store = { | ||
get: readAtom, | ||
set: writeAtom, | ||
sub: subscribeAtom, | ||
var devStore = { | ||
dev4_get_internal_weak_map: function dev4_get_internal_weak_map() { | ||
@@ -576,9 +579,9 @@ return atomStateMap; | ||
if (hasInitialValue(atom)) { | ||
var aState = getAtomState(atom); | ||
var hasPrevValue = ('v' in aState); | ||
var prevValue = aState.v; | ||
setAtomStateValueOrPromise(atom, aState, value); | ||
mountDependencies(pending, atom, aState); | ||
if (!hasPrevValue || !Object.is(prevValue, aState.v)) { | ||
addPendingAtom(pending, atom, aState); | ||
var atomState = getAtomState(atom); | ||
var hasPrevValue = 'v' in atomState; | ||
var prevValue = atomState.v; | ||
setAtomStateValueOrPromise(atom, atomState, value); | ||
mountDependencies(pending, atom, atomState); | ||
if (!hasPrevValue || !Object.is(prevValue, atomState.v)) { | ||
addPendingAtom(pending, atom, atomState); | ||
recomputeDependents(pending, atom); | ||
@@ -591,9 +594,5 @@ } | ||
}; | ||
return store; | ||
Object.assign(store, devStore); | ||
} | ||
return { | ||
get: readAtom, | ||
set: writeAtom, | ||
sub: subscribeAtom | ||
}; | ||
return store; | ||
}; | ||
@@ -600,0 +599,0 @@ var defaultStore; |
@@ -40,3 +40,4 @@ type Getter = <Value>(atom: Atom<Value>) => Value; | ||
export declare function atom<Value, Args extends unknown[], Result>(initialValue: Value, write: Write<Args, Result>): WritableAtom<Value, Args, Result> & WithInitialValue<Value>; | ||
export declare function atom<Value>(): PrimitiveAtom<Value | undefined> & WithInitialValue<Value | undefined>; | ||
export declare function atom<Value>(initialValue: Value): PrimitiveAtom<Value> & WithInitialValue<Value>; | ||
export {}; |
@@ -29,3 +29,3 @@ 'use strict'; | ||
if (t) return (t = t.call(r)).next.bind(t); | ||
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e ) { | ||
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) { | ||
t && (r = t); | ||
@@ -32,0 +32,0 @@ var o = 0; |
@@ -1,2 +0,2 @@ | ||
import { PrimitiveAtom } from 'jotai/vanilla'; | ||
import type { PrimitiveAtom } from 'jotai/vanilla'; | ||
export declare function atomWithLazy<Value>(makeInitial: () => Value): PrimitiveAtom<Value>; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
416234
9082