xstate 5.0.0-beta.10 → 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.js +29 -5
- package/actions/dist/{xstate-actions.cjs.dev.js → xstate-actions.development.cjs.js} +2 -2
- 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.js +20 -5
- package/actors/dist/{xstate-actors.cjs.dev.js → xstate-actors.development.cjs.js} +2 -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.js +45 -4
- package/{dist/index-0f3fdf0c.cjs.prod.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/utils.d.ts +0 -1
- package/dist/declarations/src/waitFor.d.ts +1 -1
- package/dist/xstate.cjs.js +802 -4
- package/dist/xstate.development.cjs.js +808 -0
- package/dist/xstate.development.esm.js +770 -0
- package/dist/xstate.esm.js +543 -662
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +13 -5
- package/guards/dist/{xstate-guards.cjs.prod.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 +52 -1
- package/actions/dist/xstate-actions.cjs.prod.js +0 -31
- package/actors/dist/xstate-actors.cjs.prod.js +0 -22
- package/dev/dist/xstate-dev.cjs.dev.js +0 -11
- package/dev/dist/xstate-dev.cjs.prod.js +0 -11
- package/dist/actions-109712d3.cjs.dev.js +0 -4357
- package/dist/actions-67f1d04e.esm.js +0 -4270
- package/dist/actions-d0262a43.cjs.prod.js +0 -4333
- 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/spawn.d.ts +0 -2
- package/dist/declarations/src/system.d.ts +0 -2
- package/dist/index-ebaab3c9.cjs.dev.js +0 -52
- package/dist/xstate.cjs.dev.js +0 -933
- package/dist/xstate.cjs.prod.js +0 -930
- package/guards/dist/xstate-guards.cjs.dev.js +0 -15
|
@@ -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;
|
|
@@ -2,8 +2,8 @@
|
|
|
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
|
|
|
@@ -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 {
|
|
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 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})}));
|
|
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
|