UNPKG

1.13 kBJavaScriptView Raw
1System.register(["xstate","jotai"],function(h){"use strict";var m,s;return{setters:[function(c){m=c.interpret},function(c){s=c.atom}],execute:function(){h("atomWithMachine",w);const c=h("RESTART",Symbol());function w(a,u){const l=s(null),o=s(t=>{const n=t(l);if(n)return n;let e=!0;const r=W=>{if(e)return t(W);throw new Error("get not allowed after initialization")},i=d(a)?a(r):a,v=d(u)?u(r):u;e=!1;const{guards:y,actions:S,services:g,delays:p,context:R,...x}=v||{},A={...y&&{guards:y},...S&&{actions:S},...g&&{services:g},...p&&{delays:p}},M=i.withConfig(A,()=>({...i.context,...R})),E=m(M,x);return{machine:M,service:E}},(t,n,e)=>{n(l,t(o))});o.onMount=t=>{t()};const f=s(null),T=s(t=>{var n;return(n=t(f))!=null?n:t(o).machine.initialState},(t,n,e)=>{const{service:r}=t(o);r.onTransition(i=>{n(f,i)}),r.start(),e(()=>{const{service:i}=t(o);i.stop()})});return T.onMount=t=>{let n;return t(e=>{n===!1?e():n=e}),()=>{n&&n(),n=!1}},s(t=>t(T),(t,n,e)=>{const{service:r}=t(o);if(e===c){r.stop(),n(l,null),n(o,null);const{service:i}=t(o);i.onTransition(v=>{n(f,v)}),i.start()}else r.send(e)})}const d=a=>typeof a=="function"}}});