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