xstate 5.0.0-beta.39 → 5.0.0-beta.41
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 +2 -2
- package/actors/dist/xstate-actors.development.cjs.js +2 -2
- package/actors/dist/xstate-actors.development.esm.js +2 -2
- 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/dist/declarations/src/State.d.ts +1 -1
- package/dist/declarations/src/StateMachine.d.ts +1 -1
- package/dist/declarations/src/actors/callback.d.ts +1 -1
- package/dist/declarations/src/index.d.ts +2 -2
- package/dist/declarations/src/interpreter.d.ts +2 -10
- package/dist/declarations/src/system.d.ts +7 -3
- package/dist/declarations/src/types.d.ts +4 -9
- package/dist/{interpreter-1e8c1c0c.esm.js → interpreter-480db258.esm.js} +28 -33
- package/dist/{interpreter-03a5c3f5.development.cjs.js → interpreter-70ed981b.development.cjs.js} +28 -34
- package/dist/{interpreter-70cd9217.development.esm.js → interpreter-936da690.development.esm.js} +28 -33
- package/dist/{interpreter-5dfcd203.cjs.js → interpreter-fb2829f1.cjs.js} +28 -34
- package/dist/{raise-17cb3d9d.development.cjs.js → raise-5ab465ed.development.cjs.js} +9 -9
- package/dist/{raise-62de3670.esm.js → raise-9d6921da.esm.js} +8 -8
- package/dist/{raise-291d2181.cjs.js → raise-beae3fd3.cjs.js} +8 -8
- package/dist/{raise-e044f460.development.esm.js → raise-f757be00.development.esm.js} +9 -9
- package/dist/{send-1249d4ac.esm.js → send-a931d1b8.esm.js} +4 -5
- package/dist/{send-f1a2a827.development.esm.js → send-b26e3812.development.esm.js} +4 -5
- package/dist/{send-af152aca.cjs.js → send-ca5f706c.cjs.js} +4 -5
- package/dist/{send-33433787.development.cjs.js → send-fb87a01a.development.cjs.js} +4 -5
- package/dist/xstate.cjs.js +8 -10
- package/dist/xstate.cjs.mjs +0 -2
- package/dist/xstate.development.cjs.js +8 -10
- package/dist/xstate.development.cjs.mjs +0 -2
- package/dist/xstate.development.esm.js +11 -11
- package/dist/xstate.esm.js +11 -11
- 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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { StateNode } from "./StateNode.js";
|
|
2
2
|
import type { State } from "./State.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { Clock, Actor } from "./interpreter.js";
|
|
4
4
|
import type { MachineSnapshot, StateMachine } from "./StateMachine.js";
|
|
5
5
|
import { TypegenDisabled, ResolveTypegenMeta, TypegenConstraint, MarkAllImplementationsAsProvided, AreAllImplementationsAssumedToBeProvided } from "./typegenTypes.js";
|
|
6
6
|
import { PromiseActorLogic } from "./actors/promise.js";
|
|
@@ -559,10 +559,6 @@ export interface StateConfig<TContext extends MachineContext, TEvent extends Eve
|
|
|
559
559
|
machine?: StateMachine<TContext, TEvent, any, any, any, any, any, any, any>;
|
|
560
560
|
}
|
|
561
561
|
export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
562
|
-
/**
|
|
563
|
-
* Whether state actions should be executed immediately upon transition. Defaults to `true`.
|
|
564
|
-
*/
|
|
565
|
-
execute?: boolean;
|
|
566
562
|
clock?: Clock;
|
|
567
563
|
logger?: (...args: any[]) => void;
|
|
568
564
|
parent?: ActorRef<any, any>;
|
|
@@ -589,7 +585,7 @@ export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
|
589
585
|
/**
|
|
590
586
|
* The source definition.
|
|
591
587
|
*/
|
|
592
|
-
src?: string;
|
|
588
|
+
src?: string | AnyActorLogic;
|
|
593
589
|
inspect?: Observer<InspectionEvent> | ((inspectionEvent: InspectionEvent) => void);
|
|
594
590
|
}
|
|
595
591
|
export type AnyActor = Actor<any>;
|
|
@@ -636,8 +632,7 @@ export interface ActorRef<TEvent extends EventObject, TSnapshot extends Snapshot
|
|
|
636
632
|
toJSON?: () => any;
|
|
637
633
|
_parent?: ActorRef<any, any>;
|
|
638
634
|
system?: ActorSystem<any>;
|
|
639
|
-
|
|
640
|
-
src?: string;
|
|
635
|
+
src: string | AnyActorLogic;
|
|
641
636
|
}
|
|
642
637
|
export type AnyActorRef = ActorRef<any, any>;
|
|
643
638
|
export type ActorLogicFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<any, any, any, any, any, any, any, any, any> ? R : R extends Promise<infer U> ? PromiseActorLogic<U> : never : never;
|
|
@@ -694,7 +689,7 @@ export interface ActorLogic<TSnapshot extends Snapshot<unknown>, TEvent extends
|
|
|
694
689
|
/**
|
|
695
690
|
* @returns Persisted state
|
|
696
691
|
*/
|
|
697
|
-
getPersistedState: (state: TSnapshot) => Snapshot<unknown>;
|
|
692
|
+
getPersistedState: (state: TSnapshot, options?: unknown) => Snapshot<unknown>;
|
|
698
693
|
}
|
|
699
694
|
export type AnyActorLogic = ActorLogic<any, // snapshot
|
|
700
695
|
any, // event
|
|
@@ -172,7 +172,7 @@ function createSystem(rootActor) {
|
|
|
172
172
|
system._sendInspectionEvent({
|
|
173
173
|
type: '@xstate.event',
|
|
174
174
|
sourceRef: source,
|
|
175
|
-
|
|
175
|
+
actorRef: target,
|
|
176
176
|
event
|
|
177
177
|
});
|
|
178
178
|
target._send(event);
|
|
@@ -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,12 +588,14 @@ 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',
|
|
602
597
|
sourceRef: this._parent,
|
|
603
|
-
|
|
598
|
+
actorRef: this,
|
|
604
599
|
event: initEvent
|
|
605
600
|
});
|
|
606
601
|
const status = this._state.status;
|
|
@@ -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,8 @@ class Actor {
|
|
|
803
798
|
id: this.id
|
|
804
799
|
};
|
|
805
800
|
}
|
|
806
|
-
getPersistedState() {
|
|
807
|
-
return this.logic.getPersistedState(this._state);
|
|
801
|
+
getPersistedState(options) {
|
|
802
|
+
return this.logic.getPersistedState(this._state, options);
|
|
808
803
|
}
|
|
809
804
|
[symbolObservable]() {
|
|
810
805
|
return this;
|
|
@@ -852,4 +847,4 @@ const interpret = createActor;
|
|
|
852
847
|
* @deprecated Use `Actor` instead.
|
|
853
848
|
*/
|
|
854
849
|
|
|
855
|
-
export { $$ACTOR_TYPE as $, Actor as A,
|
|
850
|
+
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, matchesState as e, interpret as f, toObserver as g, createErrorActorEvent as h, isErrorActorEvent as i, toStateValue as j, STATE_IDENTIFIER as k, toStatePath as l, mapValues as m, normalizeTarget as n, createDoneStateEvent as o, pathToStateValue as p, resolveOutput as q, resolveReferencedActor as r, XSTATE_INIT as s, toArray as t, createAfterEvent as u, flatten as v, XSTATE_ERROR as w };
|
package/dist/{interpreter-03a5c3f5.development.cjs.js → interpreter-70ed981b.development.cjs.js}
RENAMED
|
@@ -174,7 +174,7 @@ function createSystem(rootActor) {
|
|
|
174
174
|
system._sendInspectionEvent({
|
|
175
175
|
type: '@xstate.event',
|
|
176
176
|
sourceRef: source,
|
|
177
|
-
|
|
177
|
+
actorRef: target,
|
|
178
178
|
event
|
|
179
179
|
});
|
|
180
180
|
target._send(event);
|
|
@@ -336,17 +336,13 @@ function resolveReferencedActor(machine, src) {
|
|
|
336
336
|
}
|
|
337
337
|
|
|
338
338
|
const $$ACTOR_TYPE = 1;
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
339
|
+
// those values are currently used by @xstate/react directly so it's important to keep the assigned values in sync
|
|
340
|
+
let ProcessingStatus = /*#__PURE__*/function (ProcessingStatus) {
|
|
341
|
+
ProcessingStatus[ProcessingStatus["NotStarted"] = 0] = "NotStarted";
|
|
342
|
+
ProcessingStatus[ProcessingStatus["Running"] = 1] = "Running";
|
|
343
|
+
ProcessingStatus[ProcessingStatus["Stopped"] = 2] = "Stopped";
|
|
344
|
+
return ProcessingStatus;
|
|
344
345
|
}({});
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* @deprecated Use `ActorStatus` instead.
|
|
348
|
-
*/
|
|
349
|
-
const InterpreterStatus = ActorStatus;
|
|
350
346
|
const defaultOptions = {
|
|
351
347
|
clock: {
|
|
352
348
|
setTimeout: (fn, ms) => {
|
|
@@ -376,9 +372,7 @@ class Actor {
|
|
|
376
372
|
* The unique identifier for this actor relative to its parent.
|
|
377
373
|
*/
|
|
378
374
|
|
|
379
|
-
/**
|
|
380
|
-
* Whether the service is started.
|
|
381
|
-
*/
|
|
375
|
+
/** @internal */
|
|
382
376
|
|
|
383
377
|
// Actor Ref
|
|
384
378
|
|
|
@@ -408,7 +402,7 @@ class Actor {
|
|
|
408
402
|
this.delayedEventsMap = {};
|
|
409
403
|
this.observers = new Set();
|
|
410
404
|
this.logger = void 0;
|
|
411
|
-
this.
|
|
405
|
+
this._processingStatus = ProcessingStatus.NotStarted;
|
|
412
406
|
this._parent = void 0;
|
|
413
407
|
this.ref = void 0;
|
|
414
408
|
this._actorScope = void 0;
|
|
@@ -441,7 +435,7 @@ class Actor {
|
|
|
441
435
|
this.clock = clock;
|
|
442
436
|
this._parent = parent;
|
|
443
437
|
this.options = resolvedOptions;
|
|
444
|
-
this.src = resolvedOptions.src;
|
|
438
|
+
this.src = resolvedOptions.src ?? logic;
|
|
445
439
|
this.ref = this;
|
|
446
440
|
this._actorScope = {
|
|
447
441
|
self: this,
|
|
@@ -467,14 +461,14 @@ class Actor {
|
|
|
467
461
|
type: '@xstate.actor',
|
|
468
462
|
actorRef: this
|
|
469
463
|
});
|
|
470
|
-
this._initState();
|
|
464
|
+
this._initState(options?.state);
|
|
471
465
|
if (systemId && this._state.status === 'active') {
|
|
472
466
|
this._systemId = systemId;
|
|
473
467
|
this.system._set(systemId, this);
|
|
474
468
|
}
|
|
475
469
|
}
|
|
476
|
-
_initState() {
|
|
477
|
-
this._state =
|
|
470
|
+
_initState(persistedState) {
|
|
471
|
+
this._state = persistedState ? this.logic.restoreState ? this.logic.restoreState(persistedState, this._actorScope) : persistedState : this.logic.getInitialState(this._actorScope, this.options?.input);
|
|
478
472
|
}
|
|
479
473
|
|
|
480
474
|
// array of functions to defer
|
|
@@ -489,7 +483,6 @@ class Actor {
|
|
|
489
483
|
deferredFn();
|
|
490
484
|
}
|
|
491
485
|
for (const observer of this.observers) {
|
|
492
|
-
// TODO: should observers be notified in case of the error?
|
|
493
486
|
try {
|
|
494
487
|
observer.next?.(snapshot);
|
|
495
488
|
} catch (err) {
|
|
@@ -572,7 +565,7 @@ class Actor {
|
|
|
572
565
|
|
|
573
566
|
subscribe(nextListenerOrObserver, errorListener, completeListener) {
|
|
574
567
|
const observer = toObserver(nextListenerOrObserver, errorListener, completeListener);
|
|
575
|
-
if (this.
|
|
568
|
+
if (this._processingStatus !== ProcessingStatus.Stopped) {
|
|
576
569
|
this.observers.add(observer);
|
|
577
570
|
} else {
|
|
578
571
|
try {
|
|
@@ -592,7 +585,7 @@ class Actor {
|
|
|
592
585
|
* Starts the Actor from the initial state
|
|
593
586
|
*/
|
|
594
587
|
start() {
|
|
595
|
-
if (this.
|
|
588
|
+
if (this._processingStatus === ProcessingStatus.Running) {
|
|
596
589
|
// Do not restart the service if it is already started
|
|
597
590
|
return this;
|
|
598
591
|
}
|
|
@@ -600,12 +593,14 @@ class Actor {
|
|
|
600
593
|
if (this._systemId) {
|
|
601
594
|
this.system._set(this._systemId, this);
|
|
602
595
|
}
|
|
603
|
-
this.
|
|
596
|
+
this._processingStatus = ProcessingStatus.Running;
|
|
597
|
+
|
|
598
|
+
// TODO: this isn't correct when rehydrating
|
|
604
599
|
const initEvent = createInitEvent(this.options.input);
|
|
605
600
|
this.system._sendInspectionEvent({
|
|
606
601
|
type: '@xstate.event',
|
|
607
602
|
sourceRef: this._parent,
|
|
608
|
-
|
|
603
|
+
actorRef: this,
|
|
609
604
|
event: initEvent
|
|
610
605
|
});
|
|
611
606
|
const status = this._state.status;
|
|
@@ -668,12 +663,12 @@ class Actor {
|
|
|
668
663
|
}
|
|
669
664
|
}
|
|
670
665
|
_stop() {
|
|
671
|
-
if (this.
|
|
666
|
+
if (this._processingStatus === ProcessingStatus.Stopped) {
|
|
672
667
|
return this;
|
|
673
668
|
}
|
|
674
669
|
this.mailbox.clear();
|
|
675
|
-
if (this.
|
|
676
|
-
this.
|
|
670
|
+
if (this._processingStatus === ProcessingStatus.NotStarted) {
|
|
671
|
+
this._processingStatus = ProcessingStatus.Stopped;
|
|
677
672
|
return this;
|
|
678
673
|
}
|
|
679
674
|
this.mailbox.enqueue({
|
|
@@ -724,7 +719,7 @@ class Actor {
|
|
|
724
719
|
}
|
|
725
720
|
}
|
|
726
721
|
_stopProcedure() {
|
|
727
|
-
if (this.
|
|
722
|
+
if (this._processingStatus !== ProcessingStatus.Running) {
|
|
728
723
|
// Actor already stopped; do nothing
|
|
729
724
|
return this;
|
|
730
725
|
}
|
|
@@ -741,7 +736,7 @@ class Actor {
|
|
|
741
736
|
// it seems like this should be the common behavior for all of our consumers
|
|
742
737
|
// so perhaps this should be unified somehow for all of them
|
|
743
738
|
this.mailbox = new Mailbox(this._process.bind(this));
|
|
744
|
-
this.
|
|
739
|
+
this._processingStatus = ProcessingStatus.Stopped;
|
|
745
740
|
this.system._unregister(this);
|
|
746
741
|
return this;
|
|
747
742
|
}
|
|
@@ -750,7 +745,7 @@ class Actor {
|
|
|
750
745
|
* @internal
|
|
751
746
|
*/
|
|
752
747
|
_send(event) {
|
|
753
|
-
if (this.
|
|
748
|
+
if (this._processingStatus === ProcessingStatus.Stopped) {
|
|
754
749
|
// do nothing
|
|
755
750
|
{
|
|
756
751
|
const eventString = JSON.stringify(event);
|
|
@@ -816,8 +811,8 @@ class Actor {
|
|
|
816
811
|
id: this.id
|
|
817
812
|
};
|
|
818
813
|
}
|
|
819
|
-
getPersistedState() {
|
|
820
|
-
return this.logic.getPersistedState(this._state);
|
|
814
|
+
getPersistedState(options) {
|
|
815
|
+
return this.logic.getPersistedState(this._state, options);
|
|
821
816
|
}
|
|
822
817
|
[symbolObservable]() {
|
|
823
818
|
return this;
|
|
@@ -867,9 +862,8 @@ const interpret = createActor;
|
|
|
867
862
|
|
|
868
863
|
exports.$$ACTOR_TYPE = $$ACTOR_TYPE;
|
|
869
864
|
exports.Actor = Actor;
|
|
870
|
-
exports.ActorStatus = ActorStatus;
|
|
871
|
-
exports.InterpreterStatus = InterpreterStatus;
|
|
872
865
|
exports.NULL_EVENT = NULL_EVENT;
|
|
866
|
+
exports.ProcessingStatus = ProcessingStatus;
|
|
873
867
|
exports.STATE_DELIMITER = STATE_DELIMITER;
|
|
874
868
|
exports.STATE_IDENTIFIER = STATE_IDENTIFIER;
|
|
875
869
|
exports.WILDCARD = WILDCARD;
|
package/dist/{interpreter-70cd9217.development.esm.js → interpreter-936da690.development.esm.js}
RENAMED
|
@@ -172,7 +172,7 @@ function createSystem(rootActor) {
|
|
|
172
172
|
system._sendInspectionEvent({
|
|
173
173
|
type: '@xstate.event',
|
|
174
174
|
sourceRef: source,
|
|
175
|
-
|
|
175
|
+
actorRef: target,
|
|
176
176
|
event
|
|
177
177
|
});
|
|
178
178
|
target._send(event);
|
|
@@ -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,12 +591,14 @@ 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',
|
|
605
600
|
sourceRef: this._parent,
|
|
606
|
-
|
|
601
|
+
actorRef: this,
|
|
607
602
|
event: initEvent
|
|
608
603
|
});
|
|
609
604
|
const status = this._state.status;
|
|
@@ -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,8 @@ class Actor {
|
|
|
814
809
|
id: this.id
|
|
815
810
|
};
|
|
816
811
|
}
|
|
817
|
-
getPersistedState() {
|
|
818
|
-
return this.logic.getPersistedState(this._state);
|
|
812
|
+
getPersistedState(options) {
|
|
813
|
+
return this.logic.getPersistedState(this._state, options);
|
|
819
814
|
}
|
|
820
815
|
[symbolObservable]() {
|
|
821
816
|
return this;
|
|
@@ -863,4 +858,4 @@ const interpret = createActor;
|
|
|
863
858
|
* @deprecated Use `Actor` instead.
|
|
864
859
|
*/
|
|
865
860
|
|
|
866
|
-
export { $$ACTOR_TYPE as $, Actor as A,
|
|
861
|
+
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, matchesState as e, interpret as f, toObserver as g, createErrorActorEvent as h, isErrorActorEvent as i, toStateValue as j, STATE_IDENTIFIER as k, toStatePath as l, mapValues as m, normalizeTarget as n, createDoneStateEvent as o, pathToStateValue as p, resolveOutput as q, resolveReferencedActor as r, XSTATE_INIT as s, toArray as t, createAfterEvent as u, flatten as v, XSTATE_ERROR as w };
|