xstate 5.0.0-alpha.6 → 5.0.0-beta.11
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.d.mts +2 -0
- package/actions/dist/xstate-actions.cjs.d.mts.map +1 -0
- package/actions/dist/xstate-actions.cjs.d.ts +1 -0
- package/actions/dist/xstate-actions.cjs.d.ts.map +1 -0
- package/actions/dist/xstate-actions.cjs.js +29 -5
- package/actions/dist/xstate-actions.cjs.mjs +24 -0
- package/actions/dist/{xstate-actions.cjs.dev.js → xstate-actions.development.cjs.js} +3 -3
- package/actions/dist/xstate-actions.development.esm.js +2 -0
- package/actions/dist/xstate-actions.esm.js +2 -2
- 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.d.mts +2 -0
- package/actors/dist/xstate-actors.cjs.d.mts.map +1 -0
- package/actors/dist/xstate-actors.cjs.d.ts +1 -0
- package/actors/dist/xstate-actors.cjs.d.ts.map +1 -0
- package/actors/dist/xstate-actors.cjs.js +20 -5
- package/actors/dist/xstate-actors.cjs.mjs +15 -0
- package/actors/dist/{xstate-actors.cjs.dev.js → xstate-actors.development.cjs.js} +3 -2
- package/actors/dist/xstate-actors.development.esm.js +2 -0
- package/actors/dist/xstate-actors.esm.js +2 -2
- package/actors/dist/xstate-actors.umd.min.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dev/dist/xstate-dev.cjs.d.mts +2 -0
- package/dev/dist/xstate-dev.cjs.d.mts.map +1 -0
- package/dev/dist/xstate-dev.cjs.d.ts +1 -0
- package/dev/dist/xstate-dev.cjs.d.ts.map +1 -0
- package/dev/dist/xstate-dev.cjs.js +45 -4
- package/dev/dist/xstate-dev.cjs.mjs +5 -0
- package/{dist/index-ebaab3c9.cjs.dev.js → dev/dist/xstate-dev.development.cjs.js} +6 -7
- package/{dist/index-50bd0aff.esm.js → dev/dist/xstate-dev.development.esm.js} +6 -8
- package/dev/dist/xstate-dev.esm.js +42 -1
- package/dev/dist/xstate-dev.umd.min.js +1 -1
- package/dev/dist/xstate-dev.umd.min.js.map +1 -1
- package/dist/actions-26f9aa9d.cjs.js +3388 -0
- package/dist/actions-acbe7aa1.development.cjs.js +3423 -0
- package/dist/actions-b82e841e.esm.js +3306 -0
- package/dist/actions-cff79077.development.esm.js +3341 -0
- package/dist/declarations/src/State.d.ts +2 -3
- package/dist/declarations/src/StateMachine.d.ts +6 -6
- package/dist/declarations/src/StateNode.d.ts +3 -9
- package/dist/declarations/src/actions/send.d.ts +0 -7
- package/dist/declarations/src/actions.d.ts +9 -8
- package/dist/declarations/src/actors/index.d.ts +2 -1
- package/dist/declarations/src/actors/observable.d.ts +1 -2
- package/dist/declarations/src/actors/promise.d.ts +1 -2
- package/dist/declarations/src/guards.d.ts +2 -2
- package/dist/declarations/src/index.d.ts +13 -29
- package/dist/declarations/src/interpreter.d.ts +5 -4
- package/dist/declarations/src/stateUtils.d.ts +9 -14
- package/dist/declarations/src/typegenTypes.d.ts +7 -1
- package/dist/declarations/src/types.d.ts +18 -92
- package/dist/declarations/src/utils.d.ts +3 -6
- package/dist/declarations/src/waitFor.d.ts +33 -0
- package/dist/xstate.cjs.d.mts +2 -0
- package/dist/xstate.cjs.d.mts.map +1 -0
- package/dist/xstate.cjs.d.ts +1 -0
- package/dist/xstate.cjs.d.ts.map +1 -0
- package/dist/xstate.cjs.js +802 -4
- package/dist/xstate.cjs.mjs +38 -0
- package/dist/xstate.development.cjs.js +808 -0
- package/dist/xstate.development.esm.js +770 -0
- package/dist/xstate.esm.js +594 -706
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.d.mts +2 -0
- package/guards/dist/xstate-guards.cjs.d.mts.map +1 -0
- package/guards/dist/xstate-guards.cjs.d.ts +1 -0
- package/guards/dist/xstate-guards.cjs.d.ts.map +1 -0
- package/guards/dist/xstate-guards.cjs.js +13 -5
- package/guards/dist/xstate-guards.cjs.mjs +8 -0
- package/guards/dist/{xstate-guards.cjs.dev.js → xstate-guards.development.cjs.js} +2 -2
- package/guards/dist/xstate-guards.development.esm.js +2 -0
- package/guards/dist/xstate-guards.esm.js +2 -2
- package/guards/dist/xstate-guards.umd.min.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +58 -1
- package/actions/dist/xstate-actions.cjs.prod.js +0 -31
- package/actors/dist/xstate-actors.cjs.prod.js +0 -21
- package/dev/dist/xstate-dev.cjs.dev.js +0 -11
- package/dev/dist/xstate-dev.cjs.prod.js +0 -48
- package/dist/actions-41b74cdc.esm.js +0 -4287
- package/dist/actions-bf7bb1c5.cjs.dev.js +0 -4342
- package/dist/actions-c46e4911.cjs.prod.js +0 -4304
- package/dist/declarations/actions/dynamicAction.d.ts +0 -5
- package/dist/declarations/src/Mailbox.d.ts +0 -12
- package/dist/declarations/src/actions/invoke.d.ts +0 -3
- package/dist/declarations/src/environment.d.ts +0 -1
- package/dist/declarations/src/memo.d.ts +0 -2
- package/dist/declarations/src/schema.d.ts +0 -2
- package/dist/declarations/src/spawn.d.ts +0 -2
- package/dist/declarations/src/system.d.ts +0 -2
- package/dist/xstate.cjs.dev.js +0 -921
- package/dist/xstate.cjs.prod.js +0 -921
- package/guards/dist/xstate-guards.cjs.prod.js +0 -15
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xstate-actors.cjs.d.mts","sourceRoot":"","sources":["../../dist/declarations/src/actors/index.d.ts"],"names":[],"mappings":"AAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xstate-actors.cjs.d.ts","sourceRoot":"","sources":["../../dist/declarations/src/actors/index.d.ts"],"names":[],"mappings":"AAAA"}
|
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var actors_dist_xstateActors = require('../../dist/actions-26f9aa9d.cjs.js');
|
|
6
|
+
require('../../dev/dist/xstate-dev.cjs.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.createEmptyActor = actors_dist_xstateActors.createEmptyActor;
|
|
11
|
+
exports.fromCallback = actors_dist_xstateActors.fromCallback;
|
|
12
|
+
exports.fromEventObservable = actors_dist_xstateActors.fromEventObservable;
|
|
13
|
+
exports.fromObservable = actors_dist_xstateActors.fromObservable;
|
|
14
|
+
exports.fromPromise = actors_dist_xstateActors.fromPromise;
|
|
15
|
+
exports.fromTransition = actors_dist_xstateActors.fromTransition;
|
|
16
|
+
exports.isActorRef = actors_dist_xstateActors.isActorRef;
|
|
17
|
+
exports.isSignal = actors_dist_xstateActors.isSignal;
|
|
18
|
+
exports.startSignal = actors_dist_xstateActors.startSignal;
|
|
19
|
+
exports.startSignalType = actors_dist_xstateActors.startSignalType;
|
|
20
|
+
exports.stopSignal = actors_dist_xstateActors.stopSignal;
|
|
21
|
+
exports.stopSignalType = actors_dist_xstateActors.stopSignalType;
|
|
22
|
+
exports.toActorRef = actors_dist_xstateActors.toActorRef;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export {
|
|
2
|
+
createEmptyActor,
|
|
3
|
+
fromCallback,
|
|
4
|
+
fromEventObservable,
|
|
5
|
+
fromObservable,
|
|
6
|
+
fromPromise,
|
|
7
|
+
fromTransition,
|
|
8
|
+
isActorRef,
|
|
9
|
+
isSignal,
|
|
10
|
+
startSignal,
|
|
11
|
+
startSignalType,
|
|
12
|
+
stopSignal,
|
|
13
|
+
stopSignalType,
|
|
14
|
+
toActorRef
|
|
15
|
+
} from "./xstate-actors.cjs.js";
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var actors_dist_xstateActors = require('../../dist/actions-
|
|
6
|
-
require('../../dist/
|
|
5
|
+
var actors_dist_xstateActors = require('../../dist/actions-acbe7aa1.development.cjs.js');
|
|
6
|
+
require('../../dev/dist/xstate-dev.development.cjs.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
+
exports.createEmptyActor = actors_dist_xstateActors.createEmptyActor;
|
|
10
11
|
exports.fromCallback = actors_dist_xstateActors.fromCallback;
|
|
11
12
|
exports.fromEventObservable = actors_dist_xstateActors.fromEventObservable;
|
|
12
13
|
exports.fromObservable = actors_dist_xstateActors.fromObservable;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { ai as createEmptyActor, a2 as fromCallback, a3 as fromEventObservable, a1 as fromObservable, a0 as fromPromise, a4 as fromTransition, ag as isActorRef, af as isSignal, ad as startSignal, ab as startSignalType, ae as stopSignal, ac as stopSignalType, ah as toActorRef } from '../../dist/actions-cff79077.development.esm.js';
|
|
2
|
+
import '../../dev/dist/xstate-dev.development.esm.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { as as fromCallback,
|
|
2
|
-
import '../../dist/
|
|
1
|
+
export { ai as createEmptyActor, a2 as fromCallback, a3 as fromEventObservable, a1 as fromObservable, a0 as fromPromise, a4 as fromTransition, ag as isActorRef, af as isSignal, ad as startSignal, ab as startSignalType, ae as stopSignal, ac as stopSignalType, ah as toActorRef } from '../../dist/actions-b82e841e.esm.js';
|
|
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).XStateActors={})}(this,(function(t){"use strict";function e(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 n(t,n,r){return(n=e(n))in t?Object.defineProperty(t,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[n]=r,t}function r(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 o(t){for(var e=1;e<arguments.length;e++){var o=null!=arguments[e]?arguments[e]:{};e%2?r(Object(o),!0).forEach((function(e){n(t,e,o[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(o)):r(Object(o)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(o,e))}))}return t}function i(t){return(i="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)}var a="function"==typeof Symbol&&Symbol.observable||"@@observable";var u,s;!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"}(u||(u={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(s||(s={}));u.Stop,u.Raise,u.Send,u.Cancel,u.Assign,u.After,u.DoneState,u.Log;var c=u.Init;u.Invoke,u.ErrorExecution,u.ErrorPlatform,u.ErrorCustom,u.Choose,u.Pure;function f(t){return"function"==typeof t}function d(t){return"$$type"in t&&"scxml"===t.$$type}function p(t,e){return d(t)?t:o({name:t.type,data:t,$$type:"scxml",type:"external"},e)}p({type:c});function l(t,e){var n="".concat(u.DoneInvoke,".").concat(t),r={type:n,output:e,toString:function(){return n}};return r}function v(t,e){var n="".concat(u.ErrorPlatform,".").concat(t),r={type:n,data:e,toString:function(){return n}};return r}var b;!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(b||(b={}));(function(t){function e(e,n){return t.apply(this,arguments)}e.toString=function(){return t.toString()}})((function(t,e){return setTimeout(t,e)})),function(t){function e(e){return t.apply(this,arguments)}e.toString=function(){return t.toString()}}((function(t){return clearTimeout(t)})),console.log.bind(console);var y="xstate.init",g="xstate.stop";function S(t){return t===y||t===g}t.fromCallback=function(t){return{start:function(t,e){e.self.send({type:y})},transition:function(e,n,r){var o,a=r.self,u=r.id,s=p(n);if(s.name===y){return e.dispose=t((function(t){var n;if(e.canceled)return e;null===(n=a._parent)||void 0===n||n.send(p(t,{origin:a}))}),(function(t){e.receivers.add(t)}),{input:e.input}),((o=e.dispose)instanceof Promise||null!==o&&(f(o)||"object"===i(o))&&f(o.then))&&e.dispose.then((function(t){var n;null===(n=a._parent)||void 0===n||n.send(p(l(u,t),{origin:a})),e.canceled=!0}),(function(t){var n,r=v(u,t);null===(n=a._parent)||void 0===n||n.send(p(r,{origin:a})),e.canceled=!0})),e}if(s.name===g)return e.canceled=!0,f(e.dispose)&&e.dispose(),e;if(S(s.name))return e;var c=d(n)?n.data:n;return S(c.type)||e.receivers.forEach((function(t){return t(c)})),e},getInitialState:function(t,e){return{canceled:!1,receivers:new Set,dispose:void 0,input:e}},getSnapshot:function(){},getPersistedState:function(t){return t.input}}},t.fromEventObservable=function(t){var e="$$xstate.error",n="$$xstate.complete";return{transition:function(t,r){var o=p(r);if(t.canceled)return t;switch(o.name){case e:return t.status="error",delete t.input,t.data=o.data.data,t;case n:return t.status="done",delete t.input,t;case g:return t.canceled=!0,delete t.input,t.subscription.unsubscribe(),t;default:return t}},getInitialState:function(){return{subscription:void 0,canceled:!1,status:"active",data:void 0}},start:function(r,o){var i=o.self;"done"!==r.status&&(r.subscription=t({input:r.input}).subscribe({next:function(t){var e;null===(e=i._parent)||void 0===e||e.send(p(t,{origin:i}))},error:function(t){i.send({type:e,data:t})},complete:function(){i.send({type:n})}}))},getSnapshot:function(t){},getPersistedState:function(t){return{canceled:t.canceled,status:t.status,data:t.data,input:t.input}},getStatus:function(t){return t},restoreState:function(t){return o(o({},t),{},{subscription:void 0})}}},t.fromObservable=function(t){var e="$$xstate.next",n="$$xstate.error",r="$$xstate.complete";return{transition:function(t,o,i){var a=i.self,u=i.id,s=i.defer,c=p(o);if(t.canceled)return t;switch(c.name){case e:return t.data=o.data.data,s((function(){var t;null===(t=a._parent)||void 0===t||t.send(p({type:"xstate.snapshot.".concat(u),data:c.data.data},{origin:a}))})),t;case n:return t.status="error",delete t.input,t.data=c.data.data,t;case r:return t.status="done",delete t.input,t;case g:return t.canceled=!0,delete t.input,t.subscription.unsubscribe(),t;default:return t}},getInitialState:function(t,e){return{subscription:void 0,canceled:!1,status:"active",data:void 0,input:e}},start:function(o,i){var a=i.self;"done"!==o.status&&(o.subscription=t({input:o.input}).subscribe({next:function(t){a.send({type:e,data:t})},error:function(t){a.send({type:n,data:t})},complete:function(){a.send({type:r})}}))},getSnapshot:function(t){return t.data},getPersistedState:function(t){return{canceled:t.canceled,status:t.status,data:t.data,input:t.input}},getStatus:function(t){return t},restoreState:function(t){return o(o({},t),{},{subscription:void 0})}}},t.fromPromise=function(t){var e="$$xstate.resolve",n="$$xstate.reject";return{transition:function(t,r){var o=p(r);if(t.canceled)return t;var i=o.data;switch(o.name){case e:return t.status="done",t.data=i.data,delete t.input,t;case n:return t.status="error",t.data=i.data,delete t.input,t;case g:return t.canceled=!0,delete t.input,t;default:return t}},start:function(r,o){var i=o.self;"active"===r.status&&Promise.resolve(t({input:r.input})).then((function(t){i.send({type:e,data:t})}),(function(t){i.send({type:n,data:t})}))},getInitialState:function(t,e){return{canceled:!1,status:"active",data:void 0,input:e}},getSnapshot:function(t){return t.data},getStatus:function(t){return t},getPersistedState:function(t){return t},restoreState:function(t){return t}}},t.fromTransition=function(t,e){return{transition:function(e,n,r){var o=d(n)?n.data:n;return t(e,o,r)},getInitialState:function(t,n){return"function"==typeof e?e({input:n}):e},getSnapshot:function(t){return t},getPersistedState:function(t){return t},restoreState:function(t){return t}}},t.isActorRef=function(t){return!!t&&"object"===i(t)&&"function"==typeof t.send},t.isSignal=S,t.startSignal={type:"xstate.init"},t.startSignalType=y,t.stopSignal={type:"xstate.stop"},t.stopSignalType=g,t.toActorRef=function(t){var e;return o((n(e={subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",sessionId:"",getSnapshot:function(){}},a,(function(){return this})),n(e,"status",b.Running),n(e,"stop",(function(){})),e),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).XStateActors={})}(this,(function(t){"use strict";const e="function"==typeof Symbol&&Symbol.observable||"@@observable";class s{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}}let i=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}({});function n(t){return"function"==typeof t}function o(t,e){const s=`${i.DoneInvoke}.${t}`,n={type:s,output:e,toString:()=>s};return n}function r(t,e){const s=`${i.ErrorPlatform}.${t}`,n={type:s,data:e,toString:()=>s};return n}function a(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const u=t=>{const e=a();e&&e.register(t)};let d=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const c={deferEvents:!0,clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class h{constructor(t,e){this.behavior=t,this._state=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new s(this._process.bind(this)),this.delayedEventsMap={},this.observers=new Set,this.logger=void 0,this.status=d.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 i={...c,...e},{clock:n,logger:o,parent:r,id:a,systemId:u}=i;this.system=r?.system??function(){let t=0;const e=new Map,s=new Map,i=new WeakMap;return{_bookId:()=>"x:"+t++,_register:(t,s)=>(e.set(t,s),t),_unregister:t=>{e.delete(t.sessionId);const n=i.get(t);void 0!==n&&(s.delete(n),i.delete(t))},get:t=>s.get(t),_set:(t,e)=>{const n=s.get(t);if(n&&n!==e)throw new Error(`Actor with system ID '${t}' already exists.`);s.set(t,e),i.set(e,t)}}}(),u&&(this._systemId=u,this.system._set(u,this)),this.sessionId=this.system._bookId(),this.id=a??this.sessionId,this.logger=o,this.clock=n,this._parent=r,this.options=i,this.src=i.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.behavior.restoreState?this.behavior.restoreState(this.options.state,this._actorContext):this.options.state:this.behavior.getInitialState(this._actorContext,this.options?.input)}update(t){this._state=t;const e=this.getSnapshot();let s;for(;s=this._deferred.shift();)s(t);for(const t of this.observers)t.next?.(e);const i=this.behavior.getStatus?.(t);switch(i?.status){case"done":this._stopProcedure(),this._doneEvent=o(this.id,i.data),this._parent?.send(this._doneEvent),this._complete();break;case"error":this._stopProcedure(),this._parent?.send(r(this.id,i.data)),this._error(i.data)}}subscribe(t,e,s){const i=function(t,e,s){const i=()=>{},n="object"==typeof t,o=n?t:null;return{next:((n?t.next:t)||i).bind(o),error:((n?t.error:e)||i).bind(o),complete:((n?t.complete:s)||i).bind(o)}}(t,e,s);return this.observers.add(i),this.status===d.Stopped&&(i.complete?.(),this.observers.delete(i)),{unsubscribe:()=>{this.observers.delete(i)}}}onDone(t){return this.status===d.Stopped&&this._doneEvent?t(this._doneEvent):this.observers.add({complete:()=>{this._doneEvent&&t(this._doneEvent)}}),this}start(){return this.status===d.Running||(this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this.status=d.Running,this.behavior.start&&this.behavior.start(this._state,this._actorContext),this.update(this._state),this.options.devTools&&this.attachDevTools(),this.mailbox.start()),this}_process(t){try{const e=this.behavior.transition(this._state,t,this._actorContext);this.update(e),t.type===f&&(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===d.Stopped?this:(this.mailbox.clear(),this.status===d.NotStarted?(this.status=d.Stopped,this):(this.mailbox.enqueue({type:f}),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!==d.Running)return this;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.mailbox.clear(),this.mailbox=new s(this._process.bind(this)),this.status=d.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!==d.Stopped){if(this.status!==d.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:u)(this)}}toJSON(){return{id:this.id}}getPersistedState(){return this.behavior.getPersistedState?.(this._state)}[e](){return this}getSnapshot(){return this.behavior.getSnapshot?this.behavior.getSnapshot(this._state):this._state}}function p(t,e){return{config:t,transition:(e,s,i)=>t(e,s,i),getInitialState:(t,s)=>"function"==typeof e?e({input:s}):e,getSnapshot:t=>t,getPersistedState:t=>t,restoreState:t=>t}}const l="xstate.init",f="xstate.stop";function v(t){return t===l||t===f}const _=p((t=>{}),void 0);t.createEmptyActor=function(){return new h(_,t);var t},t.fromCallback=function(t){return{config:t,start:(t,{self:e})=>{e.send({type:l})},transition:(e,s,{self:i,id:a})=>{if(s.type===l){const s=t=>{e.canceled||i._parent?.send(t)},d=t=>{e.receivers.add(t)};return e.dispose=t(s,d,{input:e.input}),((u=e.dispose)instanceof Promise||null!==u&&(n(u)||"object"==typeof u)&&n(u.then))&&e.dispose.then((t=>{i._parent?.send(o(a,t)),e.canceled=!0}),(t=>{e.canceled=!0,i._parent?.send(r(a,t))})),e}var u;return s.type===f?(e.canceled=!0,n(e.dispose)&&e.dispose(),e):(v(s.type)||v(s.type)||e.receivers.forEach((t=>t(s))),e)},getInitialState:(t,e)=>({canceled:!1,receivers:new Set,dispose:void 0,input:e}),getSnapshot:()=>{},getPersistedState:({input:t})=>t}},t.fromEventObservable=function(t){const e="$$xstate.error",s="$$xstate.complete";return{config:t,transition:(t,i)=>{if("active"!==t.status)return t;switch(i.type){case e:return{...t,status:"error",input:void 0,data:i.data,subscription:void 0};case s:return{...t,status:"done",input:void 0,subscription:void 0};case f:return t.subscription.unsubscribe(),{...t,status:"canceled",input:void 0,subscription:void 0};default:return t}},getInitialState:(t,e)=>({subscription:void 0,status:"active",data:void 0,input:e}),start:(i,{self:n})=>{"done"!==i.status&&(i.subscription=t({input:i.input}).subscribe({next:t=>{n._parent?.send(t)},error:t=>{n.send({type:e,data:t})},complete:()=>{n.send({type:s})}}))},getSnapshot:t=>{},getPersistedState:({status:t,data:e,input:s})=>({status:t,data:e,input:s}),getStatus:t=>t,restoreState:t=>({...t,subscription:void 0})}},t.fromObservable=function(t){const e="$$xstate.next",s="$$xstate.error",i="$$xstate.complete";return{config:t,transition:(t,n,{self:o,id:r,defer:a})=>{if("active"!==t.status)return t;switch(n.type){case e:return a((()=>{o._parent?.send({type:`xstate.snapshot.${r}`,data:n.data})})),{...t,data:n.data};case s:return{...t,status:"error",input:void 0,data:n.data,subscription:void 0};case i:return{...t,status:"done",input:void 0,subscription:void 0};case f:return t.subscription.unsubscribe(),{...t,status:"canceled",input:void 0,subscription:void 0};default:return t}},getInitialState:(t,e)=>({subscription:void 0,status:"active",data:void 0,input:e}),start:(n,{self:o})=>{"done"!==n.status&&(n.subscription=t({input:n.input}).subscribe({next:t=>{o.send({type:e,data:t})},error:t=>{o.send({type:s,data:t})},complete:()=>{o.send({type:i})}}))},getSnapshot:t=>t.data,getPersistedState:({status:t,data:e,input:s})=>({status:t,data:e,input:s}),getStatus:t=>t,restoreState:t=>({...t,subscription:void 0})}},t.fromPromise=function(t){const e="$$xstate.resolve",s="$$xstate.reject";return{config:t,transition:(t,i)=>{if("active"!==t.status)return t;switch(i.type){case e:return{...t,status:"done",data:i.data,input:void 0};case s:return{...t,status:"error",data:i.data,input:void 0};case f:return{...t,status:"canceled",input:void 0};default:return t}},start:(i,{self:n})=>{if("active"!==i.status)return;Promise.resolve(t({input:i.input})).then((t=>{"active"===n._state.status&&n.send({type:e,data:t})}),(t=>{"active"===n._state.status&&n.send({type:s,data:t})}))},getInitialState:(t,e)=>({status:"active",data:void 0,input:e}),getSnapshot:t=>t.data,getStatus:t=>t,getPersistedState:t=>t,restoreState:t=>t}},t.fromTransition=p,t.isActorRef=function(t){return!!t&&"object"==typeof t&&"function"==typeof t.send},t.isSignal=v,t.startSignal={type:"xstate.init"},t.startSignalType=l,t.stopSignal={type:"xstate.stop"},t.stopSignalType=f,t.toActorRef=function(t){return{subscribe:()=>({unsubscribe:()=>{}}),id:"anonymous",sessionId:"",getSnapshot:()=>{},[e]:function(){return this},status:d.Running,stop:()=>{},...t}},Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
2
2
|
//# sourceMappingURL=xstate-actors.umd.min.js.map
|