xstate 5.0.0-beta.28 → 5.0.0-beta.29
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 +3 -3
- package/actions/dist/xstate-actions.development.cjs.js +3 -3
- package/actions/dist/xstate-actions.development.esm.js +3 -3
- package/actions/dist/xstate-actions.esm.js +3 -3
- 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 +1 -36
- package/actors/dist/xstate-actors.cjs.mjs +1 -3
- package/actors/dist/xstate-actors.development.cjs.js +1 -36
- package/actors/dist/xstate-actors.development.cjs.mjs +1 -3
- package/actors/dist/xstate-actors.development.esm.js +2 -35
- package/actors/dist/xstate-actors.esm.js +2 -35
- package/actors/dist/xstate-actors.umd.min.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/declarations/src/actions/assign.d.ts +4 -4
- package/dist/declarations/src/actions/cancel.d.ts +4 -4
- package/dist/declarations/src/actions/choose.d.ts +3 -3
- package/dist/declarations/src/actions/log.d.ts +4 -4
- package/dist/declarations/src/actions/pure.d.ts +1 -1
- package/dist/declarations/src/actions/raise.d.ts +2 -2
- package/dist/declarations/src/actions/send.d.ts +7 -7
- package/dist/declarations/src/actions/stop.d.ts +4 -4
- package/dist/declarations/src/actors/callback.d.ts +2 -2
- package/dist/declarations/src/actors/index.d.ts +1 -3
- package/dist/declarations/src/types.d.ts +24 -32
- package/dist/{interpreter-b5203bcb.esm.js → interpreter-498891b2.esm.js} +1 -17
- package/dist/{interpreter-a77bb0ec.development.esm.js → interpreter-6e7909c8.development.esm.js} +1 -17
- package/dist/{interpreter-672794ae.cjs.js → interpreter-c357bc50.cjs.js} +0 -19
- package/dist/{interpreter-a1432c7d.development.cjs.js → interpreter-e2c6a579.development.cjs.js} +0 -19
- package/dist/{raise-436a57a2.cjs.js → raise-03e57569.cjs.js} +1 -1
- package/dist/{raise-b9c9a234.esm.js → raise-59f2c242.esm.js} +1 -1
- package/dist/{raise-a60c9290.development.esm.js → raise-e778a828.development.esm.js} +1 -1
- package/dist/{raise-74b72ca5.development.cjs.js → raise-f751dfac.development.cjs.js} +1 -1
- package/dist/{send-e63b7b83.development.esm.js → send-42c83fb2.development.esm.js} +2 -2
- package/dist/{send-35e1a689.cjs.js → send-51717e53.cjs.js} +2 -2
- package/dist/{send-e8b55d00.development.cjs.js → send-f53778f6.development.cjs.js} +2 -2
- package/dist/{send-4192e7bc.esm.js → send-fff224db.esm.js} +2 -2
- package/dist/xstate.cjs.js +9 -11
- package/dist/xstate.cjs.mjs +0 -2
- package/dist/xstate.development.cjs.js +9 -11
- package/dist/xstate.development.cjs.mjs +0 -2
- package/dist/xstate.development.esm.js +13 -13
- package/dist/xstate.esm.js +13 -13
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +2 -2
- package/guards/dist/xstate-guards.development.cjs.js +2 -2
- package/guards/dist/xstate-guards.development.esm.js +2 -2
- package/guards/dist/xstate-guards.esm.js +2 -2
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var interpreter = require('../../dist/interpreter-
|
|
5
|
+
var interpreter = require('../../dist/interpreter-c357bc50.cjs.js');
|
|
6
6
|
require('../../dev/dist/xstate-dev.cjs.js');
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -63,15 +63,6 @@ function fromCallback(invokeCallback) {
|
|
|
63
63
|
sendBack,
|
|
64
64
|
receive
|
|
65
65
|
});
|
|
66
|
-
if (interpreter.isPromiseLike(state.dispose)) {
|
|
67
|
-
state.dispose.then(resolved => {
|
|
68
|
-
self._parent?.send(interpreter.createDoneActorEvent(id, resolved));
|
|
69
|
-
state.canceled = true;
|
|
70
|
-
}, errorData => {
|
|
71
|
-
state.canceled = true;
|
|
72
|
-
self._parent?.send(interpreter.createErrorActorEvent(id, errorData));
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
66
|
return state;
|
|
76
67
|
}
|
|
77
68
|
if (event.type === interpreter.XSTATE_STOP) {
|
|
@@ -408,30 +399,6 @@ promiseCreator) {
|
|
|
408
399
|
return logic;
|
|
409
400
|
}
|
|
410
401
|
|
|
411
|
-
function isActorRef(item) {
|
|
412
|
-
return !!item && typeof item === 'object' && typeof item.send === 'function';
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
// TODO: refactor the return type, this could be written in a better way
|
|
416
|
-
// but it's best to avoid unneccessary breaking changes now
|
|
417
|
-
// @deprecated use `interpret(actorLogic)` instead
|
|
418
|
-
function toActorRef(actorRefLike) {
|
|
419
|
-
return {
|
|
420
|
-
subscribe: () => ({
|
|
421
|
-
unsubscribe: () => void 0
|
|
422
|
-
}),
|
|
423
|
-
id: 'anonymous',
|
|
424
|
-
sessionId: '',
|
|
425
|
-
getSnapshot: () => undefined,
|
|
426
|
-
// TODO: this isn't safe
|
|
427
|
-
[interpreter.symbolObservable]: function () {
|
|
428
|
-
return this;
|
|
429
|
-
},
|
|
430
|
-
status: interpreter.ActorStatus.Running,
|
|
431
|
-
stop: () => void 0,
|
|
432
|
-
...actorRefLike
|
|
433
|
-
};
|
|
434
|
-
}
|
|
435
402
|
const emptyLogic = fromTransition(_ => undefined, undefined);
|
|
436
403
|
function createEmptyActor() {
|
|
437
404
|
return interpreter.createActor(emptyLogic);
|
|
@@ -443,5 +410,3 @@ exports.fromEventObservable = fromEventObservable;
|
|
|
443
410
|
exports.fromObservable = fromObservable;
|
|
444
411
|
exports.fromPromise = fromPromise;
|
|
445
412
|
exports.fromTransition = fromTransition;
|
|
446
|
-
exports.isActorRef = isActorRef;
|
|
447
|
-
exports.toActorRef = toActorRef;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var interpreter = require('../../dist/interpreter-
|
|
5
|
+
var interpreter = require('../../dist/interpreter-e2c6a579.development.cjs.js');
|
|
6
6
|
require('../../dev/dist/xstate-dev.development.cjs.js');
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -63,15 +63,6 @@ function fromCallback(invokeCallback) {
|
|
|
63
63
|
sendBack,
|
|
64
64
|
receive
|
|
65
65
|
});
|
|
66
|
-
if (interpreter.isPromiseLike(state.dispose)) {
|
|
67
|
-
state.dispose.then(resolved => {
|
|
68
|
-
self._parent?.send(interpreter.createDoneActorEvent(id, resolved));
|
|
69
|
-
state.canceled = true;
|
|
70
|
-
}, errorData => {
|
|
71
|
-
state.canceled = true;
|
|
72
|
-
self._parent?.send(interpreter.createErrorActorEvent(id, errorData));
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
66
|
return state;
|
|
76
67
|
}
|
|
77
68
|
if (event.type === interpreter.XSTATE_STOP) {
|
|
@@ -408,30 +399,6 @@ promiseCreator) {
|
|
|
408
399
|
return logic;
|
|
409
400
|
}
|
|
410
401
|
|
|
411
|
-
function isActorRef(item) {
|
|
412
|
-
return !!item && typeof item === 'object' && typeof item.send === 'function';
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
// TODO: refactor the return type, this could be written in a better way
|
|
416
|
-
// but it's best to avoid unneccessary breaking changes now
|
|
417
|
-
// @deprecated use `interpret(actorLogic)` instead
|
|
418
|
-
function toActorRef(actorRefLike) {
|
|
419
|
-
return {
|
|
420
|
-
subscribe: () => ({
|
|
421
|
-
unsubscribe: () => void 0
|
|
422
|
-
}),
|
|
423
|
-
id: 'anonymous',
|
|
424
|
-
sessionId: '',
|
|
425
|
-
getSnapshot: () => undefined,
|
|
426
|
-
// TODO: this isn't safe
|
|
427
|
-
[interpreter.symbolObservable]: function () {
|
|
428
|
-
return this;
|
|
429
|
-
},
|
|
430
|
-
status: interpreter.ActorStatus.Running,
|
|
431
|
-
stop: () => void 0,
|
|
432
|
-
...actorRefLike
|
|
433
|
-
};
|
|
434
|
-
}
|
|
435
402
|
const emptyLogic = fromTransition(_ => undefined, undefined);
|
|
436
403
|
function createEmptyActor() {
|
|
437
404
|
return interpreter.createActor(emptyLogic);
|
|
@@ -443,5 +410,3 @@ exports.fromEventObservable = fromEventObservable;
|
|
|
443
410
|
exports.fromObservable = fromObservable;
|
|
444
411
|
exports.fromPromise = fromPromise;
|
|
445
412
|
exports.fromTransition = fromTransition;
|
|
446
|
-
exports.isActorRef = isActorRef;
|
|
447
|
-
exports.toActorRef = toActorRef;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { X as XSTATE_INIT, j as
|
|
1
|
+
import { X as XSTATE_INIT, j as XSTATE_STOP, d as createActor } from '../../dist/interpreter-6e7909c8.development.esm.js';
|
|
2
2
|
import '../../dev/dist/xstate-dev.development.esm.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -59,15 +59,6 @@ function fromCallback(invokeCallback) {
|
|
|
59
59
|
sendBack,
|
|
60
60
|
receive
|
|
61
61
|
});
|
|
62
|
-
if (isPromiseLike(state.dispose)) {
|
|
63
|
-
state.dispose.then(resolved => {
|
|
64
|
-
self._parent?.send(createDoneActorEvent(id, resolved));
|
|
65
|
-
state.canceled = true;
|
|
66
|
-
}, errorData => {
|
|
67
|
-
state.canceled = true;
|
|
68
|
-
self._parent?.send(createErrorActorEvent(id, errorData));
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
62
|
return state;
|
|
72
63
|
}
|
|
73
64
|
if (event.type === XSTATE_STOP) {
|
|
@@ -404,33 +395,9 @@ promiseCreator) {
|
|
|
404
395
|
return logic;
|
|
405
396
|
}
|
|
406
397
|
|
|
407
|
-
function isActorRef(item) {
|
|
408
|
-
return !!item && typeof item === 'object' && typeof item.send === 'function';
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
// TODO: refactor the return type, this could be written in a better way
|
|
412
|
-
// but it's best to avoid unneccessary breaking changes now
|
|
413
|
-
// @deprecated use `interpret(actorLogic)` instead
|
|
414
|
-
function toActorRef(actorRefLike) {
|
|
415
|
-
return {
|
|
416
|
-
subscribe: () => ({
|
|
417
|
-
unsubscribe: () => void 0
|
|
418
|
-
}),
|
|
419
|
-
id: 'anonymous',
|
|
420
|
-
sessionId: '',
|
|
421
|
-
getSnapshot: () => undefined,
|
|
422
|
-
// TODO: this isn't safe
|
|
423
|
-
[symbolObservable]: function () {
|
|
424
|
-
return this;
|
|
425
|
-
},
|
|
426
|
-
status: ActorStatus.Running,
|
|
427
|
-
stop: () => void 0,
|
|
428
|
-
...actorRefLike
|
|
429
|
-
};
|
|
430
|
-
}
|
|
431
398
|
const emptyLogic = fromTransition(_ => undefined, undefined);
|
|
432
399
|
function createEmptyActor() {
|
|
433
400
|
return createActor(emptyLogic);
|
|
434
401
|
}
|
|
435
402
|
|
|
436
|
-
export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition
|
|
403
|
+
export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { X as XSTATE_INIT, j as
|
|
1
|
+
import { X as XSTATE_INIT, j as XSTATE_STOP, d as createActor } from '../../dist/interpreter-498891b2.esm.js';
|
|
2
2
|
import '../../dev/dist/xstate-dev.esm.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -59,15 +59,6 @@ function fromCallback(invokeCallback) {
|
|
|
59
59
|
sendBack,
|
|
60
60
|
receive
|
|
61
61
|
});
|
|
62
|
-
if (isPromiseLike(state.dispose)) {
|
|
63
|
-
state.dispose.then(resolved => {
|
|
64
|
-
self._parent?.send(createDoneActorEvent(id, resolved));
|
|
65
|
-
state.canceled = true;
|
|
66
|
-
}, errorData => {
|
|
67
|
-
state.canceled = true;
|
|
68
|
-
self._parent?.send(createErrorActorEvent(id, errorData));
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
62
|
return state;
|
|
72
63
|
}
|
|
73
64
|
if (event.type === XSTATE_STOP) {
|
|
@@ -404,33 +395,9 @@ promiseCreator) {
|
|
|
404
395
|
return logic;
|
|
405
396
|
}
|
|
406
397
|
|
|
407
|
-
function isActorRef(item) {
|
|
408
|
-
return !!item && typeof item === 'object' && typeof item.send === 'function';
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
// TODO: refactor the return type, this could be written in a better way
|
|
412
|
-
// but it's best to avoid unneccessary breaking changes now
|
|
413
|
-
// @deprecated use `interpret(actorLogic)` instead
|
|
414
|
-
function toActorRef(actorRefLike) {
|
|
415
|
-
return {
|
|
416
|
-
subscribe: () => ({
|
|
417
|
-
unsubscribe: () => void 0
|
|
418
|
-
}),
|
|
419
|
-
id: 'anonymous',
|
|
420
|
-
sessionId: '',
|
|
421
|
-
getSnapshot: () => undefined,
|
|
422
|
-
// TODO: this isn't safe
|
|
423
|
-
[symbolObservable]: function () {
|
|
424
|
-
return this;
|
|
425
|
-
},
|
|
426
|
-
status: ActorStatus.Running,
|
|
427
|
-
stop: () => void 0,
|
|
428
|
-
...actorRefLike
|
|
429
|
-
};
|
|
430
|
-
}
|
|
431
398
|
const emptyLogic = fromTransition(_ => undefined, undefined);
|
|
432
399
|
function createEmptyActor() {
|
|
433
400
|
return createActor(emptyLogic);
|
|
434
401
|
}
|
|
435
402
|
|
|
436
|
-
export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition
|
|
403
|
+
export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition };
|
|
@@ -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";class e{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}}const s="xstate.init",i="xstate.stop";function n(t,e){return{type:`xstate.done.actor.${t}`,output:e}}function o(t,e){return{type:`xstate.error.actor.${t}`,data:e}}function r(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const a=t=>{const e=r();e&&e.register(t)};function c(t){setTimeout((()=>{throw t}))}const d="function"==typeof Symbol&&Symbol.observable||"@@observable";let u=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const h={deferEvents:!0,clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class p{constructor(t,s){this.logic=t,this._state=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new e(this._process.bind(this)),this.delayedEventsMap={},this.observers=new Set,this.logger=void 0,this.status=u.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={...h,...s},{clock:n,logger:o,parent:r,id:a,systemId:c}=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)}}}(),c&&(this._systemId=c,this.system._set(c,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.logic.restoreState?this.logic.restoreState(this.options.state,this._actorContext):this.options.state:this.logic.getInitialState(this._actorContext,this.options?.input)}update(t){this._state=t;const e=this.getSnapshot();let s;for(;s=this._deferred.shift();)s();for(const t of this.observers)try{t.next?.(e)}catch(t){c(t)}const i=this.logic.getStatus?.(t);switch(i?.status){case"done":this._stopProcedure(),this._complete(),this._doneEvent=n(this.id,i.data),this._parent?.send(this._doneEvent);break;case"error":this._stopProcedure(),this._error(i.data),this._parent?.send(o(this.id,i.data))}}subscribe(t,e,s){const i=function(t,e,s){const i="object"==typeof t,n=i?t:void 0;return{next:(i?t.next:t)?.bind(n),error:(i?t.error:e)?.bind(n),complete:(i?t.complete:s)?.bind(n)}}(t,e,s);if(this.status!==u.Stopped)this.observers.add(i);else try{i.complete?.()}catch(t){c(t)}return{unsubscribe:()=>{this.observers.delete(i)}}}start(){if(this.status===u.Running)return this;this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this.status=u.Running;const t=this.logic.getStatus?.(this._state);switch(t?.status){case"done":this.update(this._state);case"error":return this}if(this.logic.start)try{this.logic.start(this._state,this._actorContext)}catch(t){return this._stopProcedure(),this._error(t),this._parent?.send(o(this.id,t)),this}return this.update(this._state),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let e,s;try{e=this.logic.transition(this._state,t,this._actorContext)}catch(t){s={err:t}}if(s){const{err:t}=s;return this._stopProcedure(),this._error(t),void this._parent?.send(o(this.id,t))}this.update(e),t.type===i&&(this._stopProcedure(),this._complete())}_stop(){return this.status===u.Stopped?this:(this.mailbox.clear(),this.status===u.NotStarted?(this.status=u.Stopped,this):(this.mailbox.enqueue({type:i}),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)try{t.complete?.()}catch(t){c(t)}this.observers.clear()}_error(t){if(!this.observers.size)return void(this._parent||c(t));let e=!1;for(const s of this.observers){const i=s.error;e||=!i;try{i?.(t)}catch(t){c(t)}}this.observers.clear(),e&&c(t)}_stopProcedure(){if(this.status!==u.Running)return this;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.mailbox.clear(),this.mailbox=new e(this._process.bind(this)),this.status=u.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!==u.Stopped){if(this.status!==u.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({event:t,id:e,delay:s,to:i}){const n=this.clock.setTimeout((()=>{i?i.send(t):this.send(t)}),s);e&&(this.delayedEventsMap[e]=n)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}attachDevTools(){const{devTools:t}=this.options;if(t){("function"==typeof t?t:a)(this)}}toJSON(){return{id:this.id}}getPersistedState(){return this.logic.getPersistedState?.(this._state)}[d](){return this}getSnapshot(){return this.logic.getSnapshot?this.logic.getSnapshot(this._state):this._state}}function l(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 f="$$xstate.resolve",_="$$xstate.reject";const v=l((t=>{}),void 0);t.createEmptyActor=function(){return new p(v,t);var t},t.fromCallback=function(t){return{config:t,start:(t,{self:e})=>{e.send({type:s})},transition:(e,r,{self:a,id:c,system:d})=>{if(r.type===s){const s=t=>{e.canceled||a._parent?.send(t)},i=t=>{e.receivers.add(t)};return e.dispose=t({input:e.input,system:d,self:a,sendBack:s,receive:i}),((u=e.dispose)instanceof Promise||null!==u&&("function"==typeof u||"object"==typeof u)&&"function"==typeof u.then)&&e.dispose.then((t=>{a._parent?.send(n(c,t)),e.canceled=!0}),(t=>{e.canceled=!0,a._parent?.send(o(c,t))})),e}var u;return r.type===i?(e.canceled=!0,"function"==typeof e.dispose&&e.dispose(),e):(e.receivers.forEach((t=>t(r))),e)},getInitialState:(t,e)=>({canceled:!1,receivers:new Set,dispose:void 0,input:e}),getSnapshot:()=>{},getPersistedState:({input:t,canceled:e})=>({input:t,canceled:e})}},t.fromEventObservable=function(t){const e="$$xstate.error",s="$$xstate.complete";return{config:t,transition:(t,n)=>{if("active"!==t.status)return t;switch(n.type){case e:return{...t,status:"error",input:void 0,data:n.data,subscription:void 0};case s:return{...t,status:"done",input:void 0,subscription:void 0};case i: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,system:o})=>{"done"!==i.status&&(i.subscription=t({input:i.input,system:o,self:n}).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",n="$$xstate.complete";return{config:t,transition:(t,o,{self:r,id:a,defer:c})=>{if("active"!==t.status)return t;switch(o.type){case e:return c((()=>{r._parent?.send({type:`xstate.snapshot.${a}`,data:o.data})})),{...t,data:o.data};case s:return{...t,status:"error",input:void 0,data:o.data,subscription:void 0};case n:return{...t,status:"done",input:void 0,subscription:void 0};case i: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:o,system:r})=>{"done"!==i.status&&(i.subscription=t({input:i.input,system:r,self:o}).subscribe({next:t=>{o.send({type:e,data:t})},error:t=>{o.send({type:s,data:t})},complete:()=>{o.send({type:n})}}))},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){return{config:t,transition:(t,e)=>{if("active"!==t.status)return t;switch(e.type){case f:return{...t,status:"done",data:e.data,input:void 0};case _:return{...t,status:"error",data:e.data,input:void 0};case i:return{...t,status:"canceled",input:void 0};default:return t}},start:(e,{self:s,system:i})=>{if("active"!==e.status)return;Promise.resolve(t({input:e.input,system:i,self:s})).then((t=>{"active"===s._state.status&&s.send({type:f,data:t})}),(t=>{"active"===s._state.status&&s.send({type:_,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=l,t.isActorRef=function(t){return!!t&&"object"==typeof t&&"function"==typeof t.send},t.toActorRef=function(t){return{subscribe:()=>({unsubscribe:()=>{}}),id:"anonymous",sessionId:"",getSnapshot:()=>{},[d]:function(){return this},status:u.Running,stop:()=>{},...t}},Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
1
|
+
!function(t,s){"object"==typeof exports&&"undefined"!=typeof module?s(exports):"function"==typeof define&&define.amd?define(["exports"],s):s((t="undefined"!=typeof globalThis?globalThis:t||self).XStateActors={})}(this,(function(t){"use strict";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 s={value:t,next:null};if(this._current)return this._last.next=s,void(this._last=s);this._current=s,this._last=s,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}}const e="xstate.init",i="xstate.stop";function r(t,s){return{type:`xstate.error.actor.${t}`,data:s}}function o(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const n=t=>{const s=o();s&&s.register(t)};function a(t){setTimeout((()=>{throw t}))}const c="function"==typeof Symbol&&Symbol.observable||"@@observable";let d=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const h={clock:{setTimeout:(t,s)=>setTimeout(t,s),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class u{constructor(t,e){this.logic=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={...h,...e},{clock:r,logger:o,parent:n,id:a,systemId:c}=i;this.system=n?.system??function(){let t=0;const s=new Map,e=new Map,i=new WeakMap;return{_bookId:()=>"x:"+t++,_register:(t,e)=>(s.set(t,e),t),_unregister:t=>{s.delete(t.sessionId);const r=i.get(t);void 0!==r&&(e.delete(r),i.delete(t))},get:t=>e.get(t),_set:(t,s)=>{const r=e.get(t);if(r&&r!==s)throw new Error(`Actor with system ID '${t}' already exists.`);e.set(t,s),i.set(s,t)}}}(),c&&(this._systemId=c,this.system._set(c,this)),this.sessionId=this.system._bookId(),this.id=a??this.sessionId,this.logger=o,this.clock=r,this._parent=n,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.logic.restoreState?this.logic.restoreState(this.options.state,this._actorContext):this.options.state:this.logic.getInitialState(this._actorContext,this.options?.input)}update(t){this._state=t;const s=this.getSnapshot();let e;for(;e=this._deferred.shift();)e();for(const t of this.observers)try{t.next?.(s)}catch(t){a(t)}const i=this.logic.getStatus?.(t);switch(i?.status){case"done":this._stopProcedure(),this._complete(),this._doneEvent=(o=this.id,n=i.data,{type:`xstate.done.actor.${o}`,output:n}),this._parent?.send(this._doneEvent);break;case"error":this._stopProcedure(),this._error(i.data),this._parent?.send(r(this.id,i.data))}var o,n}subscribe(t,s,e){const i=function(t,s,e){const i="object"==typeof t,r=i?t:void 0;return{next:(i?t.next:t)?.bind(r),error:(i?t.error:s)?.bind(r),complete:(i?t.complete:e)?.bind(r)}}(t,s,e);if(this.status!==d.Stopped)this.observers.add(i);else try{i.complete?.()}catch(t){a(t)}return{unsubscribe:()=>{this.observers.delete(i)}}}start(){if(this.status===d.Running)return this;this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this.status=d.Running;const t=this.logic.getStatus?.(this._state);switch(t?.status){case"done":this.update(this._state);case"error":return this}if(this.logic.start)try{this.logic.start(this._state,this._actorContext)}catch(t){return this._stopProcedure(),this._error(t),this._parent?.send(r(this.id,t)),this}return this.update(this._state),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let s,e;try{s=this.logic.transition(this._state,t,this._actorContext)}catch(t){e={err:t}}if(e){const{err:t}=e;return this._stopProcedure(),this._error(t),void this._parent?.send(r(this.id,t))}this.update(s),t.type===i&&(this._stopProcedure(),this._complete())}_stop(){return this.status===d.Stopped?this:(this.mailbox.clear(),this.status===d.NotStarted?(this.status=d.Stopped,this):(this.mailbox.enqueue({type:i}),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)try{t.complete?.()}catch(t){a(t)}this.observers.clear()}_error(t){if(!this.observers.size)return void(this._parent||a(t));let s=!1;for(const e of this.observers){const i=e.error;s||=!i;try{i?.(t)}catch(t){a(t)}}this.observers.clear(),s&&a(t)}_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`);this.status!==d.Stopped&&this.mailbox.enqueue(t)}delaySend({event:t,id:s,delay:e,to:i}){const r=this.clock.setTimeout((()=>{i?i.send(t):this.send(t)}),e);s&&(this.delayedEventsMap[s]=r)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}attachDevTools(){const{devTools:t}=this.options;if(t){("function"==typeof t?t:n)(this)}}toJSON(){return{id:this.id}}getPersistedState(){return this.logic.getPersistedState?.(this._state)}[c](){return this}getSnapshot(){return this.logic.getSnapshot?this.logic.getSnapshot(this._state):this._state}}function p(t,s){return{config:t,transition:(s,e,i)=>t(s,e,i),getInitialState:(t,e)=>"function"==typeof s?s({input:e}):s,getSnapshot:t=>t,getPersistedState:t=>t,restoreState:t=>t}}const l="$$xstate.resolve",f="$$xstate.reject";const _=p((t=>{}),void 0);t.createEmptyActor=function(){return new u(_,t);var t},t.fromCallback=function(t){return{config:t,start:(t,{self:s})=>{s.send({type:e})},transition:(s,r,{self:o,id:n,system:a})=>{if(r.type===e){const e=t=>{s.canceled||o._parent?.send(t)},i=t=>{s.receivers.add(t)};return s.dispose=t({input:s.input,system:a,self:o,sendBack:e,receive:i}),s}return r.type===i?(s.canceled=!0,"function"==typeof s.dispose&&s.dispose(),s):(s.receivers.forEach((t=>t(r))),s)},getInitialState:(t,s)=>({canceled:!1,receivers:new Set,dispose:void 0,input:s}),getSnapshot:()=>{},getPersistedState:({input:t,canceled:s})=>({input:t,canceled:s})}},t.fromEventObservable=function(t){const s="$$xstate.error",e="$$xstate.complete";return{config:t,transition:(t,r)=>{if("active"!==t.status)return t;switch(r.type){case s:return{...t,status:"error",input:void 0,data:r.data,subscription:void 0};case e:return{...t,status:"done",input:void 0,subscription:void 0};case i:return t.subscription.unsubscribe(),{...t,status:"canceled",input:void 0,subscription:void 0};default:return t}},getInitialState:(t,s)=>({subscription:void 0,status:"active",data:void 0,input:s}),start:(i,{self:r,system:o})=>{"done"!==i.status&&(i.subscription=t({input:i.input,system:o,self:r}).subscribe({next:t=>{r._parent?.send(t)},error:t=>{r.send({type:s,data:t})},complete:()=>{r.send({type:e})}}))},getSnapshot:t=>{},getPersistedState:({status:t,data:s,input:e})=>({status:t,data:s,input:e}),getStatus:t=>t,restoreState:t=>({...t,subscription:void 0})}},t.fromObservable=function(t){const s="$$xstate.next",e="$$xstate.error",r="$$xstate.complete";return{config:t,transition:(t,o,{self:n,id:a,defer:c})=>{if("active"!==t.status)return t;switch(o.type){case s:return c((()=>{n._parent?.send({type:`xstate.snapshot.${a}`,data:o.data})})),{...t,data:o.data};case e:return{...t,status:"error",input:void 0,data:o.data,subscription:void 0};case r:return{...t,status:"done",input:void 0,subscription:void 0};case i:return t.subscription.unsubscribe(),{...t,status:"canceled",input:void 0,subscription:void 0};default:return t}},getInitialState:(t,s)=>({subscription:void 0,status:"active",data:void 0,input:s}),start:(i,{self:o,system:n})=>{"done"!==i.status&&(i.subscription=t({input:i.input,system:n,self:o}).subscribe({next:t=>{o.send({type:s,data:t})},error:t=>{o.send({type:e,data:t})},complete:()=>{o.send({type:r})}}))},getSnapshot:t=>t.data,getPersistedState:({status:t,data:s,input:e})=>({status:t,data:s,input:e}),getStatus:t=>t,restoreState:t=>({...t,subscription:void 0})}},t.fromPromise=function(t){return{config:t,transition:(t,s)=>{if("active"!==t.status)return t;switch(s.type){case l:return{...t,status:"done",data:s.data,input:void 0};case f:return{...t,status:"error",data:s.data,input:void 0};case i:return{...t,status:"canceled",input:void 0};default:return t}},start:(s,{self:e,system:i})=>{if("active"!==s.status)return;Promise.resolve(t({input:s.input,system:i,self:e})).then((t=>{"active"===e._state.status&&e.send({type:l,data:t})}),(t=>{"active"===e._state.status&&e.send({type:f,data:t})}))},getInitialState:(t,s)=>({status:"active",data:void 0,input:s}),getSnapshot:t=>t.data,getStatus:t=>t,getPersistedState:t=>t,restoreState:t=>t}},t.fromTransition=p,Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
2
2
|
//# sourceMappingURL=xstate-actors.umd.min.js.map
|