UNPKG

5.77 kBJavaScriptView Raw
1System.register(["react","jotai"],function(J){"use strict";var M,R,_,$,w,P,I,j;return{setters:[function(v){M=v.useContext,R=v.useState,_=v.useEffect,$=v.useDebugValue,w=v.useRef,P=v.useCallback},function(v){I=v.SECRET_INTERNAL_getScopeContext,j=v.useAtom}],execute:function(){J({useAtomDevtools:W,useAtomsDevtools:ne,useAtomsSnapshot:Q,useGotoAtomsSnapshot:Y});const v="h",D="n",L="l",U="a",x="m",k=e=>e.debugLabel||e.toString(),q=([e,n])=>Object.fromEntries(n.flatMap(t=>{var s,r;const o=(s=e[x])==null?void 0:s.call(e,t);if(!o)return[];const c=o.t,a=((r=e[U])==null?void 0:r.call(e,t))||{};return[[k(t),{..."e"in a&&{error:a.e},..."p"in a&&{promise:a.p},..."v"in a&&{value:a.v},dependents:Array.from(c).map(k)}]]})),re=J("useAtomsDebugValue",e=>{var n;const t=(n=e==null?void 0:e.enabled)!=null?n:!1,s=I(e==null?void 0:e.scope),{s:r}=M(s),[o,c]=R([]);_(()=>{var a;if(!t)return;const f=()=>{var S;c(Array.from(((S=r[L])==null?void 0:S.call(r))||[]))},m=(a=r[D])==null?void 0:a.call(r,f);return f(),m},[t,r]),$([r,o],q)});function W(e,n,t){(typeof n=="string"||typeof t<"u")&&(console.warn("DEPRECATED [useAtomDevtools] use DevtoolOptions"),n={name:n,scope:t});const{enabled:s,name:r,scope:o}=n||{};let c;try{c=(s!=null?s:!1)&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}const[a,f]=j(e,o),m=w(a),S=w(!1),i=w(),T=r||e.debugLabel||e.toString();_(()=>{if(!c)return;const y=u=>{if(typeof f=="function"){f(u);return}console.warn(`[Warn] you cannot do write operations (Time-travelling, etc) in read-only atoms
2`,e)};i.current=c.connect({name:T});const A=i.current.subscribe(u=>{var d,p,l,E,N,g;if(u.type==="ACTION"&&u.payload)try{y(JSON.parse(u.payload))}catch(b){console.error(`please dispatch a serializable value that JSON.parse() support
3`,b)}else u.type==="DISPATCH"&&u.state?(((d=u.payload)==null?void 0:d.type)==="JUMP_TO_ACTION"||((p=u.payload)==null?void 0:p.type)==="JUMP_TO_STATE")&&(S.current=!0,y(JSON.parse(u.state))):u.type==="DISPATCH"&&((l=u.payload)==null?void 0:l.type)==="COMMIT"?(E=i.current)==null||E.init(m.current):u.type==="DISPATCH"&&((N=u.payload)==null?void 0:N.type)==="IMPORT_STATE"&&(((g=u.payload.nextLiftedState)==null?void 0:g.computedStates)||[]).forEach(({state:b},z)=>{var h;z===0?(h=i.current)==null||h.init(b):y(b)})});return i.current.shouldInit=!0,A},[e,c,T,f]),_(()=>{!i.current||(m.current=a,i.current.shouldInit?(i.current.init(a),i.current.shouldInit=!1):S.current?S.current=!1:i.current.send(`${T} - ${new Date().toLocaleString()}`,a))},[e,c,T,a])}const F=(e,n)=>e.size===n.size&&Array.from(e).every(([t,s])=>Object.is(n.get(t),s)),K=(e,n)=>e.size===n.size&&Array.from(e).every(([t,s])=>{const r=n.get(t);return r&&s.size===r.size&&Array.from(s).every(o=>r.has(o))});function Q(e){const n=I(e),t=M(n).s;if(!t[D])throw new Error("useAtomsSnapshot can only be used in dev mode.");const[s,r]=R(()=>({values:new Map,dependents:new Map}));return _(()=>{var o;let c=new Map,a=new Map;const f=new Set,m=()=>{var i,T,y;const A=new Map,u=new Map;let d=!1;for(const p of((i=t[L])==null?void 0:i.call(t))||[]){const l=(T=t[U])==null?void 0:T.call(t,p);if(l){if(!l.y){if("p"in l)return;f.has(p)||(f.add(p),d=!0)}"v"in l&&A.set(p,l.v)}const E=(y=t[x])==null?void 0:y.call(t,p);E&&u.set(p,E.t)}d||F(c,A)&&K(a,u)||(c=A,a=u,f.clear(),r({values:A,dependents:u}))},S=(o=t[D])==null?void 0:o.call(t,m);return m(),S},[t]),s}function Y(e){const n=I(e),{s:t,w:s}=M(n);if(!t[D])throw new Error("useGotoAtomsSnapshot can only be used in dev mode.");return P(r=>{const o=c=>{s?s(a=>{t[v](c,a)}):t[v](c)};if(Z(r)){o(r);return}o(r.values)},[t,s])}const Z=e=>typeof e[Symbol.iterator]=="function",ee=(e,n)=>e.size===n.size&&Array.from(e).every(([t,s])=>Object.is(n.get(t),s)),te=(e,n)=>e.size===n.size&&Array.from(e).every(([t,s])=>{const r=n.get(t);return r&&s.size===r.size&&Array.from(s).every(o=>r.has(o))}),G=e=>e.debugLabel?`${e}:${e.debugLabel}`:`${e}`,H=e=>{const n={};e.values.forEach((s,r)=>{n[G(r)]=s});const t={};return e.dependents.forEach((s,r)=>{t[G(r)]=Array.from(s).map(G)}),{values:n,dependents:t}};function ne(e,n){typeof n<"u"&&typeof n!="object"&&(console.warn("DEPRECATED [useAtomsDevtools] use DevtoolsOptions"),n={scope:n});const{enabled:t,scope:s}=n||{},r=I(s),{s:o,w:c}=M(r);let a;try{a=(t!=null?t:!1)&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(a&&!o[D])throw new Error("useAtomsDevtools can only be used in dev mode.");const[f,m]=R(()=>({values:new Map,dependents:new Map}));_(()=>{var u;if(!a)return;let d=new Map,p=new Map;const l=new Set,E=()=>{var g,b,z;const h=new Map,V=new Map;let X=!1;for(const O of((g=o[L])==null?void 0:g.call(o))||[]){const C=(b=o[U])==null?void 0:b.call(o,O);if(C){if(!C.y){if("p"in C)return;l.has(O)||(l.add(O),X=!0)}"v"in C&&h.set(O,C.v)}const B=(z=o[x])==null?void 0:z.call(o,O);B&&V.set(O,B.t)}X||ee(d,h)&&te(p,V)||(d=h,p=V,l.clear(),m({values:h,dependents:V}))},N=(u=o[D])==null?void 0:u.call(o,E);return E(),N},[a,o]);const S=P(u=>{const{values:d}=u;c?c(p=>{o[v](d,p)}):o[v](d)},[o,c]),i=w(!1),T=w(!0),y=w(),A=w([]);_(()=>{if(!a)return;const u=(l=A.current.length-1)=>{const E=A.current[l>=0?l:0];if(!E)throw new Error("snaphost index out of bounds");return E},d=a.connect({name:e}),p=d.subscribe(l=>{var E;switch(l.type){case"DISPATCH":switch((E=l.payload)==null?void 0:E.type){case"RESET":break;case"COMMIT":d.init(H(u())),A.current=[];break;case"JUMP_TO_ACTION":case"JUMP_TO_STATE":i.current=!0,S(u(l.payload.actionId-1));break;case"PAUSE_RECORDING":T.current=!T.current;break}}});return y.current=d,y.current.shouldInit=!0,p},[a,S,e]),_(()=>{if(y.current){if(y.current.shouldInit){y.current.init(void 0),y.current.shouldInit=!1;return}i.current?i.current=!1:T.current&&(A.current.push(f),y.current.send({type:`${A.current.length}`,updatedAt:new Date().toLocaleString()},H(f)))}},[f])}}}});