xstate 5.14.0 → 5.16.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 +1 -1
- 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 +23 -27
- package/dist/declarations/src/StateMachine.d.ts +19 -31
- 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 +21 -18
- 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 +1 -2
- 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 +164 -189
- package/dist/declarations/src/waitFor.d.ts +9 -9
- package/dist/{log-c943e6aa.development.esm.js → log-17f4495d.development.esm.js} +115 -117
- package/dist/{log-505687fd.development.cjs.js → log-31321d85.development.cjs.js} +115 -117
- package/dist/{log-b87cb6bd.esm.js → log-8320f5e6.esm.js} +115 -117
- package/dist/{log-7ae0ddf8.cjs.js → log-f9587b82.cjs.js} +115 -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(() => {
|
|
@@ -440,29 +441,29 @@ const defaultOptions = {
|
|
|
440
441
|
};
|
|
441
442
|
|
|
442
443
|
/**
|
|
443
|
-
* An Actor is a running process that can receive events, send events and change
|
|
444
|
+
* An Actor is a running process that can receive events, send events and change
|
|
445
|
+
* its behavior based on the events it receives, which can cause effects outside
|
|
446
|
+
* of the actor. When you run a state machine, it becomes an actor.
|
|
444
447
|
*/
|
|
445
448
|
class Actor {
|
|
446
449
|
/**
|
|
447
|
-
* Creates a new actor instance for the given logic with the provided options,
|
|
450
|
+
* Creates a new actor instance for the given logic with the provided options,
|
|
451
|
+
* if any.
|
|
448
452
|
*
|
|
449
453
|
* @param logic The logic to create an actor from
|
|
450
454
|
* @param options Actor options
|
|
451
455
|
*/
|
|
452
456
|
constructor(logic, options) {
|
|
453
457
|
this.logic = logic;
|
|
454
|
-
/**
|
|
455
|
-
* The current internal state of the actor.
|
|
456
|
-
*/
|
|
458
|
+
/** The current internal state of the actor. */
|
|
457
459
|
this._snapshot = void 0;
|
|
458
460
|
/**
|
|
459
|
-
* The clock that is responsible for setting and clearing timeouts, such as
|
|
461
|
+
* The clock that is responsible for setting and clearing timeouts, such as
|
|
462
|
+
* delayed events and transitions.
|
|
460
463
|
*/
|
|
461
464
|
this.clock = void 0;
|
|
462
465
|
this.options = void 0;
|
|
463
|
-
/**
|
|
464
|
-
* The unique identifier for this actor relative to its parent.
|
|
465
|
-
*/
|
|
466
|
+
/** The unique identifier for this actor relative to its parent. */
|
|
466
467
|
this.id = void 0;
|
|
467
468
|
this.mailbox = new Mailbox(this._process.bind(this));
|
|
468
469
|
this.observers = new Set();
|
|
@@ -478,13 +479,9 @@ class Actor {
|
|
|
478
479
|
// TODO: add typings for system
|
|
479
480
|
this._actorScope = void 0;
|
|
480
481
|
this._systemId = void 0;
|
|
481
|
-
/**
|
|
482
|
-
* The globally unique process ID for this invocation.
|
|
483
|
-
*/
|
|
482
|
+
/** The globally unique process ID for this invocation. */
|
|
484
483
|
this.sessionId = void 0;
|
|
485
|
-
/**
|
|
486
|
-
* The system to which this actor belongs.
|
|
487
|
-
*/
|
|
484
|
+
/** The system to which this actor belongs. */
|
|
488
485
|
this.system = void 0;
|
|
489
486
|
this._doneEvent = void 0;
|
|
490
487
|
this.src = void 0;
|
|
@@ -648,11 +645,15 @@ class Actor {
|
|
|
648
645
|
* Subscribe an observer to an actor’s snapshot values.
|
|
649
646
|
*
|
|
650
647
|
* @remarks
|
|
651
|
-
* The observer will receive the actor’s snapshot value when it is emitted.
|
|
648
|
+
* The observer will receive the actor’s snapshot value when it is emitted.
|
|
649
|
+
* The observer can be:
|
|
650
|
+
*
|
|
652
651
|
* - A plain function that receives the latest snapshot, or
|
|
653
|
-
* - An observer object whose `.next(snapshot)` method receives the latest
|
|
652
|
+
* - An observer object whose `.next(snapshot)` method receives the latest
|
|
653
|
+
* snapshot
|
|
654
654
|
*
|
|
655
655
|
* @example
|
|
656
|
+
*
|
|
656
657
|
* ```ts
|
|
657
658
|
* // Observer as a plain function
|
|
658
659
|
* const subscription = actor.subscribe((snapshot) => {
|
|
@@ -661,6 +662,7 @@ class Actor {
|
|
|
661
662
|
* ```
|
|
662
663
|
*
|
|
663
664
|
* @example
|
|
665
|
+
*
|
|
664
666
|
* ```ts
|
|
665
667
|
* // Observer as an object
|
|
666
668
|
* const subscription = actor.subscribe({
|
|
@@ -672,13 +674,16 @@ class Actor {
|
|
|
672
674
|
* },
|
|
673
675
|
* complete() {
|
|
674
676
|
* // ...
|
|
675
|
-
* }
|
|
677
|
+
* }
|
|
676
678
|
* });
|
|
677
679
|
* ```
|
|
678
680
|
*
|
|
679
|
-
* The return value of `actor.subscribe(observer)` is a subscription object
|
|
681
|
+
* The return value of `actor.subscribe(observer)` is a subscription object
|
|
682
|
+
* that has an `.unsubscribe()` method. You can call
|
|
683
|
+
* `subscription.unsubscribe()` to unsubscribe the observer:
|
|
680
684
|
*
|
|
681
685
|
* @example
|
|
686
|
+
*
|
|
682
687
|
* ```ts
|
|
683
688
|
* const subscription = actor.subscribe((snapshot) => {
|
|
684
689
|
* // ...
|
|
@@ -688,9 +693,12 @@ class Actor {
|
|
|
688
693
|
* subscription.unsubscribe();
|
|
689
694
|
* ```
|
|
690
695
|
*
|
|
691
|
-
* When the actor is stopped, all of its observers will automatically be
|
|
696
|
+
* When the actor is stopped, all of its observers will automatically be
|
|
697
|
+
* unsubscribed.
|
|
692
698
|
*
|
|
693
|
-
* @param observer - Either a plain function that receives the latest
|
|
699
|
+
* @param observer - Either a plain function that receives the latest
|
|
700
|
+
* snapshot, or an observer object whose `.next(snapshot)` method receives
|
|
701
|
+
* the latest snapshot
|
|
694
702
|
*/
|
|
695
703
|
|
|
696
704
|
subscribe(nextListenerOrObserver, errorListener, completeListener) {
|
|
@@ -743,9 +751,7 @@ class Actor {
|
|
|
743
751
|
};
|
|
744
752
|
}
|
|
745
753
|
|
|
746
|
-
/**
|
|
747
|
-
* Starts the Actor from the initial state
|
|
748
|
-
*/
|
|
754
|
+
/** Starts the Actor from the initial state */
|
|
749
755
|
start() {
|
|
750
756
|
if (this._processingStatus === ProcessingStatus.Running) {
|
|
751
757
|
// Do not restart the service if it is already started
|
|
@@ -861,9 +867,7 @@ class Actor {
|
|
|
861
867
|
return this;
|
|
862
868
|
}
|
|
863
869
|
|
|
864
|
-
/**
|
|
865
|
-
* Stops the Actor and unsubscribe all listeners.
|
|
866
|
-
*/
|
|
870
|
+
/** Stops the Actor and unsubscribe all listeners. */
|
|
867
871
|
stop() {
|
|
868
872
|
if (this._parent) {
|
|
869
873
|
throw new Error('A non-root actor cannot be stopped directly.');
|
|
@@ -935,9 +939,7 @@ class Actor {
|
|
|
935
939
|
return this;
|
|
936
940
|
}
|
|
937
941
|
|
|
938
|
-
/**
|
|
939
|
-
* @internal
|
|
940
|
-
*/
|
|
942
|
+
/** @internal */
|
|
941
943
|
_send(event) {
|
|
942
944
|
if (this._processingStatus === ProcessingStatus.Stopped) {
|
|
943
945
|
return;
|
|
@@ -975,10 +977,11 @@ class Actor {
|
|
|
975
977
|
* @remarks
|
|
976
978
|
* The internal state can be persisted from any actor, not only machines.
|
|
977
979
|
*
|
|
978
|
-
* Note that the persisted state is not the same as the snapshot from
|
|
980
|
+
* Note that the persisted state is not the same as the snapshot from
|
|
981
|
+
* {@link Actor.getSnapshot}. Persisted state represents the internal state of
|
|
982
|
+
* the actor, while snapshots represent the actor's last emitted value.
|
|
979
983
|
*
|
|
980
984
|
* Can be restored with {@link ActorOptions.state}
|
|
981
|
-
*
|
|
982
985
|
* @see https://stately.ai/docs/persistence
|
|
983
986
|
*/
|
|
984
987
|
|
|
@@ -995,11 +998,11 @@ class Actor {
|
|
|
995
998
|
* @remarks
|
|
996
999
|
* The snapshot represent an actor's last emitted value.
|
|
997
1000
|
*
|
|
998
|
-
* When an actor receives an event, its internal state may change.
|
|
999
|
-
*
|
|
1000
|
-
*
|
|
1001
|
-
* Note that some actors, such as callback actors generated with `fromCallback`, will not emit snapshots.
|
|
1001
|
+
* When an actor receives an event, its internal state may change. An actor
|
|
1002
|
+
* may emit a snapshot when a state transition occurs.
|
|
1002
1003
|
*
|
|
1004
|
+
* Note that some actors, such as callback actors generated with
|
|
1005
|
+
* `fromCallback`, will not emit snapshots.
|
|
1003
1006
|
* @see {@link Actor.subscribe} to subscribe to an actor’s snapshot values.
|
|
1004
1007
|
* @see {@link Actor.getPersistedSnapshot} to persist the internal state of an actor (which is more than just a snapshot).
|
|
1005
1008
|
*/
|
|
@@ -1008,13 +1011,16 @@ class Actor {
|
|
|
1008
1011
|
}
|
|
1009
1012
|
}
|
|
1010
1013
|
/**
|
|
1011
|
-
* Creates a new actor instance for the given actor logic with the provided
|
|
1014
|
+
* Creates a new actor instance for the given actor logic with the provided
|
|
1015
|
+
* options, if any.
|
|
1012
1016
|
*
|
|
1013
1017
|
* @remarks
|
|
1014
|
-
* When you create an actor from actor logic via `createActor(logic)`, you
|
|
1015
|
-
*
|
|
1016
|
-
*
|
|
1018
|
+
* When you create an actor from actor logic via `createActor(logic)`, you
|
|
1019
|
+
* implicitly create an actor system where the created actor is the root actor.
|
|
1020
|
+
* Any actors spawned from this root actor and its descendants are part of that
|
|
1021
|
+
* actor system.
|
|
1017
1022
|
* @example
|
|
1023
|
+
*
|
|
1018
1024
|
* ```ts
|
|
1019
1025
|
* import { createActor } from 'xstate';
|
|
1020
1026
|
* import { someActorLogic } from './someActorLogic.ts';
|
|
@@ -1036,7 +1042,10 @@ class Actor {
|
|
|
1036
1042
|
* actor.stop();
|
|
1037
1043
|
* ```
|
|
1038
1044
|
*
|
|
1039
|
-
* @param logic - The actor logic to create an actor from. For a state machine
|
|
1045
|
+
* @param logic - The actor logic to create an actor from. For a state machine
|
|
1046
|
+
* actor logic creator, see {@link createMachine}. Other actor logic creators
|
|
1047
|
+
* include {@link fromCallback}, {@link fromEventObservable},
|
|
1048
|
+
* {@link fromObservable}, {@link fromPromise}, and {@link fromTransition}.
|
|
1040
1049
|
* @param options - Actor options
|
|
1041
1050
|
*/
|
|
1042
1051
|
function createActor(logic, ...[options]) {
|
|
@@ -1044,15 +1053,14 @@ function createActor(logic, ...[options]) {
|
|
|
1044
1053
|
}
|
|
1045
1054
|
|
|
1046
1055
|
/**
|
|
1047
|
-
* Creates a new Interpreter instance for the given machine with the provided
|
|
1056
|
+
* Creates a new Interpreter instance for the given machine with the provided
|
|
1057
|
+
* options, if any.
|
|
1048
1058
|
*
|
|
1049
1059
|
* @deprecated Use `createActor` instead
|
|
1050
1060
|
*/
|
|
1051
1061
|
const interpret = createActor;
|
|
1052
1062
|
|
|
1053
|
-
/**
|
|
1054
|
-
* @deprecated Use `Actor` instead.
|
|
1055
|
-
*/
|
|
1063
|
+
/** @deprecated Use `Actor` instead. */
|
|
1056
1064
|
|
|
1057
1065
|
function resolveCancel(_, snapshot, actionArgs, actionParams, {
|
|
1058
1066
|
sendId
|
|
@@ -1066,30 +1074,36 @@ function executeCancel(actorScope, resolvedSendId) {
|
|
|
1066
1074
|
});
|
|
1067
1075
|
}
|
|
1068
1076
|
/**
|
|
1069
|
-
* Cancels a delayed `sendTo(...)` action that is waiting to be executed. The
|
|
1070
|
-
* will not send its event or execute, unless the
|
|
1077
|
+
* Cancels a delayed `sendTo(...)` action that is waiting to be executed. The
|
|
1078
|
+
* canceled `sendTo(...)` action will not send its event or execute, unless the
|
|
1079
|
+
* `delay` has already elapsed before `cancel(...)` is called.
|
|
1071
1080
|
*
|
|
1072
|
-
* @param sendId The `id` of the `sendTo(...)` action to cancel.
|
|
1073
|
-
*
|
|
1074
1081
|
* @example
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1082
|
+
*
|
|
1083
|
+
* ```ts
|
|
1084
|
+
* import { createMachine, sendTo, cancel } from 'xstate';
|
|
1085
|
+
*
|
|
1086
|
+
* const machine = createMachine({
|
|
1087
|
+
* // ...
|
|
1088
|
+
* on: {
|
|
1089
|
+
* sendEvent: {
|
|
1090
|
+
* actions: sendTo(
|
|
1091
|
+
* 'some-actor',
|
|
1092
|
+
* { type: 'someEvent' },
|
|
1093
|
+
* {
|
|
1094
|
+
* id: 'some-id',
|
|
1095
|
+
* delay: 1000
|
|
1096
|
+
* }
|
|
1097
|
+
* )
|
|
1098
|
+
* },
|
|
1099
|
+
* cancelEvent: {
|
|
1100
|
+
* actions: cancel('some-id')
|
|
1101
|
+
* }
|
|
1102
|
+
* }
|
|
1103
|
+
* });
|
|
1104
|
+
* ```
|
|
1105
|
+
*
|
|
1106
|
+
* @param sendId The `id` of the `sendTo(...)` action to cancel.
|
|
1093
1107
|
*/
|
|
1094
1108
|
function cancel(sendId) {
|
|
1095
1109
|
function cancel(args, params) {
|
|
@@ -1257,30 +1271,33 @@ function checkNot(snapshot, {
|
|
|
1257
1271
|
}
|
|
1258
1272
|
|
|
1259
1273
|
/**
|
|
1260
|
-
* Higher-order guard that evaluates to `true` if the `guard` passed to it
|
|
1274
|
+
* Higher-order guard that evaluates to `true` if the `guard` passed to it
|
|
1275
|
+
* evaluates to `false`.
|
|
1261
1276
|
*
|
|
1262
1277
|
* @category Guards
|
|
1263
1278
|
* @example
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
*
|
|
1279
|
+
*
|
|
1280
|
+
* ```ts
|
|
1281
|
+
* import { setup, not } from 'xstate';
|
|
1282
|
+
*
|
|
1283
|
+
* const machine = setup({
|
|
1284
|
+
* guards: {
|
|
1285
|
+
* someNamedGuard: () => false
|
|
1286
|
+
* }
|
|
1287
|
+
* }).createMachine({
|
|
1288
|
+
* on: {
|
|
1289
|
+
* someEvent: {
|
|
1290
|
+
* guard: not('someNamedGuard'),
|
|
1291
|
+
* actions: () => {
|
|
1292
|
+
* // will be executed if guard in `not(...)`
|
|
1293
|
+
* // evaluates to `false`
|
|
1294
|
+
* }
|
|
1295
|
+
* }
|
|
1296
|
+
* }
|
|
1297
|
+
* });
|
|
1298
|
+
* ```
|
|
1299
|
+
*
|
|
1300
|
+
* @returns A guard
|
|
1284
1301
|
*/
|
|
1285
1302
|
function not(guard) {
|
|
1286
1303
|
function not(args, params) {
|
|
@@ -1305,28 +1322,27 @@ function checkAnd(snapshot, {
|
|
|
1305
1322
|
*
|
|
1306
1323
|
* @category Guards
|
|
1307
1324
|
* @example
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
```
|
|
1325
|
+
*
|
|
1326
|
+
* ```ts
|
|
1327
|
+
* import { setup, and } from 'xstate';
|
|
1328
|
+
*
|
|
1329
|
+
* const machine = setup({
|
|
1330
|
+
* guards: {
|
|
1331
|
+
* someNamedGuard: () => true
|
|
1332
|
+
* }
|
|
1333
|
+
* }).createMachine({
|
|
1334
|
+
* on: {
|
|
1335
|
+
* someEvent: {
|
|
1336
|
+
* guard: and([({ context }) => context.value > 0, 'someNamedGuard']),
|
|
1337
|
+
* actions: () => {
|
|
1338
|
+
* // will be executed if all guards in `and(...)`
|
|
1339
|
+
* // evaluate to true
|
|
1340
|
+
* }
|
|
1341
|
+
* }
|
|
1342
|
+
* }
|
|
1343
|
+
* });
|
|
1344
|
+
* ```
|
|
1345
|
+
*
|
|
1330
1346
|
* @returns A guard action object
|
|
1331
1347
|
*/
|
|
1332
1348
|
function and(guards) {
|
|
@@ -1347,33 +1363,32 @@ function checkOr(snapshot, {
|
|
|
1347
1363
|
}
|
|
1348
1364
|
|
|
1349
1365
|
/**
|
|
1350
|
-
* Higher-order guard that evaluates to `true` if any of the `guards` passed to
|
|
1351
|
-
* evaluate to `true`.
|
|
1366
|
+
* Higher-order guard that evaluates to `true` if any of the `guards` passed to
|
|
1367
|
+
* it evaluate to `true`.
|
|
1352
1368
|
*
|
|
1353
1369
|
* @category Guards
|
|
1354
1370
|
* @example
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
```
|
|
1371
|
+
*
|
|
1372
|
+
* ```ts
|
|
1373
|
+
* import { setup, or } from 'xstate';
|
|
1374
|
+
*
|
|
1375
|
+
* const machine = setup({
|
|
1376
|
+
* guards: {
|
|
1377
|
+
* someNamedGuard: () => true
|
|
1378
|
+
* }
|
|
1379
|
+
* }).createMachine({
|
|
1380
|
+
* on: {
|
|
1381
|
+
* someEvent: {
|
|
1382
|
+
* guard: or([({ context }) => context.value > 0, 'someNamedGuard']),
|
|
1383
|
+
* actions: () => {
|
|
1384
|
+
* // will be executed if any of the guards in `or(...)`
|
|
1385
|
+
* // evaluate to true
|
|
1386
|
+
* }
|
|
1387
|
+
* }
|
|
1388
|
+
* }
|
|
1389
|
+
* });
|
|
1390
|
+
* ```
|
|
1391
|
+
*
|
|
1377
1392
|
* @returns A guard action object
|
|
1378
1393
|
*/
|
|
1379
1394
|
function or(guards) {
|
|
@@ -1550,9 +1565,7 @@ function getCandidates(stateNode, receivedEventType) {
|
|
|
1550
1565
|
return candidates;
|
|
1551
1566
|
}
|
|
1552
1567
|
|
|
1553
|
-
/**
|
|
1554
|
-
* All delayed transitions from the config.
|
|
1555
|
-
*/
|
|
1568
|
+
/** All delayed transitions from the config. */
|
|
1556
1569
|
function getDelayedTransitions(stateNode) {
|
|
1557
1570
|
const afterConfig = stateNode.config.after;
|
|
1558
1571
|
if (!afterConfig) {
|
|
@@ -1739,9 +1752,7 @@ function getInitialStateNodes(stateNode) {
|
|
|
1739
1752
|
iter(stateNode);
|
|
1740
1753
|
return set;
|
|
1741
1754
|
}
|
|
1742
|
-
/**
|
|
1743
|
-
* Returns the child state node from its relative `stateKey`, or throws.
|
|
1744
|
-
*/
|
|
1755
|
+
/** Returns the child state node from its relative `stateKey`, or throws. */
|
|
1745
1756
|
function getStateNode(stateNode, stateKey) {
|
|
1746
1757
|
if (isStateId(stateKey)) {
|
|
1747
1758
|
return stateNode.machine.getStateNodeById(stateKey);
|
|
@@ -1982,9 +1993,7 @@ function areStateNodeCollectionsEqual(prevStateNodes, nextStateNodeSet) {
|
|
|
1982
1993
|
return true;
|
|
1983
1994
|
}
|
|
1984
1995
|
|
|
1985
|
-
/**
|
|
1986
|
-
* https://www.w3.org/TR/scxml/#microstepProcedure
|
|
1987
|
-
*/
|
|
1996
|
+
/** https://www.w3.org/TR/scxml/#microstepProcedure */
|
|
1988
1997
|
function microstep(transitions, currentSnapshot, actorScope, event, isInitial, internalQueue) {
|
|
1989
1998
|
if (!transitions.length) {
|
|
1990
1999
|
return currentSnapshot;
|
|
@@ -2394,7 +2403,8 @@ function selectEventlessTransitions(nextState, event) {
|
|
|
2394
2403
|
}
|
|
2395
2404
|
|
|
2396
2405
|
/**
|
|
2397
|
-
* Resolves a partial state value with its full representation in the state
|
|
2406
|
+
* Resolves a partial state value with its full representation in the state
|
|
2407
|
+
* node's machine.
|
|
2398
2408
|
*
|
|
2399
2409
|
* @param stateValue The partial state value to resolve.
|
|
2400
2410
|
*/
|