xstate 5.0.0-beta.40 → 5.0.0-beta.42
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 -1
- package/actors/dist/xstate-actors.development.cjs.js +1 -1
- package/actors/dist/xstate-actors.development.esm.js +1 -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/declarations/src/State.d.ts +36 -43
- package/dist/declarations/src/StateMachine.d.ts +13 -30
- package/dist/declarations/src/StateNode.d.ts +2 -2
- package/dist/declarations/src/index.d.ts +4 -5
- package/dist/declarations/src/interpreter.d.ts +14 -10
- package/dist/declarations/src/stateUtils.d.ts +7 -8
- package/dist/declarations/src/types.d.ts +114 -22
- package/dist/{interpreter-bae5c279.development.cjs.js → interpreter-23e4041c.development.cjs.js} +49 -42
- package/dist/{interpreter-ed0fac7e.esm.js → interpreter-3d0c0ff2.esm.js} +49 -40
- package/dist/{interpreter-586abde4.cjs.js → interpreter-b6bdd134.cjs.js} +49 -42
- package/dist/{interpreter-410d7ca9.development.esm.js → interpreter-f2620ea7.development.esm.js} +49 -40
- package/dist/{raise-37f9f3b8.development.esm.js → raise-51ae36e5.development.esm.js} +84 -183
- package/dist/{raise-27909189.cjs.js → raise-6b64c553.cjs.js} +81 -181
- package/dist/{raise-8325e2df.development.cjs.js → raise-8f482ce9.development.cjs.js} +85 -185
- package/dist/{raise-2b2fdec3.esm.js → raise-d2084327.esm.js} +80 -179
- package/dist/{send-59f66c58.esm.js → send-4e732fa5.esm.js} +7 -6
- package/dist/{send-f6b49072.development.esm.js → send-7a350091.development.esm.js} +7 -6
- package/dist/{send-4fdf275e.cjs.js → send-85b562d8.cjs.js} +7 -6
- package/dist/{send-c45d0d2c.development.cjs.js → send-cc8f864e.development.cjs.js} +7 -6
- package/dist/xstate.cjs.js +27 -56
- package/dist/xstate.cjs.mjs +0 -4
- package/dist/xstate.development.cjs.js +27 -56
- package/dist/xstate.development.cjs.mjs +0 -4
- package/dist/xstate.development.esm.js +31 -56
- package/dist/xstate.esm.js +31 -56
- 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
- package/dist/declarations/src/mapState.d.ts +0 -3
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
import { devToolsAdapter } from '../dev/dist/xstate-dev.esm.js';
|
|
2
2
|
|
|
3
|
-
const STATE_DELIMITER = '.';
|
|
4
|
-
const TARGETLESS_KEY = '';
|
|
5
|
-
const NULL_EVENT = '';
|
|
6
|
-
const STATE_IDENTIFIER = '#';
|
|
7
|
-
const WILDCARD = '*';
|
|
8
|
-
const XSTATE_INIT = 'xstate.init';
|
|
9
|
-
const XSTATE_ERROR = 'xstate.error';
|
|
10
|
-
const XSTATE_STOP = 'xstate.stop';
|
|
11
|
-
|
|
12
3
|
class Mailbox {
|
|
13
4
|
constructor(_process) {
|
|
14
5
|
this._process = _process;
|
|
@@ -56,6 +47,15 @@ class Mailbox {
|
|
|
56
47
|
}
|
|
57
48
|
}
|
|
58
49
|
|
|
50
|
+
const STATE_DELIMITER = '.';
|
|
51
|
+
const TARGETLESS_KEY = '';
|
|
52
|
+
const NULL_EVENT = '';
|
|
53
|
+
const STATE_IDENTIFIER = '#';
|
|
54
|
+
const WILDCARD = '*';
|
|
55
|
+
const XSTATE_INIT = 'xstate.init';
|
|
56
|
+
const XSTATE_ERROR = 'xstate.error';
|
|
57
|
+
const XSTATE_STOP = 'xstate.stop';
|
|
58
|
+
|
|
59
59
|
/**
|
|
60
60
|
* Returns an event that represents an implicit event that
|
|
61
61
|
* is sent after the specified `delay`.
|
|
@@ -331,17 +331,13 @@ function resolveReferencedActor(machine, src) {
|
|
|
331
331
|
}
|
|
332
332
|
|
|
333
333
|
const $$ACTOR_TYPE = 1;
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
334
|
+
// those values are currently used by @xstate/react directly so it's important to keep the assigned values in sync
|
|
335
|
+
let ProcessingStatus = /*#__PURE__*/function (ProcessingStatus) {
|
|
336
|
+
ProcessingStatus[ProcessingStatus["NotStarted"] = 0] = "NotStarted";
|
|
337
|
+
ProcessingStatus[ProcessingStatus["Running"] = 1] = "Running";
|
|
338
|
+
ProcessingStatus[ProcessingStatus["Stopped"] = 2] = "Stopped";
|
|
339
|
+
return ProcessingStatus;
|
|
339
340
|
}({});
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* @deprecated Use `ActorStatus` instead.
|
|
343
|
-
*/
|
|
344
|
-
const InterpreterStatus = ActorStatus;
|
|
345
341
|
const defaultOptions = {
|
|
346
342
|
clock: {
|
|
347
343
|
setTimeout: (fn, ms) => {
|
|
@@ -371,9 +367,7 @@ class Actor {
|
|
|
371
367
|
* The unique identifier for this actor relative to its parent.
|
|
372
368
|
*/
|
|
373
369
|
|
|
374
|
-
/**
|
|
375
|
-
* Whether the service is started.
|
|
376
|
-
*/
|
|
370
|
+
/** @internal */
|
|
377
371
|
|
|
378
372
|
// Actor Ref
|
|
379
373
|
|
|
@@ -403,7 +397,7 @@ class Actor {
|
|
|
403
397
|
this.delayedEventsMap = {};
|
|
404
398
|
this.observers = new Set();
|
|
405
399
|
this.logger = void 0;
|
|
406
|
-
this.
|
|
400
|
+
this._processingStatus = ProcessingStatus.NotStarted;
|
|
407
401
|
this._parent = void 0;
|
|
408
402
|
this.ref = void 0;
|
|
409
403
|
this._actorScope = void 0;
|
|
@@ -436,7 +430,7 @@ class Actor {
|
|
|
436
430
|
this.clock = clock;
|
|
437
431
|
this._parent = parent;
|
|
438
432
|
this.options = resolvedOptions;
|
|
439
|
-
this.src = resolvedOptions.src;
|
|
433
|
+
this.src = resolvedOptions.src ?? logic;
|
|
440
434
|
this.ref = this;
|
|
441
435
|
this._actorScope = {
|
|
442
436
|
self: this,
|
|
@@ -462,14 +456,14 @@ class Actor {
|
|
|
462
456
|
type: '@xstate.actor',
|
|
463
457
|
actorRef: this
|
|
464
458
|
});
|
|
465
|
-
this._initState();
|
|
459
|
+
this._initState(options?.state);
|
|
466
460
|
if (systemId && this._state.status === 'active') {
|
|
467
461
|
this._systemId = systemId;
|
|
468
462
|
this.system._set(systemId, this);
|
|
469
463
|
}
|
|
470
464
|
}
|
|
471
|
-
_initState() {
|
|
472
|
-
this._state =
|
|
465
|
+
_initState(persistedState) {
|
|
466
|
+
this._state = persistedState ? this.logic.restoreState ? this.logic.restoreState(persistedState, this._actorScope) : persistedState : this.logic.getInitialState(this._actorScope, this.options?.input);
|
|
473
467
|
}
|
|
474
468
|
|
|
475
469
|
// array of functions to defer
|
|
@@ -484,7 +478,6 @@ class Actor {
|
|
|
484
478
|
deferredFn();
|
|
485
479
|
}
|
|
486
480
|
for (const observer of this.observers) {
|
|
487
|
-
// TODO: should observers be notified in case of the error?
|
|
488
481
|
try {
|
|
489
482
|
observer.next?.(snapshot);
|
|
490
483
|
} catch (err) {
|
|
@@ -567,7 +560,7 @@ class Actor {
|
|
|
567
560
|
|
|
568
561
|
subscribe(nextListenerOrObserver, errorListener, completeListener) {
|
|
569
562
|
const observer = toObserver(nextListenerOrObserver, errorListener, completeListener);
|
|
570
|
-
if (this.
|
|
563
|
+
if (this._processingStatus !== ProcessingStatus.Stopped) {
|
|
571
564
|
this.observers.add(observer);
|
|
572
565
|
} else {
|
|
573
566
|
try {
|
|
@@ -587,7 +580,7 @@ class Actor {
|
|
|
587
580
|
* Starts the Actor from the initial state
|
|
588
581
|
*/
|
|
589
582
|
start() {
|
|
590
|
-
if (this.
|
|
583
|
+
if (this._processingStatus === ProcessingStatus.Running) {
|
|
591
584
|
// Do not restart the service if it is already started
|
|
592
585
|
return this;
|
|
593
586
|
}
|
|
@@ -595,7 +588,9 @@ class Actor {
|
|
|
595
588
|
if (this._systemId) {
|
|
596
589
|
this.system._set(this._systemId, this);
|
|
597
590
|
}
|
|
598
|
-
this.
|
|
591
|
+
this._processingStatus = ProcessingStatus.Running;
|
|
592
|
+
|
|
593
|
+
// TODO: this isn't correct when rehydrating
|
|
599
594
|
const initEvent = createInitEvent(this.options.input);
|
|
600
595
|
this.system._sendInspectionEvent({
|
|
601
596
|
type: '@xstate.event',
|
|
@@ -663,12 +658,12 @@ class Actor {
|
|
|
663
658
|
}
|
|
664
659
|
}
|
|
665
660
|
_stop() {
|
|
666
|
-
if (this.
|
|
661
|
+
if (this._processingStatus === ProcessingStatus.Stopped) {
|
|
667
662
|
return this;
|
|
668
663
|
}
|
|
669
664
|
this.mailbox.clear();
|
|
670
|
-
if (this.
|
|
671
|
-
this.
|
|
665
|
+
if (this._processingStatus === ProcessingStatus.NotStarted) {
|
|
666
|
+
this._processingStatus = ProcessingStatus.Stopped;
|
|
672
667
|
return this;
|
|
673
668
|
}
|
|
674
669
|
this.mailbox.enqueue({
|
|
@@ -719,7 +714,7 @@ class Actor {
|
|
|
719
714
|
}
|
|
720
715
|
}
|
|
721
716
|
_stopProcedure() {
|
|
722
|
-
if (this.
|
|
717
|
+
if (this._processingStatus !== ProcessingStatus.Running) {
|
|
723
718
|
// Actor already stopped; do nothing
|
|
724
719
|
return this;
|
|
725
720
|
}
|
|
@@ -736,7 +731,7 @@ class Actor {
|
|
|
736
731
|
// it seems like this should be the common behavior for all of our consumers
|
|
737
732
|
// so perhaps this should be unified somehow for all of them
|
|
738
733
|
this.mailbox = new Mailbox(this._process.bind(this));
|
|
739
|
-
this.
|
|
734
|
+
this._processingStatus = ProcessingStatus.Stopped;
|
|
740
735
|
this.system._unregister(this);
|
|
741
736
|
return this;
|
|
742
737
|
}
|
|
@@ -745,7 +740,7 @@ class Actor {
|
|
|
745
740
|
* @internal
|
|
746
741
|
*/
|
|
747
742
|
_send(event) {
|
|
748
|
-
if (this.
|
|
743
|
+
if (this._processingStatus === ProcessingStatus.Stopped) {
|
|
749
744
|
return;
|
|
750
745
|
}
|
|
751
746
|
this.mailbox.enqueue(event);
|
|
@@ -803,8 +798,22 @@ class Actor {
|
|
|
803
798
|
id: this.id
|
|
804
799
|
};
|
|
805
800
|
}
|
|
806
|
-
|
|
807
|
-
|
|
801
|
+
|
|
802
|
+
/**
|
|
803
|
+
* Obtain the internal state of the actor, which can be persisted.
|
|
804
|
+
*
|
|
805
|
+
* @remarks
|
|
806
|
+
* The internal state can be persisted from any actor, not only machines.
|
|
807
|
+
*
|
|
808
|
+
* Note that the persisted state is not the same as the snapshot from {@link Actor.getSnapshot}. Persisted state represents the internal state of the actor, while snapshots represent the actor's last emitted value.
|
|
809
|
+
*
|
|
810
|
+
* Can be restored with {@link ActorOptions.state}
|
|
811
|
+
*
|
|
812
|
+
* @see https://stately.ai/docs/persistence
|
|
813
|
+
*/
|
|
814
|
+
|
|
815
|
+
getPersistedState(options) {
|
|
816
|
+
return this.logic.getPersistedState(this._state, options);
|
|
808
817
|
}
|
|
809
818
|
[symbolObservable]() {
|
|
810
819
|
return this;
|
|
@@ -852,4 +861,4 @@ const interpret = createActor;
|
|
|
852
861
|
* @deprecated Use `Actor` instead.
|
|
853
862
|
*/
|
|
854
863
|
|
|
855
|
-
export { $$ACTOR_TYPE as $, Actor as A,
|
|
864
|
+
export { $$ACTOR_TYPE as $, Actor as A, NULL_EVENT as N, ProcessingStatus as P, STATE_DELIMITER as S, WILDCARD as W, XSTATE_STOP as X, toTransitionConfigArray as a, createInitEvent as b, createInvokeId as c, createActor as d, interpret as e, matchesState as f, toObserver as g, createErrorActorEvent as h, isErrorActorEvent as i, STATE_IDENTIFIER as j, toStatePath as k, createDoneStateEvent as l, mapValues as m, normalizeTarget as n, resolveOutput as o, pathToStateValue as p, XSTATE_INIT as q, resolveReferencedActor as r, createAfterEvent as s, toArray as t, flatten as u, XSTATE_ERROR as v };
|
|
@@ -2,15 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
var dev_dist_xstateDev = require('../dev/dist/xstate-dev.cjs.js');
|
|
4
4
|
|
|
5
|
-
const STATE_DELIMITER = '.';
|
|
6
|
-
const TARGETLESS_KEY = '';
|
|
7
|
-
const NULL_EVENT = '';
|
|
8
|
-
const STATE_IDENTIFIER = '#';
|
|
9
|
-
const WILDCARD = '*';
|
|
10
|
-
const XSTATE_INIT = 'xstate.init';
|
|
11
|
-
const XSTATE_ERROR = 'xstate.error';
|
|
12
|
-
const XSTATE_STOP = 'xstate.stop';
|
|
13
|
-
|
|
14
5
|
class Mailbox {
|
|
15
6
|
constructor(_process) {
|
|
16
7
|
this._process = _process;
|
|
@@ -58,6 +49,15 @@ class Mailbox {
|
|
|
58
49
|
}
|
|
59
50
|
}
|
|
60
51
|
|
|
52
|
+
const STATE_DELIMITER = '.';
|
|
53
|
+
const TARGETLESS_KEY = '';
|
|
54
|
+
const NULL_EVENT = '';
|
|
55
|
+
const STATE_IDENTIFIER = '#';
|
|
56
|
+
const WILDCARD = '*';
|
|
57
|
+
const XSTATE_INIT = 'xstate.init';
|
|
58
|
+
const XSTATE_ERROR = 'xstate.error';
|
|
59
|
+
const XSTATE_STOP = 'xstate.stop';
|
|
60
|
+
|
|
61
61
|
/**
|
|
62
62
|
* Returns an event that represents an implicit event that
|
|
63
63
|
* is sent after the specified `delay`.
|
|
@@ -333,17 +333,13 @@ function resolveReferencedActor(machine, src) {
|
|
|
333
333
|
}
|
|
334
334
|
|
|
335
335
|
const $$ACTOR_TYPE = 1;
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
336
|
+
// those values are currently used by @xstate/react directly so it's important to keep the assigned values in sync
|
|
337
|
+
let ProcessingStatus = /*#__PURE__*/function (ProcessingStatus) {
|
|
338
|
+
ProcessingStatus[ProcessingStatus["NotStarted"] = 0] = "NotStarted";
|
|
339
|
+
ProcessingStatus[ProcessingStatus["Running"] = 1] = "Running";
|
|
340
|
+
ProcessingStatus[ProcessingStatus["Stopped"] = 2] = "Stopped";
|
|
341
|
+
return ProcessingStatus;
|
|
341
342
|
}({});
|
|
342
|
-
|
|
343
|
-
/**
|
|
344
|
-
* @deprecated Use `ActorStatus` instead.
|
|
345
|
-
*/
|
|
346
|
-
const InterpreterStatus = ActorStatus;
|
|
347
343
|
const defaultOptions = {
|
|
348
344
|
clock: {
|
|
349
345
|
setTimeout: (fn, ms) => {
|
|
@@ -373,9 +369,7 @@ class Actor {
|
|
|
373
369
|
* The unique identifier for this actor relative to its parent.
|
|
374
370
|
*/
|
|
375
371
|
|
|
376
|
-
/**
|
|
377
|
-
* Whether the service is started.
|
|
378
|
-
*/
|
|
372
|
+
/** @internal */
|
|
379
373
|
|
|
380
374
|
// Actor Ref
|
|
381
375
|
|
|
@@ -405,7 +399,7 @@ class Actor {
|
|
|
405
399
|
this.delayedEventsMap = {};
|
|
406
400
|
this.observers = new Set();
|
|
407
401
|
this.logger = void 0;
|
|
408
|
-
this.
|
|
402
|
+
this._processingStatus = ProcessingStatus.NotStarted;
|
|
409
403
|
this._parent = void 0;
|
|
410
404
|
this.ref = void 0;
|
|
411
405
|
this._actorScope = void 0;
|
|
@@ -438,7 +432,7 @@ class Actor {
|
|
|
438
432
|
this.clock = clock;
|
|
439
433
|
this._parent = parent;
|
|
440
434
|
this.options = resolvedOptions;
|
|
441
|
-
this.src = resolvedOptions.src;
|
|
435
|
+
this.src = resolvedOptions.src ?? logic;
|
|
442
436
|
this.ref = this;
|
|
443
437
|
this._actorScope = {
|
|
444
438
|
self: this,
|
|
@@ -464,14 +458,14 @@ class Actor {
|
|
|
464
458
|
type: '@xstate.actor',
|
|
465
459
|
actorRef: this
|
|
466
460
|
});
|
|
467
|
-
this._initState();
|
|
461
|
+
this._initState(options?.state);
|
|
468
462
|
if (systemId && this._state.status === 'active') {
|
|
469
463
|
this._systemId = systemId;
|
|
470
464
|
this.system._set(systemId, this);
|
|
471
465
|
}
|
|
472
466
|
}
|
|
473
|
-
_initState() {
|
|
474
|
-
this._state =
|
|
467
|
+
_initState(persistedState) {
|
|
468
|
+
this._state = persistedState ? this.logic.restoreState ? this.logic.restoreState(persistedState, this._actorScope) : persistedState : this.logic.getInitialState(this._actorScope, this.options?.input);
|
|
475
469
|
}
|
|
476
470
|
|
|
477
471
|
// array of functions to defer
|
|
@@ -486,7 +480,6 @@ class Actor {
|
|
|
486
480
|
deferredFn();
|
|
487
481
|
}
|
|
488
482
|
for (const observer of this.observers) {
|
|
489
|
-
// TODO: should observers be notified in case of the error?
|
|
490
483
|
try {
|
|
491
484
|
observer.next?.(snapshot);
|
|
492
485
|
} catch (err) {
|
|
@@ -569,7 +562,7 @@ class Actor {
|
|
|
569
562
|
|
|
570
563
|
subscribe(nextListenerOrObserver, errorListener, completeListener) {
|
|
571
564
|
const observer = toObserver(nextListenerOrObserver, errorListener, completeListener);
|
|
572
|
-
if (this.
|
|
565
|
+
if (this._processingStatus !== ProcessingStatus.Stopped) {
|
|
573
566
|
this.observers.add(observer);
|
|
574
567
|
} else {
|
|
575
568
|
try {
|
|
@@ -589,7 +582,7 @@ class Actor {
|
|
|
589
582
|
* Starts the Actor from the initial state
|
|
590
583
|
*/
|
|
591
584
|
start() {
|
|
592
|
-
if (this.
|
|
585
|
+
if (this._processingStatus === ProcessingStatus.Running) {
|
|
593
586
|
// Do not restart the service if it is already started
|
|
594
587
|
return this;
|
|
595
588
|
}
|
|
@@ -597,7 +590,9 @@ class Actor {
|
|
|
597
590
|
if (this._systemId) {
|
|
598
591
|
this.system._set(this._systemId, this);
|
|
599
592
|
}
|
|
600
|
-
this.
|
|
593
|
+
this._processingStatus = ProcessingStatus.Running;
|
|
594
|
+
|
|
595
|
+
// TODO: this isn't correct when rehydrating
|
|
601
596
|
const initEvent = createInitEvent(this.options.input);
|
|
602
597
|
this.system._sendInspectionEvent({
|
|
603
598
|
type: '@xstate.event',
|
|
@@ -665,12 +660,12 @@ class Actor {
|
|
|
665
660
|
}
|
|
666
661
|
}
|
|
667
662
|
_stop() {
|
|
668
|
-
if (this.
|
|
663
|
+
if (this._processingStatus === ProcessingStatus.Stopped) {
|
|
669
664
|
return this;
|
|
670
665
|
}
|
|
671
666
|
this.mailbox.clear();
|
|
672
|
-
if (this.
|
|
673
|
-
this.
|
|
667
|
+
if (this._processingStatus === ProcessingStatus.NotStarted) {
|
|
668
|
+
this._processingStatus = ProcessingStatus.Stopped;
|
|
674
669
|
return this;
|
|
675
670
|
}
|
|
676
671
|
this.mailbox.enqueue({
|
|
@@ -721,7 +716,7 @@ class Actor {
|
|
|
721
716
|
}
|
|
722
717
|
}
|
|
723
718
|
_stopProcedure() {
|
|
724
|
-
if (this.
|
|
719
|
+
if (this._processingStatus !== ProcessingStatus.Running) {
|
|
725
720
|
// Actor already stopped; do nothing
|
|
726
721
|
return this;
|
|
727
722
|
}
|
|
@@ -738,7 +733,7 @@ class Actor {
|
|
|
738
733
|
// it seems like this should be the common behavior for all of our consumers
|
|
739
734
|
// so perhaps this should be unified somehow for all of them
|
|
740
735
|
this.mailbox = new Mailbox(this._process.bind(this));
|
|
741
|
-
this.
|
|
736
|
+
this._processingStatus = ProcessingStatus.Stopped;
|
|
742
737
|
this.system._unregister(this);
|
|
743
738
|
return this;
|
|
744
739
|
}
|
|
@@ -747,7 +742,7 @@ class Actor {
|
|
|
747
742
|
* @internal
|
|
748
743
|
*/
|
|
749
744
|
_send(event) {
|
|
750
|
-
if (this.
|
|
745
|
+
if (this._processingStatus === ProcessingStatus.Stopped) {
|
|
751
746
|
return;
|
|
752
747
|
}
|
|
753
748
|
this.mailbox.enqueue(event);
|
|
@@ -805,8 +800,22 @@ class Actor {
|
|
|
805
800
|
id: this.id
|
|
806
801
|
};
|
|
807
802
|
}
|
|
808
|
-
|
|
809
|
-
|
|
803
|
+
|
|
804
|
+
/**
|
|
805
|
+
* Obtain the internal state of the actor, which can be persisted.
|
|
806
|
+
*
|
|
807
|
+
* @remarks
|
|
808
|
+
* The internal state can be persisted from any actor, not only machines.
|
|
809
|
+
*
|
|
810
|
+
* Note that the persisted state is not the same as the snapshot from {@link Actor.getSnapshot}. Persisted state represents the internal state of the actor, while snapshots represent the actor's last emitted value.
|
|
811
|
+
*
|
|
812
|
+
* Can be restored with {@link ActorOptions.state}
|
|
813
|
+
*
|
|
814
|
+
* @see https://stately.ai/docs/persistence
|
|
815
|
+
*/
|
|
816
|
+
|
|
817
|
+
getPersistedState(options) {
|
|
818
|
+
return this.logic.getPersistedState(this._state, options);
|
|
810
819
|
}
|
|
811
820
|
[symbolObservable]() {
|
|
812
821
|
return this;
|
|
@@ -856,9 +865,8 @@ const interpret = createActor;
|
|
|
856
865
|
|
|
857
866
|
exports.$$ACTOR_TYPE = $$ACTOR_TYPE;
|
|
858
867
|
exports.Actor = Actor;
|
|
859
|
-
exports.ActorStatus = ActorStatus;
|
|
860
|
-
exports.InterpreterStatus = InterpreterStatus;
|
|
861
868
|
exports.NULL_EVENT = NULL_EVENT;
|
|
869
|
+
exports.ProcessingStatus = ProcessingStatus;
|
|
862
870
|
exports.STATE_DELIMITER = STATE_DELIMITER;
|
|
863
871
|
exports.STATE_IDENTIFIER = STATE_IDENTIFIER;
|
|
864
872
|
exports.WILDCARD = WILDCARD;
|
|
@@ -883,5 +891,4 @@ exports.resolveReferencedActor = resolveReferencedActor;
|
|
|
883
891
|
exports.toArray = toArray;
|
|
884
892
|
exports.toObserver = toObserver;
|
|
885
893
|
exports.toStatePath = toStatePath;
|
|
886
|
-
exports.toStateValue = toStateValue;
|
|
887
894
|
exports.toTransitionConfigArray = toTransitionConfigArray;
|
package/dist/{interpreter-410d7ca9.development.esm.js → interpreter-f2620ea7.development.esm.js}
RENAMED
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
import { devToolsAdapter } from '../dev/dist/xstate-dev.development.esm.js';
|
|
2
2
|
|
|
3
|
-
const STATE_DELIMITER = '.';
|
|
4
|
-
const TARGETLESS_KEY = '';
|
|
5
|
-
const NULL_EVENT = '';
|
|
6
|
-
const STATE_IDENTIFIER = '#';
|
|
7
|
-
const WILDCARD = '*';
|
|
8
|
-
const XSTATE_INIT = 'xstate.init';
|
|
9
|
-
const XSTATE_ERROR = 'xstate.error';
|
|
10
|
-
const XSTATE_STOP = 'xstate.stop';
|
|
11
|
-
|
|
12
3
|
class Mailbox {
|
|
13
4
|
constructor(_process) {
|
|
14
5
|
this._process = _process;
|
|
@@ -56,6 +47,15 @@ class Mailbox {
|
|
|
56
47
|
}
|
|
57
48
|
}
|
|
58
49
|
|
|
50
|
+
const STATE_DELIMITER = '.';
|
|
51
|
+
const TARGETLESS_KEY = '';
|
|
52
|
+
const NULL_EVENT = '';
|
|
53
|
+
const STATE_IDENTIFIER = '#';
|
|
54
|
+
const WILDCARD = '*';
|
|
55
|
+
const XSTATE_INIT = 'xstate.init';
|
|
56
|
+
const XSTATE_ERROR = 'xstate.error';
|
|
57
|
+
const XSTATE_STOP = 'xstate.stop';
|
|
58
|
+
|
|
59
59
|
/**
|
|
60
60
|
* Returns an event that represents an implicit event that
|
|
61
61
|
* is sent after the specified `delay`.
|
|
@@ -334,17 +334,13 @@ function resolveReferencedActor(machine, src) {
|
|
|
334
334
|
}
|
|
335
335
|
|
|
336
336
|
const $$ACTOR_TYPE = 1;
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
337
|
+
// those values are currently used by @xstate/react directly so it's important to keep the assigned values in sync
|
|
338
|
+
let ProcessingStatus = /*#__PURE__*/function (ProcessingStatus) {
|
|
339
|
+
ProcessingStatus[ProcessingStatus["NotStarted"] = 0] = "NotStarted";
|
|
340
|
+
ProcessingStatus[ProcessingStatus["Running"] = 1] = "Running";
|
|
341
|
+
ProcessingStatus[ProcessingStatus["Stopped"] = 2] = "Stopped";
|
|
342
|
+
return ProcessingStatus;
|
|
342
343
|
}({});
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* @deprecated Use `ActorStatus` instead.
|
|
346
|
-
*/
|
|
347
|
-
const InterpreterStatus = ActorStatus;
|
|
348
344
|
const defaultOptions = {
|
|
349
345
|
clock: {
|
|
350
346
|
setTimeout: (fn, ms) => {
|
|
@@ -374,9 +370,7 @@ class Actor {
|
|
|
374
370
|
* The unique identifier for this actor relative to its parent.
|
|
375
371
|
*/
|
|
376
372
|
|
|
377
|
-
/**
|
|
378
|
-
* Whether the service is started.
|
|
379
|
-
*/
|
|
373
|
+
/** @internal */
|
|
380
374
|
|
|
381
375
|
// Actor Ref
|
|
382
376
|
|
|
@@ -406,7 +400,7 @@ class Actor {
|
|
|
406
400
|
this.delayedEventsMap = {};
|
|
407
401
|
this.observers = new Set();
|
|
408
402
|
this.logger = void 0;
|
|
409
|
-
this.
|
|
403
|
+
this._processingStatus = ProcessingStatus.NotStarted;
|
|
410
404
|
this._parent = void 0;
|
|
411
405
|
this.ref = void 0;
|
|
412
406
|
this._actorScope = void 0;
|
|
@@ -439,7 +433,7 @@ class Actor {
|
|
|
439
433
|
this.clock = clock;
|
|
440
434
|
this._parent = parent;
|
|
441
435
|
this.options = resolvedOptions;
|
|
442
|
-
this.src = resolvedOptions.src;
|
|
436
|
+
this.src = resolvedOptions.src ?? logic;
|
|
443
437
|
this.ref = this;
|
|
444
438
|
this._actorScope = {
|
|
445
439
|
self: this,
|
|
@@ -465,14 +459,14 @@ class Actor {
|
|
|
465
459
|
type: '@xstate.actor',
|
|
466
460
|
actorRef: this
|
|
467
461
|
});
|
|
468
|
-
this._initState();
|
|
462
|
+
this._initState(options?.state);
|
|
469
463
|
if (systemId && this._state.status === 'active') {
|
|
470
464
|
this._systemId = systemId;
|
|
471
465
|
this.system._set(systemId, this);
|
|
472
466
|
}
|
|
473
467
|
}
|
|
474
|
-
_initState() {
|
|
475
|
-
this._state =
|
|
468
|
+
_initState(persistedState) {
|
|
469
|
+
this._state = persistedState ? this.logic.restoreState ? this.logic.restoreState(persistedState, this._actorScope) : persistedState : this.logic.getInitialState(this._actorScope, this.options?.input);
|
|
476
470
|
}
|
|
477
471
|
|
|
478
472
|
// array of functions to defer
|
|
@@ -487,7 +481,6 @@ class Actor {
|
|
|
487
481
|
deferredFn();
|
|
488
482
|
}
|
|
489
483
|
for (const observer of this.observers) {
|
|
490
|
-
// TODO: should observers be notified in case of the error?
|
|
491
484
|
try {
|
|
492
485
|
observer.next?.(snapshot);
|
|
493
486
|
} catch (err) {
|
|
@@ -570,7 +563,7 @@ class Actor {
|
|
|
570
563
|
|
|
571
564
|
subscribe(nextListenerOrObserver, errorListener, completeListener) {
|
|
572
565
|
const observer = toObserver(nextListenerOrObserver, errorListener, completeListener);
|
|
573
|
-
if (this.
|
|
566
|
+
if (this._processingStatus !== ProcessingStatus.Stopped) {
|
|
574
567
|
this.observers.add(observer);
|
|
575
568
|
} else {
|
|
576
569
|
try {
|
|
@@ -590,7 +583,7 @@ class Actor {
|
|
|
590
583
|
* Starts the Actor from the initial state
|
|
591
584
|
*/
|
|
592
585
|
start() {
|
|
593
|
-
if (this.
|
|
586
|
+
if (this._processingStatus === ProcessingStatus.Running) {
|
|
594
587
|
// Do not restart the service if it is already started
|
|
595
588
|
return this;
|
|
596
589
|
}
|
|
@@ -598,7 +591,9 @@ class Actor {
|
|
|
598
591
|
if (this._systemId) {
|
|
599
592
|
this.system._set(this._systemId, this);
|
|
600
593
|
}
|
|
601
|
-
this.
|
|
594
|
+
this._processingStatus = ProcessingStatus.Running;
|
|
595
|
+
|
|
596
|
+
// TODO: this isn't correct when rehydrating
|
|
602
597
|
const initEvent = createInitEvent(this.options.input);
|
|
603
598
|
this.system._sendInspectionEvent({
|
|
604
599
|
type: '@xstate.event',
|
|
@@ -666,12 +661,12 @@ class Actor {
|
|
|
666
661
|
}
|
|
667
662
|
}
|
|
668
663
|
_stop() {
|
|
669
|
-
if (this.
|
|
664
|
+
if (this._processingStatus === ProcessingStatus.Stopped) {
|
|
670
665
|
return this;
|
|
671
666
|
}
|
|
672
667
|
this.mailbox.clear();
|
|
673
|
-
if (this.
|
|
674
|
-
this.
|
|
668
|
+
if (this._processingStatus === ProcessingStatus.NotStarted) {
|
|
669
|
+
this._processingStatus = ProcessingStatus.Stopped;
|
|
675
670
|
return this;
|
|
676
671
|
}
|
|
677
672
|
this.mailbox.enqueue({
|
|
@@ -722,7 +717,7 @@ class Actor {
|
|
|
722
717
|
}
|
|
723
718
|
}
|
|
724
719
|
_stopProcedure() {
|
|
725
|
-
if (this.
|
|
720
|
+
if (this._processingStatus !== ProcessingStatus.Running) {
|
|
726
721
|
// Actor already stopped; do nothing
|
|
727
722
|
return this;
|
|
728
723
|
}
|
|
@@ -739,7 +734,7 @@ class Actor {
|
|
|
739
734
|
// it seems like this should be the common behavior for all of our consumers
|
|
740
735
|
// so perhaps this should be unified somehow for all of them
|
|
741
736
|
this.mailbox = new Mailbox(this._process.bind(this));
|
|
742
|
-
this.
|
|
737
|
+
this._processingStatus = ProcessingStatus.Stopped;
|
|
743
738
|
this.system._unregister(this);
|
|
744
739
|
return this;
|
|
745
740
|
}
|
|
@@ -748,7 +743,7 @@ class Actor {
|
|
|
748
743
|
* @internal
|
|
749
744
|
*/
|
|
750
745
|
_send(event) {
|
|
751
|
-
if (this.
|
|
746
|
+
if (this._processingStatus === ProcessingStatus.Stopped) {
|
|
752
747
|
// do nothing
|
|
753
748
|
{
|
|
754
749
|
const eventString = JSON.stringify(event);
|
|
@@ -814,8 +809,22 @@ class Actor {
|
|
|
814
809
|
id: this.id
|
|
815
810
|
};
|
|
816
811
|
}
|
|
817
|
-
|
|
818
|
-
|
|
812
|
+
|
|
813
|
+
/**
|
|
814
|
+
* Obtain the internal state of the actor, which can be persisted.
|
|
815
|
+
*
|
|
816
|
+
* @remarks
|
|
817
|
+
* The internal state can be persisted from any actor, not only machines.
|
|
818
|
+
*
|
|
819
|
+
* Note that the persisted state is not the same as the snapshot from {@link Actor.getSnapshot}. Persisted state represents the internal state of the actor, while snapshots represent the actor's last emitted value.
|
|
820
|
+
*
|
|
821
|
+
* Can be restored with {@link ActorOptions.state}
|
|
822
|
+
*
|
|
823
|
+
* @see https://stately.ai/docs/persistence
|
|
824
|
+
*/
|
|
825
|
+
|
|
826
|
+
getPersistedState(options) {
|
|
827
|
+
return this.logic.getPersistedState(this._state, options);
|
|
819
828
|
}
|
|
820
829
|
[symbolObservable]() {
|
|
821
830
|
return this;
|
|
@@ -863,4 +872,4 @@ const interpret = createActor;
|
|
|
863
872
|
* @deprecated Use `Actor` instead.
|
|
864
873
|
*/
|
|
865
874
|
|
|
866
|
-
export { $$ACTOR_TYPE as $, Actor as A,
|
|
875
|
+
export { $$ACTOR_TYPE as $, Actor as A, NULL_EVENT as N, ProcessingStatus as P, STATE_DELIMITER as S, WILDCARD as W, XSTATE_STOP as X, toTransitionConfigArray as a, createInitEvent as b, createInvokeId as c, createActor as d, interpret as e, matchesState as f, toObserver as g, createErrorActorEvent as h, isErrorActorEvent as i, STATE_IDENTIFIER as j, toStatePath as k, createDoneStateEvent as l, mapValues as m, normalizeTarget as n, resolveOutput as o, pathToStateValue as p, XSTATE_INIT as q, resolveReferencedActor as r, createAfterEvent as s, toArray as t, flatten as u, XSTATE_ERROR as v };
|