xstate 5.0.0-beta.15 → 5.0.0-beta.17
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 +2 -7
- package/actions/dist/xstate-actions.cjs.mjs +2 -7
- package/actions/dist/xstate-actions.development.cjs.js +2 -7
- package/actions/dist/xstate-actions.development.esm.js +1 -1
- package/actions/dist/xstate-actions.esm.js +1 -1
- 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 +1 -1
- package/actors/dist/xstate-actors.development.cjs.js +1 -1
- package/actors/dist/xstate-actors.development.esm.js +1 -1
- package/actors/dist/xstate-actors.esm.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/{actions-98f362b9.development.esm.js → actions-13190b25.development.esm.js} +1335 -1537
- package/dist/{actions-d71ac253.development.cjs.js → actions-40bd643f.development.cjs.js} +1336 -1546
- package/dist/{actions-6884fae8.esm.js → actions-4d6514d2.esm.js} +1310 -1539
- package/dist/{actions-81cc7f2b.cjs.js → actions-5fb9f10d.cjs.js} +1311 -1548
- package/dist/declarations/src/State.d.ts +1 -1
- package/dist/declarations/src/StateMachine.d.ts +2 -4
- package/dist/declarations/src/StateNode.d.ts +4 -4
- package/dist/declarations/src/actions/assign.d.ts +11 -2
- package/dist/declarations/src/actions/cancel.d.ts +14 -3
- package/dist/declarations/src/actions/choose.d.ts +11 -3
- package/dist/declarations/src/actions/log.d.ts +22 -3
- package/dist/declarations/src/actions/pure.d.ts +17 -3
- package/dist/declarations/src/actions/raise.d.ts +5 -2
- package/dist/declarations/src/actions/send.d.ts +64 -22
- package/dist/declarations/src/actions/stop.d.ts +14 -2
- package/dist/declarations/src/actions.d.ts +5 -11
- package/dist/declarations/src/constantPrefixes.d.ts +6 -0
- package/dist/declarations/src/interpreter.d.ts +8 -3
- package/dist/declarations/src/stateUtils.d.ts +4 -8
- package/dist/declarations/src/types.d.ts +38 -223
- package/dist/declarations/src/utils.d.ts +1 -6
- package/dist/xstate.cjs.js +61 -52
- package/dist/xstate.cjs.mjs +1 -1
- package/dist/xstate.development.cjs.js +61 -52
- package/dist/xstate.development.esm.js +61 -52
- package/dist/xstate.esm.js +61 -52
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.esm.js +1 -1
- package/guards/dist/xstate-guards.esm.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/actions/dynamicAction.ts +0 -42
- package/dist/declarations/src/actionTypes.d.ts +0 -16
- package/dist/declarations/src/constants.d.ts +0 -5
|
@@ -2,30 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var actors_dist_xstateActors = require('../../dist/actions-
|
|
5
|
+
var actors_dist_xstateActors = require('../../dist/actions-5fb9f10d.cjs.js');
|
|
6
6
|
require('../../dev/dist/xstate-dev.cjs.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
exports.actionTypes = actors_dist_xstateActors.actionTypes;
|
|
11
10
|
exports.after = actors_dist_xstateActors.after;
|
|
12
11
|
exports.assign = actors_dist_xstateActors.assign;
|
|
13
12
|
exports.cancel = actors_dist_xstateActors.cancel;
|
|
14
13
|
exports.choose = actors_dist_xstateActors.choose;
|
|
14
|
+
exports.constantPrefixes = actors_dist_xstateActors.constantPrefixes;
|
|
15
15
|
exports.createInitEvent = actors_dist_xstateActors.createInitEvent;
|
|
16
16
|
exports.done = actors_dist_xstateActors.done;
|
|
17
17
|
exports.doneInvoke = actors_dist_xstateActors.doneInvoke;
|
|
18
18
|
exports.error = actors_dist_xstateActors.error;
|
|
19
19
|
exports.escalate = actors_dist_xstateActors.escalate;
|
|
20
20
|
exports.forwardTo = actors_dist_xstateActors.forwardTo;
|
|
21
|
-
exports.initEvent = actors_dist_xstateActors.initEvent;
|
|
22
21
|
exports.log = actors_dist_xstateActors.log;
|
|
23
22
|
exports.pure = actors_dist_xstateActors.pure;
|
|
24
23
|
exports.raise = actors_dist_xstateActors.raise;
|
|
25
|
-
exports.resolveActionObject = actors_dist_xstateActors.resolveActionObject;
|
|
26
|
-
exports.send = actors_dist_xstateActors.send;
|
|
27
24
|
exports.sendParent = actors_dist_xstateActors.sendParent;
|
|
28
25
|
exports.sendTo = actors_dist_xstateActors.sendTo;
|
|
29
26
|
exports.stop = actors_dist_xstateActors.stop;
|
|
30
|
-
exports.toActionObject = actors_dist_xstateActors.toActionObject;
|
|
31
|
-
exports.toActionObjects = actors_dist_xstateActors.toActionObjects;
|
|
@@ -1,24 +1,19 @@
|
|
|
1
1
|
export {
|
|
2
|
-
actionTypes,
|
|
3
2
|
after,
|
|
4
3
|
assign,
|
|
5
4
|
cancel,
|
|
6
5
|
choose,
|
|
6
|
+
constantPrefixes,
|
|
7
7
|
createInitEvent,
|
|
8
8
|
done,
|
|
9
9
|
doneInvoke,
|
|
10
10
|
error,
|
|
11
11
|
escalate,
|
|
12
12
|
forwardTo,
|
|
13
|
-
initEvent,
|
|
14
13
|
log,
|
|
15
14
|
pure,
|
|
16
15
|
raise,
|
|
17
|
-
resolveActionObject,
|
|
18
|
-
send,
|
|
19
16
|
sendParent,
|
|
20
17
|
sendTo,
|
|
21
|
-
stop
|
|
22
|
-
toActionObject,
|
|
23
|
-
toActionObjects
|
|
18
|
+
stop
|
|
24
19
|
} from "./xstate-actions.cjs.js";
|
|
@@ -2,30 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var actors_dist_xstateActors = require('../../dist/actions-
|
|
5
|
+
var actors_dist_xstateActors = require('../../dist/actions-40bd643f.development.cjs.js');
|
|
6
6
|
require('../../dev/dist/xstate-dev.development.cjs.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
exports.actionTypes = actors_dist_xstateActors.actionTypes;
|
|
11
10
|
exports.after = actors_dist_xstateActors.after;
|
|
12
11
|
exports.assign = actors_dist_xstateActors.assign;
|
|
13
12
|
exports.cancel = actors_dist_xstateActors.cancel;
|
|
14
13
|
exports.choose = actors_dist_xstateActors.choose;
|
|
14
|
+
exports.constantPrefixes = actors_dist_xstateActors.constantPrefixes;
|
|
15
15
|
exports.createInitEvent = actors_dist_xstateActors.createInitEvent;
|
|
16
16
|
exports.done = actors_dist_xstateActors.done;
|
|
17
17
|
exports.doneInvoke = actors_dist_xstateActors.doneInvoke;
|
|
18
18
|
exports.error = actors_dist_xstateActors.error;
|
|
19
19
|
exports.escalate = actors_dist_xstateActors.escalate;
|
|
20
20
|
exports.forwardTo = actors_dist_xstateActors.forwardTo;
|
|
21
|
-
exports.initEvent = actors_dist_xstateActors.initEvent;
|
|
22
21
|
exports.log = actors_dist_xstateActors.log;
|
|
23
22
|
exports.pure = actors_dist_xstateActors.pure;
|
|
24
23
|
exports.raise = actors_dist_xstateActors.raise;
|
|
25
|
-
exports.resolveActionObject = actors_dist_xstateActors.resolveActionObject;
|
|
26
|
-
exports.send = actors_dist_xstateActors.send;
|
|
27
24
|
exports.sendParent = actors_dist_xstateActors.sendParent;
|
|
28
25
|
exports.sendTo = actors_dist_xstateActors.sendTo;
|
|
29
26
|
exports.stop = actors_dist_xstateActors.stop;
|
|
30
|
-
exports.toActionObject = actors_dist_xstateActors.toActionObject;
|
|
31
|
-
exports.toActionObjects = actors_dist_xstateActors.toActionObjects;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { ah as after, x as assign, P as cancel, Q as choose, ag as constantPrefixes, y as createInitEvent, ai as done, O as doneInvoke, B as error, aj as escalate, K as forwardTo, R as log, T as pure, U as raise, J as sendParent, I as sendTo, V as stop } from '../../dist/actions-13190b25.development.esm.js';
|
|
2
2
|
import '../../dev/dist/xstate-dev.development.esm.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { ah as after, x as assign, P as cancel, Q as choose, ag as constantPrefixes, y as createInitEvent, ai as done, O as doneInvoke, B as error, aj as escalate, K as forwardTo, R as log, T as pure, U as raise, J as sendParent, I as sendTo, V as stop } from '../../dist/actions-4d6514d2.esm.js';
|
|
2
2
|
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";let e=function(t){return t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Pure="xstate.pure",t.Choose="xstate.choose",t}({}),n=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});const s=e.Stop,o=e.Raise,r=e.Send,i=e.Cancel,a=e.Assign,c=e.After,u=e.DoneState,d=e.Log,h=e.Init,p=e.Invoke,l=e.ErrorExecution,f=e.ErrorPlatform,y=e.ErrorCustom,m=e.Choose,v=e.Pure;var g=Object.freeze({__proto__:null,stop:s,raise:o,send:r,cancel:i,assign:a,after:c,doneState:u,log:d,init:h,invoke:p,errorExecution:l,errorPlatform:f,error:y,choose:m,pure:v});const x=".";function _(t,e){const n=b(t),s=b(e);return k(s)?!!k(n)&&s===n:k(n)?n in s:Object.keys(n).every((t=>t in s&&_(n[t],s[t])))}function b(t){if("object"==typeof(e=t)&&"value"in e&&"context"in e&&"event"in e)return t.value;var e;if(I(t))return w(t);if("string"!=typeof t)return t;return w(function(t){try{return I(t)?t:t.toString().split(x)}catch(e){throw new Error(`'${t}' is not a valid state path.`)}}(t))}function w(t){if(1===t.length)return t[0];const e={};let n=e;for(let e=0;e<t.length-1;e++)if(e===t.length-2)n[t[e]]=t[e+1];else{const s=n;n={},s[t[e]]=n}return e}function S(t){return[].concat(...t)}function E(t){return void 0===t?[]:function(t){return I(t)?t:[t]}(t)}function I(t){return Array.isArray(t)}function $(t){return"function"==typeof t}function k(t){return"string"==typeof t}function C(t){return t?"transition"in t?{src:t,input:void 0}:t:void 0}function T(t,e){return{type:t.type,params:t.params,resolve:e}}function j(t){return"object"==typeof t&&null!==t&&"resolve"in t}function O(t,e){return T({type:r,params:{to:e?e.to:void 0,delay:e?e.delay:void 0,event:t,id:e&&void 0!==e.id?e.id:$(t)?t.name:t.type}},((s,{actorContext:o,state:i})=>{const a={to:e?e.to:void 0,delay:e?e.delay:void 0,event:t,id:e&&void 0!==e.id?e.id:$(t)?t.name:t.type},c={context:i.context,event:s,self:o?.self??null,system:o?.system},u=i.machine.implementations.delays;if("string"==typeof t)throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${t}" }) instead`);const d=$(t)?t(c):t;let h;if(k(a.delay)){const t=u&&u[a.delay];h=$(t)?t(c):t}else h=$(a.delay)?a.delay(c):a.delay;const p=$(a.to)?a.to(c):a.to;let l;if("string"==typeof p){if(l=p===n.Parent?o?.self._parent:p===n.Internal?o?.self:p.startsWith("#_")?i.children[p.slice(2)]:i.children[p],!l)throw new Error(`Unable to send event to actor '${p}' from machine '${i.machine.id}'.`)}else l=p||o?.self;const f={type:r,params:{...a,to:l,event:d,delay:h,internal:p===n.Internal},execute:t=>{const e=f;if("number"!=typeof e.params.delay){const n=e.params.to,s=e.params.event;t.defer((()=>{n.send(s.type===y?{type:`${ht(t.self.id)}`,data:s.data}:e.params.event)}))}else t.self.delaySend(e)}};return[i,f]}))}function P(t,e){return O(t,{...e,to:n.Parent})}const A=new WeakMap;const M="function"==typeof Symbol&&Symbol.observable||"@@observable";class D{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)}prepend(t){this._current?this._current={value:t,next:this._current}:this.enqueue(t)}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),t===this._current&&(this._current=this._current.next)}this._last=null}}function R(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const N=t=>{const e=R();e&&e.register(t)};let q=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const z={deferEvents:!0,clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class J{constructor(t,e){this.logic=t,this._state=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new D(this._process.bind(this)),this.delayedEventsMap={},this.observers=new Set,this.logger=void 0,this.status=q.NotStarted,this._parent=void 0,this.ref=void 0,this._actorContext=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={...z,...e},{clock:s,logger:o,parent:r,id:i,systemId:a}=n;this.system=r?.system??function(){let t=0;const e=new Map,n=new Map,s=new WeakMap;return{_bookId:()=>"x:"+t++,_register:(t,n)=>(e.set(t,n),t),_unregister:t=>{e.delete(t.sessionId);const o=s.get(t);void 0!==o&&(n.delete(o),s.delete(t))},get:t=>n.get(t),_set:(t,e)=>{const o=n.get(t);if(o&&o!==e)throw new Error(`Actor with system ID '${t}' already exists.`);n.set(t,e),s.set(e,t)}}}(),a&&(this._systemId=a,this.system._set(a,this)),this.sessionId=this.system._bookId(),this.id=i??this.sessionId,this.logger=o,this.clock=s,this._parent=r,this.options=n,this.src=n.src,this.ref=this,this._actorContext={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._initState()}_initState(){this._state=this.options.state?this.logic.restoreState?this.logic.restoreState(this.options.state,this._actorContext):this.options.state:this.logic.getInitialState(this._actorContext,this.options?.input)}update(t){this._state=t;const e=this.getSnapshot();let n;for(;n=this._deferred.shift();)n();for(const t of this.observers)t.next?.(e);const s=this.logic.getStatus?.(t);switch(s?.status){case"done":this._stopProcedure(),this._doneEvent=dt(this.id,s.data),this._parent?.send(this._doneEvent),this._complete();break;case"error":this._stopProcedure(),this._parent?.send(ht(this.id,s.data)),this._error(s.data)}}subscribe(t,e,n){const s=function(t,e,n){const s=()=>{},o="object"==typeof t,r=o?t:null;return{next:((o?t.next:t)||s).bind(r),error:((o?t.error:e)||s).bind(r),complete:((o?t.complete:n)||s).bind(r)}}(t,e,n);return this.observers.add(s),this.status===q.Stopped&&(s.complete?.(),this.observers.delete(s)),{unsubscribe:()=>{this.observers.delete(s)}}}start(){return this.status===q.Running||(this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this.status=q.Running,this.logic.start&&this.logic.start(this._state,this._actorContext),this.update(this._state),this.options.devTools&&this.attachDevTools(),this.mailbox.start()),this}_process(t){try{const e=this.logic.transition(this._state,t,this._actorContext);this.update(e),t.type===V&&(this._stopProcedure(),this._complete())}catch(t){if(!(this.observers.size>0))throw t;this.observers.forEach((e=>{e.error?.(t)})),this.stop()}}_stop(){return this.status===q.Stopped?this:(this.mailbox.clear(),this.status===q.NotStarted?(this.status=q.Stopped,this):(this.mailbox.enqueue({type:V}),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)t.complete?.();this.observers.clear()}_error(t){for(const e of this.observers)e.error?.(t);this.observers.clear()}_stopProcedure(){if(this.status!==q.Running)return this;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.mailbox.clear(),this.mailbox=new D(this._process.bind(this)),this.status=q.Stopped,this.system._unregister(this),this}send(t){if("string"==typeof t)throw new Error(`Only event objects may be sent to actors; use .send({ type: "${t}" }) instead`);if(this.status!==q.Stopped){if(this.status!==q.Running&&!this.options.deferEvents)throw new Error(`Event "${t.type}" was sent to uninitialized actor "${this.id}". Make sure .start() is called for this actor, or set { deferEvents: true } in the actor options.\nEvent: ${JSON.stringify(t)}`);this.mailbox.enqueue(t)}}delaySend(t){this.delayedEventsMap[t.params.id]=this.clock.setTimeout((()=>{"to"in t.params&&t.params.to?t.params.to.send(t.params.event):this.send(t.params.event)}),t.params.delay)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}attachDevTools(){const{devTools:t}=this.options;if(t){("function"==typeof t?t:N)(this)}}toJSON(){return{id:this.id}}getPersistedState(){return this.logic.getPersistedState?.(this._state)}[M](){return this}getSnapshot(){return this.logic.getSnapshot?this.logic.getSnapshot(this._state):this._state}}function Q(t,e){return new J(t,e)}const V="xstate.stop";function W(t){return T({type:p,params:t},((e,{state:n,actorContext:s})=>{const o=p,{id:r,src:i}=t;let a;if((c=i)&&"object"==typeof c&&"function"==typeof c.send)a={type:o,params:{...t,ref:i}};else{const c=C(n.machine.implementations.actors[i]);if(c){const u="input"in t?t.input:c.input,d=Q(c.src,{id:r,src:i,parent:s?.self,systemId:t.systemId,input:"function"==typeof u?u({context:n.context,event:e,self:s?.self}):u});a={type:o,params:{...t,ref:d}}}else a={type:o,params:t}}var c;const u=a.params.ref,d=ot(n,{children:{...n.children,[r]:u}});return a.execute=t=>{const e=t.self,{id:n,ref:s}=a.params;s&&t.defer((()=>{if(u.status!==q.Stopped)try{u.start?.()}catch(t){return void e.send(ht(n,t))}}))},[d,a]}))}function B(t,e,n,s){const{machine:o}=s,r=o?.implementations?.guards?.[t.type]??t.predicate;if(!r)throw new Error(`Guard '${t.type}' is not implemented.'.`);return r({context:e,event:n,state:s,guard:t,evaluate:B})}function L(t,e){if(k(t)){const n=e?.(t);return $(n)?{type:t,predicate:n,params:{type:t}}:n||{type:t,params:{type:t}}}if($(t))return{type:t.name,predicate:t,params:{type:t.name,name:t.name}};const n=e?.(t.type);return $(n)?{type:t.type,params:t.params||t,children:t.children?.map((t=>L(t,e))),predicate:e?.(t.type)||t.predicate}:n||{type:t.type,params:t.params||t,children:t.children?.map((t=>L(t,e))),predicate:t.predicate}}const U=t=>"atomic"===t.type||"final"===t.type;function G(t){return Object.values(t.states).filter((t=>"history"!==t.type))}function X(t,e){const n=[];let s=t.parent;for(;s&&s!==e;)n.push(s),s=s.parent;return n}function F(t){const e=new Set(t),n=new Set(t),s=K(n);for(const t of e)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const e of G(t))if("history"!==e.type&&!n.has(e))for(const t of tt(e))n.add(t)}else tt(t).forEach((t=>n.add(t)));for(const t of n){let e=t.parent;for(;e;)n.add(e),e=e.parent}return n}function H(t,e){const n=e.get(t);if(!n)return{};if("compound"===t.type){const t=n[0];if(!t)return{};if(U(t))return t.key}const s={};for(const t of n)s[t.key]=H(t,e);return s}function K(t){const e=new Map;for(const n of t)e.has(n)||e.set(n,[]),n.parent&&(e.has(n.parent)||e.set(n.parent,[]),e.get(n.parent).push(n));return e}function Y(t,e){return H(t,K(F(e)))}const Z=t=>"#"===t[0];function tt(t){const e=new Set;return function n(s){if(!e.has(s))if(e.add(s),"compound"===s.type)for(const o of s.initial.target){for(const n of X(o,t))e.add(n);n(o)}else if("parallel"===s.type)for(const t of G(s))n(t)}(t),[...e]}function et(t,e){if(Z(e))return t.machine.getStateNodeById(e);if(!t.states)throw new Error(`Unable to retrieve child state '${e}' from '${t.id}'; no child states exist.`);const n=t.states[e];if(!n)throw new Error(`Child state '${e}' does not exist on '${t.id}'`);return n}function nt(t,e){const n=e instanceof st?e.value:b(e);if(k(n))return[t,t.states[n]];const s=Object.keys(n),o=s.map((e=>et(t,e))).filter(Boolean);return[t.machine.root,t].concat(o,s.reduce(((e,s)=>{const o=et(t,s);if(!o)return e;const r=nt(o,n[s]);return e.concat(r)}),[]))}class st{static from(t,e={},n){if(t instanceof st)return t.context!==e?new st({value:t.value,context:e,meta:{},configuration:[],children:{}},n):t;const s=F(nt(n.root,t));return new st({value:t,context:e,meta:void 0,configuration:Array.from(s),children:{}},n)}constructor(t,e){this.machine=e,this.tags=void 0,this.value=void 0,this.done=void 0,this.output=void 0,this.context=void 0,this.historyValue={},this._internalQueue=void 0,this.configuration=void 0,this.children=void 0,this.context=t.context,this._internalQueue=t._internalQueue??[],this.historyValue=t.historyValue||{},this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration??Array.from(F(nt(e.root,t.value))),this.children=t.children,this.value=Y(e.root,this.configuration),this.tags=new Set(S(this.configuration.map((t=>t.tags)))),this.done=t.done??!1,this.output=t.output}toStrings(t=this.value){if(k(t))return[t];const e=Object.keys(t);return e.concat(...e.map((e=>this.toStrings(t[e]).map((t=>e+x+t)))))}toJSON(){const{configuration:t,tags:e,machine:n,...s}=this;return{...s,tags:Array.from(e),meta:this.meta}}matches(t){return _(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,n){let s=A.get(t);return s?e in s||(s[e]=n()):(s={[e]:n()},A.set(t,s)),s[e]}(this,"nextEvents",(()=>[...new Set(S([...this.configuration.map((t=>t.ownEvents))]))]))}get meta(){return this.configuration.reduce(((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t)),{})}}function ot(t,e={}){return new st({...t,...e},t.machine)}const rt=({context:t,event:e})=>({context:t,event:e});function it(t,e,n,s,o){return(r,i={})=>{const{systemId:a}=i;if(k(r)){const c=C(e.implementations.actors[r]);if(c){const e="input"in i?i.input:c.input,r=Q(c.src,{id:i.id,parent:t,input:"function"==typeof e?e({context:n,event:s,self:t}):e});return o.push(W({id:r.id,src:r,ref:r,meta:void 0,input:e,systemId:a})),r}throw new Error(`Actor logic '${r}' not implemented in machine '${e.id}'`)}{const e=Q(r,{id:i.id,parent:t,input:i.input,systemId:a});return o.push(W({src:e,ref:e,id:e.id,meta:void 0,input:i.input})),e}}}const at={type:h};function ct(t){if(j(t))return t;if("string"==typeof t)return{type:t,params:{}};if("function"==typeof t){const e="xstate.function";return T({type:e,params:{}},((n,{state:s})=>{const o={type:e,params:{function:t},execute:e=>t({context:s.context,event:n,action:o,self:e.self,system:e.system})};return[s,o]}))}return t}const ut=t=>{if(!t)return[];return(I(t)?t:[t]).map(ct)};function dt(t,n){const s=`${e.DoneInvoke}.${t}`,o={type:s,output:n,toString:()=>s};return o}function ht(t,n){const s=`${e.ErrorPlatform}.${t}`,o={type:s,data:n,toString:()=>s};return o}t.actionTypes=g,t.after=function(t,n){const s=n?`#${n}`:"";return`${e.After}(${t})${s}`},t.assign=function(t){return T({type:a,params:{assignment:t}},((e,{state:n,action:s,actorContext:o})=>{const r=[];if(!n.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const i={context:n.context,event:e,action:s,spawn:it(o?.self,n.machine,n.context,e,r),self:o?.self??{},system:o?.system};let c={};if($(t))c=t(i);else for(const e of Object.keys(t)){const n=t[e];c[e]=$(n)?n(i):n}const u=Object.assign({},n.context,c);return[ot(n,{context:u}),{type:a,params:{context:u,actions:r}}]}))},t.cancel=function(t){return T({type:i,params:{sendId:t}},((e,{state:n,actorContext:s})=>{const o=$(t)?t({context:n.context,event:e,self:s?.self??{},system:s?.system}):t;return[n,{type:"xstate.cancel",params:{sendId:o},execute:t=>{t.self.cancel(o)}}]}))},t.choose=function(t){return T({type:m,params:{guards:t}},((e,{state:n})=>{const s=t.find((t=>{const s=t.guard&&L(t.guard,(t=>n.machine.implementations.guards[t]));return!s||B(s,n.context,e,n)}))?.actions;return[n,{type:m,params:{actions:ut(s)}}]}))},t.createInitEvent=function(t){return{type:h,input:t}},t.done=function(t,n){const s=`${e.DoneState}.${t}`,o={type:s,output:n,toString:()=>s};return o},t.doneInvoke=dt,t.error=ht,t.escalate=function(t,e){return P((e=>({type:y,data:$(t)?t(e):t})),{...e,to:n.Parent})},t.forwardTo=function(t,e){return O((({event:t})=>t),{...e,to:t})},t.initEvent=at,t.log=function(t=rt,e){return T({type:d,params:{label:e,expr:t}},((n,{state:s,actorContext:o})=>{const r="function"==typeof t?t({context:s.context,event:n,self:o?.self??{},system:o?.system}):t;return[s,{type:"xstate.log",params:{label:e,value:r},execute:t=>{e?t.logger?.(e,r):t.logger?.(r)}}]}))},t.pure=function(t){return T({type:v,params:{get:t}},((e,{state:n})=>[n,{type:v,params:{actions:E(ut(t({context:n.context,event:e})))??[]}}]))},t.raise=function(t,e){return T({type:o,params:{delay:e?e.delay:void 0,event:t,id:e&&void 0!==e.id?e.id:"function"==typeof t?t.name:t.type}},((n,{state:s,actorContext:r})=>{const i={delay:e?e.delay:void 0,event:t,id:e&&void 0!==e.id?e.id:"function"==typeof t?t.name:t.type},a={context:s.context,event:n,self:r?.self??{},system:r?.system},c=s.machine.implementations.delays;if("string"==typeof t)throw new Error(`Only event objects may be used with raise; use raise({ type: "${t}" }) instead`);const u="function"==typeof t?t(a):t;let d;if("string"==typeof i.delay){const t=c&&c[i.delay];d="function"==typeof t?t(a):t}else d="function"==typeof i.delay?i.delay(a):i.delay;const h={type:o,params:{...i,event:u,delay:d},execute:t=>{"number"!=typeof h.params.delay||t.self.delaySend(h)}};return[s,h]}))},t.resolveActionObject=function(t,e){if(j(t))return t;const n=e[t.type];return"function"==typeof n?T({type:"xstate.function",params:t.params??{}},((e,{state:s})=>{const o={type:t.type,params:t.params,execute:t=>n({context:s.context,event:e,action:o,system:t.system,self:t.self})};return[s,o]})):n||t},t.send=O,t.sendParent=P,t.sendTo=function(t,e,n){return O(e,{...n,to:t})},t.stop=function(t){const e=t;return T({type:s,params:{actor:e}},((t,{state:n})=>{const s=$(e)?e({context:n.context,event:t}):e,o="string"==typeof s?n.children[s]:s;let r=n.children;return o&&(r={...r},delete r[o.id]),[ot(n,{children:r}),{type:"xstate.stop",params:{actor:o},execute:t=>{o&&(o.status===q.Running?t.defer((()=>{t.stopChild(o)})):t.stopChild(o))}}]}))},t.toActionObject=ct,t.toActionObjects=ut,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";let e=function(t){return t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t}({}),n=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});const s=e.After,i=e.DoneState,o=e.ErrorExecution,r=e.ErrorPlatform,a=e.ErrorCustom;var c=Object.freeze({__proto__:null,after:s,doneState:i,errorExecution:o,errorPlatform:r,error:a});const u=".";function h(t,e,s,{to:i,event:o,id:r,delay:a}){const c=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 u="function"==typeof o?o(s):o;let h;if("string"==typeof a){const t=c&&c[a];h="function"==typeof t?t(s):t}else h="function"==typeof a?a(s):a;const f="function"==typeof i?i(s):i;let d;if("string"==typeof f){if(d=f===n.Parent?t?.self._parent:f===n.Internal?t?.self:f.startsWith("#_")?e.children[f.slice(2)]:e.children[f],!d)throw new Error(`Unable to send event to actor '${f}' from machine '${e.machine.id}'.`)}else d=f||t?.self;return[e,{to:d,event:u,id:r,delay:h}]}function f(t,e){if("number"==typeof e.delay)return void t.self.delaySend(e);const{to:n,event:s}=e;t.defer((()=>{n.send(s.type===a?{type:`${it(t.self.id)}`,data:s.data}:s)}))}function d(t,e,n){function s(t){}return s.type="xstate.sendTo",s.to=t,s.event=e,s.id=n?.id,s.delay=n?.delay,s.resolve=h,s.execute=f,s}function l(t,e){return d(n.Parent,t,e)}const p=new WeakMap;function y(t,e,n,{sendId:s}){return[e,"function"==typeof s?s(n):s]}function v(t,e){t.self.cancel(e)}class m{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)}prepend(t){this._current?this._current={value:t,next:this._current}:this.enqueue(t)}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),t===this._current&&(this._current=this._current.next)}this._last=null}}const g="function"==typeof Symbol&&Symbol.observable||"@@observable";function _(t,e){const n=b(t),s=b(e);return"string"==typeof s?"string"==typeof n&&s===n:"string"==typeof n?n in s:Object.keys(n).every((t=>t in s&&_(n[t],s[t])))}function b(t){if("object"==typeof(e=t)&&"value"in e&&"context"in e&&"event"in e)return t.value;var e;if(E(t))return x(t);if("string"!=typeof t)return t;return x(function(t){try{return E(t)?t:t.toString().split(u)}catch(e){throw new Error(`'${t}' is not a valid state path.`)}}(t))}function x(t){if(1===t.length)return t[0];const e={};let n=e;for(let e=0;e<t.length-1;e++)if(e===t.length-2)n[t[e]]=t[e+1];else{const s=n;n={},s[t[e]]=n}return e}function w(t){return[].concat(...t)}function S(t){return void 0===t?[]:function(t){return E(t)?t:[t]}(t)}function E(t){return Array.isArray(t)}const $="xstate.stop";function I(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const k=t=>{const e=I();e&&e.register(t)};let T=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const j={deferEvents:!0,clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class O{constructor(t,e){this.logic=t,this._state=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new m(this._process.bind(this)),this.delayedEventsMap={},this.observers=new Set,this.logger=void 0,this.status=T.NotStarted,this._parent=void 0,this.ref=void 0,this._actorContext=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={...j,...e},{clock:s,logger:i,parent:o,id:r,systemId:a}=n;this.system=o?.system??function(){let t=0;const e=new Map,n=new Map,s=new WeakMap;return{_bookId:()=>"x:"+t++,_register:(t,n)=>(e.set(t,n),t),_unregister:t=>{e.delete(t.sessionId);const i=s.get(t);void 0!==i&&(n.delete(i),s.delete(t))},get:t=>n.get(t),_set:(t,e)=>{const i=n.get(t);if(i&&i!==e)throw new Error(`Actor with system ID '${t}' already exists.`);n.set(t,e),s.set(e,t)}}}(),a&&(this._systemId=a,this.system._set(a,this)),this.sessionId=this.system._bookId(),this.id=r??this.sessionId,this.logger=i,this.clock=s,this._parent=o,this.options=n,this.src=n.src,this.ref=this,this._actorContext={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._initState()}_initState(){this._state=this.options.state?this.logic.restoreState?this.logic.restoreState(this.options.state,this._actorContext):this.options.state:this.logic.getInitialState(this._actorContext,this.options?.input)}update(t){this._state=t;const e=this.getSnapshot();let n;for(;n=this._deferred.shift();)n();for(const t of this.observers)t.next?.(e);const s=this.logic.getStatus?.(t);switch(s?.status){case"done":this._stopProcedure(),this._doneEvent=st(this.id,s.data),this._parent?.send(this._doneEvent),this._complete();break;case"error":this._stopProcedure(),this._parent?.send(it(this.id,s.data)),this._error(s.data)}}subscribe(t,e,n){const s=function(t,e,n){const s=()=>{},i="object"==typeof t,o=i?t:null;return{next:((i?t.next:t)||s).bind(o),error:((i?t.error:e)||s).bind(o),complete:((i?t.complete:n)||s).bind(o)}}(t,e,n);return this.observers.add(s),this.status===T.Stopped&&(s.complete?.(),this.observers.delete(s)),{unsubscribe:()=>{this.observers.delete(s)}}}start(){return this.status===T.Running||(this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this.status=T.Running,this.logic.start&&this.logic.start(this._state,this._actorContext),this.update(this._state),this.options.devTools&&this.attachDevTools(),this.mailbox.start()),this}_process(t){try{const e=this.logic.transition(this._state,t,this._actorContext);this.update(e),t.type===$&&(this._stopProcedure(),this._complete())}catch(t){if(!(this.observers.size>0))throw t;this.observers.forEach((e=>{e.error?.(t)})),this.stop()}}_stop(){return this.status===T.Stopped?this:(this.mailbox.clear(),this.status===T.NotStarted?(this.status=T.Stopped,this):(this.mailbox.enqueue({type:$}),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)t.complete?.();this.observers.clear()}_error(t){for(const e of this.observers)e.error?.(t);this.observers.clear()}_stopProcedure(){if(this.status!==T.Running)return this;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.mailbox.clear(),this.mailbox=new m(this._process.bind(this)),this.status=T.Stopped,this.system._unregister(this),this}send(t){if("string"==typeof t)throw new Error(`Only event objects may be sent to actors; use .send({ type: "${t}" }) instead`);if(this.status!==T.Stopped){if(this.status!==T.Running&&!this.options.deferEvents)throw new Error(`Event "${t.type}" was sent to uninitialized actor "${this.id}". Make sure .start() is called for this actor, or set { deferEvents: true } in the actor options.\nEvent: ${JSON.stringify(t)}`);this.mailbox.enqueue(t)}}delaySend({event:t,id:e,delay:n,to:s}){const i=this.clock.setTimeout((()=>{s?s.send(t):this.send(t)}),n);e&&(this.delayedEventsMap[e]=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:k)(this)}}toJSON(){return{id:this.id}}getPersistedState(){return this.logic.getPersistedState?.(this._state)}[g](){return this}getSnapshot(){return this.logic.getSnapshot?this.logic.getSnapshot(this._state):this._state}}function P(t,e){return new O(t,e)}function C(t,e,n,s){const{machine:i}=s,o=i?.implementations?.guards?.[t.type]??t.predicate;if(!o)throw new Error(`Guard '${t.type}' is not implemented.'.`);return o({context:e,event:n,state:s,guard:t,evaluate:C})}function M(t,e){if("string"==typeof t){const n=e?.(t);return"function"==typeof n?{type:t,predicate:n,params:{type:t}}:n||{type:t,params:{type:t}}}if("function"==typeof t)return{type:t.name,predicate:t,params:{type:t.name,name:t.name}};const n=e?.(t.type);return"function"==typeof n?{type:t.type,params:t.params||t,children:t.children?.map((t=>M(t,e))),predicate:e?.(t.type)||t.predicate}:n||{type:t.type,params:t.params||t,children:t.children?.map((t=>M(t,e))),predicate:t.predicate}}const A=t=>"atomic"===t.type||"final"===t.type;function D(t){return Object.values(t.states).filter((t=>"history"!==t.type))}function R(t,e){const n=[];let s=t.parent;for(;s&&s!==e;)n.push(s),s=s.parent;return n}function N(t){const e=new Set(t),n=new Set(t),s=q(n);for(const t of e)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const e of D(t))if("history"!==e.type&&!n.has(e))for(const t of V(e))n.add(t)}else V(t).forEach((t=>n.add(t)));for(const t of n){let e=t.parent;for(;e;)n.add(e),e=e.parent}return n}function Q(t,e){const n=e.get(t);if(!n)return{};if("compound"===t.type){const t=n[0];if(!t)return{};if(A(t))return t.key}const s={};for(const t of n)s[t.key]=Q(t,e);return s}function q(t){const e=new Map;for(const n of t)e.has(n)||e.set(n,[]),n.parent&&(e.has(n.parent)||e.set(n.parent,[]),e.get(n.parent).push(n));return e}function z(t,e){return Q(t,q(N(e)))}const J=t=>"#"===t[0];function V(t){const e=new Set;return function n(s){if(!e.has(s))if(e.add(s),"compound"===s.type)for(const i of s.initial.target){for(const n of R(i,t))e.add(n);n(i)}else if("parallel"===s.type)for(const t of D(s))n(t)}(t),[...e]}function W(t,e){if(J(e))return t.machine.getStateNodeById(e);if(!t.states)throw new Error(`Unable to retrieve child state '${e}' from '${t.id}'; no child states exist.`);const n=t.states[e];if(!n)throw new Error(`Child state '${e}' does not exist on '${t.id}'`);return n}function B(t,e){const n=e instanceof U?e.value:b(e);if("string"==typeof n)return[t,t.states[n]];const s=Object.keys(n),i=s.map((e=>W(t,e))).filter(Boolean);return[t.machine.root,t].concat(i,s.reduce(((e,s)=>{const i=W(t,s);if(!i)return e;const o=B(i,n[s]);return e.concat(o)}),[]))}class U{static from(t,e={},n){if(t instanceof U)return t.context!==e?new U({value:t.value,context:e,meta:{},configuration:[],children:{}},n):t;const s=N(B(n.root,t));return new U({value:t,context:e,meta:void 0,configuration:Array.from(s),children:{}},n)}constructor(t,e){this.machine=e,this.tags=void 0,this.value=void 0,this.done=void 0,this.output=void 0,this.context=void 0,this.historyValue={},this._internalQueue=void 0,this.configuration=void 0,this.children=void 0,this.context=t.context,this._internalQueue=t._internalQueue??[],this.historyValue=t.historyValue||{},this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration??Array.from(N(B(e.root,t.value))),this.children=t.children,this.value=z(e.root,this.configuration),this.tags=new Set(w(this.configuration.map((t=>t.tags)))),this.done=t.done??!1,this.output=t.output}toStrings(t=this.value){if("string"==typeof t)return[t];const e=Object.keys(t);return e.concat(...e.map((e=>this.toStrings(t[e]).map((t=>e+u+t)))))}toJSON(){const{configuration:t,tags:e,machine:n,...s}=this;return{...s,tags:Array.from(e),meta:this.meta}}matches(t){return _(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,n){let s=p.get(t);return s?e in s||(s[e]=n()):(s={[e]:n()},p.set(t,s)),s[e]}(this,"nextEvents",(()=>[...new Set(w([...this.configuration.map((t=>t.ownEvents))]))]))}get meta(){return this.configuration.reduce(((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t)),{})}}function G(t,e={}){return new U({...t,...e},t.machine)}function X(t,e,n,{actorRef:s}){const i="function"==typeof s?s(n):s,o="string"==typeof i?e.children[i]:i;let r=e.children;return o&&(r={...r},delete r[o.id]),[G(e,{children:r}),o]}function F(t,e){e&&(e.status===T.Running?t.defer((()=>{t.stopChild(e)})):t.stopChild(e))}function H(t,e,n,{value:s,label:i}){return[e,{value:"function"==typeof s?s(n):s,label:i}]}function K({logger:t},{value:e,label:n}){n?t(n,e):t(e)}function L(t,{machine:e,context:n},s,i){return(o,r)=>{const a=((o,r={})=>{const{systemId:a}=r;if("string"==typeof o){const c=function(t){return t?"transition"in t?{src:t,input:void 0}:t:void 0}(e.implementations.actors[o]);if(!c)throw new Error(`Actor logic '${o}' not implemented in machine '${e.id}'`);const u="input"in r?r.input:c.input,h=P(c.src,{id:r.id,parent:t.self,input:"function"==typeof u?u({context:n,event:s,self:t.self}):u,systemId:a});return i[h.id]=h,h}return P(o,{id:r.id,parent:t.self,input:r.input,systemId:a})})(o,r);return i[a.id]=a,t.defer((()=>{if(a.status!==T.Stopped)try{a.start?.()}catch(e){return void t.self.send(it(a.id,e))}})),a}}function Y(t,e,n,{assignment:s}){if(!e.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const i={},o={context:e.context,event:n.event,action:n.action,spawn:L(t,e,n.event,i),self:t?.self,system:t?.system};let r={};if("function"==typeof s)r=s(o);else for(const t of Object.keys(s)){const e=s[t];r[t]="function"==typeof e?e(o):e}return[G(e,{context:Object.assign({},e.context,r),children:Object.keys(i).length?{...e.children,...i}:e.children})]}function Z(t,e,n,{event:s,id:i,delay:o}){const r=e.machine.implementations.delays;if("string"==typeof s)throw new Error(`Only event objects may be used with raise; use raise({ type: "${s}" }) instead`);const a="function"==typeof s?s(n):s;let c;if("string"==typeof o){const t=r&&r[o];c="function"==typeof t?t(n):t}else c="function"==typeof o?o(n):o;return["number"!=typeof c?G(e,{_internalQueue:e._internalQueue.concat(a)}):e,{event:a,id:i,delay:c}]}function tt(t,e){"number"!=typeof e.delay||t.self.delaySend(e)}function et(t,e,n,{branches:s}){const i=s.find((t=>{const s=t.guard&&M(t.guard,(t=>e.machine.implementations.guards[t]));return!s||C(s,e.context,n.event,e)}))?.actions;return[e,void 0,S(i)]}function nt(t,e,n,{get:s}){return[e,void 0,S(s({context:e.context,event:n.event}))]}function st(t,n){const s=`${e.DoneInvoke}.${t}`,i={type:s,output:n,toString:()=>s};return i}function it(t,n){const s=`${e.ErrorPlatform}.${t}`,i={type:s,data:n,toString:()=>s};return i}t.after=function(t,n){const s=n?`#${n}`:"";return`${e.After}(${t})${s}`},t.assign=function(t){function e(t){}return e.type="xstate.assign",e.assignment=t,e.resolve=Y,e},t.cancel=function(t){function e(t){}return e.type="xstate.cancel",e.sendId=t,e.resolve=y,e.execute=v,e},t.choose=function(t){function e(t){}return e.type="xstate.choose",e.branches=t,e.resolve=et,e},t.constantPrefixes=c,t.createInitEvent=function(t){return{type:"xstate.init",input:t}},t.done=function(t,n){const s=`${e.DoneState}.${t}`,i={type:s,output:n,toString:()=>s};return i},t.doneInvoke=st,t.error=it,t.escalate=function(t,e){return l((e=>({type:a,data:"function"==typeof t?t(e):t})),e)},t.forwardTo=function(t,e){return d(t,(({event:t})=>t),e)},t.log=function(t=(({context:t,event:e})=>({context:t,event:e})),e){function n(t){}return n.type="xstate.log",n.value=t,n.label=e,n.resolve=H,n.execute=K,n},t.pure=function(t){function e(t){}return e.type="xstate.pure",e.get=t,e.resolve=nt,e},t.raise=function(t,e){function n(t){}return n.type="xstate.raise",n.event=t,n.id=e?.id,n.delay=e?.delay,n.resolve=Z,n.execute=tt,n},t.sendParent=l,t.sendTo=d,t.stop=function(t){function e(t){}return e.type="xstate.stop",e.actorRef=t,e.resolve=X,e.execute=F,e},Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
2
2
|
//# sourceMappingURL=xstate-actions.umd.min.js.map
|