xstate 5.0.0-beta.42 → 5.0.0-beta.43
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.
- package/actions/dist/xstate-actions.cjs.js +3 -3
- package/actions/dist/xstate-actions.development.cjs.js +3 -3
- package/actions/dist/xstate-actions.development.esm.js +3 -3
- package/actions/dist/xstate-actions.esm.js +3 -3
- package/actions/dist/xstate-actions.umd.min.js +1 -1
- package/actions/dist/xstate-actions.umd.min.js.map +1 -1
- package/actors/dist/xstate-actors.cjs.js +45 -1
- package/actors/dist/xstate-actors.development.cjs.js +45 -1
- package/actors/dist/xstate-actors.development.esm.js +45 -1
- package/actors/dist/xstate-actors.esm.js +45 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/declarations/src/State.d.ts +5 -5
- package/dist/declarations/src/actions/spawn.d.ts +3 -3
- package/dist/declarations/src/actors/promise.d.ts +53 -0
- package/dist/declarations/src/types.d.ts +41 -6
- package/dist/declarations/src/utils.d.ts +2 -8
- package/dist/{interpreter-b6bdd134.cjs.js → interpreter-36d5556e.cjs.js} +2 -9
- package/dist/{interpreter-23e4041c.development.cjs.js → interpreter-4e8e2a0d.development.cjs.js} +2 -9
- package/dist/{interpreter-3d0c0ff2.esm.js → interpreter-63c80754.esm.js} +2 -9
- package/dist/{interpreter-f2620ea7.development.esm.js → interpreter-80eb3bec.development.esm.js} +2 -9
- package/dist/{raise-8f482ce9.development.cjs.js → raise-23dea0d7.development.cjs.js} +69 -56
- package/dist/{raise-d2084327.esm.js → raise-8dc8e1aa.esm.js} +66 -53
- package/dist/{raise-6b64c553.cjs.js → raise-e0fe5c2d.cjs.js} +66 -53
- package/dist/{raise-51ae36e5.development.esm.js → raise-f4ad5a87.development.esm.js} +69 -56
- package/dist/{send-cc8f864e.development.cjs.js → send-0174c155.development.cjs.js} +7 -9
- package/dist/{send-7a350091.development.esm.js → send-5d129d95.development.esm.js} +7 -9
- package/dist/{send-4e732fa5.esm.js → send-84e2e742.esm.js} +7 -9
- package/dist/{send-85b562d8.cjs.js → send-87bbaaab.cjs.js} +7 -9
- package/dist/xstate.cjs.js +4 -4
- package/dist/xstate.development.cjs.js +4 -4
- package/dist/xstate.development.esm.js +7 -7
- package/dist/xstate.esm.js +7 -7
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +2 -2
- package/guards/dist/xstate-guards.development.cjs.js +2 -2
- package/guards/dist/xstate-guards.development.esm.js +2 -2
- package/guards/dist/xstate-guards.esm.js +2 -2
- package/package.json +1 -1
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var send = require('../../dist/send-
|
|
6
|
-
var guards_dist_xstateGuards = require('../../dist/raise-
|
|
7
|
-
require('../../dist/interpreter-
|
|
5
|
+
var send = require('../../dist/send-87bbaaab.cjs.js');
|
|
6
|
+
var guards_dist_xstateGuards = require('../../dist/raise-e0fe5c2d.cjs.js');
|
|
7
|
+
require('../../dist/interpreter-36d5556e.cjs.js');
|
|
8
8
|
require('../../dev/dist/xstate-dev.cjs.js');
|
|
9
9
|
|
|
10
10
|
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var send = require('../../dist/send-
|
|
6
|
-
var guards_dist_xstateGuards = require('../../dist/raise-
|
|
7
|
-
require('../../dist/interpreter-
|
|
5
|
+
var send = require('../../dist/send-0174c155.development.cjs.js');
|
|
6
|
+
var guards_dist_xstateGuards = require('../../dist/raise-23dea0d7.development.cjs.js');
|
|
7
|
+
require('../../dist/interpreter-4e8e2a0d.development.cjs.js');
|
|
8
8
|
require('../../dev/dist/xstate-dev.development.cjs.js');
|
|
9
9
|
|
|
10
10
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { a as assign, c as choose, e as escalate, f as forwardTo, l as log, p as pure, s as sendParent, b as sendTo } from '../../dist/send-
|
|
2
|
-
export { z as cancel, A as raise, C as spawn, B as stop } from '../../dist/raise-
|
|
3
|
-
import '../../dist/interpreter-
|
|
1
|
+
export { a as assign, c as choose, e as escalate, f as forwardTo, l as log, p as pure, s as sendParent, b as sendTo } from '../../dist/send-5d129d95.development.esm.js';
|
|
2
|
+
export { z as cancel, A as raise, C as spawn, B as stop } from '../../dist/raise-f4ad5a87.development.esm.js';
|
|
3
|
+
import '../../dist/interpreter-80eb3bec.development.esm.js';
|
|
4
4
|
import '../../dev/dist/xstate-dev.development.esm.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { a as assign, c as choose, e as escalate, f as forwardTo, l as log, p as pure, s as sendParent, b as sendTo } from '../../dist/send-
|
|
2
|
-
export { z as cancel, A as raise, C as spawn, B as stop } from '../../dist/raise-
|
|
3
|
-
import '../../dist/interpreter-
|
|
1
|
+
export { a as assign, c as choose, e as escalate, f as forwardTo, l as log, p as pure, s as sendParent, b as sendTo } from '../../dist/send-84e2e742.esm.js';
|
|
2
|
+
export { z as cancel, A as raise, C as spawn, B as stop } from '../../dist/raise-8dc8e1aa.esm.js';
|
|
3
|
+
import '../../dist/interpreter-63c80754.esm.js';
|
|
4
4
|
import '../../dev/dist/xstate-dev.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).XStateActions={})}(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=".",n="xstate.error",i="xstate.stop";function o(t,e){return{type:`xstate.error.actor.${t}`,data:e}}function r(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const c=t=>{const e=r();e&&e.register(t)};function a(t){setTimeout((()=>{throw t}))}const u="function"==typeof Symbol&&Symbol.observable||"@@observable";let h=0;function d(t,e){const s=f(t),n=f(e);return"string"==typeof n?"string"==typeof s&&n===s:"string"==typeof s?s in n:Object.keys(s).every((t=>t in n&&d(s[t],n[t])))}function f(t){if("object"==typeof(e=t)&&"value"in e&&"context"in e&&"event"in e)return t.value;var e;if(_(t))return p(t);if("string"!=typeof t)return t;return p(function(t){try{return _(t)?t:t.toString().split(s)}catch(e){throw new Error(`'${t}' is not a valid state path.`)}}(t))}function p(t){if(1===t.length)return t[0];const e={};let s=e;for(let e=0;e<t.length-1;e++)if(e===t.length-2)s[t[e]]=t[e+1];else{const n=s;s={},n[t[e]]=s}return e}function l(t){return[].concat(...t)}function y(t){return void 0===t?[]:function(t){return _(t)?t:[t]}(t)}function _(t){return Array.isArray(t)}function v(t,e,s){const n="object"==typeof t,i=n?t:void 0;return{next:(n?t.next:t)?.bind(i),error:(n?t.error:e)?.bind(i),complete:(n?t.complete:s)?.bind(i)}}function g(t,e){if(e.startsWith("xstate#")){const[,s]=e.match(/\[(\d+)\]$/),n=t.getStateNodeById(e.slice(7,-(s.length+2))).config.invoke;return{src:(Array.isArray(n)?n[s]:n).src,input:void 0}}const s=t.implementations.actors[e];return s?"transition"in s?{src:s,input:void 0}:s:void 0}let m=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const x={clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class b{constructor(t,s){this.logic=t,this._state=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new e(this._process.bind(this)),this.delayedEventsMap={},this.observers=new Set,this.logger=void 0,this._processingStatus=m.NotStarted,this._parent=void 0,this.ref=void 0,this._actorScope=void 0,this._systemId=void 0,this.sessionId=void 0,this.system=void 0,this._doneEvent=void 0,this.src=void 0,this._deferred=[];const n={...x,...s},{clock:i,logger:o,parent:r,id:c,systemId:a,inspect:u}=n;this.system=r?.system??function(t){const e=new Map,s=new Map,n=new WeakMap,i=new Set,o={_bookId:()=>"x:"+h++,_register:(t,s)=>(e.set(t,s),t),_unregister:t=>{e.delete(t.sessionId);const i=n.get(t);void 0!==i&&(s.delete(i),n.delete(t))},get:t=>s.get(t),_set:(t,e)=>{const i=s.get(t);if(i&&i!==e)throw new Error(`Actor with system ID '${t}' already exists.`);s.set(t,e),n.set(e,t)},inspect:t=>{i.add(t)},_sendInspectionEvent:e=>{const s={...e,rootId:t.sessionId};i.forEach((t=>t.next?.(s)))},_relay:(t,e,s)=>{o._sendInspectionEvent({type:"@xstate.event",sourceRef:t,actorRef:e,event:s}),e._send(s)}};return o}(this),u&&!r&&this.system.inspect(v(u)),this.sessionId=this.system._bookId(),this.id=c??this.sessionId,this.logger=o,this.clock=i,this._parent=r,this.options=n,this.src=n.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()}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),this._initState(s?.state),a&&"active"===this._state.status&&(this._systemId=a,this.system._set(a,this))}_initState(t){this._state=t?this.logic.restoreState?this.logic.restoreState(t,this._actorScope):t:this.logic.getInitialState(this._actorScope,this.options?.input)}update(t,e){let s;for(this._state=t;s=this._deferred.shift();)s();for(const e of this.observers)try{e.next?.(t)}catch(t){a(t)}switch(this._state.status){case"done":this._stopProcedure(),this._complete(),this._doneEvent=(n=this.id,i=this._state.output,{type:`xstate.done.actor.${n}`,output:i}),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._stopProcedure(),this._error(this._state.error),this._parent&&this.system._relay(this,this._parent,o(this.id,this._state.error))}var n,i;this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:e,snapshot:t})}subscribe(t,e,s){const n=v(t,e,s);if(this._processingStatus!==m.Stopped)this.observers.add(n);else try{n.complete?.()}catch(t){a(t)}return{unsubscribe:()=>{this.observers.delete(n)}}}start(){if(this._processingStatus===m.Running)return this;this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this._processingStatus=m.Running;const t={type:"xstate.init",input:this.options.input};this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:t});switch(this._state.status){case"done":this.update(this._state,t);case"error":return this}if(this.logic.start)try{this.logic.start(this._state,this._actorScope)}catch(t){return this._stopProcedure(),this._error(t),this._parent?.send(o(this.id,t)),this}return this.update(this._state,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let e,s;try{e=this.logic.transition(this._state,t,this._actorScope)}catch(t){s={err:t}}if(s){const{err:t}=s;return this._stopProcedure(),this._error(t),void this._parent?.send(o(this.id,t))}this.update(e,t),t.type===i&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===m.Stopped?this:(this.mailbox.clear(),this._processingStatus===m.NotStarted?(this._processingStatus=m.Stopped,this):(this.mailbox.enqueue({type:i}),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){a(t)}this.observers.clear()}_error(t){if(!this.observers.size)return void(this._parent||a(t));let e=!1;for(const s of this.observers){const n=s.error;e||=!n;try{n?.(t)}catch(t){a(t)}}this.observers.clear(),e&&a(t)}_stopProcedure(){if(this._processingStatus!==m.Running)return this;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.mailbox.clear(),this.mailbox=new e(this._process.bind(this)),this._processingStatus=m.Stopped,this.system._unregister(this),this}_send(t){this._processingStatus!==m.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}delaySend(t){const{event:e,id:s,delay:n}=t,i=this.clock.setTimeout((()=>{this.system._relay(this,t.to??this,e)}),n);s&&(this.delayedEventsMap[s]=i)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}attachDevTools(){const{devTools:t}=this.options;if(t){("function"==typeof t?t:c)(this)}}toJSON(){return{xstate$$type:1,id:this.id}}getPersistedState(t){return this.logic.getPersistedState(this._state,t)}[u](){return this}getSnapshot(){return this._state}}function S(t,e){return new b(t,e)}const w=new WeakMap;function I(t,e,s,n,{sendId:i}){return[e,"function"==typeof i?i(s,n):i]}function E(t,e){t.self.cancel(e)}function T(t,e,s,n,{id:i,systemId:o,src:r,input:c,syncSnapshot:a}){const u="string"==typeof r?g(e.machine,r):{src:r,input:void 0},h="function"==typeof i?i(s):i;let d;if(u){const n=c||u.input;d=S(u.src,{id:h,src:r,parent:t?.self,systemId:o,input:"function"==typeof n?n({context:e.context,event:s.event,self:t?.self}):n}),a&&d.subscribe({next:e=>{"active"===e.status&&t.self.send({type:`xstate.snapshot.${i}`,snapshot:e})},error:()=>{}})}return[q(e,{children:{...e.children,[h]:d}}),{id:i,actorRef:d}]}function k(t,{id:e,actorRef:s}){s&&t.defer((()=>{if(s._processingStatus!==m.Stopped)try{s.start?.()}catch(s){return void t.self.send(o(e,s))}}))}function $(t,e,s,n,{actorRef:i}){const o="function"==typeof i?i(s,n):i,r="string"==typeof o?e.children[o]:o;let c=e.children;return r&&(c={...c},delete c[r.id]),[q(e,{children:c}),r]}function R(t,e){e&&(t.system._unregister(e),e._processingStatus===m.Running?t.defer((()=>{t.stopChild(e)})):t.stopChild(e))}function P(t,e,s,n){const{machine:i}=n,o="function"==typeof t,r=o?t:i.implementations.guards["string"==typeof t?t:t.type];if(!o&&!r)throw new Error(`Guard '${"string"==typeof t?t:t.type}' is not implemented.'.`);if("function"!=typeof r)return P(r,e,s,n);const c={context:e,event:s},a=o||"string"==typeof t?void 0:"params"in t?"function"==typeof t.params?t.params({context:e,event:s}):t.params:void 0;if(!("check"in r))return r(c,a);return r.check(n,c,r)}const j=t=>"atomic"===t.type||"final"===t.type;function M(t){return Object.values(t.states).filter((t=>"history"!==t.type))}function O(t,e){const s=[];if(e===t)return s;let n=t.parent;for(;n&&n!==e;)s.push(n),n=n.parent;return s}function A(t,e){const s=e.get(t);if(!s)return{};if("compound"===t.type){const t=s[0];if(!t)return{};if(j(t))return t.key}const n={};for(const t of s)n[t.key]=A(t,e);return n}function N(t){const e=new Map;for(const s of t)e.has(s)||e.set(s,[]),s.parent&&(e.has(s.parent)||e.set(s.parent,[]),e.get(s.parent).push(s));return e}function C(t,e){const s=function(t){const e=new Set(t),s=new Set(t),n=N(s);for(const t of e)if("compound"!==t.type||n.get(t)&&n.get(t).length){if("parallel"===t.type)for(const e of M(t))if("history"!==e.type&&!s.has(e)){const t=D(e);for(const e of t)s.add(e)}}else D(t).forEach((t=>s.add(t)));for(const t of s){let e=t.parent;for(;e;)s.add(e),e=e.parent}return s}(e);return A(t,N(s))}function D(t){const e=function(t){const e=new Set;function s(t){if(!e.has(t))if(e.add(t),"compound"===t.type)s(t.initial.target[0]);else if("parallel"===t.type)for(const e of M(t))s(e)}return s(t),e}(t);for(const s of e)for(const n of O(s,t))e.add(n);return e}function W(t,e){return{status:t.status,output:t.output,error:t.error,machine:e,context:t.context,configuration:t.configuration,value:C(e.root,t.configuration),tags:new Set(l(t.configuration.map((t=>t.tags)))),children:t.children,historyValue:t.historyValue||{},matches(t){return d(t,this.value)},hasTag(t){return this.tags.has(t)},can(t){const e=this.machine.getTransitionData(this,t);return!!e?.length&&e.some((t=>void 0!==t.target||t.actions.length))},get nextEvents(){return function(t,e,s){let n=w.get(t);return n?e in n||(n[e]=s()):(n={[e]:s()},w.set(t,n)),n[e]}(this,"nextEvents",(()=>[...new Set(l([...this.configuration.map((t=>t.ownEvents))]))]))},get meta(){return this.configuration.reduce(((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t)),{})},toJSON(){const{configuration:t,tags:e,machine:s,nextEvents:n,toJSON:i,can:o,hasTag:r,matches:c,...a}=this;return{...a,tags:Array.from(e)}}}}function q(t,e={}){return W({...t,...e},t.machine)}function J(t,{machine:e,context:s},n,i){return(r,c)=>{const a=((o,r={})=>{const{systemId:c}=r;if("string"==typeof o){const a=g(e,o);if(!a)throw new Error(`Actor logic '${o}' not implemented in machine '${e.id}'`);const u="input"in r?r.input:a.input,h=S(a.src,{id:r.id,parent:t.self,input:"function"==typeof u?u({context:s,event:n,self:t.self}):u,src:o,systemId:c});return i[h.id]=h,r.syncSnapshot&&h.subscribe({next:e=>{"active"===e.status&&t.self.send({type:`xstate.snapshot.${h.id}`,snapshot:e})},error:()=>{}}),h}{const e=S(o,{id:r.id,parent:t.self,input:r.input,src:o,systemId:c});return r.syncSnapshot&&e.subscribe({next:s=>{"active"===s.status&&t.self.send({type:`xstate.snapshot.${e.id}`,snapshot:s,id:e.id})},error:()=>{}}),e}})(r,c);return i[a.id]=a,t.defer((()=>{if(a._processingStatus!==m.Stopped)try{a.start?.()}catch(e){return void t.self.send(o(a.id,e))}})),a}}function V(t,e,s,n,{assignment:i}){if(!e.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const o={},r={context:e.context,event:s.event,spawn:J(t,e,s.event,o),self:t?.self,system:t?.system};let c={};if("function"==typeof i)c=i(r,n);else for(const t of Object.keys(i)){const e=i[t];c[t]="function"==typeof e?e(r,n):e}return[q(e,{context:Object.assign({},e.context,c),children:Object.keys(o).length?{...e.children,...o}:e.children})]}function z(t,e,s,n,{branches:i}){const o=i.find((t=>!t.guard||P(t.guard,e.context,s.event,e)))?.actions;return[e,void 0,y(o)]}function B(t,e,s,n,{value:i,label:o}){return[e,{value:"function"==typeof i?i(s,n):i,label:o}]}function G({logger:t},{value:e,label:s}){s?t(s,e):t(e)}function Q(t,e,s,n,{get:i}){return[e,void 0,y(i({context:s.context,event:s.event}))]}function U(t,e,s,n,{event:i,id:o,delay:r},{internalQueue:c}){const a=e.machine.implementations.delays;if("string"==typeof i)throw new Error(`Only event objects may be used with raise; use raise({ type: "${i}" }) instead`);const u="function"==typeof i?i(s,n):i;let h;if("string"==typeof r){const t=a&&a[r];h="function"==typeof t?t(s,n):t}else h="function"==typeof r?r(s,n):r;return"number"!=typeof h&&c.push(u),[e,{event:u,id:o,delay:h}]}function X(t,e){"number"!=typeof e.delay||t.self.delaySend(e)}let F=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});function H(t,e,s,n,{to:i,event:o,id:r,delay:c},a){const u=e.machine.implementations.delays;if("string"==typeof o)throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${o}" }) instead`);const h="function"==typeof o?o(s,n):o;let d;if("string"==typeof c){const t=u&&u[c];d="function"==typeof t?t(s,n):t}else d="function"==typeof c?c(s,n):c;const f="function"==typeof i?i(s,n):i;let p;if("string"==typeof f){if(p=f===F.Parent?t?.self._parent:f===F.Internal?t?.self:f.startsWith("#_")?e.children[f.slice(2)]:a.deferredActorIds?.includes(f)?f:e.children[f],!p)throw new Error(`Unable to send event to actor '${f}' from machine '${e.machine.id}'.`)}else p=f||t?.self;return[e,{to:p,event:h,id:r,delay:d}]}function K(t,e,s){"string"==typeof s.to&&(s.to=e.children[s.to])}function L(t,e){"number"!=typeof e.delay?t.defer((()=>{const{to:s,event:i}=e;t?.system._relay(t.self,s,i.type===n?o(t.self.id,i.data):i)})):t.self.delaySend(e)}function Y(t,e,s){function n(t,e){}return n.type="xstate.sendTo",n.to=t,n.event=e,n.id=s?.id,n.delay=s?.delay,n.resolve=H,n.retryResolve=K,n.execute=L,n}function Z(t,e){return Y(F.Parent,t,e)}t.assign=function(t){function e(t,e){}return e.type="xstate.assign",e.assignment=t,e.resolve=V,e},t.cancel=function(t){function e(t,e){}return e.type="xstate.cancel",e.sendId=t,e.resolve=I,e.execute=E,e},t.choose=function(t){function e(t,e){}return e.type="xstate.choose",e.branches=t,e.resolve=z,e},t.escalate=function(t,e){return Z((e=>({type:n,data:"function"==typeof t?t(e):t})),e)},t.forwardTo=function(t,e){return Y(t,(({event:t})=>t),e)},t.log=function(t=(({context:t,event:e})=>({context:t,event:e})),e){function s(t,e){}return s.type="xstate.log",s.value=t,s.label=e,s.resolve=B,s.execute=G,s},t.pure=function(t){function e(t,e){}return e.type="xstate.pure",e.get=t,e.resolve=Q,e},t.raise=function(t,e){function s(t,e){}return s.type="xstate.raise",s.event=t,s.id=e?.id,s.delay=e?.delay,s.resolve=U,s.execute=X,s},t.sendParent=Z,t.sendTo=Y,t.spawn=function(...[t,{id:e,systemId:s,input:n,syncSnapshot:i=!1}={}]){function o(t,e){}return o.type="xstate.spawn",o.id=e,o.systemId=s,o.src=t,o.input=n,o.syncSnapshot=i,o.resolve=T,o.execute=k,o},t.stop=function(t){function e(t,e){}return e.type="xstate.stop",e.actorRef=t,e.resolve=$,e.execute=R,e},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).XStateActions={})}(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=".",n="xstate.error",i="xstate.stop";function o(t,e){return{type:`xstate.error.actor.${t}`,data:e}}function r(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const c=t=>{const e=r();e&&e.register(t)};function a(t){setTimeout((()=>{throw t}))}const u="function"==typeof Symbol&&Symbol.observable||"@@observable";let h=0;function f(t,e){const s=d(t),n=d(e);return"string"==typeof n?"string"==typeof s&&n===s:"string"==typeof s?s in n:Object.keys(s).every((t=>t in n&&f(s[t],n[t])))}function d(t){if("object"==typeof(e=t)&&"value"in e&&"context"in e&&"event"in e)return t.value;var e;if(_(t))return l(t);if("string"!=typeof t)return t;return l(function(t){try{return _(t)?t:t.toString().split(s)}catch(e){throw new Error(`'${t}' is not a valid state path.`)}}(t))}function l(t){if(1===t.length)return t[0];const e={};let s=e;for(let e=0;e<t.length-1;e++)if(e===t.length-2)s[t[e]]=t[e+1];else{const n=s;s={},n[t[e]]=s}return e}function p(t){return[].concat(...t)}function y(t){return void 0===t?[]:function(t){return _(t)?t:[t]}(t)}function _(t){return Array.isArray(t)}function g(t,e,s){const n="object"==typeof t,i=n?t:void 0;return{next:(n?t.next:t)?.bind(i),error:(n?t.error:e)?.bind(i),complete:(n?t.complete:s)?.bind(i)}}function v(t,e){if(e.startsWith("xstate#")){const[,s]=e.match(/\[(\d+)\]$/),n=t.getStateNodeById(e.slice(7,-(s.length+2))).config.invoke;return(Array.isArray(n)?n[s]:n).src}return t.implementations.actors[e]}let m=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const x={clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class b{constructor(t,s){this.logic=t,this._state=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new e(this._process.bind(this)),this.delayedEventsMap={},this.observers=new Set,this.logger=void 0,this._processingStatus=m.NotStarted,this._parent=void 0,this.ref=void 0,this._actorScope=void 0,this._systemId=void 0,this.sessionId=void 0,this.system=void 0,this._doneEvent=void 0,this.src=void 0,this._deferred=[];const n={...x,...s},{clock:i,logger:o,parent:r,id:c,systemId:a,inspect:u}=n;this.system=r?.system??function(t){const e=new Map,s=new Map,n=new WeakMap,i=new Set,o={_bookId:()=>"x:"+h++,_register:(t,s)=>(e.set(t,s),t),_unregister:t=>{e.delete(t.sessionId);const i=n.get(t);void 0!==i&&(s.delete(i),n.delete(t))},get:t=>s.get(t),_set:(t,e)=>{const i=s.get(t);if(i&&i!==e)throw new Error(`Actor with system ID '${t}' already exists.`);s.set(t,e),n.set(e,t)},inspect:t=>{i.add(t)},_sendInspectionEvent:e=>{const s={...e,rootId:t.sessionId};i.forEach((t=>t.next?.(s)))},_relay:(t,e,s)=>{o._sendInspectionEvent({type:"@xstate.event",sourceRef:t,actorRef:e,event:s}),e._send(s)}};return o}(this),u&&!r&&this.system.inspect(g(u)),this.sessionId=this.system._bookId(),this.id=c??this.sessionId,this.logger=o,this.clock=i,this._parent=r,this.options=n,this.src=n.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()}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),this._initState(s?.state),a&&"active"===this._state.status&&(this._systemId=a,this.system._set(a,this))}_initState(t){this._state=t?this.logic.restoreState?this.logic.restoreState(t,this._actorScope):t:this.logic.getInitialState(this._actorScope,this.options?.input)}update(t,e){let s;for(this._state=t;s=this._deferred.shift();)s();for(const e of this.observers)try{e.next?.(t)}catch(t){a(t)}switch(this._state.status){case"done":this._stopProcedure(),this._complete(),this._doneEvent=(n=this.id,i=this._state.output,{type:`xstate.done.actor.${n}`,output:i}),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._stopProcedure(),this._error(this._state.error),this._parent&&this.system._relay(this,this._parent,o(this.id,this._state.error))}var n,i;this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:e,snapshot:t})}subscribe(t,e,s){const n=g(t,e,s);if(this._processingStatus!==m.Stopped)this.observers.add(n);else try{n.complete?.()}catch(t){a(t)}return{unsubscribe:()=>{this.observers.delete(n)}}}start(){if(this._processingStatus===m.Running)return this;this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this._processingStatus=m.Running;const t={type:"xstate.init",input:this.options.input};this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:t});switch(this._state.status){case"done":this.update(this._state,t);case"error":return this}if(this.logic.start)try{this.logic.start(this._state,this._actorScope)}catch(t){return this._stopProcedure(),this._error(t),this._parent?.send(o(this.id,t)),this}return this.update(this._state,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let e,s;try{e=this.logic.transition(this._state,t,this._actorScope)}catch(t){s={err:t}}if(s){const{err:t}=s;return this._stopProcedure(),this._error(t),void this._parent?.send(o(this.id,t))}this.update(e,t),t.type===i&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===m.Stopped?this:(this.mailbox.clear(),this._processingStatus===m.NotStarted?(this._processingStatus=m.Stopped,this):(this.mailbox.enqueue({type:i}),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){a(t)}this.observers.clear()}_error(t){if(!this.observers.size)return void(this._parent||a(t));let e=!1;for(const s of this.observers){const n=s.error;e||=!n;try{n?.(t)}catch(t){a(t)}}this.observers.clear(),e&&a(t)}_stopProcedure(){if(this._processingStatus!==m.Running)return this;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.mailbox.clear(),this.mailbox=new e(this._process.bind(this)),this._processingStatus=m.Stopped,this.system._unregister(this),this}_send(t){this._processingStatus!==m.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}delaySend(t){const{event:e,id:s,delay:n}=t,i=this.clock.setTimeout((()=>{this.system._relay(this,t.to??this,e)}),n);s&&(this.delayedEventsMap[s]=i)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}attachDevTools(){const{devTools:t}=this.options;if(t){("function"==typeof t?t:c)(this)}}toJSON(){return{xstate$$type:1,id:this.id}}getPersistedState(t){return this.logic.getPersistedState(this._state,t)}[u](){return this}getSnapshot(){return this._state}}function S(t,e){return new b(t,e)}const w=new WeakMap;function I(t,e,s,n,{sendId:i}){return[e,"function"==typeof i?i(s,n):i]}function E(t,e){t.self.cancel(e)}function T(t,e,s,n,{id:i,systemId:o,src:r,input:c,syncSnapshot:a}){const u="string"==typeof r?v(e.machine,r):r,h="function"==typeof i?i(s):i;let f;return u&&(f=S(u,{id:h,src:r,parent:t?.self,systemId:o,input:"function"==typeof c?c({context:e.context,event:s.event,self:t?.self}):c}),a&&f.subscribe({next:e=>{"active"===e.status&&t.self.send({type:`xstate.snapshot.${i}`,snapshot:e})},error:()=>{}})),[G(e,{children:{...e.children,[h]:f}}),{id:i,actorRef:f}]}function k(t,{id:e,actorRef:s}){s&&t.defer((()=>{if(s._processingStatus!==m.Stopped)try{s.start?.()}catch(s){return void t.self.send(o(e,s))}}))}function $(t,e,s,n,{actorRef:i}){const o="function"==typeof i?i(s,n):i,r="string"==typeof o?e.children[o]:o;let c=e.children;return r&&(c={...c},delete c[r.id]),[G(e,{children:c}),r]}function R(t,e){e&&(t.system._unregister(e),e._processingStatus===m.Running?t.defer((()=>{t.stopChild(e)})):t.stopChild(e))}function P(t,e,s,n){const{machine:i}=n,o="function"==typeof t,r=o?t:i.implementations.guards["string"==typeof t?t:t.type];if(!o&&!r)throw new Error(`Guard '${"string"==typeof t?t:t.type}' is not implemented.'.`);if("function"!=typeof r)return P(r,e,s,n);const c={context:e,event:s},a=o||"string"==typeof t?void 0:"params"in t?"function"==typeof t.params?t.params({context:e,event:s}):t.params:void 0;if(!("check"in r))return r(c,a);return r.check(n,c,r)}const j=t=>"atomic"===t.type||"final"===t.type;function O(t){return Object.values(t.states).filter((t=>"history"!==t.type))}function M(t,e){const s=[];if(e===t)return s;let n=t.parent;for(;n&&n!==e;)s.push(n),n=n.parent;return s}function A(t,e){const s=e.get(t);if(!s)return{};if("compound"===t.type){const t=s[0];if(!t)return{};if(j(t))return t.key}const n={};for(const t of s)n[t.key]=A(t,e);return n}function N(t){const e=new Map;for(const s of t)e.has(s)||e.set(s,[]),s.parent&&(e.has(s.parent)||e.set(s.parent,[]),e.get(s.parent).push(s));return e}function C(t,e){const s=function(t){const e=new Set(t),s=new Set(t),n=N(s);for(const t of e)if("compound"!==t.type||n.get(t)&&n.get(t).length){if("parallel"===t.type)for(const e of O(t))if("history"!==e.type&&!s.has(e)){const t=D(e);for(const e of t)s.add(e)}}else D(t).forEach((t=>s.add(t)));for(const t of s){let e=t.parent;for(;e;)s.add(e),e=e.parent}return s}(e);return A(t,N(s))}function D(t){const e=function(t){const e=new Set;function s(t){if(!e.has(t))if(e.add(t),"compound"===t.type)s(t.initial.target[0]);else if("parallel"===t.type)for(const e of O(t))s(e)}return s(t),e}(t);for(const s of e)for(const n of M(s,t))e.add(n);return e}const W=function(t){return f(t,this.value)},q=function(t){return this.tags.has(t)},J=function(t){const e=this.machine.getTransitionData(this,t);return!!e?.length&&e.some((t=>void 0!==t.target||t.actions.length))},V=function(){const{configuration:t,tags:e,machine:s,nextEvents:n,toJSON:i,can:o,hasTag:r,matches:c,...a}=this;return{...a,tags:Array.from(e)}},z=function(){return function(t,e,s){let n=w.get(t);return n?e in n||(n[e]=s()):(n={[e]:s()},w.set(t,n)),n[e]}(this,"nextEvents",(()=>[...new Set(p([...this.configuration.map((t=>t.ownEvents))]))]))},B=function(){return this.configuration.reduce(((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t)),{})};function G(t,e={}){return function(t,e){const s={status:t.status,output:t.output,error:t.error,machine:e,context:t.context,configuration:t.configuration,value:C(e.root,t.configuration),tags:new Set(p(t.configuration.map((t=>t.tags)))),children:t.children,historyValue:t.historyValue||{},matches:W,hasTag:q,can:J,toJSON:V};return Object.defineProperties(s,{nextEvents:{get:z,configurable:!0,enumerable:!0},meta:{get:B,configurable:!0,enumerable:!0}}),s}({...t,...e},t.machine)}function Q(t,{machine:e,context:s},n,i){return(r,c)=>{const a=((o,r={})=>{const{systemId:c,input:a}=r;if("string"==typeof o){const u=v(e,o);if(!u)throw new Error(`Actor logic '${o}' not implemented in machine '${e.id}'`);const h=S(u,{id:r.id,parent:t.self,input:"function"==typeof a?a({context:s,event:n,self:t.self}):a,src:o,systemId:c});return i[h.id]=h,r.syncSnapshot&&h.subscribe({next:e=>{"active"===e.status&&t.self.send({type:`xstate.snapshot.${h.id}`,snapshot:e})},error:()=>{}}),h}{const e=S(o,{id:r.id,parent:t.self,input:r.input,src:o,systemId:c});return r.syncSnapshot&&e.subscribe({next:s=>{"active"===s.status&&t.self.send({type:`xstate.snapshot.${e.id}`,snapshot:s,id:e.id})},error:()=>{}}),e}})(r,c);return i[a.id]=a,t.defer((()=>{if(a._processingStatus!==m.Stopped)try{a.start?.()}catch(e){return void t.self.send(o(a.id,e))}})),a}}function U(t,e,s,n,{assignment:i}){if(!e.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const o={},r={context:e.context,event:s.event,spawn:Q(t,e,s.event,o),self:t?.self,system:t?.system};let c={};if("function"==typeof i)c=i(r,n);else for(const t of Object.keys(i)){const e=i[t];c[t]="function"==typeof e?e(r,n):e}return[G(e,{context:Object.assign({},e.context,c),children:Object.keys(o).length?{...e.children,...o}:e.children})]}function X(t,e,s,n,{branches:i}){const o=i.find((t=>!t.guard||P(t.guard,e.context,s.event,e)))?.actions;return[e,void 0,y(o)]}function F(t,e,s,n,{value:i,label:o}){return[e,{value:"function"==typeof i?i(s,n):i,label:o}]}function H({logger:t},{value:e,label:s}){s?t(s,e):t(e)}function K(t,e,s,n,{get:i}){return[e,void 0,y(i({context:s.context,event:s.event}))]}function L(t,e,s,n,{event:i,id:o,delay:r},{internalQueue:c}){const a=e.machine.implementations.delays;if("string"==typeof i)throw new Error(`Only event objects may be used with raise; use raise({ type: "${i}" }) instead`);const u="function"==typeof i?i(s,n):i;let h;if("string"==typeof r){const t=a&&a[r];h="function"==typeof t?t(s,n):t}else h="function"==typeof r?r(s,n):r;return"number"!=typeof h&&c.push(u),[e,{event:u,id:o,delay:h}]}function Y(t,e){"number"!=typeof e.delay||t.self.delaySend(e)}let Z=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});function tt(t,e,s,n,{to:i,event:o,id:r,delay:c},a){const u=e.machine.implementations.delays;if("string"==typeof o)throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${o}" }) instead`);const h="function"==typeof o?o(s,n):o;let f;if("string"==typeof c){const t=u&&u[c];f="function"==typeof t?t(s,n):t}else f="function"==typeof c?c(s,n):c;const d="function"==typeof i?i(s,n):i;let l;if("string"==typeof d){if(l=d===Z.Parent?t?.self._parent:d===Z.Internal?t?.self:d.startsWith("#_")?e.children[d.slice(2)]:a.deferredActorIds?.includes(d)?d:e.children[d],!l)throw new Error(`Unable to send event to actor '${d}' from machine '${e.machine.id}'.`)}else l=d||t?.self;return[e,{to:l,event:h,id:r,delay:f}]}function et(t,e,s){"string"==typeof s.to&&(s.to=e.children[s.to])}function st(t,e){"number"!=typeof e.delay?t.defer((()=>{const{to:s,event:i}=e;t?.system._relay(t.self,s,i.type===n?o(t.self.id,i.data):i)})):t.self.delaySend(e)}function nt(t,e,s){function n(t,e){}return n.type="xstate.sendTo",n.to=t,n.event=e,n.id=s?.id,n.delay=s?.delay,n.resolve=tt,n.retryResolve=et,n.execute=st,n}function it(t,e){return nt(Z.Parent,t,e)}t.assign=function(t){function e(t,e){}return e.type="xstate.assign",e.assignment=t,e.resolve=U,e},t.cancel=function(t){function e(t,e){}return e.type="xstate.cancel",e.sendId=t,e.resolve=I,e.execute=E,e},t.choose=function(t){function e(t,e){}return e.type="xstate.choose",e.branches=t,e.resolve=X,e},t.escalate=function(t,e){return it((e=>({type:n,data:"function"==typeof t?t(e):t})),e)},t.forwardTo=function(t,e){return nt(t,(({event:t})=>t),e)},t.log=function(t=(({context:t,event:e})=>({context:t,event:e})),e){function s(t,e){}return s.type="xstate.log",s.value=t,s.label=e,s.resolve=F,s.execute=H,s},t.pure=function(t){function e(t,e){}return e.type="xstate.pure",e.get=t,e.resolve=K,e},t.raise=function(t,e){function s(t,e){}return s.type="xstate.raise",s.event=t,s.id=e?.id,s.delay=e?.delay,s.resolve=L,s.execute=Y,s},t.sendParent=it,t.sendTo=nt,t.spawn=function(...[t,{id:e,systemId:s,input:n,syncSnapshot:i=!1}={}]){function o(t,e){}return o.type="xstate.spawn",o.id=e,o.systemId=s,o.src=t,o.input=n,o.syncSnapshot=i,o.resolve=T,o.execute=k,o},t.stop=function(t){function e(t,e){}return e.type="xstate.stop",e.actorRef=t,e.resolve=$,e.execute=R,e},Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
2
2
|
//# sourceMappingURL=xstate-actions.umd.min.js.map
|