xstate 5.0.0-alpha.6 → 5.0.0-beta.10
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.dev.js +2 -2
- package/actions/dist/xstate-actions.cjs.mjs +24 -0
- package/actions/dist/xstate-actions.cjs.prod.js +3 -3
- 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.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.dev.js +2 -1
- package/actors/dist/xstate-actors.cjs.mjs +15 -0
- package/actors/dist/xstate-actors.cjs.prod.js +3 -2
- 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/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.mjs +5 -0
- package/dev/dist/xstate-dev.cjs.prod.js +6 -43
- package/dev/dist/xstate-dev.umd.min.js.map +1 -1
- package/dist/{actions-bf7bb1c5.cjs.dev.js → actions-109712d3.cjs.dev.js} +386 -371
- package/dist/{actions-41b74cdc.esm.js → actions-67f1d04e.esm.js} +341 -358
- package/dist/{actions-c46e4911.cjs.prod.js → actions-d0262a43.cjs.prod.js} +409 -380
- 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/spawn.d.ts +2 -2
- 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 -5
- package/dist/declarations/src/waitFor.d.ts +33 -0
- package/dist/index-0f3fdf0c.cjs.prod.js +52 -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.dev.js +117 -105
- package/dist/xstate.cjs.mjs +38 -0
- package/dist/xstate.cjs.prod.js +115 -106
- package/dist/xstate.esm.js +100 -93
- 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.dev.js +1 -1
- package/guards/dist/xstate-guards.cjs.mjs +8 -0
- package/guards/dist/xstate-guards.cjs.prod.js +2 -2
- 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 +7 -1
- package/dist/declarations/src/schema.d.ts +0 -2
|
@@ -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"}
|
|
@@ -2,11 +2,12 @@
|
|
|
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-109712d3.cjs.dev.js');
|
|
6
6
|
require('../../dist/index-ebaab3c9.cjs.dev.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,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('../../
|
|
5
|
+
var actors_dist_xstateActors = require('../../dist/actions-d0262a43.cjs.prod.js');
|
|
6
|
+
require('../../dist/index-0f3fdf0c.cjs.prod.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;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { as as fromCallback,
|
|
1
|
+
export { aq as createEmptyActor, aa as fromCallback, ab as fromEventObservable, a9 as fromObservable, a8 as fromPromise, ac as fromTransition, ao as isActorRef, an as isSignal, al as startSignal, aj as startSignalType, am as stopSignal, ak as stopSignalType, ap as toActorRef } from '../../dist/actions-67f1d04e.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).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";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 i=n.call(t,e||"default");if("object"!=typeof i)return i;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,i){return(n=e(n))in t?Object.defineProperty(t,n,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[n]=i,t}function i(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,i)}return n}function r(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?i(Object(r),!0).forEach((function(e){n(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):i(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function s(t){return s="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},s(t)}var o="function"==typeof Symbol&&Symbol.observable||"@@observable";function a(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}function u(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return a(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)?a(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var i=0,r=function(){};return{s:r,n:function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:r}}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 s,o=!0,u=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return o=t.done,t},e:function(t){u=!0,s=t},f:function(){try{o||null==n.return||n.return()}finally{if(u)throw s}}}}function c(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function l(t,n){for(var i=0;i<n.length;i++){var r=n[i];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,e(r.key),r)}}function d(t,e,n){return e&&l(t.prototype,e),n&&l(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}var f,h,p=function(){function t(e){c(this,t),this._process=e,n(this,"_active",!1),n(this,"_current",null),n(this,"_last",null)}return d(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}();!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"}(f||(f={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(h||(h={}));function v(t){return"function"==typeof t}function y(t,e){var n="".concat(f.DoneInvoke,".").concat(t),i={type:n,output:e,toString:function(){return n}};return i}function b(t,e){var n="".concat(f.ErrorPlatform,".").concat(t),i={type:n,data:e,toString:function(){return n}};return i}function _(){var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}var g,m=function(t){var e=_();e&&e.register(t)};!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(g||(g={}));var S={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},x=function(){function t(e,i){var s,o=this;c(this,t),this.behavior=e,n(this,"_state",void 0),n(this,"clock",void 0),n(this,"options",void 0),n(this,"id",void 0),n(this,"mailbox",new p(this._process.bind(this))),n(this,"delayedEventsMap",{}),n(this,"observers",new Set),n(this,"logger",void 0),n(this,"status",g.NotStarted),n(this,"_parent",void 0),n(this,"ref",void 0),n(this,"_actorContext",void 0),n(this,"_systemId",void 0),n(this,"sessionId",void 0),n(this,"system",void 0),n(this,"_doneEvent",void 0),n(this,"src",void 0),n(this,"_deferred",[]);var a,u,l,d,f=r(r({},S),i),h=f.clock,v=f.logger,y=f.parent,b=f.id,_=f.systemId;this.system=null!==(s=null==y?void 0:y.system)&&void 0!==s?s:(a=0,u=new Map,l=new Map,d=new WeakMap,{_bookId:function(){return"x:".concat(a++)},_register:function(t,e){return u.set(t,e),t},_unregister:function(t){u.delete(t.sessionId);var e=d.get(t);void 0!==e&&(l.delete(e),d.delete(t))},get:function(t){return l.get(t)},_set:function(t,e){var n=l.get(t);if(n&&n!==e)throw new Error("Actor with system ID '".concat(t,"' already exists."));l.set(t,e),d.set(e,t)}}),_&&(this._systemId=_,this.system._set(_,this)),this.sessionId=this.system._bookId(),this.id=null!=b?b:this.sessionId,this.logger=v,this.clock=h,this._parent=y,this.options=f,this.src=f.src,this.ref=this,this._actorContext={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:function(t){o._deferred.push(t)},system:this.system,stopChild:function(t){if(t._parent!==o)throw new Error("Cannot stop child actor ".concat(t.id," of ").concat(o.id," because it is not a child"));t._stop()}},this.send=this.send.bind(this),this._initState()}return d(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,i,r;this._state=t;for(var s,o=this.getSnapshot();s=this._deferred.shift();)s(t);var a,c=u(this.observers);try{for(c.s();!(a=c.n()).done;){var l,d=a.value;null===(l=d.next)||void 0===l||l.call(d,o)}}catch(t){c.e(t)}finally{c.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._stopProcedure(),this._doneEvent=y(this.id,f.data),null===(i=this._parent)||void 0===i||i.send(this._doneEvent),this._complete();break;case"error":this._stopProcedure(),null===(r=this._parent)||void 0===r||r.send(b(this.id,f.data)),this._error(f.data)}}},{key:"subscribe",value:function(t,e,n){var i,r=this,o=function(t,e,n){var i=function(){},r="object"===s(t),o=r?t:null;return{next:((r?t.next:t)||i).bind(o),error:((r?t.error:e)||i).bind(o),complete:((r?t.complete:n)||i).bind(o)}}(t,e,n);(this.observers.add(o),this.status===g.Stopped)&&(null===(i=o.complete)||void 0===i||i.call(o),this.observers.delete(o));return{unsubscribe:function(){r.observers.delete(o)}}}},{key:"onDone",value:function(t){var e=this;return this.status===g.Stopped&&this._doneEvent?t(this._doneEvent):this.observers.add({complete:function(){e._doneEvent&&t(e._doneEvent)}}),this}},{key:"start",value:function(){return this.status===g.Running||(this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this.status=g.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.type===E&&(this._stopProcedure(),this._complete())}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===g.Stopped?this:(this.mailbox.clear(),this.status===g.NotStarted?(this.status=g.Stopped,this):(this.mailbox.enqueue({type:E}),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=u(this.observers);try{for(e.s();!(t=e.n()).done;){var n,i=t.value;null===(n=i.complete)||void 0===n||n.call(i)}}catch(t){e.e(t)}finally{e.f()}this.observers.clear()}},{key:"_error",value:function(t){var e,n=u(this.observers);try{for(n.s();!(e=n.n()).done;){var i,r=e.value;null===(i=r.error)||void 0===i||i.call(r,t)}}catch(t){n.e(t)}finally{n.f()}this.observers.clear()}},{key:"_stopProcedure",value:function(){if(this.status!==g.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 p(this._process.bind(this)),this.status=g.Stopped,this.system._unregister(this),this}},{key:"send",value:function(t){if("string"==typeof t)throw new Error('Only event objects may be sent to actors; use .send({ type: "'.concat(t,'" }) instead'));if(this.status!==g.Stopped){if(this.status!==g.Running&&!this.options.deferEvents)throw new Error('Event "'.concat(t.type,'" 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(t)));this.mailbox.enqueue(t)}else;}},{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:m)(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:o,value:function(){return this}},{key:"getSnapshot",value:function(){return this.behavior.getSnapshot?this.behavior.getSnapshot(this._state):this._state}}]),t}();function k(t,e){return{config:t,transition:function(e,n,i){return t(e,n,i)},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}}}var w="xstate.init",E="xstate.stop";function P(t){return t===w||t===E}var I=k((function(t){}),void 0);t.createEmptyActor=function(){return new x(I,t);var t},t.fromCallback=function(t){return{config:t,start:function(t,e){e.self.send({type:w})},transition:function(e,n,i){var r,o=i.self,a=i.id;if(n.type===w){return e.dispose=t((function(t){var n;e.canceled||null===(n=o._parent)||void 0===n||n.send(t)}),(function(t){e.receivers.add(t)}),{input:e.input}),((r=e.dispose)instanceof Promise||null!==r&&(v(r)||"object"===s(r))&&v(r.then))&&e.dispose.then((function(t){var n;null===(n=o._parent)||void 0===n||n.send(y(a,t)),e.canceled=!0}),(function(t){var n;e.canceled=!0,null===(n=o._parent)||void 0===n||n.send(b(a,t))})),e}return n.type===E?(e.canceled=!0,v(e.dispose)&&e.dispose(),e):(P(n.type)||P(n.type)||e.receivers.forEach((function(t){return t(n)})),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{config:t,transition:function(t,i){if("active"!==t.status)return t;switch(i.type){case e:return r(r({},t),{},{status:"error",input:void 0,data:i.data,subscription:void 0});case n:return r(r({},t),{},{status:"done",input:void 0,subscription:void 0});case E:return t.subscription.unsubscribe(),r(r({},t),{},{status:"canceled",input:void 0,subscription:void 0});default:return t}},getInitialState:function(){return{subscription:void 0,status:"active",data:void 0}},start:function(i,r){var s=r.self;"done"!==i.status&&(i.subscription=t({input:i.input}).subscribe({next:function(t){var e;null===(e=s._parent)||void 0===e||e.send(t)},error:function(t){s.send({type:e,data:t})},complete:function(){s.send({type:n})}}))},getSnapshot:function(t){},getPersistedState:function(t){return{status:t.status,data:t.data,input:t.input}},getStatus:function(t){return t},restoreState:function(t){return r(r({},t),{},{subscription:void 0})}}},t.fromObservable=function(t){var e="$$xstate.next",n="$$xstate.error",i="$$xstate.complete";return{config:t,transition:function(t,s,o){var a=o.self,u=o.id,c=o.defer;if("active"!==t.status)return t;switch(s.type){case e:return c((function(){var t;null===(t=a._parent)||void 0===t||t.send({type:"xstate.snapshot.".concat(u),data:s.data})})),r(r({},t),{},{data:s.data});case n:return r(r({},t),{},{status:"error",input:void 0,data:s.data,subscription:void 0});case i:return r(r({},t),{},{status:"done",input:void 0,subscription:void 0});case E:return t.subscription.unsubscribe(),r(r({},t),{},{status:"canceled",input:void 0,subscription:void 0});default:return t}},getInitialState:function(t,e){return{subscription:void 0,status:"active",data:void 0,input:e}},start:function(r,s){var o=s.self;"done"!==r.status&&(r.subscription=t({input:r.input}).subscribe({next:function(t){o.send({type:e,data:t})},error:function(t){o.send({type:n,data:t})},complete:function(){o.send({type:i})}}))},getSnapshot:function(t){return t.data},getPersistedState:function(t){return{status:t.status,data:t.data,input:t.input}},getStatus:function(t){return t},restoreState:function(t){return r(r({},t),{},{subscription:void 0})}}},t.fromPromise=function(t){var e="$$xstate.resolve",n="$$xstate.reject";return{config:t,transition:function(t,i){if("active"!==t.status)return t;switch(i.type){case e:return r(r({},t),{},{status:"done",data:i.data,input:void 0});case n:return r(r({},t),{},{status:"error",data:i.data,input:void 0});case E:return r(r({},t),{},{status:"canceled",input:void 0});default:return t}},start:function(i,r){var s=r.self;"active"===i.status&&Promise.resolve(t({input:i.input})).then((function(t){"active"===s._state.status&&s.send({type:e,data:t})}),(function(t){"active"===s._state.status&&s.send({type:n,data:t})}))},getInitialState:function(t,e){return{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=k,t.isActorRef=function(t){return!!t&&"object"===s(t)&&"function"==typeof t.send},t.isSignal=P,t.startSignal={type:"xstate.init"},t.startSignalType=w,t.stopSignal={type:"xstate.stop"},t.stopSignalType=E,t.toActorRef=function(t){var e;return r((n(e={subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",sessionId:"",getSnapshot:function(){}},o,(function(){return this})),n(e,"status",g.Running),n(e,"stop",(function(){})),e),t)},Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
2
2
|
//# sourceMappingURL=xstate-actors.umd.min.js.map
|