xstate 5.0.0-alpha.5 → 5.0.0-beta.7
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.dev.js +1 -1
- package/actions/dist/xstate-actions.cjs.prod.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.dev.js +1 -1
- package/actors/dist/xstate-actors.cjs.prod.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-96f799fc.cjs.dev.js → actions-0fcf4fd9.cjs.dev.js} +19 -16
- package/dist/{actions-2479953d.cjs.prod.js → actions-a1a641d3.cjs.prod.js} +19 -16
- package/dist/{actions-7678b87b.esm.js → actions-b334e916.esm.js} +19 -17
- package/dist/declarations/src/StateNode.d.ts +2 -2
- package/dist/declarations/src/actions.d.ts +4 -4
- package/dist/declarations/src/stateUtils.d.ts +6 -0
- package/dist/declarations/src/typegenTypes.d.ts +3 -3
- package/dist/declarations/src/types.d.ts +11 -11
- package/dist/xstate.cjs.dev.js +11 -9
- package/dist/xstate.cjs.prod.js +11 -9
- package/dist/xstate.esm.js +12 -10
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.dev.js +1 -1
- package/guards/dist/xstate-guards.cjs.prod.js +1 -1
- package/guards/dist/xstate-guards.esm.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@
|
|
|
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-0fcf4fd9.cjs.dev.js');
|
|
6
6
|
require('../../dist/index-ebaab3c9.cjs.dev.js');
|
|
7
7
|
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@
|
|
|
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-a1a641d3.cjs.prod.js');
|
|
6
6
|
require('../../dev/dist/xstate-dev.cjs.prod.js');
|
|
7
7
|
|
|
8
8
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { ay as actionTypes, a4 as after, a3 as assign, a1 as cancel, a9 as choose, z as createInitEvent, a5 as done, ac as doneInvoke, M as error, a8 as escalate, a7 as forwardTo, V as initEvent, a0 as log, X as raise, az as resolveActionObject, a6 as respond, Y as send, Z as sendParent, $ as sendTo, a2 as stop, aA as toActionObject, a as toActionObjects } from '../../dist/actions-b334e916.esm.js';
|
|
2
2
|
import '../../dist/index-50bd0aff.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";var e,n;!function(t){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"}(e||(e={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(n||(n={}));var r=e.Stop,i=e.Raise,o=e.Send,a=e.Cancel,s=e.Assign,u=e.After,c=e.DoneState,l=e.Log,f=e.Init,d=e.Invoke,v=e.ErrorExecution,h=e.ErrorPlatform,p=e.ErrorCustom,y=e.Choose,m=e.Pure,g=Object.freeze({__proto__:null,stop:r,raise:i,send:o,cancel:a,assign:s,after:u,doneState:c,log:l,init:f,invoke:d,errorExecution:v,errorPlatform:h,error:p,choose:y,pure:m});function b(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}function _(t,e,n){return(e=b(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function x(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function S(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?x(Object(n),!0).forEach((function(e){_(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):x(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function w(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function k(t,e){if(t){if("string"==typeof t)return w(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?w(t,e):void 0}}function E(t){return function(t){if(Array.isArray(t))return w(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||k(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function O(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=k(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,i=function(){};return{s:i,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){s=!0,o=t},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}function j(t){return(j="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function I(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:".",r=P(t,n),i=P(e,n);return M(i)?!!M(r)&&i===r:M(r)?r in i:Object.keys(r).every((function(t){return t in i&&I(r[t],i[t])}))}function P(t,e){return"object"===j(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:T(t)?C(t):"string"!=typeof t?t:C(function(t,e){try{return T(t)?t:t.toString().split(e)}catch(e){throw new Error("'".concat(t,"' is not a valid state path."))}}(t,e));var n}function C(t){if(1===t.length)return t[0];for(var e={},n=e,r=0;r<t.length-1;r++)r===t.length-2?n[t[r]]=t[r+1]:(n[t[r]]={},n=n[t[r]]);return e}function A(t){var e;return(e=[]).concat.apply(e,E(t))}function T(t){return Array.isArray(t)}function D(t){return"function"==typeof t}function M(t){return"string"==typeof t}function N(t,e){return function(t){return"$$type"in t&&"scxml"===t.$$type}(t)?t:S({name:t.type,data:t,$$type:"scxml",type:"external"},e)}function R(t){return t?"transition"in t?{src:t,input:void 0}:t:void 0}function $(t,e){return{type:t.type,params:t.params,resolve:e}}function q(t){return"object"===j(t)&&null!==t&&"resolve"in t}function z(t,e){return $({type:o,params:{to:e?e.to:void 0,delay:e?e.delay:void 0,event:t,id:e&&void 0!==e.id?e.id:D(t)?t.name:t.type}},(function(r,i){var a,s,u=i.actorContext,c=i.state,l={to:e?e.to:void 0,delay:e?e.delay:void 0,event:t,id:e&&void 0!==e.id?e.id:D(t)?t.name:t.type},f={context:c.context,event:r.data,_event:r,self:null!==(a=null==u?void 0:u.self)&&void 0!==a?a:null,system:null==u?void 0:u.system},d=c.machine.options.delays,v=N(D(t)?t(f):t);if(M(l.delay)){var h=d&&d[l.delay];s=D(h)?h(f):h}else s=D(l.delay)?l.delay(f):l.delay;var y,m=D(l.to)?l.to(f):l.to;if("string"==typeof m){if(!(y=m===n.Parent?null==u?void 0:u.self._parent:m===n.Internal?null==u?void 0:u.self:m.startsWith("#_")?c.children[m.slice(2)]:c.children[m]))throw new Error("Unable to send event to actor '".concat(m,"' from machine '").concat(c.machine.id,"'."))}else y=m||(null==u?void 0:u.self);var g={type:o,params:S(S({},l),{},{to:y,_event:v,event:v.data,delay:s,internal:m===n.Internal}),execute:function(t){var e=g;if("number"!=typeof e.params.delay){var n=e.params.to,r=e.params._event;t.defer((function(){var e=t.self,i=S(S({},r),{},{name:r.name===p?"".concat(St(e.id)):r.name,origin:e});n.send(i)}))}else t.self.delaySend(e)}};return[c,g]}))}function B(t,e){return z(t,S(S({},e),{},{to:n.Parent}))}function J(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function Q(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,b(r.key),r)}}function U(t,e,n){return e&&Q(t.prototype,e),n&&Q(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}var V=function(){function t(e){J(this,t),this._process=e,_(this,"_active",!1),_(this,"_current",null),_(this,"_last",null)}return U(t,[{key:"start",value:function(){this._active=!0,this.flush()}},{key:"clear",value:function(){this._current&&(this._current.next=null,this._last=this._current)}},{key:"prepend",value:function(t){this._current?this._current={value:t,next:this._current}:this.enqueue(t)}},{key:"enqueue",value:function(t){var 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()}},{key:"flush",value:function(){for(;this._current;){var t=this._current;this._process(t.value),t===this._current&&(this._current=this._current.next)}this._last=null}}]),t}(),W="function"==typeof Symbol&&Symbol.observable||"@@observable",L="xstate.stop";function G(){var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}var X,F=function(t){var e=G();e&&e.register(t)};!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(X||(X={}));var H={deferEvents:!0,clock:{setTimeout:function(t){function e(e,n){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}((function(t,e){return setTimeout(t,e)})),clearTimeout:function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}((function(t){return clearTimeout(t)}))},logger:console.log.bind(console),devTools:!1},K=function(){function t(e,n){var r,i=this;J(this,t),this.behavior=e,_(this,"_state",void 0),_(this,"clock",void 0),_(this,"options",void 0),_(this,"id",void 0),_(this,"mailbox",new V(this._process.bind(this))),_(this,"delayedEventsMap",{}),_(this,"observers",new Set),_(this,"logger",void 0),_(this,"status",X.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",[]);var o,a,s,u,c=S(S({},H),n),l=c.clock,f=c.logger,d=c.parent,v=c.id,h=c.systemId;this.system=null!==(r=null==d?void 0:d.system)&&void 0!==r?r:(o=0,a=new Map,s=new Map,u=new WeakMap,{_bookId:function(){return"x:".concat(o++)},_register:function(t,e){return a.set(t,e),t},_unregister:function(t){a.delete(t.sessionId);var e=u.get(t);void 0!==e&&(s.delete(e),u.delete(t))},get:function(t){return s.get(t)},_set:function(t,e){var n=s.get(t);if(n&&n!==e)throw new Error("Actor with system ID '".concat(t,"' already exists."));s.set(t,e),u.set(e,t)}}),h&&(this._systemId=h,this.system._set(h,this)),this.sessionId=this.system._bookId(),this.id=null!=v?v:this.sessionId,this.logger=f,this.clock=l,this._parent=d,this.options=c,this.src=c.src,this.ref=this,this._actorContext={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:function(t){i._deferred.push(t)},system:this.system,stopChild:function(t){if(t._parent!==i)throw new Error("Cannot stop child actor ".concat(t.id," of ").concat(i.id," because it is not a child"));t._stop()}},this.send=this.send.bind(this),this._initState()}return U(t,[{key:"_initState",value:function(){var t;this._state=this.options.state?this.behavior.restoreState?this.behavior.restoreState(this.options.state,this._actorContext):this.options.state:this.behavior.getInitialState(this._actorContext,null===(t=this.options)||void 0===t?void 0:t.input)}},{key:"update",value:function(t){var e,n,r,i;this._state=t;for(var o,a=this.getSnapshot();o=this._deferred.shift();)o(t);var s,u=O(this.observers);try{for(u.s();!(s=u.n()).done;){var c,l=s.value;null===(c=l.next)||void 0===c||c.call(l,a)}}catch(t){u.e(t)}finally{u.f()}var f=null===(e=(n=this.behavior).getStatus)||void 0===e?void 0:e.call(n,t);switch(null==f?void 0:f.status){case"done":this._doneEvent=xt(this.id,f.data),null===(r=this._parent)||void 0===r||r.send(N(this._doneEvent,{origin:this,invokeid:this.id})),this._stopProcedure();break;case"error":null===(i=this._parent)||void 0===i||i.send(N(St(this.id,f.data),{origin:this}));var d,v=O(this.observers);try{for(v.s();!(d=v.n()).done;){var h,p=d.value;null===(h=p.error)||void 0===h||h.call(p,f.data)}}catch(t){v.e(t)}finally{v.f()}}}},{key:"subscribe",value:function(t,e,n){var r,i=this,o=function(t,e,n){var r=function(){},i="object"===j(t),o=i?t:null;return{next:((i?t.next:t)||r).bind(o),error:((i?t.error:e)||r).bind(o),complete:((i?t.complete:n)||r).bind(o)}}(t,e,n);(this.observers.add(o),this.status===X.Stopped)&&(null===(r=o.complete)||void 0===r||r.call(o),this.observers.delete(o));return{unsubscribe:function(){i.observers.delete(o)}}}},{key:"onDone",value:function(t){var e=this;return this.status===X.Stopped&&this._doneEvent?t(this._doneEvent):this.observers.add({complete:function(){e._doneEvent&&t(e._doneEvent)}}),this}},{key:"start",value:function(){return this.status===X.Running||(this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this.status=X.Running,this.behavior.start&&this.behavior.start(this._state,this._actorContext),this.update(this._state),this.options.devTools&&this.attachDevTools(),this.mailbox.start()),this}},{key:"_process",value:function(t){try{var e=this.behavior.transition(this._state,t,this._actorContext);this.update(e),t.name===L&&this._stopProcedure()}catch(t){if(!(this.observers.size>0))throw t;this.observers.forEach((function(e){var n;null===(n=e.error)||void 0===n||n.call(e,t)})),this.stop()}}},{key:"_stop",value:function(){return this.status===X.Stopped?this:(this.mailbox.clear(),this.status===X.NotStarted?(this.status=X.Stopped,this):(this.mailbox.enqueue(N({type:L})),this))}},{key:"stop",value:function(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}},{key:"_complete",value:function(){var t,e=O(this.observers);try{for(e.s();!(t=e.n()).done;){var n,r=t.value;null===(n=r.complete)||void 0===n||n.call(r)}}catch(t){e.e(t)}finally{e.f()}this.observers.clear()}},{key:"_stopProcedure",value:function(){if(this._complete(),this.status!==X.Running)return this;for(var t=0,e=Object.keys(this.delayedEventsMap);t<e.length;t++){var n=e[t];this.clock.clearTimeout(this.delayedEventsMap[n])}return this.mailbox.clear(),this.mailbox=new V(this._process.bind(this)),this.status=X.Stopped,this.system._unregister(this),this}},{key:"send",value:function(t){var e=N(t);if(this.status!==X.Stopped){if(this.status!==X.Running&&!this.options.deferEvents)throw new Error('Event "'.concat(e.name,'" was sent to uninitialized actor "').concat(this.id,'". Make sure .start() is called for this actor, or set { deferEvents: true } in the actor options.\nEvent: ').concat(JSON.stringify(e.data)));this.mailbox.enqueue(e)}}},{key:"delaySend",value:function(t){var e=this;this.delayedEventsMap[t.params.id]=this.clock.setTimeout((function(){"to"in t.params&&t.params.to?t.params.to.send(t.params._event):e.send(t.params._event)}),t.params.delay)}},{key:"cancel",value:function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}},{key:"attachDevTools",value:function(){var t=this.options.devTools;t&&("function"==typeof t?t:F)(this)}},{key:"toJSON",value:function(){return{id:this.id}}},{key:"getPersistedState",value:function(){var t,e;return null===(t=(e=this.behavior).getPersistedState)||void 0===t?void 0:t.call(e,this._state)}},{key:W,value:function(){return this}},{key:"getSnapshot",value:function(){return this.behavior.getSnapshot?this.behavior.getSnapshot(this._state):this._state}}]),t}();function Y(t,e){return new K(t,e)}var Z=function(t){return{context:t.context,event:t.event}};function tt(t,e){if(null==t)return{};var n,r,i=function(t,e){if(null==t)return{};var n,r,i={},o=Object.keys(t);for(r=0;r<o.length;r++)n=o[r],e.indexOf(n)>=0||(i[n]=t[n]);return i}(t,e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);for(r=0;r<o.length;r++)n=o[r],e.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(t,n)&&(i[n]=t[n])}return i}var et=new WeakMap;function nt(t,e,n,r){var i,o,a,s=r.machine,u=null!==(i=null==s||null===(o=s.options)||void 0===o||null===(a=o.guards)||void 0===a?void 0:a[t.type])&&void 0!==i?i:t.predicate;if(!u)throw new Error("Guard '".concat(t.type,"' is not implemented.'."));return u({context:e,event:n.data,state:r,guard:t,_event:n,evaluate:nt})}function rt(t,e){var n;return M(t)?{type:t,predicate:(null==e?void 0:e(t))||void 0,params:{type:t}}:D(t)?{type:t.name,predicate:t,params:{type:t.name,name:t.name}}:{type:t.type,params:t.params||t,children:null===(n=t.children)||void 0===n?void 0:n.map((function(t){return rt(t,e)})),predicate:(null==e?void 0:e(t.type))||t.predicate}}function it(t){return Object.values(t.states).filter((function(t){return"history"!==t.type}))}function ot(t,e){for(var n=[],r=t.parent;r&&r!==e;)n.push(r),r=r.parent;return n}function at(t){var e,n=new Set(t),r=new Set(t),i=ut(r),o=O(n);try{for(o.s();!(e=o.n()).done;){var a=e.value;if("compound"!==a.type||i.get(a)&&i.get(a).length){if("parallel"===a.type){var s,u=O(it(a));try{for(u.s();!(s=u.n()).done;){var c=s.value;if("history"!==c.type&&!r.has(c))for(var l=0,f=lt(c);l<f.length;l++){var d=f[l];r.add(d)}}}catch(t){u.e(t)}finally{u.f()}}}else lt(a).forEach((function(t){return r.add(t)}))}}catch(t){o.e(t)}finally{o.f()}var v,h=O(r);try{for(h.s();!(v=h.n()).done;)for(var p=v.value.parent;p;)r.add(p),p=p.parent}catch(t){h.e(t)}finally{h.f()}return r}function st(t,e){var n,r=e.get(t);if(!r)return{};if("compound"===t.type){var i=r[0];if(!i)return{};if("atomic"===(n=i).type||"final"===n.type)return i.key}var o,a={},s=O(r);try{for(s.s();!(o=s.n()).done;){var u=o.value;a[u.key]=st(u,e)}}catch(t){s.e(t)}finally{s.f()}return a}function ut(t){var e,n=new Map,r=O(t);try{for(r.s();!(e=r.n()).done;){var i=e.value;n.has(i)||n.set(i,[]),i.parent&&(n.has(i.parent)||n.set(i.parent,[]),n.get(i.parent).push(i))}}catch(t){r.e(t)}finally{r.f()}return n}function ct(t,e){return st(t,ut(at(e)))}function lt(t){var e=new Set;return function n(r){if(!e.has(r))if(e.add(r),"compound"===r.type){var i,o=O(r.initial.target);try{for(o.s();!(i=o.n()).done;){var a,s=i.value,u=O(ot(s,t));try{for(u.s();!(a=u.n()).done;){var c=a.value;e.add(c)}}catch(t){u.e(t)}finally{u.f()}n(s)}}catch(t){o.e(t)}finally{o.f()}}else if("parallel"===r.type){var l,f=O(it(r));try{for(f.s();!(l=f.n()).done;){n(l.value)}}catch(t){f.e(t)}finally{f.f()}}}(t),E(e)}function ft(t,e){if("#"===e[0])return t.machine.getStateNodeById(e);if(!t.states)throw new Error("Unable to retrieve child state '".concat(e,"' from '").concat(t.id,"'; no child states exist."));var n=t.states[e];if(!n)throw new Error("Child state '".concat(e,"' does not exist on '").concat(t.id,"'"));return n}function dt(t,e){var n=e instanceof ht?e.value:P(e,t.machine.delimiter);if(M(n))return[t,t.states[n]];var r=Object.keys(n),i=r.map((function(e){return ft(t,e)})).filter(Boolean);return[t.machine.root,t].concat(i,r.reduce((function(e,r){var i=ft(t,r);if(!i)return e;var o=dt(i,n[r]);return e.concat(o)}),[]))}var vt=["configuration","transitions","tags","machine"],ht=function(){function t(e,n){var r,i,o,a;J(this,t),this.machine=n,_(this,"tags",void 0),_(this,"value",void 0),_(this,"done",void 0),_(this,"output",void 0),_(this,"context",void 0),_(this,"historyValue",{}),_(this,"actions",[]),_(this,"event",void 0),_(this,"_internalQueue",void 0),_(this,"_event",void 0),_(this,"_initial",!1),_(this,"changed",void 0),_(this,"configuration",void 0),_(this,"transitions",void 0),_(this,"children",void 0),this.context=e.context,this._event=e._event,this._internalQueue=null!==(r=e._internalQueue)&&void 0!==r?r:[],this.event=this._event.data,this.historyValue=e.historyValue||{},this.actions=null!==(i=e.actions)&&void 0!==i?i:[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=null!==(o=e.configuration)&&void 0!==o?o:Array.from(at(dt(n.root,e.value))),this.transitions=e.transitions,this.children=e.children,this.value=ct(n.root,this.configuration),this.tags=new Set(A(this.configuration.map((function(t){return t.tags})))),this.done=null!==(a=e.done)&&void 0!==a&&a,this.output=e.output}return U(t,[{key:"toStrings",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.value,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:".";if(M(e))return[e];var r=Object.keys(e);return r.concat.apply(r,E(r.map((function(r){return t.toStrings(e[r],n).map((function(t){return r+n+t}))}))))}},{key:"toJSON",value:function(){this.configuration,this.transitions;var t=this.tags;this.machine;return S(S({},tt(this,vt)),{},{tags:Array.from(t),meta:this.meta})}},{key:"matches",value:function(t){return I(t,this.value)}},{key:"hasTag",value:function(t){return this.tags.has(t)}},{key:"can",value:function(t){this.machine;var e=this.machine.getTransitionData(this,N(t));return!(null==e||!e.length)&&e.some((function(t){return void 0!==t.target||t.actions.length}))}},{key:"nextEvents",get:function(){var t,e,n,r,i=this;return t=this,e="nextEvents",n=function(){return E(new Set(A(E(i.configuration.map((function(t){return t.ownEvents}))))))},(r=et.get(t))?e in r||(r[e]=n()):(r=_({},e,n()),et.set(t,r)),r[e]}},{key:"meta",get:function(){return this.configuration.reduce((function(t,e){return void 0!==e.meta&&(t[e.id]=e.meta),t}),{})}}],[{key:"from",value:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2?arguments[2]:void 0;if(e instanceof t)return e.context!==n?new t({value:e.value,context:n,_event:e._event,actions:[],meta:{},configuration:[],transitions:[],children:{}},r):e;var i=wt({}),o=at(dt(r.root,e));return new t({value:e,context:n,_event:i,actions:[],meta:void 0,configuration:Array.from(o),transitions:[],children:{}},r)}}]),t}();function pt(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new ht(S(S({},t),e),t.machine)}function yt(t){return $({type:d,params:t},(function(e,n){var r,i,o=n.state,a=n.actorContext,s=d,u=t.id,c=t.src;if((i=c)&&"object"===j(i)&&"function"==typeof i.send)r={type:s,params:S(S({},t),{},{ref:c})};else{var l=R(o.machine.options.actors[c]);if(l){var f="input"in t?t.input:l.input,v=Y(l.src,{id:u,src:c,parent:null==a?void 0:a.self,systemId:t.systemId,input:"function"==typeof f?f({context:o.context,event:e.data,self:null==a?void 0:a.self}):f});r={type:s,params:S(S({},t),{},{ref:v})}}else r={type:s,params:t}}var h=r.params.ref,p=pt(o,{children:S(S({},o.children),{},_({},u,h))});return r.execute=function(t){var e=t.self,n=r.params,i=n.id;n.ref&&t.defer((function(){if(h.status!==X.Stopped)try{var t;null===(t=h.start)||void 0===t||t.call(h)}catch(t){return void e.send(St(i,t))}}))},[p,r]}))}function mt(t,e,n,r,i){return function(o){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(M(o)){var s=R(e.options.actors[o]);if(s){var u,c=null!==(u=a.id)&&void 0!==u?u:"anon",l="input"in a?a.input:s.input,f=Y(s.src,{id:c,parent:t,input:"function"==typeof l?l({context:n,event:r.data,self:t}):l});return i.push(yt({id:f.id,src:f,ref:f,meta:void 0,input:l})),f}throw new Error("Behavior '".concat(o,"' not implemented in machine '").concat(e.id,"'"))}var d=Y(o,{id:a.id||"anonymous",parent:t,input:a.input});return i.push(yt({src:d,ref:d,id:d.id,meta:void 0,input:a.input})),d}}var gt=N({type:f});function bt(t){if(q(t))return t;if("string"==typeof t)return{type:t,params:{}};if("function"==typeof t){var e="xstate.function";return $({type:e,params:{}},(function(n,r){var i=r.state,o={type:e,params:{function:t},execute:function(e){return t({context:i.context,event:n.data,action:o,_event:n,self:e.self,system:e.system})}};return[i,o]}))}return t}var _t=function(t){return t?(T(t)?t:[t]).map(bt):[]};function xt(t,n){var r="".concat(e.DoneInvoke,".").concat(t),i={type:r,data:n,toString:function(){return r}};return i}function St(t,n){var r="".concat(e.ErrorPlatform,".").concat(t),i={type:r,data:n,toString:function(){return r}};return i}function wt(t){return N({type:f,input:t})}t.actionTypes=g,t.after=function(t,n){var r=n?"#".concat(n):"";return"".concat(e.After,"(").concat(t,")").concat(r)},t.assign=function(t){return $({type:s,params:{assignment:t}},(function(e,n){var r,i=n.state,o=n.action,a=n.actorContext,u=[];if(!i.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");var c={context:i.context,event:e.data,action:o,_event:e,spawn:mt(null==a?void 0:a.self,i.machine,i.context,e,u),self:null!==(r=null==a?void 0:a.self)&&void 0!==r?r:{},system:null==a?void 0:a.system},l={};if(D(t))l=t(c);else for(var f=0,d=Object.keys(t);f<d.length;f++){var v=d[f],h=t[v];l[v]=D(h)?h(c):h}var p=Object.assign({},i.context,l);return[pt(i,{context:p}),{type:s,params:{context:p,actions:u}}]}))},t.cancel=function(t){return $({type:a,params:{sendId:t}},(function(e,n){var r,i=n.state,o=n.actorContext,a=D(t)?t({context:i.context,event:e.data,_event:e,self:null!==(r=null==o?void 0:o.self)&&void 0!==r?r:{},system:null==o?void 0:o.system}):t;return[i,{type:"xstate.cancel",params:{sendId:a},execute:function(t){t.self.cancel(a)}}]}))},t.choose=function(t){return $({type:y,params:{guards:t}},(function(e,n){var r,i=n.state,o=null===(r=t.find((function(t){var n=t.guard&&rt(t.guard,(function(t){return i.machine.options.guards[t]}));return!n||nt(n,i.context,e,i)})))||void 0===r?void 0:r.actions;return[i,{type:y,params:{actions:_t(o)}}]}))},t.createInitEvent=wt,t.done=function(t,n){var r="".concat(e.DoneState,".").concat(t),i={type:r,data:n,toString:function(){return r}};return i},t.doneInvoke=xt,t.error=St,t.escalate=function(t,e){return B((function(e){return{type:p,data:D(t)?t(e):t}}),S(S({},e),{},{to:n.Parent}))},t.forwardTo=function(t,e){if("production"!==process.env.NODE_END&&(!t||"function"==typeof t)){var n=t;t=function(){var t="function"==typeof n?n.apply(void 0,arguments):n;if(!t)throw new Error("Attempted to forward event to undefined actor. This risks an infinite loop in the sender.");return t}}return z((function(t){return t.event}),S(S({},e),{},{to:t}))},t.initEvent=gt,t.log=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Z,e=arguments.length>1?arguments[1]:void 0;return $({type:l,params:{label:e,expr:t}},(function(n,r){var i,o=r.state,a=r.actorContext,s="function"==typeof t?t({context:o.context,event:n.data,_event:n,self:null!==(i=null==a?void 0:a.self)&&void 0!==i?i:{},system:null==a?void 0:a.system}):t;return[o,{type:"xstate.log",params:{label:e,value:s},execute:function(t){var n,r;e?null===(n=t.logger)||void 0===n||n.call(t,e,s):null===(r=t.logger)||void 0===r||r.call(t,s)}}]}))},t.raise=function(t,e){return $({type:i,params:{delay:e?e.delay:void 0,event:t,id:e&&void 0!==e.id?e.id:"function"==typeof t?t.name:t.type}},(function(n,r){var o,a,s=r.state,u=r.actorContext,c={delay:e?e.delay:void 0,event:t,id:e&&void 0!==e.id?e.id:"function"==typeof t?t.name:t.type},l={context:s.context,event:n.data,_event:n,self:null!==(o=null==u?void 0:u.self)&&void 0!==o?o:{},system:null==u?void 0:u.system},f=s.machine.options.delays,d=N("function"==typeof t?t(l):t);if("string"==typeof c.delay){var v=f&&f[c.delay];a="function"==typeof v?v(l):v}else a="function"==typeof c.delay?c.delay(l):c.delay;var h={type:i,params:S(S({},c),{},{_event:d,event:d.data,delay:a}),execute:function(t){"number"!=typeof h.params.delay||t.self.delaySend(h)}};return[s,h]}))},t.resolveActionObject=function(t,e){if(q(t))return t;var n,r=e[t.type];return"function"==typeof r?$({type:"xstate.function",params:null!==(n=t.params)&&void 0!==n?n:{}},(function(e,n){var i=n.state,o={type:t.type,params:t.params,execute:function(t){return r({context:i.context,event:i.event,action:o,_event:i._event,system:t.system,self:t.self})}};return[i,o]})):r||t},t.respond=function(t,e){return z(t,S(S({},e),{},{to:function(t){return t._event.origin}}))},t.send=z,t.sendParent=B,t.sendTo=function(t,e,n){return z(e,S(S({},n),{},{to:t}))},t.stop=function(t){var e=t;return $({type:r,params:{actor:e}},(function(t,n){var r=n.state,i=D(e)?e({context:r.context,event:t.data}):e,o="string"==typeof i?r.children[i]:i;return[r,{type:"xstate.stop",params:{actor:o},execute:function(t){o&&(o.status===X.Running?t.defer((function(){t.stopChild(o)})):t.stopChild(o))}}]}))},t.toActionObject=bt,t.toActionObjects=_t,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";var e,n;!function(t){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"}(e||(e={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(n||(n={}));var r=e.Stop,i=e.Raise,o=e.Send,a=e.Cancel,s=e.Assign,u=e.After,c=e.DoneState,l=e.Log,f=e.Init,d=e.Invoke,v=e.ErrorExecution,h=e.ErrorPlatform,p=e.ErrorCustom,y=e.Choose,m=e.Pure,g=Object.freeze({__proto__:null,stop:r,raise:i,send:o,cancel:a,assign:s,after:u,doneState:c,log:l,init:f,invoke:d,errorExecution:v,errorPlatform:h,error:p,choose:y,pure:m});function b(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}function _(t,e,n){return(e=b(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function x(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function S(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?x(Object(n),!0).forEach((function(e){_(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):x(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function w(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function k(t,e){if(t){if("string"==typeof t)return w(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?w(t,e):void 0}}function E(t){return function(t){if(Array.isArray(t))return w(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||k(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function O(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=k(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,i=function(){};return{s:i,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){s=!0,o=t},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}function j(t){return(j="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function I(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:".",r=P(t,n),i=P(e,n);return M(i)?!!M(r)&&i===r:M(r)?r in i:Object.keys(r).every((function(t){return t in i&&I(r[t],i[t])}))}function P(t,e){return"object"===j(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:T(t)?C(t):"string"!=typeof t?t:C(function(t,e){try{return T(t)?t:t.toString().split(e)}catch(e){throw new Error("'".concat(t,"' is not a valid state path."))}}(t,e));var n}function C(t){if(1===t.length)return t[0];for(var e={},n=e,r=0;r<t.length-1;r++)r===t.length-2?n[t[r]]=t[r+1]:(n[t[r]]={},n=n[t[r]]);return e}function A(t){var e;return(e=[]).concat.apply(e,E(t))}function T(t){return Array.isArray(t)}function D(t){return"function"==typeof t}function M(t){return"string"==typeof t}function N(t,e){return function(t){return"$$type"in t&&"scxml"===t.$$type}(t)?t:S({name:t.type,data:t,$$type:"scxml",type:"external"},e)}function R(t){return t?"transition"in t?{src:t,input:void 0}:t:void 0}function $(t,e){return{type:t.type,params:t.params,resolve:e}}function q(t){return"object"===j(t)&&null!==t&&"resolve"in t}function z(t,e){return $({type:o,params:{to:e?e.to:void 0,delay:e?e.delay:void 0,event:t,id:e&&void 0!==e.id?e.id:D(t)?t.name:t.type}},(function(r,i){var a,s,u=i.actorContext,c=i.state,l={to:e?e.to:void 0,delay:e?e.delay:void 0,event:t,id:e&&void 0!==e.id?e.id:D(t)?t.name:t.type},f={context:c.context,event:r.data,_event:r,self:null!==(a=null==u?void 0:u.self)&&void 0!==a?a:null,system:null==u?void 0:u.system},d=c.machine.options.delays,v=N(D(t)?t(f):t);if(M(l.delay)){var h=d&&d[l.delay];s=D(h)?h(f):h}else s=D(l.delay)?l.delay(f):l.delay;var y,m=D(l.to)?l.to(f):l.to;if("string"==typeof m){if(!(y=m===n.Parent?null==u?void 0:u.self._parent:m===n.Internal?null==u?void 0:u.self:m.startsWith("#_")?c.children[m.slice(2)]:c.children[m]))throw new Error("Unable to send event to actor '".concat(m,"' from machine '").concat(c.machine.id,"'."))}else y=m||(null==u?void 0:u.self);var g={type:o,params:S(S({},l),{},{to:y,_event:v,event:v.data,delay:s,internal:m===n.Internal}),execute:function(t){var e=g;if("number"!=typeof e.params.delay){var n=e.params.to,r=e.params._event;t.defer((function(){var e=t.self,i=S(S({},r),{},{name:r.name===p?"".concat(St(e.id)):r.name,origin:e});n.send(i)}))}else t.self.delaySend(e)}};return[c,g]}))}function B(t,e){return z(t,S(S({},e),{},{to:n.Parent}))}function J(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function Q(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,b(r.key),r)}}function U(t,e,n){return e&&Q(t.prototype,e),n&&Q(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}var V=function(){function t(e){J(this,t),this._process=e,_(this,"_active",!1),_(this,"_current",null),_(this,"_last",null)}return U(t,[{key:"start",value:function(){this._active=!0,this.flush()}},{key:"clear",value:function(){this._current&&(this._current.next=null,this._last=this._current)}},{key:"prepend",value:function(t){this._current?this._current={value:t,next:this._current}:this.enqueue(t)}},{key:"enqueue",value:function(t){var 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()}},{key:"flush",value:function(){for(;this._current;){var t=this._current;this._process(t.value),t===this._current&&(this._current=this._current.next)}this._last=null}}]),t}(),W="function"==typeof Symbol&&Symbol.observable||"@@observable",L="xstate.stop";function G(){var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}var X,F=function(t){var e=G();e&&e.register(t)};!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(X||(X={}));var H={deferEvents:!0,clock:{setTimeout:function(t){function e(e,n){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}((function(t,e){return setTimeout(t,e)})),clearTimeout:function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}((function(t){return clearTimeout(t)}))},logger:console.log.bind(console),devTools:!1},K=function(){function t(e,n){var r,i=this;J(this,t),this.behavior=e,_(this,"_state",void 0),_(this,"clock",void 0),_(this,"options",void 0),_(this,"id",void 0),_(this,"mailbox",new V(this._process.bind(this))),_(this,"delayedEventsMap",{}),_(this,"observers",new Set),_(this,"logger",void 0),_(this,"status",X.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",[]);var o,a,s,u,c=S(S({},H),n),l=c.clock,f=c.logger,d=c.parent,v=c.id,h=c.systemId;this.system=null!==(r=null==d?void 0:d.system)&&void 0!==r?r:(o=0,a=new Map,s=new Map,u=new WeakMap,{_bookId:function(){return"x:".concat(o++)},_register:function(t,e){return a.set(t,e),t},_unregister:function(t){a.delete(t.sessionId);var e=u.get(t);void 0!==e&&(s.delete(e),u.delete(t))},get:function(t){return s.get(t)},_set:function(t,e){var n=s.get(t);if(n&&n!==e)throw new Error("Actor with system ID '".concat(t,"' already exists."));s.set(t,e),u.set(e,t)}}),h&&(this._systemId=h,this.system._set(h,this)),this.sessionId=this.system._bookId(),this.id=null!=v?v:this.sessionId,this.logger=f,this.clock=l,this._parent=d,this.options=c,this.src=c.src,this.ref=this,this._actorContext={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:function(t){i._deferred.push(t)},system:this.system,stopChild:function(t){if(t._parent!==i)throw new Error("Cannot stop child actor ".concat(t.id," of ").concat(i.id," because it is not a child"));t._stop()}},this.send=this.send.bind(this),this._initState()}return U(t,[{key:"_initState",value:function(){var t;this._state=this.options.state?this.behavior.restoreState?this.behavior.restoreState(this.options.state,this._actorContext):this.options.state:this.behavior.getInitialState(this._actorContext,null===(t=this.options)||void 0===t?void 0:t.input)}},{key:"update",value:function(t){var e,n,r,i;this._state=t;for(var o,a=this.getSnapshot();o=this._deferred.shift();)o(t);var s,u=O(this.observers);try{for(u.s();!(s=u.n()).done;){var c,l=s.value;null===(c=l.next)||void 0===c||c.call(l,a)}}catch(t){u.e(t)}finally{u.f()}var f=null===(e=(n=this.behavior).getStatus)||void 0===e?void 0:e.call(n,t);switch(null==f?void 0:f.status){case"done":this._doneEvent=xt(this.id,f.data),null===(r=this._parent)||void 0===r||r.send(N(this._doneEvent,{origin:this,invokeid:this.id})),this._stopProcedure();break;case"error":null===(i=this._parent)||void 0===i||i.send(N(St(this.id,f.data),{origin:this}));var d,v=O(this.observers);try{for(v.s();!(d=v.n()).done;){var h,p=d.value;null===(h=p.error)||void 0===h||h.call(p,f.data)}}catch(t){v.e(t)}finally{v.f()}}}},{key:"subscribe",value:function(t,e,n){var r,i=this,o=function(t,e,n){var r=function(){},i="object"===j(t),o=i?t:null;return{next:((i?t.next:t)||r).bind(o),error:((i?t.error:e)||r).bind(o),complete:((i?t.complete:n)||r).bind(o)}}(t,e,n);(this.observers.add(o),this.status===X.Stopped)&&(null===(r=o.complete)||void 0===r||r.call(o),this.observers.delete(o));return{unsubscribe:function(){i.observers.delete(o)}}}},{key:"onDone",value:function(t){var e=this;return this.status===X.Stopped&&this._doneEvent?t(this._doneEvent):this.observers.add({complete:function(){e._doneEvent&&t(e._doneEvent)}}),this}},{key:"start",value:function(){return this.status===X.Running||(this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this.status=X.Running,this.behavior.start&&this.behavior.start(this._state,this._actorContext),this.update(this._state),this.options.devTools&&this.attachDevTools(),this.mailbox.start()),this}},{key:"_process",value:function(t){try{var e=this.behavior.transition(this._state,t,this._actorContext);this.update(e),t.name===L&&this._stopProcedure()}catch(t){if(!(this.observers.size>0))throw t;this.observers.forEach((function(e){var n;null===(n=e.error)||void 0===n||n.call(e,t)})),this.stop()}}},{key:"_stop",value:function(){return this.status===X.Stopped?this:(this.mailbox.clear(),this.status===X.NotStarted?(this.status=X.Stopped,this):(this.mailbox.enqueue(N({type:L})),this))}},{key:"stop",value:function(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}},{key:"_complete",value:function(){var t,e=O(this.observers);try{for(e.s();!(t=e.n()).done;){var n,r=t.value;null===(n=r.complete)||void 0===n||n.call(r)}}catch(t){e.e(t)}finally{e.f()}this.observers.clear()}},{key:"_stopProcedure",value:function(){if(this._complete(),this.status!==X.Running)return this;for(var t=0,e=Object.keys(this.delayedEventsMap);t<e.length;t++){var n=e[t];this.clock.clearTimeout(this.delayedEventsMap[n])}return this.mailbox.clear(),this.mailbox=new V(this._process.bind(this)),this.status=X.Stopped,this.system._unregister(this),this}},{key:"send",value:function(t){var e=N(t);if(this.status!==X.Stopped){if(this.status!==X.Running&&!this.options.deferEvents)throw new Error('Event "'.concat(e.name,'" was sent to uninitialized actor "').concat(this.id,'". Make sure .start() is called for this actor, or set { deferEvents: true } in the actor options.\nEvent: ').concat(JSON.stringify(e.data)));this.mailbox.enqueue(e)}}},{key:"delaySend",value:function(t){var e=this;this.delayedEventsMap[t.params.id]=this.clock.setTimeout((function(){"to"in t.params&&t.params.to?t.params.to.send(t.params._event):e.send(t.params._event)}),t.params.delay)}},{key:"cancel",value:function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}},{key:"attachDevTools",value:function(){var t=this.options.devTools;t&&("function"==typeof t?t:F)(this)}},{key:"toJSON",value:function(){return{id:this.id}}},{key:"getPersistedState",value:function(){var t,e;return null===(t=(e=this.behavior).getPersistedState)||void 0===t?void 0:t.call(e,this._state)}},{key:W,value:function(){return this}},{key:"getSnapshot",value:function(){return this.behavior.getSnapshot?this.behavior.getSnapshot(this._state):this._state}}]),t}();function Y(t,e){return new K(t,e)}var Z=function(t){return{context:t.context,event:t.event}};function tt(t,e){if(null==t)return{};var n,r,i=function(t,e){if(null==t)return{};var n,r,i={},o=Object.keys(t);for(r=0;r<o.length;r++)n=o[r],e.indexOf(n)>=0||(i[n]=t[n]);return i}(t,e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);for(r=0;r<o.length;r++)n=o[r],e.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(t,n)&&(i[n]=t[n])}return i}var et=new WeakMap;function nt(t,e,n,r){var i,o,a,s=r.machine,u=null!==(i=null==s||null===(o=s.options)||void 0===o||null===(a=o.guards)||void 0===a?void 0:a[t.type])&&void 0!==i?i:t.predicate;if(!u)throw new Error("Guard '".concat(t.type,"' is not implemented.'."));return u({context:e,event:n.data,state:r,guard:t,_event:n,evaluate:nt})}function rt(t,e){var n;return M(t)?{type:t,predicate:(null==e?void 0:e(t))||void 0,params:{type:t}}:D(t)?{type:t.name,predicate:t,params:{type:t.name,name:t.name}}:{type:t.type,params:t.params||t,children:null===(n=t.children)||void 0===n?void 0:n.map((function(t){return rt(t,e)})),predicate:(null==e?void 0:e(t.type))||t.predicate}}function it(t){return Object.values(t.states).filter((function(t){return"history"!==t.type}))}function ot(t,e){for(var n=[],r=t.parent;r&&r!==e;)n.push(r),r=r.parent;return n}function at(t){var e,n=new Set(t),r=new Set(t),i=ut(r),o=O(n);try{for(o.s();!(e=o.n()).done;){var a=e.value;if("compound"!==a.type||i.get(a)&&i.get(a).length){if("parallel"===a.type){var s,u=O(it(a));try{for(u.s();!(s=u.n()).done;){var c=s.value;if("history"!==c.type&&!r.has(c))for(var l=0,f=lt(c);l<f.length;l++){var d=f[l];r.add(d)}}}catch(t){u.e(t)}finally{u.f()}}}else lt(a).forEach((function(t){return r.add(t)}))}}catch(t){o.e(t)}finally{o.f()}var v,h=O(r);try{for(h.s();!(v=h.n()).done;)for(var p=v.value.parent;p;)r.add(p),p=p.parent}catch(t){h.e(t)}finally{h.f()}return r}function st(t,e){var n,r=e.get(t);if(!r)return{};if("compound"===t.type){var i=r[0];if(!i)return{};if("atomic"===(n=i).type||"final"===n.type)return i.key}var o,a={},s=O(r);try{for(s.s();!(o=s.n()).done;){var u=o.value;a[u.key]=st(u,e)}}catch(t){s.e(t)}finally{s.f()}return a}function ut(t){var e,n=new Map,r=O(t);try{for(r.s();!(e=r.n()).done;){var i=e.value;n.has(i)||n.set(i,[]),i.parent&&(n.has(i.parent)||n.set(i.parent,[]),n.get(i.parent).push(i))}}catch(t){r.e(t)}finally{r.f()}return n}function ct(t,e){return st(t,ut(at(e)))}function lt(t){var e=new Set;return function n(r){if(!e.has(r))if(e.add(r),"compound"===r.type){var i,o=O(r.initial.target);try{for(o.s();!(i=o.n()).done;){var a,s=i.value,u=O(ot(s,t));try{for(u.s();!(a=u.n()).done;){var c=a.value;e.add(c)}}catch(t){u.e(t)}finally{u.f()}n(s)}}catch(t){o.e(t)}finally{o.f()}}else if("parallel"===r.type){var l,f=O(it(r));try{for(f.s();!(l=f.n()).done;){n(l.value)}}catch(t){f.e(t)}finally{f.f()}}}(t),E(e)}function ft(t,e){if("#"===e[0])return t.machine.getStateNodeById(e);if(!t.states)throw new Error("Unable to retrieve child state '".concat(e,"' from '").concat(t.id,"'; no child states exist."));var n=t.states[e];if(!n)throw new Error("Child state '".concat(e,"' does not exist on '").concat(t.id,"'"));return n}function dt(t,e){var n=e instanceof ht?e.value:P(e,t.machine.delimiter);if(M(n))return[t,t.states[n]];var r=Object.keys(n),i=r.map((function(e){return ft(t,e)})).filter(Boolean);return[t.machine.root,t].concat(i,r.reduce((function(e,r){var i=ft(t,r);if(!i)return e;var o=dt(i,n[r]);return e.concat(o)}),[]))}var vt=["configuration","transitions","tags","machine"],ht=function(){function t(e,n){var r,i,o,a;J(this,t),this.machine=n,_(this,"tags",void 0),_(this,"value",void 0),_(this,"done",void 0),_(this,"output",void 0),_(this,"context",void 0),_(this,"historyValue",{}),_(this,"actions",[]),_(this,"event",void 0),_(this,"_internalQueue",void 0),_(this,"_event",void 0),_(this,"_initial",!1),_(this,"changed",void 0),_(this,"configuration",void 0),_(this,"transitions",void 0),_(this,"children",void 0),this.context=e.context,this._event=e._event,this._internalQueue=null!==(r=e._internalQueue)&&void 0!==r?r:[],this.event=this._event.data,this.historyValue=e.historyValue||{},this.actions=null!==(i=e.actions)&&void 0!==i?i:[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=null!==(o=e.configuration)&&void 0!==o?o:Array.from(at(dt(n.root,e.value))),this.transitions=e.transitions,this.children=e.children,this.value=ct(n.root,this.configuration),this.tags=new Set(A(this.configuration.map((function(t){return t.tags})))),this.done=null!==(a=e.done)&&void 0!==a&&a,this.output=e.output}return U(t,[{key:"toStrings",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.value,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:".";if(M(e))return[e];var r=Object.keys(e);return r.concat.apply(r,E(r.map((function(r){return t.toStrings(e[r],n).map((function(t){return r+n+t}))}))))}},{key:"toJSON",value:function(){this.configuration,this.transitions;var t=this.tags;this.machine;return S(S({},tt(this,vt)),{},{tags:Array.from(t),meta:this.meta})}},{key:"matches",value:function(t){return I(t,this.value)}},{key:"hasTag",value:function(t){return this.tags.has(t)}},{key:"can",value:function(t){this.machine;var e=this.machine.getTransitionData(this,N(t));return!(null==e||!e.length)&&e.some((function(t){return void 0!==t.target||t.actions.length}))}},{key:"nextEvents",get:function(){var t,e,n,r,i=this;return t=this,e="nextEvents",n=function(){return E(new Set(A(E(i.configuration.map((function(t){return t.ownEvents}))))))},(r=et.get(t))?e in r||(r[e]=n()):(r=_({},e,n()),et.set(t,r)),r[e]}},{key:"meta",get:function(){return this.configuration.reduce((function(t,e){return void 0!==e.meta&&(t[e.id]=e.meta),t}),{})}}],[{key:"from",value:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2?arguments[2]:void 0;if(e instanceof t)return e.context!==n?new t({value:e.value,context:n,_event:e._event,actions:[],meta:{},configuration:[],transitions:[],children:{}},r):e;var i=wt({}),o=at(dt(r.root,e));return new t({value:e,context:n,_event:i,actions:[],meta:void 0,configuration:Array.from(o),transitions:[],children:{}},r)}}]),t}();function pt(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new ht(S(S({},t),e),t.machine)}function yt(t){return $({type:d,params:t},(function(e,n){var r,i,o=n.state,a=n.actorContext,s=d,u=t.id,c=t.src;if((i=c)&&"object"===j(i)&&"function"==typeof i.send)r={type:s,params:S(S({},t),{},{ref:c})};else{var l=R(o.machine.options.actors[c]);if(l){var f="input"in t?t.input:l.input,v=Y(l.src,{id:u,src:c,parent:null==a?void 0:a.self,systemId:t.systemId,input:"function"==typeof f?f({context:o.context,event:e.data,self:null==a?void 0:a.self}):f});r={type:s,params:S(S({},t),{},{ref:v})}}else r={type:s,params:t}}var h=r.params.ref,p=pt(o,{children:S(S({},o.children),{},_({},u,h))});return r.execute=function(t){var e=t.self,n=r.params,i=n.id;n.ref&&t.defer((function(){if(h.status!==X.Stopped)try{var t;null===(t=h.start)||void 0===t||t.call(h)}catch(t){return void e.send(St(i,t))}}))},[p,r]}))}function mt(t,e,n,r,i){return function(o){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(M(o)){var s=R(e.options.actors[o]);if(s){var u,c=null!==(u=a.id)&&void 0!==u?u:"anon",l="input"in a?a.input:s.input,f=Y(s.src,{id:c,parent:t,input:"function"==typeof l?l({context:n,event:r.data,self:t}):l});return i.push(yt({id:f.id,src:f,ref:f,meta:void 0,input:l})),f}throw new Error("Behavior '".concat(o,"' not implemented in machine '").concat(e.id,"'"))}var d=Y(o,{id:a.id||"anonymous",parent:t,input:a.input});return i.push(yt({src:d,ref:d,id:d.id,meta:void 0,input:a.input})),d}}var gt=N({type:f});function bt(t){if(q(t))return t;if("string"==typeof t)return{type:t,params:{}};if("function"==typeof t){var e="xstate.function";return $({type:e,params:{}},(function(n,r){var i=r.state,o={type:e,params:{function:t},execute:function(e){return t({context:i.context,event:n.data,action:o,_event:n,self:e.self,system:e.system})}};return[i,o]}))}return t}var _t=function(t){return t?(T(t)?t:[t]).map(bt):[]};function xt(t,n){var r="".concat(e.DoneInvoke,".").concat(t),i={type:r,output:n,toString:function(){return r}};return i}function St(t,n){var r="".concat(e.ErrorPlatform,".").concat(t),i={type:r,data:n,toString:function(){return r}};return i}function wt(t){return N({type:f,input:t})}t.actionTypes=g,t.after=function(t,n){var r=n?"#".concat(n):"";return"".concat(e.After,"(").concat(t,")").concat(r)},t.assign=function(t){return $({type:s,params:{assignment:t}},(function(e,n){var r,i=n.state,o=n.action,a=n.actorContext,u=[];if(!i.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");var c={context:i.context,event:e.data,action:o,_event:e,spawn:mt(null==a?void 0:a.self,i.machine,i.context,e,u),self:null!==(r=null==a?void 0:a.self)&&void 0!==r?r:{},system:null==a?void 0:a.system},l={};if(D(t))l=t(c);else for(var f=0,d=Object.keys(t);f<d.length;f++){var v=d[f],h=t[v];l[v]=D(h)?h(c):h}var p=Object.assign({},i.context,l);return[pt(i,{context:p}),{type:s,params:{context:p,actions:u}}]}))},t.cancel=function(t){return $({type:a,params:{sendId:t}},(function(e,n){var r,i=n.state,o=n.actorContext,a=D(t)?t({context:i.context,event:e.data,_event:e,self:null!==(r=null==o?void 0:o.self)&&void 0!==r?r:{},system:null==o?void 0:o.system}):t;return[i,{type:"xstate.cancel",params:{sendId:a},execute:function(t){t.self.cancel(a)}}]}))},t.choose=function(t){return $({type:y,params:{guards:t}},(function(e,n){var r,i=n.state,o=null===(r=t.find((function(t){var n=t.guard&&rt(t.guard,(function(t){return i.machine.options.guards[t]}));return!n||nt(n,i.context,e,i)})))||void 0===r?void 0:r.actions;return[i,{type:y,params:{actions:_t(o)}}]}))},t.createInitEvent=wt,t.done=function(t,n){var r="".concat(e.DoneState,".").concat(t),i={type:r,output:n,toString:function(){return r}};return i},t.doneInvoke=xt,t.error=St,t.escalate=function(t,e){return B((function(e){return{type:p,data:D(t)?t(e):t}}),S(S({},e),{},{to:n.Parent}))},t.forwardTo=function(t,e){if("production"!==process.env.NODE_END&&(!t||"function"==typeof t)){var n=t;t=function(){var t="function"==typeof n?n.apply(void 0,arguments):n;if(!t)throw new Error("Attempted to forward event to undefined actor. This risks an infinite loop in the sender.");return t}}return z((function(t){return t.event}),S(S({},e),{},{to:t}))},t.initEvent=gt,t.log=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Z,e=arguments.length>1?arguments[1]:void 0;return $({type:l,params:{label:e,expr:t}},(function(n,r){var i,o=r.state,a=r.actorContext,s="function"==typeof t?t({context:o.context,event:n.data,_event:n,self:null!==(i=null==a?void 0:a.self)&&void 0!==i?i:{},system:null==a?void 0:a.system}):t;return[o,{type:"xstate.log",params:{label:e,value:s},execute:function(t){var n,r;e?null===(n=t.logger)||void 0===n||n.call(t,e,s):null===(r=t.logger)||void 0===r||r.call(t,s)}}]}))},t.raise=function(t,e){return $({type:i,params:{delay:e?e.delay:void 0,event:t,id:e&&void 0!==e.id?e.id:"function"==typeof t?t.name:t.type}},(function(n,r){var o,a,s=r.state,u=r.actorContext,c={delay:e?e.delay:void 0,event:t,id:e&&void 0!==e.id?e.id:"function"==typeof t?t.name:t.type},l={context:s.context,event:n.data,_event:n,self:null!==(o=null==u?void 0:u.self)&&void 0!==o?o:{},system:null==u?void 0:u.system},f=s.machine.options.delays,d=N("function"==typeof t?t(l):t);if("string"==typeof c.delay){var v=f&&f[c.delay];a="function"==typeof v?v(l):v}else a="function"==typeof c.delay?c.delay(l):c.delay;var h={type:i,params:S(S({},c),{},{_event:d,event:d.data,delay:a}),execute:function(t){"number"!=typeof h.params.delay||t.self.delaySend(h)}};return[s,h]}))},t.resolveActionObject=function(t,e){if(q(t))return t;var n,r=e[t.type];return"function"==typeof r?$({type:"xstate.function",params:null!==(n=t.params)&&void 0!==n?n:{}},(function(e,n){var i=n.state,o={type:t.type,params:t.params,execute:function(t){return r({context:i.context,event:i.event,action:o,_event:i._event,system:t.system,self:t.self})}};return[i,o]})):r||t},t.respond=function(t,e){return z(t,S(S({},e),{},{to:function(t){return t._event.origin}}))},t.send=z,t.sendParent=B,t.sendTo=function(t,e,n){return z(e,S(S({},n),{},{to:t}))},t.stop=function(t){var e=t;return $({type:r,params:{actor:e}},(function(t,n){var r=n.state,i=D(e)?e({context:r.context,event:t.data}):e,o="string"==typeof i?r.children[i]:i;return[r,{type:"xstate.stop",params:{actor:o},execute:function(t){o&&(o.status===X.Running?t.defer((function(){t.stopChild(o)})):t.stopChild(o))}}]}))},t.toActionObject=bt,t.toActionObjects=_t,Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
2
2
|
//# sourceMappingURL=xstate-actions.umd.min.js.map
|