xstate 5.0.0-alpha.6 → 5.0.0-beta.8
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 +2 -1
- package/actions/dist/xstate-actions.cjs.prod.js +2 -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 +2 -1
- package/actors/dist/xstate-actors.cjs.prod.js +2 -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-c46e4911.cjs.prod.js → actions-900f9761.cjs.prod.js} +100 -55
- package/dist/{actions-41b74cdc.esm.js → actions-c8d7df32.esm.js} +99 -54
- package/dist/{actions-bf7bb1c5.cjs.dev.js → actions-d06ca158.cjs.dev.js} +100 -55
- package/dist/declarations/src/StateMachine.d.ts +2 -2
- package/dist/declarations/src/actions.d.ts +1 -0
- 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/index.d.ts +12 -28
- package/dist/declarations/src/types.d.ts +5 -5
- package/dist/declarations/src/waitFor.d.ts +33 -0
- package/dist/xstate.cjs.dev.js +87 -52
- package/dist/xstate.cjs.prod.js +84 -52
- package/dist/xstate.esm.js +73 -50
- 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
- package/dist/declarations/src/schema.d.ts +0 -2
|
@@ -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-d06ca158.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;
|
|
@@ -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-900f9761.cjs.prod.js');
|
|
6
6
|
require('../../dev/dist/xstate-dev.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 { ar as createEmptyActor, ab as fromCallback, ac as fromEventObservable, aa as fromObservable, a9 as fromPromise, ad as fromTransition, ap as isActorRef, ao as isSignal, am as startSignal, ak as startSignalType, an as stopSignal, al as stopSignalType, aq as toActorRef } from '../../dist/actions-c8d7df32.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 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 i(t){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?r(Object(i),!0).forEach((function(e){n(t,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):r(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,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})(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,r=new Array(e);n<e;n++)r[n]=t[n];return r}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 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 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 r=0;r<n.length;r++){var i=n[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,e(i.key),i)}}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,v=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={}));f.Stop,f.Raise,f.Send,f.Cancel,f.Assign,f.After,f.DoneState,f.Log;var p=f.Init;f.Invoke,f.ErrorExecution,f.ErrorPlatform,f.ErrorCustom,f.Choose,f.Pure;function y(t){return"function"==typeof t}function b(t){return"$$type"in t&&"scxml"===t.$$type}function m(t,e){return b(t)?t:i({name:t.type,data:t,$$type:"scxml",type:"external"},e)}m({type:p});function g(t,e){var n="".concat(f.DoneInvoke,".").concat(t),r={type:n,output:e,toString:function(){return n}};return r}function _(t,e){var n="".concat(f.ErrorPlatform,".").concat(t),r={type:n,data:e,toString:function(){return n}};return r}function S(){var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}var x,k=function(t){var e=S();e&&e.register(t)};!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(x||(x={}));var w={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},E=function(){function t(e,r){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 v(this._process.bind(this))),n(this,"delayedEventsMap",{}),n(this,"observers",new Set),n(this,"logger",void 0),n(this,"status",x.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=i(i({},w),r),h=f.clock,p=f.logger,y=f.parent,b=f.id,m=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)}}),m&&(this._systemId=m,this.system._set(m,this)),this.sessionId=this.system._bookId(),this.id=null!=b?b:this.sessionId,this.logger=p,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,r,i;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._doneEvent=g(this.id,f.data),null===(r=this._parent)||void 0===r||r.send(m(this._doneEvent,{origin:this,invokeid:this.id})),this._stopProcedure();break;case"error":null===(i=this._parent)||void 0===i||i.send(m(_(this.id,f.data),{origin:this}));var h,v=u(this.observers);try{for(v.s();!(h=v.n()).done;){var p,y=h.value;null===(p=y.error)||void 0===p||p.call(y,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"===s(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===O&&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(m({type:O})),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,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){if("string"==typeof t)throw new Error('Only event objects may be sent to actors; use .send({ type: "'.concat(t,'" }) instead'));var e=m(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:k)(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 P(t,e){return{transition:function(e,n,r){var i=b(n)?n.data:n;return t(e,i,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}}}var I="xstate.init",O="xstate.stop";function j(t){return t===I||t===O}var T=P((function(t){}),void 0);t.createEmptyActor=function(){return new E(T,t);var t},t.fromCallback=function(t){return{start:function(t,e){e.self.send({type:I})},transition:function(e,n,r){var i,o=r.self,a=r.id,u=m(n);if(u.name===I){return e.dispose=t((function(t){var n;e.canceled||null===(n=o._parent)||void 0===n||n.send(m(t,{origin:o}))}),(function(t){e.receivers.add(t)}),{input:e.input}),((i=e.dispose)instanceof Promise||null!==i&&(y(i)||"object"===s(i))&&y(i.then))&&e.dispose.then((function(t){var n;null===(n=o._parent)||void 0===n||n.send(m(g(a,t),{origin:o})),e.canceled=!0}),(function(t){var n,r=_(a,t);null===(n=o._parent)||void 0===n||n.send(m(r,{origin:o})),e.canceled=!0})),e}if(u.name===O)return e.canceled=!0,y(e.dispose)&&e.dispose(),e;if(j(u.name))return e;var c=b(n)?n.data:n;return j(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 s=m(r);if("active"!==t.status)return t;switch(s.name){case e:return i(i({},t),{},{status:"error",input:void 0,data:s.data.data,subscription:void 0});case n:return i(i({},t),{},{status:"done",input:void 0,subscription:void 0});case O:return t.subscription.unsubscribe(),i(i({},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(r,i){var s=i.self;"done"!==r.status&&(r.subscription=t({input:r.input}).subscribe({next:function(t){var e;null===(e=s._parent)||void 0===e||e.send(m(t,{origin:s}))},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 i(i({},t),{},{subscription:void 0})}}},t.fromObservable=function(t){var e="$$xstate.next",n="$$xstate.error",r="$$xstate.complete";return{transition:function(t,s,o){var a=o.self,u=o.id,c=o.defer,l=m(s);if("active"!==t.status)return t;switch(l.name){case e:return c((function(){var t;null===(t=a._parent)||void 0===t||t.send(m({type:"xstate.snapshot.".concat(u),data:l.data.data},{origin:a}))})),i(i({},t),{},{data:s.data.data});case n:return i(i({},t),{},{status:"error",input:void 0,data:l.data.data,subscription:void 0});case r:return i(i({},t),{},{status:"done",input:void 0,subscription:void 0});case O:return t.subscription.unsubscribe(),i(i({},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(i,s){var o=s.self;"done"!==i.status&&(i.subscription=t({input:i.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:r})}}))},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 i(i({},t),{},{subscription:void 0})}}},t.fromPromise=function(t){var e="$$xstate.resolve",n="$$xstate.reject";return{transition:function(t,r){var s=m(r);if("active"!==t.status)return t;var o=s.data;switch(s.name){case e:return i(i({},t),{},{status:"done",data:o.data,input:void 0});case n:return i(i({},t),{},{status:"error",data:o.data,input:void 0});case O:return i(i({},t),{},{status:"canceled",input:void 0});default:return t}},start:function(r,i){var s=i.self;"active"===r.status&&Promise.resolve(t({input:r.input})).then((function(t){s.send({type:e,data:t})}),(function(t){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=P,t.isActorRef=function(t){return!!t&&"object"===s(t)&&"function"==typeof t.send},t.isSignal=j,t.startSignal={type:"xstate.init"},t.startSignalType=I,t.stopSignal={type:"xstate.stop"},t.stopSignalType=O,t.toActorRef=function(t){var e;return i((n(e={subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",sessionId:"",getSnapshot:function(){}},o,(function(){return this})),n(e,"status",x.Running),n(e,"stop",(function(){})),e),t)},Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
2
2
|
//# sourceMappingURL=xstate-actors.umd.min.js.map
|