xstate 5.18.0 → 5.18.2
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.d.mts +1 -1
- package/actions/dist/xstate-actions.cjs.d.ts +1 -1
- 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.d.mts +1 -1
- package/actors/dist/xstate-actors.cjs.d.ts +1 -1
- package/actors/dist/xstate-actors.cjs.js +1 -1
- package/actors/dist/xstate-actors.development.cjs.js +1 -1
- package/actors/dist/xstate-actors.development.esm.js +1 -1
- package/actors/dist/xstate-actors.esm.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dev/dist/xstate-dev.cjs.d.mts +1 -1
- package/dev/dist/xstate-dev.cjs.d.ts +1 -1
- package/dist/declarations/src/State.d.ts +1 -1
- package/dist/declarations/src/createActor.d.ts +3 -4
- package/dist/declarations/src/index.d.ts +5 -5
- package/dist/declarations/src/inspection.d.ts +2 -2
- package/dist/{log-54d038f7.esm.js → log-15d0f775.esm.js} +9 -2
- package/dist/{log-4f8360d3.development.esm.js → log-38475d87.development.esm.js} +9 -2
- package/dist/{log-f7dcaa97.cjs.js → log-98fcce74.cjs.js} +9 -2
- package/dist/{log-40d606d3.development.cjs.js → log-b7ed1b61.development.cjs.js} +9 -2
- package/dist/{State-cdbc7940.esm.js → raise-0f7cf128.esm.js} +191 -192
- package/dist/{State-34039d2a.development.esm.js → raise-5ea71f04.development.esm.js} +206 -207
- package/dist/{State-30c95050.cjs.js → raise-b1e0b9a9.cjs.js} +190 -191
- package/dist/{State-a2464a1e.development.cjs.js → raise-e919c5d4.development.cjs.js} +205 -206
- package/dist/xstate.cjs.d.mts +1 -1
- package/dist/xstate.cjs.d.ts +1 -1
- package/dist/xstate.cjs.js +106 -104
- package/dist/xstate.development.cjs.js +106 -104
- package/dist/xstate.development.esm.js +102 -100
- package/dist/xstate.esm.js +102 -100
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.d.mts +1 -1
- package/guards/dist/xstate-guards.cjs.d.ts +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 +7 -7
- package/actions/dist/xstate-actions.cjs.d.mts.map +0 -1
- package/actions/dist/xstate-actions.cjs.d.ts.map +0 -1
- package/actors/dist/xstate-actors.cjs.d.mts.map +0 -1
- package/actors/dist/xstate-actors.cjs.d.ts.map +0 -1
- package/dev/dist/xstate-dev.cjs.d.mts.map +0 -1
- package/dev/dist/xstate-dev.cjs.d.ts.map +0 -1
- package/dist/xstate.cjs.d.mts.map +0 -1
- package/dist/xstate.cjs.d.ts.map +0 -1
- package/guards/dist/xstate-guards.cjs.d.mts.map +0 -1
- package/guards/dist/xstate-guards.cjs.d.ts.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActorRefLike,
|
|
1
|
+
import { ActorRefLike, AnyEventObject, AnyTransitionDefinition, Snapshot } from "./types.js";
|
|
2
2
|
export type InspectionEvent = InspectedSnapshotEvent | InspectedEventEvent | InspectedActorEvent | InspectedMicrostepEvent | InspectedActionEvent;
|
|
3
3
|
interface BaseInspectionEventProperties {
|
|
4
4
|
rootId: string;
|
|
@@ -31,7 +31,7 @@ export interface InspectedActionEvent extends BaseInspectionEventProperties {
|
|
|
31
31
|
}
|
|
32
32
|
export interface InspectedEventEvent extends BaseInspectionEventProperties {
|
|
33
33
|
type: '@xstate.event';
|
|
34
|
-
sourceRef:
|
|
34
|
+
sourceRef: ActorRefLike | undefined;
|
|
35
35
|
event: AnyEventObject;
|
|
36
36
|
}
|
|
37
37
|
export interface InspectedActorEvent extends BaseInspectionEventProperties {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as ProcessingStatus, z as resolveReferencedActor, A as createActor, U as cloneMachineSnapshot, V as XSTATE_ERROR, W as createErrorActorEvent, e as evaluateGuard, M as cancel, O as raise, P as spawnChild, R as stopChild } from './
|
|
1
|
+
import { T as ProcessingStatus, z as resolveReferencedActor, A as createActor, U as cloneMachineSnapshot, V as XSTATE_ERROR, W as createErrorActorEvent, e as evaluateGuard, M as cancel, O as raise, P as spawnChild, R as stopChild } from './raise-0f7cf128.esm.js';
|
|
2
2
|
|
|
3
3
|
function createSpawner(actorScope, {
|
|
4
4
|
machine,
|
|
@@ -177,7 +177,7 @@ function executeEmit(actorScope, {
|
|
|
177
177
|
* // }
|
|
178
178
|
* ```
|
|
179
179
|
*/
|
|
180
|
-
function emit(
|
|
180
|
+
function emit(/** The event to emit, or an expression that returns an event to emit. */
|
|
181
181
|
eventOrExpr) {
|
|
182
182
|
function emit(args, params) {
|
|
183
183
|
}
|
|
@@ -209,8 +209,11 @@ eventOrExpr) {
|
|
|
209
209
|
|
|
210
210
|
// @TODO: Replace with native `NoInfer` when TS issue gets fixed:
|
|
211
211
|
// https://github.com/microsoft/TypeScript/pull/57673
|
|
212
|
+
|
|
212
213
|
/** @deprecated Use the built-in `NoInfer` type instead */
|
|
214
|
+
|
|
213
215
|
/** The full definition of an event, with a string `type`. */
|
|
216
|
+
|
|
214
217
|
/**
|
|
215
218
|
* The string or object representing the state value relative to the parent
|
|
216
219
|
* state node.
|
|
@@ -220,10 +223,14 @@ eventOrExpr) {
|
|
|
220
223
|
* - For complex state nodes, this is an object, e.g., `{ success:
|
|
221
224
|
* "someChildState" }`.
|
|
222
225
|
*/
|
|
226
|
+
|
|
223
227
|
// TODO: remove once TS fixes this type-widening issue
|
|
228
|
+
|
|
224
229
|
/** @deprecated Use `AnyMachineSnapshot` instead */
|
|
230
|
+
|
|
225
231
|
// TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
|
|
226
232
|
/** @ignore */
|
|
233
|
+
|
|
227
234
|
let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
228
235
|
SpecialTargets["Parent"] = "#_parent";
|
|
229
236
|
SpecialTargets["Internal"] = "#_internal";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as ProcessingStatus, z as resolveReferencedActor, A as createActor, U as
|
|
1
|
+
import { T as ProcessingStatus, z as resolveReferencedActor, A as createActor, U as cloneMachineSnapshot, V as executingCustomAction, W as XSTATE_ERROR, Y as createErrorActorEvent, e as evaluateGuard, M as cancel, O as raise, P as spawnChild, R as stopChild } from './raise-5ea71f04.development.esm.js';
|
|
2
2
|
|
|
3
3
|
function createSpawner(actorScope, {
|
|
4
4
|
machine,
|
|
@@ -186,7 +186,7 @@ function executeEmit(actorScope, {
|
|
|
186
186
|
* // }
|
|
187
187
|
* ```
|
|
188
188
|
*/
|
|
189
|
-
function emit(
|
|
189
|
+
function emit(/** The event to emit, or an expression that returns an event to emit. */
|
|
190
190
|
eventOrExpr) {
|
|
191
191
|
if (executingCustomAction) {
|
|
192
192
|
console.warn('Custom actions should not call `emit()` directly, as it is not imperative. See https://stately.ai/docs/actions#built-in-actions for more details.');
|
|
@@ -224,8 +224,11 @@ eventOrExpr) {
|
|
|
224
224
|
|
|
225
225
|
// @TODO: Replace with native `NoInfer` when TS issue gets fixed:
|
|
226
226
|
// https://github.com/microsoft/TypeScript/pull/57673
|
|
227
|
+
|
|
227
228
|
/** @deprecated Use the built-in `NoInfer` type instead */
|
|
229
|
+
|
|
228
230
|
/** The full definition of an event, with a string `type`. */
|
|
231
|
+
|
|
229
232
|
/**
|
|
230
233
|
* The string or object representing the state value relative to the parent
|
|
231
234
|
* state node.
|
|
@@ -235,10 +238,14 @@ eventOrExpr) {
|
|
|
235
238
|
* - For complex state nodes, this is an object, e.g., `{ success:
|
|
236
239
|
* "someChildState" }`.
|
|
237
240
|
*/
|
|
241
|
+
|
|
238
242
|
// TODO: remove once TS fixes this type-widening issue
|
|
243
|
+
|
|
239
244
|
/** @deprecated Use `AnyMachineSnapshot` instead */
|
|
245
|
+
|
|
240
246
|
// TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
|
|
241
247
|
/** @ignore */
|
|
248
|
+
|
|
242
249
|
let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
243
250
|
SpecialTargets["Parent"] = "#_parent";
|
|
244
251
|
SpecialTargets["Internal"] = "#_internal";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var guards_dist_xstateGuards = require('./
|
|
3
|
+
var guards_dist_xstateGuards = require('./raise-b1e0b9a9.cjs.js');
|
|
4
4
|
|
|
5
5
|
function createSpawner(actorScope, {
|
|
6
6
|
machine,
|
|
@@ -179,7 +179,7 @@ function executeEmit(actorScope, {
|
|
|
179
179
|
* // }
|
|
180
180
|
* ```
|
|
181
181
|
*/
|
|
182
|
-
function emit(
|
|
182
|
+
function emit(/** The event to emit, or an expression that returns an event to emit. */
|
|
183
183
|
eventOrExpr) {
|
|
184
184
|
function emit(args, params) {
|
|
185
185
|
}
|
|
@@ -211,8 +211,11 @@ eventOrExpr) {
|
|
|
211
211
|
|
|
212
212
|
// @TODO: Replace with native `NoInfer` when TS issue gets fixed:
|
|
213
213
|
// https://github.com/microsoft/TypeScript/pull/57673
|
|
214
|
+
|
|
214
215
|
/** @deprecated Use the built-in `NoInfer` type instead */
|
|
216
|
+
|
|
215
217
|
/** The full definition of an event, with a string `type`. */
|
|
218
|
+
|
|
216
219
|
/**
|
|
217
220
|
* The string or object representing the state value relative to the parent
|
|
218
221
|
* state node.
|
|
@@ -222,10 +225,14 @@ eventOrExpr) {
|
|
|
222
225
|
* - For complex state nodes, this is an object, e.g., `{ success:
|
|
223
226
|
* "someChildState" }`.
|
|
224
227
|
*/
|
|
228
|
+
|
|
225
229
|
// TODO: remove once TS fixes this type-widening issue
|
|
230
|
+
|
|
226
231
|
/** @deprecated Use `AnyMachineSnapshot` instead */
|
|
232
|
+
|
|
227
233
|
// TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
|
|
228
234
|
/** @ignore */
|
|
235
|
+
|
|
229
236
|
let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
230
237
|
SpecialTargets["Parent"] = "#_parent";
|
|
231
238
|
SpecialTargets["Internal"] = "#_internal";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var guards_dist_xstateGuards = require('./
|
|
3
|
+
var guards_dist_xstateGuards = require('./raise-e919c5d4.development.cjs.js');
|
|
4
4
|
|
|
5
5
|
function createSpawner(actorScope, {
|
|
6
6
|
machine,
|
|
@@ -188,7 +188,7 @@ function executeEmit(actorScope, {
|
|
|
188
188
|
* // }
|
|
189
189
|
* ```
|
|
190
190
|
*/
|
|
191
|
-
function emit(
|
|
191
|
+
function emit(/** The event to emit, or an expression that returns an event to emit. */
|
|
192
192
|
eventOrExpr) {
|
|
193
193
|
if (guards_dist_xstateGuards.executingCustomAction) {
|
|
194
194
|
console.warn('Custom actions should not call `emit()` directly, as it is not imperative. See https://stately.ai/docs/actions#built-in-actions for more details.');
|
|
@@ -226,8 +226,11 @@ eventOrExpr) {
|
|
|
226
226
|
|
|
227
227
|
// @TODO: Replace with native `NoInfer` when TS issue gets fixed:
|
|
228
228
|
// https://github.com/microsoft/TypeScript/pull/57673
|
|
229
|
+
|
|
229
230
|
/** @deprecated Use the built-in `NoInfer` type instead */
|
|
231
|
+
|
|
230
232
|
/** The full definition of an event, with a string `type`. */
|
|
233
|
+
|
|
231
234
|
/**
|
|
232
235
|
* The string or object representing the state value relative to the parent
|
|
233
236
|
* state node.
|
|
@@ -237,10 +240,14 @@ eventOrExpr) {
|
|
|
237
240
|
* - For complex state nodes, this is an object, e.g., `{ success:
|
|
238
241
|
* "someChildState" }`.
|
|
239
242
|
*/
|
|
243
|
+
|
|
240
244
|
// TODO: remove once TS fixes this type-widening issue
|
|
245
|
+
|
|
241
246
|
/** @deprecated Use `AnyMachineSnapshot` instead */
|
|
247
|
+
|
|
242
248
|
// TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
|
|
243
249
|
/** @ignore */
|
|
250
|
+
|
|
244
251
|
let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
245
252
|
SpecialTargets["Parent"] = "#_parent";
|
|
246
253
|
SpecialTargets["Internal"] = "#_internal";
|
|
@@ -1120,6 +1120,136 @@ function cancel(sendId) {
|
|
|
1120
1120
|
return cancel;
|
|
1121
1121
|
}
|
|
1122
1122
|
|
|
1123
|
+
function resolveSpawn(actorScope, snapshot, actionArgs, _actionParams, {
|
|
1124
|
+
id,
|
|
1125
|
+
systemId,
|
|
1126
|
+
src,
|
|
1127
|
+
input,
|
|
1128
|
+
syncSnapshot
|
|
1129
|
+
}) {
|
|
1130
|
+
const logic = typeof src === 'string' ? resolveReferencedActor(snapshot.machine, src) : src;
|
|
1131
|
+
const resolvedId = typeof id === 'function' ? id(actionArgs) : id;
|
|
1132
|
+
let actorRef;
|
|
1133
|
+
if (logic) {
|
|
1134
|
+
actorRef = createActor(logic, {
|
|
1135
|
+
id: resolvedId,
|
|
1136
|
+
src,
|
|
1137
|
+
parent: actorScope.self,
|
|
1138
|
+
syncSnapshot,
|
|
1139
|
+
systemId,
|
|
1140
|
+
input: typeof input === 'function' ? input({
|
|
1141
|
+
context: snapshot.context,
|
|
1142
|
+
event: actionArgs.event,
|
|
1143
|
+
self: actorScope.self
|
|
1144
|
+
}) : input
|
|
1145
|
+
});
|
|
1146
|
+
}
|
|
1147
|
+
return [cloneMachineSnapshot(snapshot, {
|
|
1148
|
+
children: {
|
|
1149
|
+
...snapshot.children,
|
|
1150
|
+
[resolvedId]: actorRef
|
|
1151
|
+
}
|
|
1152
|
+
}), {
|
|
1153
|
+
id,
|
|
1154
|
+
actorRef
|
|
1155
|
+
}];
|
|
1156
|
+
}
|
|
1157
|
+
function executeSpawn(actorScope, {
|
|
1158
|
+
id,
|
|
1159
|
+
actorRef
|
|
1160
|
+
}) {
|
|
1161
|
+
if (!actorRef) {
|
|
1162
|
+
return;
|
|
1163
|
+
}
|
|
1164
|
+
actorScope.defer(() => {
|
|
1165
|
+
if (actorRef._processingStatus === ProcessingStatus.Stopped) {
|
|
1166
|
+
return;
|
|
1167
|
+
}
|
|
1168
|
+
actorRef.start();
|
|
1169
|
+
});
|
|
1170
|
+
}
|
|
1171
|
+
function spawnChild(...[src, {
|
|
1172
|
+
id,
|
|
1173
|
+
systemId,
|
|
1174
|
+
input,
|
|
1175
|
+
syncSnapshot = false
|
|
1176
|
+
} = {}]) {
|
|
1177
|
+
function spawnChild(args, params) {
|
|
1178
|
+
}
|
|
1179
|
+
spawnChild.type = 'snapshot.spawnChild';
|
|
1180
|
+
spawnChild.id = id;
|
|
1181
|
+
spawnChild.systemId = systemId;
|
|
1182
|
+
spawnChild.src = src;
|
|
1183
|
+
spawnChild.input = input;
|
|
1184
|
+
spawnChild.syncSnapshot = syncSnapshot;
|
|
1185
|
+
spawnChild.resolve = resolveSpawn;
|
|
1186
|
+
spawnChild.execute = executeSpawn;
|
|
1187
|
+
return spawnChild;
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
function resolveStop(_, snapshot, args, actionParams, {
|
|
1191
|
+
actorRef
|
|
1192
|
+
}) {
|
|
1193
|
+
const actorRefOrString = typeof actorRef === 'function' ? actorRef(args, actionParams) : actorRef;
|
|
1194
|
+
const resolvedActorRef = typeof actorRefOrString === 'string' ? snapshot.children[actorRefOrString] : actorRefOrString;
|
|
1195
|
+
let children = snapshot.children;
|
|
1196
|
+
if (resolvedActorRef) {
|
|
1197
|
+
children = {
|
|
1198
|
+
...children
|
|
1199
|
+
};
|
|
1200
|
+
delete children[resolvedActorRef.id];
|
|
1201
|
+
}
|
|
1202
|
+
return [cloneMachineSnapshot(snapshot, {
|
|
1203
|
+
children
|
|
1204
|
+
}), resolvedActorRef];
|
|
1205
|
+
}
|
|
1206
|
+
function executeStop(actorScope, actorRef) {
|
|
1207
|
+
if (!actorRef) {
|
|
1208
|
+
return;
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
// we need to eagerly unregister it here so a new actor with the same systemId can be registered immediately
|
|
1212
|
+
// since we defer actual stopping of the actor but we don't defer actor creations (and we can't do that)
|
|
1213
|
+
// this could throw on `systemId` collision, for example, when dealing with reentering transitions
|
|
1214
|
+
actorScope.system._unregister(actorRef);
|
|
1215
|
+
|
|
1216
|
+
// this allows us to prevent an actor from being started if it gets stopped within the same macrostep
|
|
1217
|
+
// this can happen, for example, when the invoking state is being exited immediately by an always transition
|
|
1218
|
+
if (actorRef._processingStatus !== ProcessingStatus.Running) {
|
|
1219
|
+
actorScope.stopChild(actorRef);
|
|
1220
|
+
return;
|
|
1221
|
+
}
|
|
1222
|
+
// stopping a child enqueues a stop event in the child actor's mailbox
|
|
1223
|
+
// we need for all of the already enqueued events to be processed before we stop the child
|
|
1224
|
+
// the parent itself might want to send some events to a child (for example from exit actions on the invoking state)
|
|
1225
|
+
// and we don't want to ignore those events
|
|
1226
|
+
actorScope.defer(() => {
|
|
1227
|
+
actorScope.stopChild(actorRef);
|
|
1228
|
+
});
|
|
1229
|
+
}
|
|
1230
|
+
/**
|
|
1231
|
+
* Stops a child actor.
|
|
1232
|
+
*
|
|
1233
|
+
* @param actorRef The actor to stop.
|
|
1234
|
+
*/
|
|
1235
|
+
function stopChild(actorRef) {
|
|
1236
|
+
function stop(args, params) {
|
|
1237
|
+
}
|
|
1238
|
+
stop.type = 'xstate.stopChild';
|
|
1239
|
+
stop.actorRef = actorRef;
|
|
1240
|
+
stop.resolve = resolveStop;
|
|
1241
|
+
stop.execute = executeStop;
|
|
1242
|
+
return stop;
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1245
|
+
/**
|
|
1246
|
+
* Stops a child actor.
|
|
1247
|
+
*
|
|
1248
|
+
* @deprecated Use `stopChild(...)` instead
|
|
1249
|
+
* @alias
|
|
1250
|
+
*/
|
|
1251
|
+
const stop = stopChild;
|
|
1252
|
+
|
|
1123
1253
|
function checkStateIn(snapshot, _, {
|
|
1124
1254
|
stateValue
|
|
1125
1255
|
}) {
|
|
@@ -1308,196 +1438,6 @@ function evaluateGuard(guard, context, event, snapshot) {
|
|
|
1308
1438
|
);
|
|
1309
1439
|
}
|
|
1310
1440
|
|
|
1311
|
-
function resolveRaise(_, snapshot, args, actionParams, {
|
|
1312
|
-
event: eventOrExpr,
|
|
1313
|
-
id,
|
|
1314
|
-
delay
|
|
1315
|
-
}, {
|
|
1316
|
-
internalQueue
|
|
1317
|
-
}) {
|
|
1318
|
-
const delaysMap = snapshot.machine.implementations.delays;
|
|
1319
|
-
if (typeof eventOrExpr === 'string') {
|
|
1320
|
-
throw new Error(`Only event objects may be used with raise; use raise({ type: "${eventOrExpr}" }) instead`);
|
|
1321
|
-
}
|
|
1322
|
-
const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args, actionParams) : eventOrExpr;
|
|
1323
|
-
let resolvedDelay;
|
|
1324
|
-
if (typeof delay === 'string') {
|
|
1325
|
-
const configDelay = delaysMap && delaysMap[delay];
|
|
1326
|
-
resolvedDelay = typeof configDelay === 'function' ? configDelay(args, actionParams) : configDelay;
|
|
1327
|
-
} else {
|
|
1328
|
-
resolvedDelay = typeof delay === 'function' ? delay(args, actionParams) : delay;
|
|
1329
|
-
}
|
|
1330
|
-
if (typeof resolvedDelay !== 'number') {
|
|
1331
|
-
internalQueue.push(resolvedEvent);
|
|
1332
|
-
}
|
|
1333
|
-
return [snapshot, {
|
|
1334
|
-
event: resolvedEvent,
|
|
1335
|
-
id,
|
|
1336
|
-
delay: resolvedDelay
|
|
1337
|
-
}];
|
|
1338
|
-
}
|
|
1339
|
-
function executeRaise(actorScope, params) {
|
|
1340
|
-
const {
|
|
1341
|
-
event,
|
|
1342
|
-
delay,
|
|
1343
|
-
id
|
|
1344
|
-
} = params;
|
|
1345
|
-
if (typeof delay === 'number') {
|
|
1346
|
-
actorScope.defer(() => {
|
|
1347
|
-
const self = actorScope.self;
|
|
1348
|
-
actorScope.system.scheduler.schedule(self, self, event, delay, id);
|
|
1349
|
-
});
|
|
1350
|
-
return;
|
|
1351
|
-
}
|
|
1352
|
-
}
|
|
1353
|
-
/**
|
|
1354
|
-
* Raises an event. This places the event in the internal event queue, so that
|
|
1355
|
-
* the event is immediately consumed by the machine in the current step.
|
|
1356
|
-
*
|
|
1357
|
-
* @param eventType The event to raise.
|
|
1358
|
-
*/
|
|
1359
|
-
function raise(eventOrExpr, options) {
|
|
1360
|
-
function raise(args, params) {
|
|
1361
|
-
}
|
|
1362
|
-
raise.type = 'xstate.raise';
|
|
1363
|
-
raise.event = eventOrExpr;
|
|
1364
|
-
raise.id = options?.id;
|
|
1365
|
-
raise.delay = options?.delay;
|
|
1366
|
-
raise.resolve = resolveRaise;
|
|
1367
|
-
raise.execute = executeRaise;
|
|
1368
|
-
return raise;
|
|
1369
|
-
}
|
|
1370
|
-
|
|
1371
|
-
function resolveSpawn(actorScope, snapshot, actionArgs, _actionParams, {
|
|
1372
|
-
id,
|
|
1373
|
-
systemId,
|
|
1374
|
-
src,
|
|
1375
|
-
input,
|
|
1376
|
-
syncSnapshot
|
|
1377
|
-
}) {
|
|
1378
|
-
const logic = typeof src === 'string' ? resolveReferencedActor(snapshot.machine, src) : src;
|
|
1379
|
-
const resolvedId = typeof id === 'function' ? id(actionArgs) : id;
|
|
1380
|
-
let actorRef;
|
|
1381
|
-
if (logic) {
|
|
1382
|
-
actorRef = createActor(logic, {
|
|
1383
|
-
id: resolvedId,
|
|
1384
|
-
src,
|
|
1385
|
-
parent: actorScope.self,
|
|
1386
|
-
syncSnapshot,
|
|
1387
|
-
systemId,
|
|
1388
|
-
input: typeof input === 'function' ? input({
|
|
1389
|
-
context: snapshot.context,
|
|
1390
|
-
event: actionArgs.event,
|
|
1391
|
-
self: actorScope.self
|
|
1392
|
-
}) : input
|
|
1393
|
-
});
|
|
1394
|
-
}
|
|
1395
|
-
return [cloneMachineSnapshot(snapshot, {
|
|
1396
|
-
children: {
|
|
1397
|
-
...snapshot.children,
|
|
1398
|
-
[resolvedId]: actorRef
|
|
1399
|
-
}
|
|
1400
|
-
}), {
|
|
1401
|
-
id,
|
|
1402
|
-
actorRef
|
|
1403
|
-
}];
|
|
1404
|
-
}
|
|
1405
|
-
function executeSpawn(actorScope, {
|
|
1406
|
-
id,
|
|
1407
|
-
actorRef
|
|
1408
|
-
}) {
|
|
1409
|
-
if (!actorRef) {
|
|
1410
|
-
return;
|
|
1411
|
-
}
|
|
1412
|
-
actorScope.defer(() => {
|
|
1413
|
-
if (actorRef._processingStatus === ProcessingStatus.Stopped) {
|
|
1414
|
-
return;
|
|
1415
|
-
}
|
|
1416
|
-
actorRef.start();
|
|
1417
|
-
});
|
|
1418
|
-
}
|
|
1419
|
-
function spawnChild(...[src, {
|
|
1420
|
-
id,
|
|
1421
|
-
systemId,
|
|
1422
|
-
input,
|
|
1423
|
-
syncSnapshot = false
|
|
1424
|
-
} = {}]) {
|
|
1425
|
-
function spawnChild(args, params) {
|
|
1426
|
-
}
|
|
1427
|
-
spawnChild.type = 'snapshot.spawnChild';
|
|
1428
|
-
spawnChild.id = id;
|
|
1429
|
-
spawnChild.systemId = systemId;
|
|
1430
|
-
spawnChild.src = src;
|
|
1431
|
-
spawnChild.input = input;
|
|
1432
|
-
spawnChild.syncSnapshot = syncSnapshot;
|
|
1433
|
-
spawnChild.resolve = resolveSpawn;
|
|
1434
|
-
spawnChild.execute = executeSpawn;
|
|
1435
|
-
return spawnChild;
|
|
1436
|
-
}
|
|
1437
|
-
|
|
1438
|
-
function resolveStop(_, snapshot, args, actionParams, {
|
|
1439
|
-
actorRef
|
|
1440
|
-
}) {
|
|
1441
|
-
const actorRefOrString = typeof actorRef === 'function' ? actorRef(args, actionParams) : actorRef;
|
|
1442
|
-
const resolvedActorRef = typeof actorRefOrString === 'string' ? snapshot.children[actorRefOrString] : actorRefOrString;
|
|
1443
|
-
let children = snapshot.children;
|
|
1444
|
-
if (resolvedActorRef) {
|
|
1445
|
-
children = {
|
|
1446
|
-
...children
|
|
1447
|
-
};
|
|
1448
|
-
delete children[resolvedActorRef.id];
|
|
1449
|
-
}
|
|
1450
|
-
return [cloneMachineSnapshot(snapshot, {
|
|
1451
|
-
children
|
|
1452
|
-
}), resolvedActorRef];
|
|
1453
|
-
}
|
|
1454
|
-
function executeStop(actorScope, actorRef) {
|
|
1455
|
-
if (!actorRef) {
|
|
1456
|
-
return;
|
|
1457
|
-
}
|
|
1458
|
-
|
|
1459
|
-
// we need to eagerly unregister it here so a new actor with the same systemId can be registered immediately
|
|
1460
|
-
// since we defer actual stopping of the actor but we don't defer actor creations (and we can't do that)
|
|
1461
|
-
// this could throw on `systemId` collision, for example, when dealing with reentering transitions
|
|
1462
|
-
actorScope.system._unregister(actorRef);
|
|
1463
|
-
|
|
1464
|
-
// this allows us to prevent an actor from being started if it gets stopped within the same macrostep
|
|
1465
|
-
// this can happen, for example, when the invoking state is being exited immediately by an always transition
|
|
1466
|
-
if (actorRef._processingStatus !== ProcessingStatus.Running) {
|
|
1467
|
-
actorScope.stopChild(actorRef);
|
|
1468
|
-
return;
|
|
1469
|
-
}
|
|
1470
|
-
// stopping a child enqueues a stop event in the child actor's mailbox
|
|
1471
|
-
// we need for all of the already enqueued events to be processed before we stop the child
|
|
1472
|
-
// the parent itself might want to send some events to a child (for example from exit actions on the invoking state)
|
|
1473
|
-
// and we don't want to ignore those events
|
|
1474
|
-
actorScope.defer(() => {
|
|
1475
|
-
actorScope.stopChild(actorRef);
|
|
1476
|
-
});
|
|
1477
|
-
}
|
|
1478
|
-
/**
|
|
1479
|
-
* Stops a child actor.
|
|
1480
|
-
*
|
|
1481
|
-
* @param actorRef The actor to stop.
|
|
1482
|
-
*/
|
|
1483
|
-
function stopChild(actorRef) {
|
|
1484
|
-
function stop(args, params) {
|
|
1485
|
-
}
|
|
1486
|
-
stop.type = 'xstate.stopChild';
|
|
1487
|
-
stop.actorRef = actorRef;
|
|
1488
|
-
stop.resolve = resolveStop;
|
|
1489
|
-
stop.execute = executeStop;
|
|
1490
|
-
return stop;
|
|
1491
|
-
}
|
|
1492
|
-
|
|
1493
|
-
/**
|
|
1494
|
-
* Stops a child actor.
|
|
1495
|
-
*
|
|
1496
|
-
* @deprecated Use `stopChild(...)` instead
|
|
1497
|
-
* @alias
|
|
1498
|
-
*/
|
|
1499
|
-
const stop = stopChild;
|
|
1500
|
-
|
|
1501
1441
|
const isAtomicStateNode = stateNode => stateNode.type === 'atomic' || stateNode.type === 'final';
|
|
1502
1442
|
function getChildren(stateNode) {
|
|
1503
1443
|
return Object.values(stateNode.states).filter(sn => sn.type !== 'history');
|
|
@@ -1557,7 +1497,6 @@ function getValueFromAdj(baseNode, adjList) {
|
|
|
1557
1497
|
if (!childStateNodes) {
|
|
1558
1498
|
return {}; // todo: fix?
|
|
1559
1499
|
}
|
|
1560
|
-
|
|
1561
1500
|
if (baseNode.type === 'compound') {
|
|
1562
1501
|
const childStateNode = childStateNodes[0];
|
|
1563
1502
|
if (childStateNode) {
|
|
@@ -2602,4 +2541,64 @@ function persistContext(contextPart) {
|
|
|
2602
2541
|
return copy ?? contextPart;
|
|
2603
2542
|
}
|
|
2604
2543
|
|
|
2605
|
-
|
|
2544
|
+
function resolveRaise(_, snapshot, args, actionParams, {
|
|
2545
|
+
event: eventOrExpr,
|
|
2546
|
+
id,
|
|
2547
|
+
delay
|
|
2548
|
+
}, {
|
|
2549
|
+
internalQueue
|
|
2550
|
+
}) {
|
|
2551
|
+
const delaysMap = snapshot.machine.implementations.delays;
|
|
2552
|
+
if (typeof eventOrExpr === 'string') {
|
|
2553
|
+
throw new Error(`Only event objects may be used with raise; use raise({ type: "${eventOrExpr}" }) instead`);
|
|
2554
|
+
}
|
|
2555
|
+
const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args, actionParams) : eventOrExpr;
|
|
2556
|
+
let resolvedDelay;
|
|
2557
|
+
if (typeof delay === 'string') {
|
|
2558
|
+
const configDelay = delaysMap && delaysMap[delay];
|
|
2559
|
+
resolvedDelay = typeof configDelay === 'function' ? configDelay(args, actionParams) : configDelay;
|
|
2560
|
+
} else {
|
|
2561
|
+
resolvedDelay = typeof delay === 'function' ? delay(args, actionParams) : delay;
|
|
2562
|
+
}
|
|
2563
|
+
if (typeof resolvedDelay !== 'number') {
|
|
2564
|
+
internalQueue.push(resolvedEvent);
|
|
2565
|
+
}
|
|
2566
|
+
return [snapshot, {
|
|
2567
|
+
event: resolvedEvent,
|
|
2568
|
+
id,
|
|
2569
|
+
delay: resolvedDelay
|
|
2570
|
+
}];
|
|
2571
|
+
}
|
|
2572
|
+
function executeRaise(actorScope, params) {
|
|
2573
|
+
const {
|
|
2574
|
+
event,
|
|
2575
|
+
delay,
|
|
2576
|
+
id
|
|
2577
|
+
} = params;
|
|
2578
|
+
if (typeof delay === 'number') {
|
|
2579
|
+
actorScope.defer(() => {
|
|
2580
|
+
const self = actorScope.self;
|
|
2581
|
+
actorScope.system.scheduler.schedule(self, self, event, delay, id);
|
|
2582
|
+
});
|
|
2583
|
+
return;
|
|
2584
|
+
}
|
|
2585
|
+
}
|
|
2586
|
+
/**
|
|
2587
|
+
* Raises an event. This places the event in the internal event queue, so that
|
|
2588
|
+
* the event is immediately consumed by the machine in the current step.
|
|
2589
|
+
*
|
|
2590
|
+
* @param eventType The event to raise.
|
|
2591
|
+
*/
|
|
2592
|
+
function raise(eventOrExpr, options) {
|
|
2593
|
+
function raise(args, params) {
|
|
2594
|
+
}
|
|
2595
|
+
raise.type = 'xstate.raise';
|
|
2596
|
+
raise.event = eventOrExpr;
|
|
2597
|
+
raise.id = options?.id;
|
|
2598
|
+
raise.delay = options?.delay;
|
|
2599
|
+
raise.resolve = resolveRaise;
|
|
2600
|
+
raise.execute = executeRaise;
|
|
2601
|
+
return raise;
|
|
2602
|
+
}
|
|
2603
|
+
|
|
2604
|
+
export { $$ACTOR_TYPE as $, createActor as A, Actor as B, interpret as C, and as D, not as E, or as F, stateIn as G, isMachineSnapshot as H, getAllOwnEventDescriptors as I, matchesState as J, pathToStateValue as K, toObserver as L, cancel as M, NULL_EVENT as N, raise as O, spawnChild as P, stop as Q, stopChild as R, STATE_DELIMITER as S, ProcessingStatus as T, cloneMachineSnapshot as U, XSTATE_ERROR as V, createErrorActorEvent as W, XSTATE_STOP as X, toTransitionConfigArray as a, formatTransition as b, createInvokeId as c, formatInitialTransition as d, evaluateGuard as e, formatTransitions as f, getDelayedTransitions as g, getCandidates as h, getAllStateNodes as i, getStateNodes as j, createMachineSnapshot as k, isInFinalState as l, mapValues as m, macrostep as n, transitionNode as o, resolveActionsAndContext as p, createInitEvent as q, resolveStateValue as r, microstep as s, toArray as t, getInitialStateNodes as u, toStatePath as v, isStateId as w, getStateNodeByPath as x, getPersistedSnapshot as y, resolveReferencedActor as z };
|