xstate 5.14.0 → 5.15.0
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 +2 -2
- package/actions/dist/xstate-actions.development.cjs.js +2 -2
- package/actions/dist/xstate-actions.development.esm.js +2 -2
- package/actions/dist/xstate-actions.esm.js +2 -2
- package/actions/dist/xstate-actions.umd.min.js.map +1 -1
- package/actors/dist/xstate-actors.cjs.js +272 -65
- package/actors/dist/xstate-actors.development.cjs.js +272 -65
- package/actors/dist/xstate-actors.development.esm.js +272 -65
- package/actors/dist/xstate-actors.esm.js +272 -65
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/declarations/src/State.d.ts +21 -25
- package/dist/declarations/src/StateMachine.d.ts +18 -30
- package/dist/declarations/src/StateNode.d.ts +29 -51
- package/dist/declarations/src/actions/assign.d.ts +29 -27
- package/dist/declarations/src/actions/cancel.d.ts +28 -22
- package/dist/declarations/src/actions/emit.d.ts +33 -33
- package/dist/declarations/src/actions/enqueueActions.d.ts +18 -16
- package/dist/declarations/src/actions/log.d.ts +5 -4
- package/dist/declarations/src/actions/send.d.ts +5 -3
- package/dist/declarations/src/actors/callback.d.ts +65 -26
- package/dist/declarations/src/actors/index.d.ts +4 -4
- package/dist/declarations/src/actors/observable.d.ts +65 -22
- package/dist/declarations/src/actors/promise.d.ts +86 -9
- package/dist/declarations/src/actors/transition.d.ts +89 -15
- package/dist/declarations/src/assert.d.ts +21 -20
- package/dist/declarations/src/createActor.d.ts +51 -42
- package/dist/declarations/src/createMachine.d.ts +40 -54
- package/dist/declarations/src/getNextSnapshot.d.ts +27 -24
- package/dist/declarations/src/guards.d.ts +67 -66
- package/dist/declarations/src/index.d.ts +0 -1
- package/dist/declarations/src/inspection.d.ts +1 -0
- package/dist/declarations/src/setup.d.ts +1 -2
- package/dist/declarations/src/spawn.d.ts +2 -5
- package/dist/declarations/src/stateUtils.d.ts +5 -10
- package/dist/declarations/src/toPromise.d.ts +1 -0
- package/dist/declarations/src/types.d.ts +162 -188
- package/dist/declarations/src/waitFor.d.ts +9 -9
- package/dist/{log-b87cb6bd.esm.js → log-63de2429.esm.js} +112 -117
- package/dist/{log-7ae0ddf8.cjs.js → log-b8c93ee3.cjs.js} +112 -117
- package/dist/{log-505687fd.development.cjs.js → log-d2c282d6.development.cjs.js} +112 -117
- package/dist/{log-c943e6aa.development.esm.js → log-e9953143.development.esm.js} +112 -117
- package/dist/{raise-4e39e875.esm.js → raise-2cfe6b8f.esm.js} +164 -154
- package/dist/{raise-0f400094.development.esm.js → raise-7d030497.development.esm.js} +164 -154
- package/dist/{raise-f79d2832.cjs.js → raise-a6298350.cjs.js} +164 -154
- package/dist/{raise-0cd7e521.development.cjs.js → raise-bad6a97b.development.cjs.js} +164 -154
- package/dist/xstate.cjs.js +134 -157
- package/dist/xstate.development.cjs.js +134 -157
- package/dist/xstate.development.esm.js +136 -159
- package/dist/xstate.esm.js +136 -159
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.esm.js +1 -1
- package/guards/dist/xstate-guards.esm.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/dist/declarations/src/typegenTypes.d.ts +0 -168
|
@@ -57,8 +57,8 @@ const XSTATE_ERROR = 'xstate.error';
|
|
|
57
57
|
const XSTATE_STOP = 'xstate.stop';
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
|
-
* Returns an event that represents an implicit event that
|
|
61
|
-
*
|
|
60
|
+
* Returns an event that represents an implicit event that is sent after the
|
|
61
|
+
* specified `delay`.
|
|
62
62
|
*
|
|
63
63
|
* @param delayRef The delay in milliseconds
|
|
64
64
|
* @param id The state node ID where this event is handled
|
|
@@ -70,8 +70,8 @@ function createAfterEvent(delayRef, id) {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
|
-
* Returns an event that represents that a final state node
|
|
74
|
-
*
|
|
73
|
+
* Returns an event that represents that a final state node has been reached in
|
|
74
|
+
* the parent state node.
|
|
75
75
|
*
|
|
76
76
|
* @param id The final state node's parent state node `id`
|
|
77
77
|
* @param output The data to pass into the event
|
|
@@ -86,8 +86,8 @@ function createDoneStateEvent(id, output) {
|
|
|
86
86
|
/**
|
|
87
87
|
* Returns an event that represents that an invoked service has terminated.
|
|
88
88
|
*
|
|
89
|
-
* An invoked service is terminated when it has reached a top-level final state
|
|
90
|
-
* but not when it is canceled.
|
|
89
|
+
* An invoked service is terminated when it has reached a top-level final state
|
|
90
|
+
* node, but not when it is canceled.
|
|
91
91
|
*
|
|
92
92
|
* @param invokeId The invoked service ID
|
|
93
93
|
* @param output The data to pass into the event
|
|
@@ -114,11 +114,12 @@ function createInitEvent(input) {
|
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
/**
|
|
117
|
-
* This function makes sure that unhandled errors are thrown in a separate
|
|
118
|
-
* It allows those errors to be detected by global error handlers and
|
|
119
|
-
* without interrupting our own stack of
|
|
117
|
+
* This function makes sure that unhandled errors are thrown in a separate
|
|
118
|
+
* macrotask. It allows those errors to be detected by global error handlers and
|
|
119
|
+
* reported to bug tracking services without interrupting our own stack of
|
|
120
|
+
* execution.
|
|
120
121
|
*
|
|
121
|
-
* @param err
|
|
122
|
+
* @param err Error to be thrown
|
|
122
123
|
*/
|
|
123
124
|
function reportUnhandledError(err) {
|
|
124
125
|
setTimeout(() => {
|
|
@@ -441,29 +442,29 @@ const defaultOptions = {
|
|
|
441
442
|
};
|
|
442
443
|
|
|
443
444
|
/**
|
|
444
|
-
* An Actor is a running process that can receive events, send events and change
|
|
445
|
+
* An Actor is a running process that can receive events, send events and change
|
|
446
|
+
* its behavior based on the events it receives, which can cause effects outside
|
|
447
|
+
* of the actor. When you run a state machine, it becomes an actor.
|
|
445
448
|
*/
|
|
446
449
|
class Actor {
|
|
447
450
|
/**
|
|
448
|
-
* Creates a new actor instance for the given logic with the provided options,
|
|
451
|
+
* Creates a new actor instance for the given logic with the provided options,
|
|
452
|
+
* if any.
|
|
449
453
|
*
|
|
450
454
|
* @param logic The logic to create an actor from
|
|
451
455
|
* @param options Actor options
|
|
452
456
|
*/
|
|
453
457
|
constructor(logic, options) {
|
|
454
458
|
this.logic = logic;
|
|
455
|
-
/**
|
|
456
|
-
* The current internal state of the actor.
|
|
457
|
-
*/
|
|
459
|
+
/** The current internal state of the actor. */
|
|
458
460
|
this._snapshot = void 0;
|
|
459
461
|
/**
|
|
460
|
-
* The clock that is responsible for setting and clearing timeouts, such as
|
|
462
|
+
* The clock that is responsible for setting and clearing timeouts, such as
|
|
463
|
+
* delayed events and transitions.
|
|
461
464
|
*/
|
|
462
465
|
this.clock = void 0;
|
|
463
466
|
this.options = void 0;
|
|
464
|
-
/**
|
|
465
|
-
* The unique identifier for this actor relative to its parent.
|
|
466
|
-
*/
|
|
467
|
+
/** The unique identifier for this actor relative to its parent. */
|
|
467
468
|
this.id = void 0;
|
|
468
469
|
this.mailbox = new Mailbox(this._process.bind(this));
|
|
469
470
|
this.observers = new Set();
|
|
@@ -479,13 +480,9 @@ class Actor {
|
|
|
479
480
|
// TODO: add typings for system
|
|
480
481
|
this._actorScope = void 0;
|
|
481
482
|
this._systemId = void 0;
|
|
482
|
-
/**
|
|
483
|
-
* The globally unique process ID for this invocation.
|
|
484
|
-
*/
|
|
483
|
+
/** The globally unique process ID for this invocation. */
|
|
485
484
|
this.sessionId = void 0;
|
|
486
|
-
/**
|
|
487
|
-
* The system to which this actor belongs.
|
|
488
|
-
*/
|
|
485
|
+
/** The system to which this actor belongs. */
|
|
489
486
|
this.system = void 0;
|
|
490
487
|
this._doneEvent = void 0;
|
|
491
488
|
this.src = void 0;
|
|
@@ -649,11 +646,15 @@ class Actor {
|
|
|
649
646
|
* Subscribe an observer to an actor’s snapshot values.
|
|
650
647
|
*
|
|
651
648
|
* @remarks
|
|
652
|
-
* The observer will receive the actor’s snapshot value when it is emitted.
|
|
649
|
+
* The observer will receive the actor’s snapshot value when it is emitted.
|
|
650
|
+
* The observer can be:
|
|
651
|
+
*
|
|
653
652
|
* - A plain function that receives the latest snapshot, or
|
|
654
|
-
* - An observer object whose `.next(snapshot)` method receives the latest
|
|
653
|
+
* - An observer object whose `.next(snapshot)` method receives the latest
|
|
654
|
+
* snapshot
|
|
655
655
|
*
|
|
656
656
|
* @example
|
|
657
|
+
*
|
|
657
658
|
* ```ts
|
|
658
659
|
* // Observer as a plain function
|
|
659
660
|
* const subscription = actor.subscribe((snapshot) => {
|
|
@@ -662,6 +663,7 @@ class Actor {
|
|
|
662
663
|
* ```
|
|
663
664
|
*
|
|
664
665
|
* @example
|
|
666
|
+
*
|
|
665
667
|
* ```ts
|
|
666
668
|
* // Observer as an object
|
|
667
669
|
* const subscription = actor.subscribe({
|
|
@@ -673,13 +675,16 @@ class Actor {
|
|
|
673
675
|
* },
|
|
674
676
|
* complete() {
|
|
675
677
|
* // ...
|
|
676
|
-
* }
|
|
678
|
+
* }
|
|
677
679
|
* });
|
|
678
680
|
* ```
|
|
679
681
|
*
|
|
680
|
-
* The return value of `actor.subscribe(observer)` is a subscription object
|
|
682
|
+
* The return value of `actor.subscribe(observer)` is a subscription object
|
|
683
|
+
* that has an `.unsubscribe()` method. You can call
|
|
684
|
+
* `subscription.unsubscribe()` to unsubscribe the observer:
|
|
681
685
|
*
|
|
682
686
|
* @example
|
|
687
|
+
*
|
|
683
688
|
* ```ts
|
|
684
689
|
* const subscription = actor.subscribe((snapshot) => {
|
|
685
690
|
* // ...
|
|
@@ -689,9 +694,12 @@ class Actor {
|
|
|
689
694
|
* subscription.unsubscribe();
|
|
690
695
|
* ```
|
|
691
696
|
*
|
|
692
|
-
* When the actor is stopped, all of its observers will automatically be
|
|
697
|
+
* When the actor is stopped, all of its observers will automatically be
|
|
698
|
+
* unsubscribed.
|
|
693
699
|
*
|
|
694
|
-
* @param observer - Either a plain function that receives the latest
|
|
700
|
+
* @param observer - Either a plain function that receives the latest
|
|
701
|
+
* snapshot, or an observer object whose `.next(snapshot)` method receives
|
|
702
|
+
* the latest snapshot
|
|
695
703
|
*/
|
|
696
704
|
|
|
697
705
|
subscribe(nextListenerOrObserver, errorListener, completeListener) {
|
|
@@ -744,9 +752,7 @@ class Actor {
|
|
|
744
752
|
};
|
|
745
753
|
}
|
|
746
754
|
|
|
747
|
-
/**
|
|
748
|
-
* Starts the Actor from the initial state
|
|
749
|
-
*/
|
|
755
|
+
/** Starts the Actor from the initial state */
|
|
750
756
|
start() {
|
|
751
757
|
if (this._processingStatus === ProcessingStatus.Running) {
|
|
752
758
|
// Do not restart the service if it is already started
|
|
@@ -862,9 +868,7 @@ class Actor {
|
|
|
862
868
|
return this;
|
|
863
869
|
}
|
|
864
870
|
|
|
865
|
-
/**
|
|
866
|
-
* Stops the Actor and unsubscribe all listeners.
|
|
867
|
-
*/
|
|
871
|
+
/** Stops the Actor and unsubscribe all listeners. */
|
|
868
872
|
stop() {
|
|
869
873
|
if (this._parent) {
|
|
870
874
|
throw new Error('A non-root actor cannot be stopped directly.');
|
|
@@ -936,9 +940,7 @@ class Actor {
|
|
|
936
940
|
return this;
|
|
937
941
|
}
|
|
938
942
|
|
|
939
|
-
/**
|
|
940
|
-
* @internal
|
|
941
|
-
*/
|
|
943
|
+
/** @internal */
|
|
942
944
|
_send(event) {
|
|
943
945
|
if (this._processingStatus === ProcessingStatus.Stopped) {
|
|
944
946
|
// do nothing
|
|
@@ -984,10 +986,11 @@ class Actor {
|
|
|
984
986
|
* @remarks
|
|
985
987
|
* The internal state can be persisted from any actor, not only machines.
|
|
986
988
|
*
|
|
987
|
-
* Note that the persisted state is not the same as the snapshot from
|
|
989
|
+
* Note that the persisted state is not the same as the snapshot from
|
|
990
|
+
* {@link Actor.getSnapshot}. Persisted state represents the internal state of
|
|
991
|
+
* the actor, while snapshots represent the actor's last emitted value.
|
|
988
992
|
*
|
|
989
993
|
* Can be restored with {@link ActorOptions.state}
|
|
990
|
-
*
|
|
991
994
|
* @see https://stately.ai/docs/persistence
|
|
992
995
|
*/
|
|
993
996
|
|
|
@@ -1004,11 +1007,11 @@ class Actor {
|
|
|
1004
1007
|
* @remarks
|
|
1005
1008
|
* The snapshot represent an actor's last emitted value.
|
|
1006
1009
|
*
|
|
1007
|
-
* When an actor receives an event, its internal state may change.
|
|
1008
|
-
*
|
|
1009
|
-
*
|
|
1010
|
-
* Note that some actors, such as callback actors generated with `fromCallback`, will not emit snapshots.
|
|
1010
|
+
* When an actor receives an event, its internal state may change. An actor
|
|
1011
|
+
* may emit a snapshot when a state transition occurs.
|
|
1011
1012
|
*
|
|
1013
|
+
* Note that some actors, such as callback actors generated with
|
|
1014
|
+
* `fromCallback`, will not emit snapshots.
|
|
1012
1015
|
* @see {@link Actor.subscribe} to subscribe to an actor’s snapshot values.
|
|
1013
1016
|
* @see {@link Actor.getPersistedSnapshot} to persist the internal state of an actor (which is more than just a snapshot).
|
|
1014
1017
|
*/
|
|
@@ -1020,13 +1023,16 @@ class Actor {
|
|
|
1020
1023
|
}
|
|
1021
1024
|
}
|
|
1022
1025
|
/**
|
|
1023
|
-
* Creates a new actor instance for the given actor logic with the provided
|
|
1026
|
+
* Creates a new actor instance for the given actor logic with the provided
|
|
1027
|
+
* options, if any.
|
|
1024
1028
|
*
|
|
1025
1029
|
* @remarks
|
|
1026
|
-
* When you create an actor from actor logic via `createActor(logic)`, you
|
|
1027
|
-
*
|
|
1028
|
-
*
|
|
1030
|
+
* When you create an actor from actor logic via `createActor(logic)`, you
|
|
1031
|
+
* implicitly create an actor system where the created actor is the root actor.
|
|
1032
|
+
* Any actors spawned from this root actor and its descendants are part of that
|
|
1033
|
+
* actor system.
|
|
1029
1034
|
* @example
|
|
1035
|
+
*
|
|
1030
1036
|
* ```ts
|
|
1031
1037
|
* import { createActor } from 'xstate';
|
|
1032
1038
|
* import { someActorLogic } from './someActorLogic.ts';
|
|
@@ -1048,7 +1054,10 @@ class Actor {
|
|
|
1048
1054
|
* actor.stop();
|
|
1049
1055
|
* ```
|
|
1050
1056
|
*
|
|
1051
|
-
* @param logic - The actor logic to create an actor from. For a state machine
|
|
1057
|
+
* @param logic - The actor logic to create an actor from. For a state machine
|
|
1058
|
+
* actor logic creator, see {@link createMachine}. Other actor logic creators
|
|
1059
|
+
* include {@link fromCallback}, {@link fromEventObservable},
|
|
1060
|
+
* {@link fromObservable}, {@link fromPromise}, and {@link fromTransition}.
|
|
1052
1061
|
* @param options - Actor options
|
|
1053
1062
|
*/
|
|
1054
1063
|
function createActor(logic, ...[options]) {
|
|
@@ -1056,15 +1065,14 @@ function createActor(logic, ...[options]) {
|
|
|
1056
1065
|
}
|
|
1057
1066
|
|
|
1058
1067
|
/**
|
|
1059
|
-
* Creates a new Interpreter instance for the given machine with the provided
|
|
1068
|
+
* Creates a new Interpreter instance for the given machine with the provided
|
|
1069
|
+
* options, if any.
|
|
1060
1070
|
*
|
|
1061
1071
|
* @deprecated Use `createActor` instead
|
|
1062
1072
|
*/
|
|
1063
1073
|
const interpret = createActor;
|
|
1064
1074
|
|
|
1065
|
-
/**
|
|
1066
|
-
* @deprecated Use `Actor` instead.
|
|
1067
|
-
*/
|
|
1075
|
+
/** @deprecated Use `Actor` instead. */
|
|
1068
1076
|
|
|
1069
1077
|
function resolveCancel(_, snapshot, actionArgs, actionParams, {
|
|
1070
1078
|
sendId
|
|
@@ -1078,30 +1086,36 @@ function executeCancel(actorScope, resolvedSendId) {
|
|
|
1078
1086
|
});
|
|
1079
1087
|
}
|
|
1080
1088
|
/**
|
|
1081
|
-
* Cancels a delayed `sendTo(...)` action that is waiting to be executed. The
|
|
1082
|
-
* will not send its event or execute, unless the
|
|
1089
|
+
* Cancels a delayed `sendTo(...)` action that is waiting to be executed. The
|
|
1090
|
+
* canceled `sendTo(...)` action will not send its event or execute, unless the
|
|
1091
|
+
* `delay` has already elapsed before `cancel(...)` is called.
|
|
1083
1092
|
*
|
|
1084
|
-
* @param sendId The `id` of the `sendTo(...)` action to cancel.
|
|
1085
|
-
*
|
|
1086
1093
|
* @example
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1094
|
+
*
|
|
1095
|
+
* ```ts
|
|
1096
|
+
* import { createMachine, sendTo, cancel } from 'xstate';
|
|
1097
|
+
*
|
|
1098
|
+
* const machine = createMachine({
|
|
1099
|
+
* // ...
|
|
1100
|
+
* on: {
|
|
1101
|
+
* sendEvent: {
|
|
1102
|
+
* actions: sendTo(
|
|
1103
|
+
* 'some-actor',
|
|
1104
|
+
* { type: 'someEvent' },
|
|
1105
|
+
* {
|
|
1106
|
+
* id: 'some-id',
|
|
1107
|
+
* delay: 1000
|
|
1108
|
+
* }
|
|
1109
|
+
* )
|
|
1110
|
+
* },
|
|
1111
|
+
* cancelEvent: {
|
|
1112
|
+
* actions: cancel('some-id')
|
|
1113
|
+
* }
|
|
1114
|
+
* }
|
|
1115
|
+
* });
|
|
1116
|
+
* ```
|
|
1117
|
+
*
|
|
1118
|
+
* @param sendId The `id` of the `sendTo(...)` action to cancel.
|
|
1105
1119
|
*/
|
|
1106
1120
|
function cancel(sendId) {
|
|
1107
1121
|
function cancel(args, params) {
|
|
@@ -1283,30 +1297,33 @@ function checkNot(snapshot, {
|
|
|
1283
1297
|
}
|
|
1284
1298
|
|
|
1285
1299
|
/**
|
|
1286
|
-
* Higher-order guard that evaluates to `true` if the `guard` passed to it
|
|
1300
|
+
* Higher-order guard that evaluates to `true` if the `guard` passed to it
|
|
1301
|
+
* evaluates to `false`.
|
|
1287
1302
|
*
|
|
1288
1303
|
* @category Guards
|
|
1289
1304
|
* @example
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
*
|
|
1305
|
+
*
|
|
1306
|
+
* ```ts
|
|
1307
|
+
* import { setup, not } from 'xstate';
|
|
1308
|
+
*
|
|
1309
|
+
* const machine = setup({
|
|
1310
|
+
* guards: {
|
|
1311
|
+
* someNamedGuard: () => false
|
|
1312
|
+
* }
|
|
1313
|
+
* }).createMachine({
|
|
1314
|
+
* on: {
|
|
1315
|
+
* someEvent: {
|
|
1316
|
+
* guard: not('someNamedGuard'),
|
|
1317
|
+
* actions: () => {
|
|
1318
|
+
* // will be executed if guard in `not(...)`
|
|
1319
|
+
* // evaluates to `false`
|
|
1320
|
+
* }
|
|
1321
|
+
* }
|
|
1322
|
+
* }
|
|
1323
|
+
* });
|
|
1324
|
+
* ```
|
|
1325
|
+
*
|
|
1326
|
+
* @returns A guard
|
|
1310
1327
|
*/
|
|
1311
1328
|
function not(guard) {
|
|
1312
1329
|
function not(args, params) {
|
|
@@ -1333,28 +1350,27 @@ function checkAnd(snapshot, {
|
|
|
1333
1350
|
*
|
|
1334
1351
|
* @category Guards
|
|
1335
1352
|
* @example
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
```
|
|
1353
|
+
*
|
|
1354
|
+
* ```ts
|
|
1355
|
+
* import { setup, and } from 'xstate';
|
|
1356
|
+
*
|
|
1357
|
+
* const machine = setup({
|
|
1358
|
+
* guards: {
|
|
1359
|
+
* someNamedGuard: () => true
|
|
1360
|
+
* }
|
|
1361
|
+
* }).createMachine({
|
|
1362
|
+
* on: {
|
|
1363
|
+
* someEvent: {
|
|
1364
|
+
* guard: and([({ context }) => context.value > 0, 'someNamedGuard']),
|
|
1365
|
+
* actions: () => {
|
|
1366
|
+
* // will be executed if all guards in `and(...)`
|
|
1367
|
+
* // evaluate to true
|
|
1368
|
+
* }
|
|
1369
|
+
* }
|
|
1370
|
+
* }
|
|
1371
|
+
* });
|
|
1372
|
+
* ```
|
|
1373
|
+
*
|
|
1358
1374
|
* @returns A guard action object
|
|
1359
1375
|
*/
|
|
1360
1376
|
function and(guards) {
|
|
@@ -1377,33 +1393,32 @@ function checkOr(snapshot, {
|
|
|
1377
1393
|
}
|
|
1378
1394
|
|
|
1379
1395
|
/**
|
|
1380
|
-
* Higher-order guard that evaluates to `true` if any of the `guards` passed to
|
|
1381
|
-
* evaluate to `true`.
|
|
1396
|
+
* Higher-order guard that evaluates to `true` if any of the `guards` passed to
|
|
1397
|
+
* it evaluate to `true`.
|
|
1382
1398
|
*
|
|
1383
1399
|
* @category Guards
|
|
1384
1400
|
* @example
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
```
|
|
1401
|
+
*
|
|
1402
|
+
* ```ts
|
|
1403
|
+
* import { setup, or } from 'xstate';
|
|
1404
|
+
*
|
|
1405
|
+
* const machine = setup({
|
|
1406
|
+
* guards: {
|
|
1407
|
+
* someNamedGuard: () => true
|
|
1408
|
+
* }
|
|
1409
|
+
* }).createMachine({
|
|
1410
|
+
* on: {
|
|
1411
|
+
* someEvent: {
|
|
1412
|
+
* guard: or([({ context }) => context.value > 0, 'someNamedGuard']),
|
|
1413
|
+
* actions: () => {
|
|
1414
|
+
* // will be executed if any of the guards in `or(...)`
|
|
1415
|
+
* // evaluate to true
|
|
1416
|
+
* }
|
|
1417
|
+
* }
|
|
1418
|
+
* }
|
|
1419
|
+
* });
|
|
1420
|
+
* ```
|
|
1421
|
+
*
|
|
1407
1422
|
* @returns A guard action object
|
|
1408
1423
|
*/
|
|
1409
1424
|
function or(guards) {
|
|
@@ -1588,9 +1603,7 @@ function getCandidates(stateNode, receivedEventType) {
|
|
|
1588
1603
|
return candidates;
|
|
1589
1604
|
}
|
|
1590
1605
|
|
|
1591
|
-
/**
|
|
1592
|
-
* All delayed transitions from the config.
|
|
1593
|
-
*/
|
|
1606
|
+
/** All delayed transitions from the config. */
|
|
1594
1607
|
function getDelayedTransitions(stateNode) {
|
|
1595
1608
|
const afterConfig = stateNode.config.after;
|
|
1596
1609
|
if (!afterConfig) {
|
|
@@ -1782,9 +1795,7 @@ function getInitialStateNodes(stateNode) {
|
|
|
1782
1795
|
iter(stateNode);
|
|
1783
1796
|
return set;
|
|
1784
1797
|
}
|
|
1785
|
-
/**
|
|
1786
|
-
* Returns the child state node from its relative `stateKey`, or throws.
|
|
1787
|
-
*/
|
|
1798
|
+
/** Returns the child state node from its relative `stateKey`, or throws. */
|
|
1788
1799
|
function getStateNode(stateNode, stateKey) {
|
|
1789
1800
|
if (isStateId(stateKey)) {
|
|
1790
1801
|
return stateNode.machine.getStateNodeById(stateKey);
|
|
@@ -2025,9 +2036,7 @@ function areStateNodeCollectionsEqual(prevStateNodes, nextStateNodeSet) {
|
|
|
2025
2036
|
return true;
|
|
2026
2037
|
}
|
|
2027
2038
|
|
|
2028
|
-
/**
|
|
2029
|
-
* https://www.w3.org/TR/scxml/#microstepProcedure
|
|
2030
|
-
*/
|
|
2039
|
+
/** https://www.w3.org/TR/scxml/#microstepProcedure */
|
|
2031
2040
|
function microstep(transitions, currentSnapshot, actorScope, event, isInitial, internalQueue) {
|
|
2032
2041
|
if (!transitions.length) {
|
|
2033
2042
|
return currentSnapshot;
|
|
@@ -2440,7 +2449,8 @@ function selectEventlessTransitions(nextState, event) {
|
|
|
2440
2449
|
}
|
|
2441
2450
|
|
|
2442
2451
|
/**
|
|
2443
|
-
* Resolves a partial state value with its full representation in the state
|
|
2452
|
+
* Resolves a partial state value with its full representation in the state
|
|
2453
|
+
* node's machine.
|
|
2444
2454
|
*
|
|
2445
2455
|
* @param stateValue The partial state value to resolve.
|
|
2446
2456
|
*/
|