UNPKG

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