xstate 6.0.0-alpha.2 → 6.0.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/dist/{StateMachine-8d22a79c.development.cjs.js → StateMachine-0770ac71.development.cjs.js} +1 -1
  2. package/dist/{StateMachine-2dcdb1f5.esm.js → StateMachine-8249d511.esm.js} +1 -1
  3. package/dist/{StateMachine-64813f46.cjs.js → StateMachine-e1048cd6.cjs.js} +1 -1
  4. package/dist/{StateMachine-2ea0a7fa.development.esm.js → StateMachine-e6ad61d0.development.esm.js} +1 -1
  5. package/dist/declarations/src/StateMachine.d.ts +4 -4
  6. package/dist/declarations/src/createActor.d.ts +0 -2
  7. package/dist/declarations/src/index.d.ts +1 -3
  8. package/dist/declarations/src/serialize.d.ts +13 -8
  9. package/dist/declarations/src/types.d.ts +0 -4
  10. package/dist/declarations/src/types.v6.d.ts +11 -9
  11. package/dist/{index-f6ef20d1.development.cjs.js → index-269d256d.development.cjs.js} +10 -689
  12. package/dist/{index-e61170ba.development.esm.js → index-66ff64a6.development.esm.js} +11 -685
  13. package/dist/{index-93edd3bd.esm.js → index-a7e3d8b3.esm.js} +11 -685
  14. package/dist/{index-9cb3b3a0.cjs.js → index-dda021d5.cjs.js} +10 -689
  15. package/dist/xstate-actors.cjs.js +1 -1
  16. package/dist/xstate-actors.development.cjs.js +1 -1
  17. package/dist/xstate-actors.development.esm.js +1 -1
  18. package/dist/xstate-actors.esm.js +1 -1
  19. package/dist/xstate-actors.umd.min.js +1 -1
  20. package/dist/xstate-actors.umd.min.js.map +1 -1
  21. package/dist/xstate-graph.cjs.js +2 -2
  22. package/dist/xstate-graph.development.cjs.js +2 -2
  23. package/dist/xstate-graph.development.esm.js +2 -2
  24. package/dist/xstate-graph.esm.js +2 -2
  25. package/dist/xstate-graph.umd.min.js +1 -1
  26. package/dist/xstate-graph.umd.min.js.map +1 -1
  27. package/dist/xstate.cjs.js +85 -32
  28. package/dist/xstate.cjs.mjs +0 -5
  29. package/dist/xstate.development.cjs.js +85 -32
  30. package/dist/xstate.development.cjs.mjs +0 -5
  31. package/dist/xstate.development.esm.js +87 -29
  32. package/dist/xstate.esm.js +87 -29
  33. package/dist/xstate.umd.min.js +1 -1
  34. package/dist/xstate.umd.min.js.map +1 -1
  35. package/package.json +1 -1
  36. package/dist/declarations/src/atom.d.ts +0 -81
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var dist_xstateActors = require('./index-9cb3b3a0.cjs.js');
5
+ var dist_xstateActors = require('./index-dda021d5.cjs.js');
6
6
 
7
7
 
8
8
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var dist_xstateActors = require('./index-f6ef20d1.development.cjs.js');
5
+ var dist_xstateActors = require('./index-269d256d.development.cjs.js');
6
6
 
7
7
 
8
8
 
