UNPKG

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