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