@@ -1 +1 @@
1
- export { T as TimeoutError, B as createAsyncLogic, w as createCallbackLogic, v as createEmptyActor, y as createEventObservableLogic, C as createListenerLogic, z as createLogic, x as createObservableLogic, E as createSubscriptionLogic, D as listenerLogic, F as subscriptionLogic } from './index-e61170ba.development.esm.js';
1
+ export { T as TimeoutError, v as createAsyncLogic, q as createCallbackLogic, o as createEmptyActor, s as createEventObservableLogic, w as createListenerLogic, u as createLogic, r as createObservableLogic, y as createSubscriptionLogic, x as listenerLogic, z as subscriptionLogic } from './index-66ff64a6.development.esm.js';
@@ -1 +1 @@
1
- export { T as TimeoutError, B as createAsyncLogic, w as createCallbackLogic, v as createEmptyActor, y as createEventObservableLogic, C as createListenerLogic, z as createLogic, x as createObservableLogic, E as createSubscriptionLogic, D as listenerLogic, F as subscriptionLogic } from './index-93edd3bd.esm.js';
1
+ export { T as TimeoutError, v as createAsyncLogic, q as createCallbackLogic, o as createEmptyActor, s as createEventObservableLogic, w as createListenerLogic, u as createLogic, r as createObservableLogic, y as createSubscriptionLogic, x as listenerLogic, z as subscriptionLogic } from './index-a7e3d8b3.esm.js';
@@ -1,2 +1,2 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XStateActors={})}(this,function(t){"use strict";class e{constructor(t){this._process=t,this._active=!1,this._current=null,this._last=null}start(){this._active=!0,this.flush()}clear(){this._current&&(this._current.next=null,this._last=this._current)}enqueue(t){const e={value:t,next:null};if(this._current)return this._last.next=e,void(this._last=e);this._current=e,this._last=e,this._active&&this.flush()}flush(){for(;this._current;){const t=this._current;this._process(t.value),this._current=t.next}this._last=null}}const s="@xstate.init",r="@xstate.stop";function i(t){return{type:s,input:t}}function n(t){setTimeout(()=>{throw t})}const o="function"==typeof Symbol&&Symbol.observable||"@@observable",c=new WeakMap;function a(t){return{start:(e,{self:s,system:r})=>{const i=e.input.actor;if(!i||"function"==typeof i.getSnapshot&&"stopped"===i.getSnapshot().status)return;const n=t(e.input,{self:s,system:r});if(!n)return;let o,a=!1;const h=()=>{a||(a=!0,n.unsubscribe(),o?.unsubscribe())},u=s._parent;u&&(o=u.subscribe({complete:h,error:h})),c.set(s,{unsubscribe:h})},transition:(t,e,{self:s})=>e.type===r?(c.get(s)?.unsubscribe(),c.delete(s),{...t,status:"stopped",error:void 0}):t,getInitialSnapshot:(t,e)=>({status:"active",output:void 0,error:void 0,input:e}),getPersistedSnapshot:t=>t,restoreSnapshot:t=>t}}function h(t,e,s){"stopped"!==t.getSnapshot().status&&t._parent&&e._relay(t,t._parent,s())}function u(){return a(({actor:t,eventType:e,mapper:s},{self:r,system:i})=>{const n="*"!==e&&e.endsWith(".*");return t.on(n?"*":e,t=>{n&&!function(t,e){if(e===t)return!0;if("*"===e)return!0;if(!e.endsWith(".*"))return!1;const s=e.split("."),r=t.split(".");for(let t=0;t<s.length;t++){const e=s[t],i=r[t];if("*"===e){return t===s.length-1}if(e!==i)return!1}return!0}(t.type,e)||h(r,i,()=>s(t))})})}const p=u(),d=Symbol.for("xstate.atom");function l(){return a(({actor:t,mappers:e},{self:s,system:r})=>{const{done:i,error:n,snapshot:o}=e;if((c=t)&&"object"==typeof c&&d in c){if(!o)return;return t.subscribe(t=>h(s,r,()=>o(t)))}var c;return t.subscribe({next:t=>{"done"===t.status&&i?h(s,r,()=>i(t.output)):"error"===t.status&&n?h(s,r,()=>n(t.error)):"active"===t.status&&o&&h(s,r,()=>o(t))},error:t=>{n&&h(s,r,()=>n(t))},complete:()=>{}})})}const f=l();function _(t){if(void 0!==t)return"number"==typeof t?t:function(t){const e=t.trim(),s=e.match(/^(\d+)ms$/i);if(s)return parseInt(s[1],10);const r=e.match(/^(\d*)(\.?)(\d*)s$/i);if(r){const t=r[1]?parseInt(r[1],10):0,e=!!r[2],s=r[3]?parseInt(r[3].padEnd(3,"0").slice(0,3),10):0;return 1e3*t+(e?s:0)}const i=e.match(/^P(?:(?<weeks>\d+(?:[.,]\d+)?)W)?(?:(?<days>\d+(?:[.,]\d+)?)D)?(?:T(?:(?<hours>\d+(?:[.,]\d+)?)H)?(?:(?<minutes>\d+(?:[.,]\d+)?)M)?(?:(?<seconds>\d+(?:[.,]\d+)?)S)?)?$/i);if(!i?.groups)return;const{weeks:n,days:o,hours:c,minutes:a,seconds:h}=i.groups;if(!(n||o||c||a||h))return;const u=t=>t?Number(t.replace(",",".")):0;return 7*u(n)*24*60*60*1e3+24*u(o)*60*60*1e3+60*u(c)*60*1e3+60*u(a)*1e3+1e3*u(h)}(t)}function y(t,e,s){const r="object"==typeof t,i=r?t:void 0;return{next:(r?t.next:t)?.bind(i),error:(r?t.error:e)?.bind(i),complete:(r?t.complete:s)?.bind(i)}}function v(t,e){return`${t.sessionId}.${e}`}const g=new WeakMap,m="xstate.logic.effect.resolve",b="xstate.logic.effect.reject",S="xstate.logic.effect.start";function x(t){let e=g.get(t);return e||(e=new Map,g.set(t,e)),e}function k(t,e){if(t?.length)for(const s of t)switch(s.type){case"emit":e.emit(s.event);break;case"sendBack":{const t=e.self._parent;t&&e.system._relay(e.self,t,s.event);break}case"raise":e.system._relay(e.self,e.self,s.event);break;case"effect":{if(!s.key){const t=s.exec();"function"==typeof t&&x(e.self).set(Symbol(),{cleanup:t});break}const t=x(e.self);if(t.has(s.key))break;const r=s.exec();t.set(s.key,{cleanup:"function"==typeof r?r:void 0});break}case"cleanupEffects":{const t=g.get(e.self);if(!t)break;for(const{cleanup:e}of t.values())e?.();g.delete(e.self);break}}}function w(t){const e=(e,s,i)=>{if("active"!==e.status)return[e,[]];if(s.type===r)return[{...e,status:"stopped",input:void 0},[{type:"cleanupEffects"}]];if(s.type===S)return[{...e,effects:{...e.effects,[s.key]:{status:"active"}}},[]];if(s.type===m)return[{...e,effects:{...e.effects,[s.key]:{status:"done",output:s.output}}},[]];if(s.type===b)return[{...e,effects:{...e.effects,[s.key]:{status:"error",error:s.error}}},[]];const n=[],o={},c={emit:t=>{n.push({type:"emit",event:t})},sendBack:t=>{n.push({type:"sendBack",event:t})},raise:t=>{n.push({type:"raise",event:t})},effect:(t,s)=>{if("string"==typeof t)return r=t,i=s,void(e.effects?.[r]||(n.push({type:"effect",key:r,exec:i}),o[r]={status:"active"}));var r,i;n.push({type:"effect",exec:t})}},a=t.run({context:e.context,event:s,input:e.input,system:i.system,self:i.self,emit:i.emit},c),h={...e,...a||{}};return("context"in e||void 0!==a?.context)&&(h.context=a?.context??e.context),(a?.effects||Object.keys(o).length)&&(h.effects={...e.effects,...a?.effects,...o}),[h,n]};return{id:t.id,config:t,transition:e,start:(t,s)=>{const[r,n]=e(t,i(t.input),s);Object.assign(t,r),k(n,s)},getInitialSnapshot:(e,s)=>{const r=function(t,e){return"function"==typeof t?t({input:e}):t}(t.context,s),i={status:"active",output:void 0,error:void 0,input:s};return void 0!==r&&(i.context=r),{...i}},getPersistedSnapshot:t=>t,restoreSnapshot:t=>t}}let E=!1;let I=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const A={clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console)};class L{constructor(t,s){this.logic=t,this._snapshot=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this._boundProcess=this._process.bind(this),this.mailbox=new e(this._boundProcess),this.observers=new Set,this.eventListeners=new Map,this.logger=void 0,this._processingStatus=I.NotStarted,this._parent=void 0,this._syncSnapshot=void 0,this.ref=void 0,this._actorScope=void 0,this._lastSourceRef=void 0,this._collectedMicrosteps=[],this._collectedActions=[],this._collectedSent=[],this.systemId=void 0,this.sessionId=void 0,this.system=void 0,this.trigger=void 0,this.src=void 0,this._deferred=[],this._pendingEffects=void 0;const r={...A,...s},{clock:i,logger:o,parent:c,syncSnapshot:a,id:h,systemId:u,inspect:p}=r;this.system=c?c.system:function(t,e){let s=0;const r=new Map,i=new Map,n=new WeakMap,o=new Set,c={},{clock:a,logger:h}=e,u=(t,e,s,r,i)=>{o.size&&t&&(t._collectedSent??=[]).push({targetRef:e,targetId:e.id,event:s,delay:r,id:i})},p={schedule:(t,e,s,r,i=Math.random().toString(36).slice(2))=>{u(t,e,s,r,i);const n={source:t,target:e,event:s,delay:r,id:i,startedAt:Date.now()},o=v(t,i);l._snapshot._scheduledEvents[o]=n;const h=a.setTimeout(()=>{delete c[o],delete l._snapshot._scheduledEvents[o],d(t,e,s)},r);c[o]=h},cancel:(t,e)=>{const s=v(t,e),r=c[s];delete c[s],delete l._snapshot._scheduledEvents[s],void 0!==r&&a.clearTimeout(r)},cancelAll:t=>{for(const e in l._snapshot._scheduledEvents){const s=l._snapshot._scheduledEvents[e];s.source===t&&p.cancel(t,s.id)}}},d=(t,e,s)=>{const r=e.logic;if("function"==typeof r?.isInternalEventType&&r.isInternalEventType(s.type)&&t!==e)throw new Error(`Internal event "${s.type}" cannot be sent to actor "${e.id}" from outside.`);e._lastSourceRef=t,e._send(s)},l={children:r,reverseKeyedActors:n,keyedActors:i,_snapshot:{_scheduledEvents:(e?.snapshot&&e.snapshot.scheduler)??{}},_bookId:()=>"x:"+s++,_register:(t,e)=>(r.set(t,e),t),_unregister:t=>{r.delete(t.sessionId);const e=n.get(t);void 0!==e&&(i.delete(e),n.delete(t))},get:t=>i.get(t),getAll:()=>Object.fromEntries(i.entries()),_set:(t,e)=>{const s=i.get(t);if(s&&s!==e)throw new Error(`Actor with system ID '${t}' already exists.`);i.set(t,e),n.set(e,t)},inspect:t=>{const e=y(t);return o.add(e),{unsubscribe(){o.delete(e)}}},_sendInspectionEvent:e=>{if(!o.size)return;const s={...e,rootId:t.sessionId};o.forEach(t=>t.next?.(s))},_relay:(t,e,s)=>{u(t,e,s),d(t,e,s)},scheduler:p,getSnapshot:()=>({_scheduledEvents:{...l._snapshot._scheduledEvents}}),start:()=>{const t=l._snapshot._scheduledEvents;l._snapshot._scheduledEvents={};for(const e in t){const{source:s,target:r,event:i,delay:n,id:o}=t[e];p.schedule(s,r,i,n,o)}},_clock:a,_logger:h,_timerStrategy:e.timers};return l}(this,{clock:i,logger:o,timers:r.timers}),p&&!c&&this.system.inspect(y(p)),this.sessionId=this.system._bookId(),this.id=h??this.sessionId,this.logger=s?.logger??this.system._logger,this.clock=s?.clock??this.system._clock,this._parent=c,this._syncSnapshot=a,this.options=r,this.src=r.src??t,this.ref=this,this._actorScope={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:t=>{this._deferred.push(t)},system:this.system,stopChild:t=>{if(t._parent!==this)throw new Error(`Cannot stop child actor ${t.id} of ${this.id} because it is not a child`);t._stop()},emit:t=>{const e=this.eventListeners.get(t.type),s=this.eventListeners.get("*");if(e||s){if(e)for(const s of e)try{s(t)}catch(t){n(t)}if(s)for(const e of s)try{e(t)}catch(t){n(t)}}},actionExecutor:t=>{const e=()=>{if(this._collectedActions.push({type:t.type,params:t.params}),!t.exec)return;const e=E;try{E=!0,t.exec()}finally{E=e}};this._processingStatus===I.Running?e():this._deferred.push(e)}},this.send=this.send.bind(this),this.trigger=new Proxy({},{get:(t,e)=>t=>{this.send({...t,type:e})}}),u&&(this.systemId=u,this.system._set(u,this)),this._collectedMicrosteps=[];let d=s?.snapshot??s?.state;if(d&&"object"==typeof d&&"_pendingEffects"in d){const{_pendingEffects:t,...e}=d;this._pendingEffects=t,d=e}try{this._snapshot=d?this.logic.restoreSnapshot?this.logic.restoreSnapshot(d,this._actorScope):d:this.logic.getInitialSnapshot(this._actorScope,this.options?.input)}catch(t){this._snapshot={status:"error",output:void 0,error:t},this._deferred.length=0}u&&"active"!==this._snapshot.status&&this.system._unregister(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this,parentRef:this._parent,id:this.id,src:this.src,snapshot:this._snapshot})}_setErrorSnapshot(t,e=this._snapshot){this._snapshot={...e,status:"error",error:t}}_next(t){for(const e of this.observers)try{e.next?.(t)}catch(t){n(t)}}update(t,e){this._snapshot=t;for(let e=0;e<this._deferred.length;e++){const s=this._deferred[e];try{s()}catch(e){this._deferred.length=0,this._setErrorSnapshot(e,t);break}}switch(this._deferred.length=0,this._snapshot.status){case"active":this._next(t);break;case"done":{this._next(t),this._stopProcedure(),this._complete();const e=(s=this.id,r=this._snapshot.output,{type:`xstate.done.actor.${s}`,output:r,actorId:s});this._parent&&this.system._relay(this,this._parent,e);break}case"error":this._error(this._snapshot.error)}var s,r;this.system._sendInspectionEvent({type:"@xstate.transition",actorRef:this,event:e,sourceRef:this._lastSourceRef,targetRef:this,snapshot:t,microsteps:this._collectedMicrosteps,actions:this._collectedActions,sent:this._collectedSent,eventType:e.type}),this._collectedMicrosteps=[],this._collectedActions=[],this._collectedSent=[]}subscribe(t,e,s){const r=y(t,e,s);if(this._processingStatus!==I.Stopped)this.observers.add(r);else switch(this._snapshot.status){case"done":try{r.complete?.()}catch(t){n(t)}break;case"error":{const t=this._snapshot.error;if(r.error)try{r.error(t)}catch(t){n(t)}else n(t);break}}return{unsubscribe:()=>{this.observers.delete(r)}}}on(t,e){let s=this.eventListeners.get(t);return s||(s=new Set,this.eventListeners.set(t,s)),s.add(e),{unsubscribe:()=>{s.delete(e)}}}select(t,e=Object.is){return{subscribe:(s,r,i)=>{const n=y(s,r,i);let o=t(this.getSnapshot());return this.subscribe({next:s=>{const r=t(s);e(o,r)||(o=r,n.next?.(r))},error:n.error,complete:n.complete})},get:()=>t(this.get())}}start(){if(this._processingStatus===I.Running)return this;this._syncSnapshot&&this.subscribe({next:t=>{"active"===t.status&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:t})},error:()=>{}}),this.system._register(this.sessionId,this),this.systemId&&this.system._set(this.systemId,this),this._processingStatus=I.Running;const t=i(this.options.input);this._lastSourceRef=this._parent;switch(this._snapshot.status){case"done":return this.update(this._snapshot,t),this;case"error":return this._error(this._snapshot.error),this}if(this._parent||this.system.start(),this.logic.start)try{this.logic.start(this._snapshot,this._actorScope)}catch(t){return this._setErrorSnapshot(t),this._error(t),this}if(this.update(this._snapshot,t),this._pendingEffects){const t=this.options.timers??this.system._timerStrategy??"resume";for(const e of this._pendingEffects)"@xstate.raise"===e.type&&this.system.scheduler.schedule(this,this,e.event,M(t,e),e.id);this._pendingEffects=void 0}return this.mailbox.start(),this}_process(t){let e,s;try{e=this.logic.transition(this._snapshot,t,this._actorScope)}catch(t){s={err:t}}if(s){const{err:t}=s;return this._setErrorSnapshot(t),void this._error(t)}const[i,n]=Array.isArray(e)?e:[e,void 0];this.update(i,t),k(n,this._actorScope),t.type===r&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===I.Stopped?this:(this.mailbox.clear(),this._processingStatus===I.NotStarted?(this._processingStatus=I.Stopped,this):(this.mailbox.enqueue({type:r}),this.system._unregister(this),this))}stop(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}_complete(){for(const t of this.observers)try{t.complete?.()}catch(t){n(t)}this.observers.clear(),this.eventListeners.clear()}_error(t){if(this._stopProcedure(),this.observers.size){let e=!1;for(const s of this.observers){const r=s.error;e||=!r;try{r?.(t)}catch(t){n(t)}}this.observers.clear(),this.eventListeners.clear(),e&&n(t)}else this._parent||n(t),this.eventListeners.clear();var e;this._parent&&this.system._relay(this,this._parent,{type:`xstate.error.actor.${e=this.id}`,error:t,actorId:e})}_stopProcedure(){this._processingStatus===I.Running&&(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new e(this._boundProcess),this._processingStatus=I.Stopped,this.system._unregister(this))}_send(t){this._processingStatus!==I.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}toJSON(){return{xstate$$type:1,id:this.id}}getPersistedSnapshot(t){const e=this.logic.getPersistedSnapshot(this._snapshot,t),s=this.system._snapshot._scheduledEvents;let r;const i=Date.now();for(const t in s){const e=s[t];e.source===this&&e.target===this&&(r??=[]).push({type:"@xstate.raise",event:e.event,id:e.id,delay:e.delay,startedAt:e.startedAt,elapsed:Math.max(0,i-e.startedAt)})}return r??=this._pendingEffects,r?{...e,_pendingEffects:r}:e}[o](){return this}getSnapshot(){return this.get()}get(){return this._snapshot}}function M(t,e){if("function"==typeof t)return t(e);switch(t){case"restart":return e.delay;case"absolute":return Math.max(0,e.startedAt+e.delay-Date.now());default:return Math.max(0,e.delay-e.elapsed)}}const T=new WeakMap;const P="xstate.observable.next",R="xstate.observable.error",$="xstate.observable.complete";const j="xstate.async.resolve",O="xstate.async.reject";class W extends Error{constructor(t){super(`Async logic timed out after ${t}.`),this.name="TimeoutError"}}const N=w({context:void 0,run:()=>{}});t.TimeoutError=W,t.createAsyncLogic=function(t){const e=t;return w({id:e.id,schemas:e.schemas,context:void 0,run:({event:t,input:r,self:i,system:n},o)=>{switch(t.type){case j:{const e=t.data??t.output;return{status:"done",output:e,input:void 0,effects:{async:{status:"done",output:e}}}}case O:{const e=t.data??t.error;return{status:"error",error:e,input:void 0,effects:{async:{status:"error",error:e}}}}}if(t.type===s)return o.effect(()=>{const t=i,s=new AbortController,c=e.timeout,a=_(c),h=void 0===a?void 0:n._clock.setTimeout(()=>{"active"===i.getSnapshot().status&&(s.abort(),n._relay(t,t,{type:O,data:new W(c)}))},a),u=()=>{void 0!==h&&n._clock.clearTimeout(h)};return Promise.resolve(e.run({input:r,system:n,self:i,signal:s.signal},{emit:o.emit,step:async(e,s)=>{const r=i.getSnapshot().effects?.[e];if("done"===r?.status)return r.output;if("error"===r?.status)throw r.error;if("active"===r?.status)return function(t,e){return new Promise((s,r)=>{const i=t.subscribe(t=>{const n=t.effects?.[e];"done"===n?.status?(i.unsubscribe(),s(n.output)):"error"===n?.status&&(i.unsubscribe(),r(n.error))})})}(i,e);n._relay(t,t,{type:S,key:e});try{const r=await s();return n._relay(t,t,{type:m,key:e,output:r}),r}catch(s){throw n._relay(t,t,{type:b,key:e,error:s}),s}}})).then(e=>{u(),"active"===i.getSnapshot().status&&n._relay(t,t,{type:j,data:e})},e=>{u(),"active"===i.getSnapshot().status&&n._relay(t,t,{type:O,data:e})}),()=>{s.abort(),u()}}),{effects:{async:{status:"active"}}}}})},t.createCallbackLogic=function(t){const e="function"==typeof t?t:t.run;return w({schemas:"function"==typeof t?void 0:t.schemas,context:void 0,run:(t,s)=>{const{event:r,input:i,self:n,system:o}=t,c=t.emit,a=T.get(n);a?.receivers?.forEach(t=>t(r)),s.effect("callback",()=>{const t={receivers:void 0,dispose:void 0};return T.set(n,t),t.dispose=e({input:i,system:o,self:n,sendBack:t=>{if("stopped"===n.getSnapshot().status)return;const e=n._parent;e&&o._relay(n,e,t)},receive:e=>{t.receivers??=new Set,t.receivers.add(e)},emit:c}),()=>{T.delete(n),t.receivers?.clear(),t.dispose?.()}})}})},t.createEmptyActor=function(){return new L(N,t);var t},t.createEventObservableLogic=function(t){const e="function"==typeof t?t:t.run;return{config:e,transition:(t,e)=>{if("active"!==t.status)return t;switch(e.type){case R:return{...t,status:"error",error:e.data,input:void 0,_subscription:void 0};case $:return{...t,status:"done",input:void 0,_subscription:void 0};case r:return t._subscription.unsubscribe(),{...t,status:"stopped",input:void 0,_subscription:void 0};default:return t}},getInitialSnapshot:(t,e)=>({status:"active",output:void 0,error:void 0,context:void 0,input:e,_subscription:void 0}),start:(t,{self:s,system:r,emit:i})=>{"done"!==t.status&&(t._subscription=e({input:t.input,system:r,self:s,emit:i}).subscribe({next:t=>{s._parent&&r._relay(s,s._parent,t)},error:t=>{r._relay(s,s,{type:R,data:t})},complete:()=>{r._relay(s,s,{type:$})}}))},getPersistedSnapshot:({_subscription:t,...e})=>e,restoreSnapshot:t=>({...t,_subscription:void 0})}},t.createListenerLogic=u,t.createLogic=w,t.createObservableLogic=function(t){const e="function"==typeof t?t:t.run;return w({schemas:"function"==typeof t?void 0:t.schemas,context:void 0,run:(t,s)=>{const{event:r,input:i,self:n,system:o}=t,c=t.emit;switch(r.type){case P:return{context:r.data};case R:return{status:"error",error:r.data,input:void 0,effects:{observable:{status:"error",error:r.data}}};case $:return{status:"done",input:void 0,effects:{observable:{status:"done"}}}}s.effect("observable",()=>{const t=n,s=e({input:i,system:o,self:n,emit:c}).subscribe({next:e=>{o._relay(t,t,{type:P,data:e})},error:e=>{o._relay(t,t,{type:R,data:e})},complete:()=>{o._relay(t,t,{type:$})}});return()=>s.unsubscribe()})}})},t.createSubscriptionLogic=l,t.listenerLogic=p,t.subscriptionLogic=f,Object.defineProperty(t,"__esModule",{value:!0})});
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XStateActors={})}(this,function(t){"use strict";class e{constructor(t){this._process=t,this._active=!1,this._current=null,this._last=null}start(){this._active=!0,this.flush()}clear(){this._current&&(this._current.next=null,this._last=this._current)}enqueue(t){const e={value:t,next:null};if(this._current)return this._last.next=e,void(this._last=e);this._current=e,this._last=e,this._active&&this.flush()}flush(){for(;this._current;){const t=this._current;this._process(t.value),this._current=t.next}this._last=null}}const s="@xstate.init",r="@xstate.stop";function i(t){return{type:s,input:t}}function n(t){setTimeout(()=>{throw t})}const o="function"==typeof Symbol&&Symbol.observable||"@@observable",c=new WeakMap;function a(t){return{start:(e,{self:s,system:r})=>{const i=e.input.actor;if(!i||"stopped"===i.getSnapshot().status)return;const n=t(e.input,{self:s,system:r});if(!n)return;let o,a=!1;const h=()=>{a||(a=!0,n.unsubscribe(),o?.unsubscribe())},u=s._parent;u&&(o=u.subscribe({complete:h,error:h})),c.set(s,{unsubscribe:h})},transition:(t,e,{self:s})=>e.type===r?(c.get(s)?.unsubscribe(),c.delete(s),{...t,status:"stopped",error:void 0}):t,getInitialSnapshot:(t,e)=>({status:"active",output:void 0,error:void 0,input:e}),getPersistedSnapshot:t=>t,restoreSnapshot:t=>t}}function h(t,e,s){"stopped"!==t.getSnapshot().status&&t._parent&&e._relay(t,t._parent,s())}function u(){return a(({actor:t,eventType:e,mapper:s},{self:r,system:i})=>{const n="*"!==e&&e.endsWith(".*");return t.on(n?"*":e,t=>{n&&!function(t,e){if(e===t)return!0;if("*"===e)return!0;if(!e.endsWith(".*"))return!1;const s=e.split("."),r=t.split(".");for(let t=0;t<s.length;t++){const e=s[t],i=r[t];if("*"===e){return t===s.length-1}if(e!==i)return!1}return!0}(t.type,e)||h(r,i,()=>s(t))})})}const p=u();function d(){return a(({actor:t,mappers:e},{self:s,system:r})=>{const{done:i,error:n,snapshot:o}=e;return t.subscribe({next:t=>{"done"===t.status&&i?h(s,r,()=>i(t.output)):"error"===t.status&&n?h(s,r,()=>n(t.error)):"active"===t.status&&o&&h(s,r,()=>o(t))},error:t=>{n&&h(s,r,()=>n(t))},complete:()=>{}})})}const l=d();function f(t){if(void 0!==t)return"number"==typeof t?t:function(t){const e=t.trim(),s=e.match(/^(\d+)ms$/i);if(s)return parseInt(s[1],10);const r=e.match(/^(\d*)(\.?)(\d*)s$/i);if(r){const t=r[1]?parseInt(r[1],10):0,e=!!r[2],s=r[3]?parseInt(r[3].padEnd(3,"0").slice(0,3),10):0;return 1e3*t+(e?s:0)}const i=e.match(/^P(?:(?<weeks>\d+(?:[.,]\d+)?)W)?(?:(?<days>\d+(?:[.,]\d+)?)D)?(?:T(?:(?<hours>\d+(?:[.,]\d+)?)H)?(?:(?<minutes>\d+(?:[.,]\d+)?)M)?(?:(?<seconds>\d+(?:[.,]\d+)?)S)?)?$/i);if(!i?.groups)return;const{weeks:n,days:o,hours:c,minutes:a,seconds:h}=i.groups;if(!(n||o||c||a||h))return;const u=t=>t?Number(t.replace(",",".")):0;return 7*u(n)*24*60*60*1e3+24*u(o)*60*60*1e3+60*u(c)*60*1e3+60*u(a)*1e3+1e3*u(h)}(t)}function _(t,e,s){const r="object"==typeof t,i=r?t:void 0;return{next:(r?t.next:t)?.bind(i),error:(r?t.error:e)?.bind(i),complete:(r?t.complete:s)?.bind(i)}}function y(t,e){return`${t.sessionId}.${e}`}const v=new WeakMap,g="xstate.logic.effect.resolve",m="xstate.logic.effect.reject",b="xstate.logic.effect.start";function S(t){let e=v.get(t);return e||(e=new Map,v.set(t,e)),e}function x(t,e){if(t?.length)for(const s of t)switch(s.type){case"emit":e.emit(s.event);break;case"sendBack":{const t=e.self._parent;t&&e.system._relay(e.self,t,s.event);break}case"raise":e.system._relay(e.self,e.self,s.event);break;case"effect":{if(!s.key){const t=s.exec();"function"==typeof t&&S(e.self).set(Symbol(),{cleanup:t});break}const t=S(e.self);if(t.has(s.key))break;const r=s.exec();t.set(s.key,{cleanup:"function"==typeof r?r:void 0});break}case"cleanupEffects":{const t=v.get(e.self);if(!t)break;for(const{cleanup:e}of t.values())e?.();v.delete(e.self);break}}}function k(t){const e=(e,s,i)=>{if("active"!==e.status)return[e,[]];if(s.type===r)return[{...e,status:"stopped",input:void 0},[{type:"cleanupEffects"}]];if(s.type===b)return[{...e,effects:{...e.effects,[s.key]:{status:"active"}}},[]];if(s.type===g)return[{...e,effects:{...e.effects,[s.key]:{status:"done",output:s.output}}},[]];if(s.type===m)return[{...e,effects:{...e.effects,[s.key]:{status:"error",error:s.error}}},[]];const n=[],o={},c={emit:t=>{n.push({type:"emit",event:t})},sendBack:t=>{n.push({type:"sendBack",event:t})},raise:t=>{n.push({type:"raise",event:t})},effect:(t,s)=>{if("string"==typeof t)return r=t,i=s,void(e.effects?.[r]||(n.push({type:"effect",key:r,exec:i}),o[r]={status:"active"}));var r,i;n.push({type:"effect",exec:t})}},a=t.run({context:e.context,event:s,input:e.input,system:i.system,self:i.self,emit:i.emit},c),h={...e,...a||{}};return("context"in e||void 0!==a?.context)&&(h.context=a?.context??e.context),(a?.effects||Object.keys(o).length)&&(h.effects={...e.effects,...a?.effects,...o}),[h,n]};return{id:t.id,config:t,transition:e,start:(t,s)=>{const[r,n]=e(t,i(t.input),s);Object.assign(t,r),x(n,s)},getInitialSnapshot:(e,s)=>{const r=function(t,e){return"function"==typeof t?t({input:e}):t}(t.context,s),i={status:"active",output:void 0,error:void 0,input:s};return void 0!==r&&(i.context=r),{...i}},getPersistedSnapshot:t=>t,restoreSnapshot:t=>t}}let w=!1;let E=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const I={clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console)};class A{constructor(t,s){this.logic=t,this._snapshot=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this._boundProcess=this._process.bind(this),this.mailbox=new e(this._boundProcess),this.observers=new Set,this.eventListeners=new Map,this.logger=void 0,this._processingStatus=E.NotStarted,this._parent=void 0,this._syncSnapshot=void 0,this.ref=void 0,this._actorScope=void 0,this._lastSourceRef=void 0,this._collectedMicrosteps=[],this._collectedActions=[],this._collectedSent=[],this.systemId=void 0,this.sessionId=void 0,this.system=void 0,this.trigger=void 0,this.src=void 0,this._deferred=[],this._pendingEffects=void 0;const r={...I,...s},{clock:i,logger:o,parent:c,syncSnapshot:a,id:h,systemId:u,inspect:p}=r;this.system=c?c.system:function(t,e){let s=0;const r=new Map,i=new Map,n=new WeakMap,o=new Set,c={},{clock:a,logger:h}=e,u=(t,e,s,r,i)=>{o.size&&t&&(t._collectedSent??=[]).push({targetRef:e,targetId:e.id,event:s,delay:r,id:i})},p={schedule:(t,e,s,r,i=Math.random().toString(36).slice(2))=>{u(t,e,s,r,i);const n={source:t,target:e,event:s,delay:r,id:i,startedAt:Date.now()},o=y(t,i);l._snapshot._scheduledEvents[o]=n;const h=a.setTimeout(()=>{delete c[o],delete l._snapshot._scheduledEvents[o],d(t,e,s)},r);c[o]=h},cancel:(t,e)=>{const s=y(t,e),r=c[s];delete c[s],delete l._snapshot._scheduledEvents[s],void 0!==r&&a.clearTimeout(r)},cancelAll:t=>{for(const e in l._snapshot._scheduledEvents){const s=l._snapshot._scheduledEvents[e];s.source===t&&p.cancel(t,s.id)}}},d=(t,e,s)=>{const r=e.logic;if("function"==typeof r?.isInternalEventType&&r.isInternalEventType(s.type)&&t!==e)throw new Error(`Internal event "${s.type}" cannot be sent to actor "${e.id}" from outside.`);e._lastSourceRef=t,e._send(s)},l={children:r,reverseKeyedActors:n,keyedActors:i,_snapshot:{_scheduledEvents:(e?.snapshot&&e.snapshot.scheduler)??{}},_bookId:()=>"x:"+s++,_register:(t,e)=>(r.set(t,e),t),_unregister:t=>{r.delete(t.sessionId);const e=n.get(t);void 0!==e&&(i.delete(e),n.delete(t))},get:t=>i.get(t),getAll:()=>Object.fromEntries(i.entries()),_set:(t,e)=>{const s=i.get(t);if(s&&s!==e)throw new Error(`Actor with system ID '${t}' already exists.`);i.set(t,e),n.set(e,t)},inspect:t=>{const e=_(t);return o.add(e),{unsubscribe(){o.delete(e)}}},_sendInspectionEvent:e=>{if(!o.size)return;const s={...e,rootId:t.sessionId};o.forEach(t=>t.next?.(s))},_relay:(t,e,s)=>{u(t,e,s),d(t,e,s)},scheduler:p,getSnapshot:()=>({_scheduledEvents:{...l._snapshot._scheduledEvents}}),start:()=>{const t=l._snapshot._scheduledEvents;l._snapshot._scheduledEvents={};for(const e in t){const{source:s,target:r,event:i,delay:n,id:o}=t[e];p.schedule(s,r,i,n,o)}},_clock:a,_logger:h,_timerStrategy:e.timers};return l}(this,{clock:i,logger:o,timers:r.timers}),p&&!c&&this.system.inspect(_(p)),this.sessionId=this.system._bookId(),this.id=h??this.sessionId,this.logger=s?.logger??this.system._logger,this.clock=s?.clock??this.system._clock,this._parent=c,this._syncSnapshot=a,this.options=r,this.src=r.src??t,this.ref=this,this._actorScope={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:t=>{this._deferred.push(t)},system:this.system,stopChild:t=>{if(t._parent!==this)throw new Error(`Cannot stop child actor ${t.id} of ${this.id} because it is not a child`);t._stop()},emit:t=>{const e=this.eventListeners.get(t.type),s=this.eventListeners.get("*");if(e||s){if(e)for(const s of e)try{s(t)}catch(t){n(t)}if(s)for(const e of s)try{e(t)}catch(t){n(t)}}},actionExecutor:t=>{const e=()=>{if(this._collectedActions.push({type:t.type,params:t.params}),!t.exec)return;const e=w;try{w=!0,t.exec()}finally{w=e}};this._processingStatus===E.Running?e():this._deferred.push(e)}},this.send=this.send.bind(this),this.trigger=new Proxy({},{get:(t,e)=>t=>{this.send({...t,type:e})}}),u&&(this.systemId=u,this.system._set(u,this)),this._collectedMicrosteps=[];let d=s?.snapshot??s?.state;if(d&&"object"==typeof d&&"_pendingEffects"in d){const{_pendingEffects:t,...e}=d;this._pendingEffects=t,d=e}try{this._snapshot=d?this.logic.restoreSnapshot?this.logic.restoreSnapshot(d,this._actorScope):d:this.logic.getInitialSnapshot(this._actorScope,this.options?.input)}catch(t){this._snapshot={status:"error",output:void 0,error:t},this._deferred.length=0}u&&"active"!==this._snapshot.status&&this.system._unregister(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this,parentRef:this._parent,id:this.id,src:this.src,snapshot:this._snapshot})}_setErrorSnapshot(t,e=this._snapshot){this._snapshot={...e,status:"error",error:t}}_next(t){for(const e of this.observers)try{e.next?.(t)}catch(t){n(t)}}update(t,e){this._snapshot=t;for(let e=0;e<this._deferred.length;e++){const s=this._deferred[e];try{s()}catch(e){this._deferred.length=0,this._setErrorSnapshot(e,t);break}}switch(this._deferred.length=0,this._snapshot.status){case"active":this._next(t);break;case"done":{this._next(t),this._stopProcedure(),this._complete();const e=(s=this.id,r=this._snapshot.output,{type:`xstate.done.actor.${s}`,output:r,actorId:s});this._parent&&this.system._relay(this,this._parent,e);break}case"error":this._error(this._snapshot.error)}var s,r;this.system._sendInspectionEvent({type:"@xstate.transition",actorRef:this,event:e,sourceRef:this._lastSourceRef,targetRef:this,snapshot:t,microsteps:this._collectedMicrosteps,actions:this._collectedActions,sent:this._collectedSent,eventType:e.type}),this._collectedMicrosteps=[],this._collectedActions=[],this._collectedSent=[]}subscribe(t,e,s){const r=_(t,e,s);if(this._processingStatus!==E.Stopped)this.observers.add(r);else switch(this._snapshot.status){case"done":try{r.complete?.()}catch(t){n(t)}break;case"error":{const t=this._snapshot.error;if(r.error)try{r.error(t)}catch(t){n(t)}else n(t);break}}return{unsubscribe:()=>{this.observers.delete(r)}}}on(t,e){let s=this.eventListeners.get(t);return s||(s=new Set,this.eventListeners.set(t,s)),s.add(e),{unsubscribe:()=>{s.delete(e)}}}select(t,e=Object.is){return{subscribe:(s,r,i)=>{const n=_(s,r,i);let o=t(this.getSnapshot());return this.subscribe({next:s=>{const r=t(s);e(o,r)||(o=r,n.next?.(r))},error:n.error,complete:n.complete})},get:()=>t(this.getSnapshot())}}start(){if(this._processingStatus===E.Running)return this;this._syncSnapshot&&this.subscribe({next:t=>{"active"===t.status&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:t})},error:()=>{}}),this.system._register(this.sessionId,this),this.systemId&&this.system._set(this.systemId,this),this._processingStatus=E.Running;const t=i(this.options.input);this._lastSourceRef=this._parent;switch(this._snapshot.status){case"done":return this.update(this._snapshot,t),this;case"error":return this._error(this._snapshot.error),this}if(this._parent||this.system.start(),this.logic.start)try{this.logic.start(this._snapshot,this._actorScope)}catch(t){return this._setErrorSnapshot(t),this._error(t),this}if(this.update(this._snapshot,t),this._pendingEffects){const t=this.options.timers??this.system._timerStrategy??"resume";for(const e of this._pendingEffects)"@xstate.raise"===e.type&&this.system.scheduler.schedule(this,this,e.event,L(t,e),e.id);this._pendingEffects=void 0}return this.mailbox.start(),this}_process(t){let e,s;try{e=this.logic.transition(this._snapshot,t,this._actorScope)}catch(t){s={err:t}}if(s){const{err:t}=s;return this._setErrorSnapshot(t),void this._error(t)}const[i,n]=Array.isArray(e)?e:[e,void 0];this.update(i,t),x(n,this._actorScope),t.type===r&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===E.Stopped?this:(this.mailbox.clear(),this._processingStatus===E.NotStarted?(this._processingStatus=E.Stopped,this):(this.mailbox.enqueue({type:r}),this.system._unregister(this),this))}stop(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}_complete(){for(const t of this.observers)try{t.complete?.()}catch(t){n(t)}this.observers.clear(),this.eventListeners.clear()}_error(t){if(this._stopProcedure(),this.observers.size){let e=!1;for(const s of this.observers){const r=s.error;e||=!r;try{r?.(t)}catch(t){n(t)}}this.observers.clear(),this.eventListeners.clear(),e&&n(t)}else this._parent||n(t),this.eventListeners.clear();var e;this._parent&&this.system._relay(this,this._parent,{type:`xstate.error.actor.${e=this.id}`,error:t,actorId:e})}_stopProcedure(){this._processingStatus===E.Running&&(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new e(this._boundProcess),this._processingStatus=E.Stopped,this.system._unregister(this))}_send(t){this._processingStatus!==E.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}toJSON(){return{xstate$$type:1,id:this.id}}getPersistedSnapshot(t){const e=this.logic.getPersistedSnapshot(this._snapshot,t),s=this.system._snapshot._scheduledEvents;let r;const i=Date.now();for(const t in s){const e=s[t];e.source===this&&e.target===this&&(r??=[]).push({type:"@xstate.raise",event:e.event,id:e.id,delay:e.delay,startedAt:e.startedAt,elapsed:Math.max(0,i-e.startedAt)})}return r??=this._pendingEffects,r?{...e,_pendingEffects:r}:e}[o](){return this}getSnapshot(){return this._snapshot}}function L(t,e){if("function"==typeof t)return t(e);switch(t){case"restart":return e.delay;case"absolute":return Math.max(0,e.startedAt+e.delay-Date.now());default:return Math.max(0,e.delay-e.elapsed)}}const M=new WeakMap;const T="xstate.observable.next",P="xstate.observable.error",R="xstate.observable.complete";const $="xstate.async.resolve",j="xstate.async.reject";class O extends Error{constructor(t){super(`Async logic timed out after ${t}.`),this.name="TimeoutError"}}const W=k({context:void 0,run:()=>{}});t.TimeoutError=O,t.createAsyncLogic=function(t){const e=t;return k({id:e.id,schemas:e.schemas,context:void 0,run:({event:t,input:r,self:i,system:n},o)=>{switch(t.type){case $:{const e=t.data??t.output;return{status:"done",output:e,input:void 0,effects:{async:{status:"done",output:e}}}}case j:{const e=t.data??t.error;return{status:"error",error:e,input:void 0,effects:{async:{status:"error",error:e}}}}}if(t.type===s)return o.effect(()=>{const t=i,s=new AbortController,c=e.timeout,a=f(c),h=void 0===a?void 0:n._clock.setTimeout(()=>{"active"===i.getSnapshot().status&&(s.abort(),n._relay(t,t,{type:j,data:new O(c)}))},a),u=()=>{void 0!==h&&n._clock.clearTimeout(h)};return Promise.resolve(e.run({input:r,system:n,self:i,signal:s.signal},{emit:o.emit,step:async(e,s)=>{const r=i.getSnapshot().effects?.[e];if("done"===r?.status)return r.output;if("error"===r?.status)throw r.error;if("active"===r?.status)return function(t,e){return new Promise((s,r)=>{const i=t.subscribe(t=>{const n=t.effects?.[e];"done"===n?.status?(i.unsubscribe(),s(n.output)):"error"===n?.status&&(i.unsubscribe(),r(n.error))})})}(i,e);n._relay(t,t,{type:b,key:e});try{const r=await s();return n._relay(t,t,{type:g,key:e,output:r}),r}catch(s){throw n._relay(t,t,{type:m,key:e,error:s}),s}}})).then(e=>{u(),"active"===i.getSnapshot().status&&n._relay(t,t,{type:$,data:e})},e=>{u(),"active"===i.getSnapshot().status&&n._relay(t,t,{type:j,data:e})}),()=>{s.abort(),u()}}),{effects:{async:{status:"active"}}}}})},t.createCallbackLogic=function(t){const e="function"==typeof t?t:t.run;return k({schemas:"function"==typeof t?void 0:t.schemas,context:void 0,run:(t,s)=>{const{event:r,input:i,self:n,system:o}=t,c=t.emit,a=M.get(n);a?.receivers?.forEach(t=>t(r)),s.effect("callback",()=>{const t={receivers:void 0,dispose:void 0};return M.set(n,t),t.dispose=e({input:i,system:o,self:n,sendBack:t=>{if("stopped"===n.getSnapshot().status)return;const e=n._parent;e&&o._relay(n,e,t)},receive:e=>{t.receivers??=new Set,t.receivers.add(e)},emit:c}),()=>{M.delete(n),t.receivers?.clear(),t.dispose?.()}})}})},t.createEmptyActor=function(){return new A(W,t);var t},t.createEventObservableLogic=function(t){const e="function"==typeof t?t:t.run;return{config:e,transition:(t,e)=>{if("active"!==t.status)return t;switch(e.type){case P:return{...t,status:"error",error:e.data,input:void 0,_subscription:void 0};case R:return{...t,status:"done",input:void 0,_subscription:void 0};case r:return t._subscription.unsubscribe(),{...t,status:"stopped",input:void 0,_subscription:void 0};default:return t}},getInitialSnapshot:(t,e)=>({status:"active",output:void 0,error:void 0,context:void 0,input:e,_subscription:void 0}),start:(t,{self:s,system:r,emit:i})=>{"done"!==t.status&&(t._subscription=e({input:t.input,system:r,self:s,emit:i}).subscribe({next:t=>{s._parent&&r._relay(s,s._parent,t)},error:t=>{r._relay(s,s,{type:P,data:t})},complete:()=>{r._relay(s,s,{type:R})}}))},getPersistedSnapshot:({_subscription:t,...e})=>e,restoreSnapshot:t=>({...t,_subscription:void 0})}},t.createListenerLogic=u,t.createLogic=k,t.createObservableLogic=function(t){const e="function"==typeof t?t:t.run;return k({schemas:"function"==typeof t?void 0:t.schemas,context:void 0,run:(t,s)=>{const{event:r,input:i,self:n,system:o}=t,c=t.emit;switch(r.type){case T:return{context:r.data};case P:return{status:"error",error:r.data,input:void 0,effects:{observable:{status:"error",error:r.data}}};case R:return{status:"done",input:void 0,effects:{observable:{status:"done"}}}}s.effect("observable",()=>{const t=n,s=e({input:i,system:o,self:n,emit:c}).subscribe({next:e=>{o._relay(t,t,{type:T,data:e})},error:e=>{o._relay(t,t,{type:P,data:e})},complete:()=>{o._relay(t,t,{type:R})}});return()=>s.unsubscribe()})}})},t.createSubscriptionLogic=d,t.listenerLogic=p,t.subscriptionLogic=l,Object.defineProperty(t,"__esModule",{value:!0})});
2
2
  //# sourceMappingURL=xstate-actors.umd.min.js.map