xstate 5.0.0-beta.21 → 5.0.0-beta.23
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 +1 -1
- package/actions/dist/xstate-actions.development.cjs.js +1 -1
- package/actions/dist/xstate-actions.development.esm.js +1 -1
- package/actions/dist/xstate-actions.esm.js +1 -1
- 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 +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.umd.min.js.map +1 -1
- package/dist/{actions-a95d2e66.development.cjs.js → actions-0fcd4d15.development.cjs.js} +47 -30
- package/dist/{actions-5039c951.esm.js → actions-bf7f6679.esm.js} +45 -30
- package/dist/{actions-c619a105.cjs.js → actions-e83129c5.cjs.js} +47 -30
- package/dist/{actions-49f0501e.development.esm.js → actions-f6b5002d.development.esm.js} +45 -30
- package/dist/declarations/src/Machine.d.ts +2 -2
- package/dist/declarations/src/State.d.ts +5 -5
- package/dist/declarations/src/StateMachine.d.ts +24 -18
- package/dist/declarations/src/StateNode.d.ts +8 -8
- package/dist/declarations/src/actions/assign.d.ts +6 -6
- package/dist/declarations/src/actions/cancel.d.ts +7 -7
- package/dist/declarations/src/actions/choose.d.ts +4 -10
- package/dist/declarations/src/actions/log.d.ts +7 -7
- package/dist/declarations/src/actions/pure.d.ts +5 -17
- package/dist/declarations/src/actions/raise.d.ts +3 -3
- package/dist/declarations/src/actions/send.d.ts +22 -22
- package/dist/declarations/src/actions/stop.d.ts +7 -7
- package/dist/declarations/src/dev/index.d.ts +6 -6
- package/dist/declarations/src/index.d.ts +3 -2
- package/dist/declarations/src/interpreter.d.ts +31 -17
- package/dist/declarations/src/stateUtils.d.ts +12 -12
- package/dist/declarations/src/typegenTypes.d.ts +1 -1
- package/dist/declarations/src/types.d.ts +117 -136
- package/dist/declarations/src/utils.d.ts +8 -8
- package/dist/xstate.cjs.js +12 -9
- package/dist/xstate.cjs.mjs +3 -1
- package/dist/xstate.development.cjs.js +12 -9
- package/dist/xstate.development.cjs.mjs +3 -1
- package/dist/xstate.development.esm.js +9 -8
- package/dist/xstate.esm.js +9 -8
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xstate-dev.umd.min.js","sources":["../../src/dev/index.ts"],"sourcesContent":["import isDevelopment from '#is-development';\nimport {
|
|
1
|
+
{"version":3,"file":"xstate-dev.umd.min.js","sources":["../../src/dev/index.ts"],"sourcesContent":["import isDevelopment from '#is-development';\nimport { AnyActor, DevToolsAdapter } from '../types.ts';\n\ninterface DevInterface {\n services: Set<AnyActor>;\n register(service: AnyActor): void;\n onRegister(listener: ServiceListener): void;\n}\ntype ServiceListener = (service: AnyActor) => void;\n\nexport interface XStateDevInterface {\n register: (service: AnyActor) => void;\n unregister: (service: AnyActor) => void;\n onRegister: (listener: ServiceListener) => {\n unsubscribe: () => void;\n };\n services: Set<AnyActor>;\n}\n\n// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis\nexport function getGlobal(): typeof globalThis | undefined {\n if (typeof globalThis !== 'undefined') {\n return globalThis;\n }\n if (typeof self !== 'undefined') {\n return self;\n }\n if (typeof window !== 'undefined') {\n return window;\n }\n if (typeof global !== 'undefined') {\n return global;\n }\n if (isDevelopment) {\n console.warn(\n 'XState could not find a global object in this environment. Please let the maintainers know and raise an issue here: https://github.com/statelyai/xstate/issues'\n );\n }\n}\n\nfunction getDevTools(): DevInterface | undefined {\n const w = getGlobal();\n if (!!(w as any).__xstate__) {\n return (w as any).__xstate__;\n }\n\n return undefined;\n}\n\nexport function registerService(service: AnyActor) {\n if (typeof window === 'undefined') {\n return;\n }\n\n const devTools = getDevTools();\n\n if (devTools) {\n devTools.register(service);\n }\n}\n\nexport const devToolsAdapter: DevToolsAdapter = (service) => {\n if (typeof window === 'undefined') {\n return;\n }\n\n const devTools = getDevTools();\n\n if (devTools) {\n devTools.register(service);\n }\n};\n"],"names":["getGlobal","globalThis","self","window","getDevTools","w","__xstate__","service","devTools","register"],"mappings":"iPAoBO,SAASA,IACd,MAA0B,oBAAfC,WACFA,WAEW,oBAATC,KACFA,KAGAC,MAUX,CAEA,SAASC,IACP,MAAMC,EAAIL,IACV,GAAOK,EAAUC,WACf,OAAQD,EAAUC,UAItB,mBAciDC,IAK/C,MAAMC,EAAWJ,IAEbI,GACFA,EAASC,SAASF,EACpB,kCArBK,SAAyBA,GAK9B,MAAMC,EAAWJ,IAEbI,GACFA,EAASC,SAASF,EAEtB"}
|
|
@@ -941,7 +941,7 @@ function toActorRef(actorRefLike) {
|
|
|
941
941
|
}
|
|
942
942
|
const emptyLogic = fromTransition(_ => undefined, undefined);
|
|
943
943
|
function createEmptyActor() {
|
|
944
|
-
return
|
|
944
|
+
return createActor(emptyLogic);
|
|
945
945
|
}
|
|
946
946
|
|
|
947
947
|
/**
|
|
@@ -997,6 +997,11 @@ let ActorStatus = /*#__PURE__*/function (ActorStatus) {
|
|
|
997
997
|
ActorStatus[ActorStatus["Stopped"] = 2] = "Stopped";
|
|
998
998
|
return ActorStatus;
|
|
999
999
|
}({});
|
|
1000
|
+
|
|
1001
|
+
/**
|
|
1002
|
+
* @deprecated Use `ActorStatus` instead.
|
|
1003
|
+
*/
|
|
1004
|
+
const InterpreterStatus = ActorStatus;
|
|
1000
1005
|
const defaultOptions = {
|
|
1001
1006
|
deferEvents: true,
|
|
1002
1007
|
clock: {
|
|
@@ -1010,9 +1015,9 @@ const defaultOptions = {
|
|
|
1010
1015
|
logger: console.log.bind(console),
|
|
1011
1016
|
devTools: false
|
|
1012
1017
|
};
|
|
1013
|
-
class
|
|
1018
|
+
class Actor {
|
|
1014
1019
|
/**
|
|
1015
|
-
* The current state of the
|
|
1020
|
+
* The current internal state of the actor.
|
|
1016
1021
|
*/
|
|
1017
1022
|
|
|
1018
1023
|
/**
|
|
@@ -1036,10 +1041,10 @@ class Interpreter {
|
|
|
1036
1041
|
*/
|
|
1037
1042
|
|
|
1038
1043
|
/**
|
|
1039
|
-
* Creates a new
|
|
1044
|
+
* Creates a new actor instance for the given logic with the provided options, if any.
|
|
1040
1045
|
*
|
|
1041
|
-
* @param logic The logic to
|
|
1042
|
-
* @param options
|
|
1046
|
+
* @param logic The logic to create an actor from
|
|
1047
|
+
* @param options Actor options
|
|
1043
1048
|
*/
|
|
1044
1049
|
constructor(logic, options) {
|
|
1045
1050
|
this.logic = logic;
|
|
@@ -1103,7 +1108,7 @@ class Interpreter {
|
|
|
1103
1108
|
}
|
|
1104
1109
|
};
|
|
1105
1110
|
|
|
1106
|
-
// Ensure that the send method is bound to this
|
|
1111
|
+
// Ensure that the send method is bound to this Actor instance
|
|
1107
1112
|
// if destructured
|
|
1108
1113
|
this.send = this.send.bind(this);
|
|
1109
1114
|
this._initState();
|
|
@@ -1166,7 +1171,7 @@ class Interpreter {
|
|
|
1166
1171
|
}
|
|
1167
1172
|
|
|
1168
1173
|
/**
|
|
1169
|
-
* Starts the
|
|
1174
|
+
* Starts the Actor from the initial state
|
|
1170
1175
|
*/
|
|
1171
1176
|
start() {
|
|
1172
1177
|
if (this.status === ActorStatus.Running) {
|
|
@@ -1253,7 +1258,7 @@ class Interpreter {
|
|
|
1253
1258
|
}
|
|
1254
1259
|
|
|
1255
1260
|
/**
|
|
1256
|
-
* Stops the
|
|
1261
|
+
* Stops the Actor and unsubscribe all listeners.
|
|
1257
1262
|
*/
|
|
1258
1263
|
stop() {
|
|
1259
1264
|
if (this._parent) {
|
|
@@ -1295,7 +1300,7 @@ class Interpreter {
|
|
|
1295
1300
|
}
|
|
1296
1301
|
_stopProcedure() {
|
|
1297
1302
|
if (this.status !== ActorStatus.Running) {
|
|
1298
|
-
//
|
|
1303
|
+
// Actor already stopped; do nothing
|
|
1299
1304
|
return this;
|
|
1300
1305
|
}
|
|
1301
1306
|
|
|
@@ -1317,7 +1322,7 @@ class Interpreter {
|
|
|
1317
1322
|
}
|
|
1318
1323
|
|
|
1319
1324
|
/**
|
|
1320
|
-
* Sends an event to the running
|
|
1325
|
+
* Sends an event to the running Actor to trigger a transition.
|
|
1321
1326
|
*
|
|
1322
1327
|
* @param event The event to send
|
|
1323
1328
|
*/
|
|
@@ -1393,17 +1398,28 @@ class Interpreter {
|
|
|
1393
1398
|
}
|
|
1394
1399
|
|
|
1395
1400
|
/**
|
|
1396
|
-
* Creates a new
|
|
1401
|
+
* Creates a new `ActorRef` instance for the given machine with the provided options, if any.
|
|
1397
1402
|
*
|
|
1398
|
-
* @param machine The machine to
|
|
1399
|
-
* @param options
|
|
1403
|
+
* @param machine The machine to create an actor from
|
|
1404
|
+
* @param options `ActorRef` options
|
|
1400
1405
|
*/
|
|
1401
1406
|
|
|
1402
|
-
function
|
|
1403
|
-
const interpreter = new
|
|
1407
|
+
function createActor(logic, options) {
|
|
1408
|
+
const interpreter = new Actor(logic, options);
|
|
1404
1409
|
return interpreter;
|
|
1405
1410
|
}
|
|
1406
1411
|
|
|
1412
|
+
/**
|
|
1413
|
+
* Creates a new Interpreter instance for the given machine with the provided options, if any.
|
|
1414
|
+
*
|
|
1415
|
+
* @deprecated Use `createActor` instead
|
|
1416
|
+
*/
|
|
1417
|
+
const interpret = createActor;
|
|
1418
|
+
|
|
1419
|
+
/**
|
|
1420
|
+
* @deprecated Use `Actor` instead.
|
|
1421
|
+
*/
|
|
1422
|
+
|
|
1407
1423
|
function resolve$6(actorContext, state, actionArgs, {
|
|
1408
1424
|
id,
|
|
1409
1425
|
systemId,
|
|
@@ -1415,7 +1431,7 @@ function resolve$6(actorContext, state, actionArgs, {
|
|
|
1415
1431
|
if (referenced) {
|
|
1416
1432
|
// TODO: inline `input: undefined` should win over the referenced one
|
|
1417
1433
|
const configuredInput = input || referenced.input;
|
|
1418
|
-
actorRef =
|
|
1434
|
+
actorRef = createActor(referenced.src, {
|
|
1419
1435
|
id,
|
|
1420
1436
|
src,
|
|
1421
1437
|
parent: actorContext?.self,
|
|
@@ -2425,7 +2441,12 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
2425
2441
|
_internalQueue: []
|
|
2426
2442
|
});
|
|
2427
2443
|
for (const action of actions) {
|
|
2428
|
-
const
|
|
2444
|
+
const isInline = typeof action === 'function';
|
|
2445
|
+
const resolved = isInline ? action :
|
|
2446
|
+
// the existing type of `.actions` assumes non-nullable `TExpressionAction`
|
|
2447
|
+
// it's fine to cast this here to get a common type and lack of errors in the rest of the code
|
|
2448
|
+
// our logic below makes sure that we call those 2 "variants" correctly
|
|
2449
|
+
machine.implementations.actions[typeof action === 'string' ? action : action.type];
|
|
2429
2450
|
if (!resolved) {
|
|
2430
2451
|
continue;
|
|
2431
2452
|
}
|
|
@@ -2434,12 +2455,7 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
2434
2455
|
event,
|
|
2435
2456
|
self: actorCtx?.self,
|
|
2436
2457
|
system: actorCtx?.system,
|
|
2437
|
-
|
|
2438
|
-
// what those ones should receive?
|
|
2439
|
-
//
|
|
2440
|
-
// entry: ({ action }) => {}
|
|
2441
|
-
// exit: assign(({ action }) => {})
|
|
2442
|
-
action: typeof action === 'string' ? {
|
|
2458
|
+
action: isInline ? undefined : typeof action === 'string' ? {
|
|
2443
2459
|
type: action
|
|
2444
2460
|
} : action
|
|
2445
2461
|
};
|
|
@@ -2579,9 +2595,8 @@ class State {
|
|
|
2579
2595
|
*/
|
|
2580
2596
|
|
|
2581
2597
|
/**
|
|
2582
|
-
* The
|
|
2598
|
+
* The output data of the top-level finite state.
|
|
2583
2599
|
*/
|
|
2584
|
-
// TODO: add an explicit type for `output`
|
|
2585
2600
|
|
|
2586
2601
|
/**
|
|
2587
2602
|
* The enabled state nodes representative of the state value.
|
|
@@ -2870,7 +2885,7 @@ function createSpawner(actorContext, {
|
|
|
2870
2885
|
const input = 'input' in options ? options.input : referenced.input;
|
|
2871
2886
|
|
|
2872
2887
|
// TODO: this should also receive `src`
|
|
2873
|
-
const actor =
|
|
2888
|
+
const actor = createActor(referenced.src, {
|
|
2874
2889
|
id: options.id,
|
|
2875
2890
|
parent: actorContext.self,
|
|
2876
2891
|
input: typeof input === 'function' ? input({
|
|
@@ -2884,7 +2899,7 @@ function createSpawner(actorContext, {
|
|
|
2884
2899
|
return actor;
|
|
2885
2900
|
} else {
|
|
2886
2901
|
// TODO: this should also receive `src`
|
|
2887
|
-
return
|
|
2902
|
+
return createActor(src, {
|
|
2888
2903
|
id: options.id,
|
|
2889
2904
|
parent: actorContext.self,
|
|
2890
2905
|
input: options.input,
|
|
@@ -3040,7 +3055,7 @@ function resolve(_, state, args, {
|
|
|
3040
3055
|
get
|
|
3041
3056
|
}) {
|
|
3042
3057
|
return [state, undefined, toArray(get({
|
|
3043
|
-
context:
|
|
3058
|
+
context: args.context,
|
|
3044
3059
|
event: args.event
|
|
3045
3060
|
}))];
|
|
3046
3061
|
}
|
|
@@ -3119,9 +3134,10 @@ function createInitEvent(input) {
|
|
|
3119
3134
|
};
|
|
3120
3135
|
}
|
|
3121
3136
|
|
|
3137
|
+
exports.Actor = Actor;
|
|
3122
3138
|
exports.ActorStatus = ActorStatus;
|
|
3123
3139
|
exports.ConstantPrefix = ConstantPrefix;
|
|
3124
|
-
exports.
|
|
3140
|
+
exports.InterpreterStatus = InterpreterStatus;
|
|
3125
3141
|
exports.NULL_EVENT = NULL_EVENT;
|
|
3126
3142
|
exports.STATE_DELIMITER = STATE_DELIMITER;
|
|
3127
3143
|
exports.SpecialTargets = SpecialTargets;
|
|
@@ -3133,6 +3149,7 @@ exports.cancel = cancel;
|
|
|
3133
3149
|
exports.choose = choose;
|
|
3134
3150
|
exports.cloneState = cloneState;
|
|
3135
3151
|
exports.constantPrefixes = constantPrefixes;
|
|
3152
|
+
exports.createActor = createActor;
|
|
3136
3153
|
exports.createEmptyActor = createEmptyActor;
|
|
3137
3154
|
exports.createInitEvent = createInitEvent;
|
|
3138
3155
|
exports.createInvokeId = createInvokeId;
|
|
@@ -920,7 +920,7 @@ function toActorRef(actorRefLike) {
|
|
|
920
920
|
}
|
|
921
921
|
const emptyLogic = fromTransition(_ => undefined, undefined);
|
|
922
922
|
function createEmptyActor() {
|
|
923
|
-
return
|
|
923
|
+
return createActor(emptyLogic);
|
|
924
924
|
}
|
|
925
925
|
|
|
926
926
|
/**
|
|
@@ -976,6 +976,11 @@ let ActorStatus = /*#__PURE__*/function (ActorStatus) {
|
|
|
976
976
|
ActorStatus[ActorStatus["Stopped"] = 2] = "Stopped";
|
|
977
977
|
return ActorStatus;
|
|
978
978
|
}({});
|
|
979
|
+
|
|
980
|
+
/**
|
|
981
|
+
* @deprecated Use `ActorStatus` instead.
|
|
982
|
+
*/
|
|
983
|
+
const InterpreterStatus = ActorStatus;
|
|
979
984
|
const defaultOptions = {
|
|
980
985
|
deferEvents: true,
|
|
981
986
|
clock: {
|
|
@@ -989,9 +994,9 @@ const defaultOptions = {
|
|
|
989
994
|
logger: console.log.bind(console),
|
|
990
995
|
devTools: false
|
|
991
996
|
};
|
|
992
|
-
class
|
|
997
|
+
class Actor {
|
|
993
998
|
/**
|
|
994
|
-
* The current state of the
|
|
999
|
+
* The current internal state of the actor.
|
|
995
1000
|
*/
|
|
996
1001
|
|
|
997
1002
|
/**
|
|
@@ -1015,10 +1020,10 @@ class Interpreter {
|
|
|
1015
1020
|
*/
|
|
1016
1021
|
|
|
1017
1022
|
/**
|
|
1018
|
-
* Creates a new
|
|
1023
|
+
* Creates a new actor instance for the given logic with the provided options, if any.
|
|
1019
1024
|
*
|
|
1020
|
-
* @param logic The logic to
|
|
1021
|
-
* @param options
|
|
1025
|
+
* @param logic The logic to create an actor from
|
|
1026
|
+
* @param options Actor options
|
|
1022
1027
|
*/
|
|
1023
1028
|
constructor(logic, options) {
|
|
1024
1029
|
this.logic = logic;
|
|
@@ -1082,7 +1087,7 @@ class Interpreter {
|
|
|
1082
1087
|
}
|
|
1083
1088
|
};
|
|
1084
1089
|
|
|
1085
|
-
// Ensure that the send method is bound to this
|
|
1090
|
+
// Ensure that the send method is bound to this Actor instance
|
|
1086
1091
|
// if destructured
|
|
1087
1092
|
this.send = this.send.bind(this);
|
|
1088
1093
|
this._initState();
|
|
@@ -1145,7 +1150,7 @@ class Interpreter {
|
|
|
1145
1150
|
}
|
|
1146
1151
|
|
|
1147
1152
|
/**
|
|
1148
|
-
* Starts the
|
|
1153
|
+
* Starts the Actor from the initial state
|
|
1149
1154
|
*/
|
|
1150
1155
|
start() {
|
|
1151
1156
|
if (this.status === ActorStatus.Running) {
|
|
@@ -1232,7 +1237,7 @@ class Interpreter {
|
|
|
1232
1237
|
}
|
|
1233
1238
|
|
|
1234
1239
|
/**
|
|
1235
|
-
* Stops the
|
|
1240
|
+
* Stops the Actor and unsubscribe all listeners.
|
|
1236
1241
|
*/
|
|
1237
1242
|
stop() {
|
|
1238
1243
|
if (this._parent) {
|
|
@@ -1274,7 +1279,7 @@ class Interpreter {
|
|
|
1274
1279
|
}
|
|
1275
1280
|
_stopProcedure() {
|
|
1276
1281
|
if (this.status !== ActorStatus.Running) {
|
|
1277
|
-
//
|
|
1282
|
+
// Actor already stopped; do nothing
|
|
1278
1283
|
return this;
|
|
1279
1284
|
}
|
|
1280
1285
|
|
|
@@ -1296,7 +1301,7 @@ class Interpreter {
|
|
|
1296
1301
|
}
|
|
1297
1302
|
|
|
1298
1303
|
/**
|
|
1299
|
-
* Sends an event to the running
|
|
1304
|
+
* Sends an event to the running Actor to trigger a transition.
|
|
1300
1305
|
*
|
|
1301
1306
|
* @param event The event to send
|
|
1302
1307
|
*/
|
|
@@ -1367,17 +1372,28 @@ class Interpreter {
|
|
|
1367
1372
|
}
|
|
1368
1373
|
|
|
1369
1374
|
/**
|
|
1370
|
-
* Creates a new
|
|
1375
|
+
* Creates a new `ActorRef` instance for the given machine with the provided options, if any.
|
|
1371
1376
|
*
|
|
1372
|
-
* @param machine The machine to
|
|
1373
|
-
* @param options
|
|
1377
|
+
* @param machine The machine to create an actor from
|
|
1378
|
+
* @param options `ActorRef` options
|
|
1374
1379
|
*/
|
|
1375
1380
|
|
|
1376
|
-
function
|
|
1377
|
-
const interpreter = new
|
|
1381
|
+
function createActor(logic, options) {
|
|
1382
|
+
const interpreter = new Actor(logic, options);
|
|
1378
1383
|
return interpreter;
|
|
1379
1384
|
}
|
|
1380
1385
|
|
|
1386
|
+
/**
|
|
1387
|
+
* Creates a new Interpreter instance for the given machine with the provided options, if any.
|
|
1388
|
+
*
|
|
1389
|
+
* @deprecated Use `createActor` instead
|
|
1390
|
+
*/
|
|
1391
|
+
const interpret = createActor;
|
|
1392
|
+
|
|
1393
|
+
/**
|
|
1394
|
+
* @deprecated Use `Actor` instead.
|
|
1395
|
+
*/
|
|
1396
|
+
|
|
1381
1397
|
function resolve$6(actorContext, state, actionArgs, {
|
|
1382
1398
|
id,
|
|
1383
1399
|
systemId,
|
|
@@ -1389,7 +1405,7 @@ function resolve$6(actorContext, state, actionArgs, {
|
|
|
1389
1405
|
if (referenced) {
|
|
1390
1406
|
// TODO: inline `input: undefined` should win over the referenced one
|
|
1391
1407
|
const configuredInput = input || referenced.input;
|
|
1392
|
-
actorRef =
|
|
1408
|
+
actorRef = createActor(referenced.src, {
|
|
1393
1409
|
id,
|
|
1394
1410
|
src,
|
|
1395
1411
|
parent: actorContext?.self,
|
|
@@ -2382,7 +2398,12 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
2382
2398
|
_internalQueue: []
|
|
2383
2399
|
});
|
|
2384
2400
|
for (const action of actions) {
|
|
2385
|
-
const
|
|
2401
|
+
const isInline = typeof action === 'function';
|
|
2402
|
+
const resolved = isInline ? action :
|
|
2403
|
+
// the existing type of `.actions` assumes non-nullable `TExpressionAction`
|
|
2404
|
+
// it's fine to cast this here to get a common type and lack of errors in the rest of the code
|
|
2405
|
+
// our logic below makes sure that we call those 2 "variants" correctly
|
|
2406
|
+
machine.implementations.actions[typeof action === 'string' ? action : action.type];
|
|
2386
2407
|
if (!resolved) {
|
|
2387
2408
|
continue;
|
|
2388
2409
|
}
|
|
@@ -2391,12 +2412,7 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
2391
2412
|
event,
|
|
2392
2413
|
self: actorCtx?.self,
|
|
2393
2414
|
system: actorCtx?.system,
|
|
2394
|
-
|
|
2395
|
-
// what those ones should receive?
|
|
2396
|
-
//
|
|
2397
|
-
// entry: ({ action }) => {}
|
|
2398
|
-
// exit: assign(({ action }) => {})
|
|
2399
|
-
action: typeof action === 'string' ? {
|
|
2415
|
+
action: isInline ? undefined : typeof action === 'string' ? {
|
|
2400
2416
|
type: action
|
|
2401
2417
|
} : action
|
|
2402
2418
|
};
|
|
@@ -2533,9 +2549,8 @@ class State {
|
|
|
2533
2549
|
*/
|
|
2534
2550
|
|
|
2535
2551
|
/**
|
|
2536
|
-
* The
|
|
2552
|
+
* The output data of the top-level finite state.
|
|
2537
2553
|
*/
|
|
2538
|
-
// TODO: add an explicit type for `output`
|
|
2539
2554
|
|
|
2540
2555
|
/**
|
|
2541
2556
|
* The enabled state nodes representative of the state value.
|
|
@@ -2815,7 +2830,7 @@ function createSpawner(actorContext, {
|
|
|
2815
2830
|
const input = 'input' in options ? options.input : referenced.input;
|
|
2816
2831
|
|
|
2817
2832
|
// TODO: this should also receive `src`
|
|
2818
|
-
const actor =
|
|
2833
|
+
const actor = createActor(referenced.src, {
|
|
2819
2834
|
id: options.id,
|
|
2820
2835
|
parent: actorContext.self,
|
|
2821
2836
|
input: typeof input === 'function' ? input({
|
|
@@ -2829,7 +2844,7 @@ function createSpawner(actorContext, {
|
|
|
2829
2844
|
return actor;
|
|
2830
2845
|
} else {
|
|
2831
2846
|
// TODO: this should also receive `src`
|
|
2832
|
-
return
|
|
2847
|
+
return createActor(src, {
|
|
2833
2848
|
id: options.id,
|
|
2834
2849
|
parent: actorContext.self,
|
|
2835
2850
|
input: options.input,
|
|
@@ -2976,7 +2991,7 @@ function resolve(_, state, args, {
|
|
|
2976
2991
|
get
|
|
2977
2992
|
}) {
|
|
2978
2993
|
return [state, undefined, toArray(get({
|
|
2979
|
-
context:
|
|
2994
|
+
context: args.context,
|
|
2980
2995
|
event: args.event
|
|
2981
2996
|
}))];
|
|
2982
2997
|
}
|
|
@@ -3052,4 +3067,4 @@ function createInitEvent(input) {
|
|
|
3052
3067
|
};
|
|
3053
3068
|
}
|
|
3054
3069
|
|
|
3055
|
-
export {
|
|
3070
|
+
export { fromObservable as $, microstep as A, isAtomicStateNode as B, isStateId as C, getStateNodeByPath as D, getPersistedState as E, resolveReferencedActor as F, createActor as G, matchesState as H, sendTo as I, sendParent as J, forwardTo as K, interpret as L, Actor as M, NULL_EVENT as N, ActorStatus as O, InterpreterStatus as P, doneInvoke as Q, cancel as R, STATE_DELIMITER as S, choose as T, log as U, pure as V, raise as W, stop as X, pathToStateValue as Y, toObserver as Z, fromPromise as _, toTransitionConfigArray as a, fromCallback as a0, fromEventObservable as a1, fromTransition as a2, stateIn as a3, not as a4, and as a5, or as a6, ConstantPrefix as a7, SpecialTargets as a8, startSignalType as a9, stopSignalType as aa, startSignal as ab, stopSignal as ac, isSignal as ad, isActorRef as ae, toActorRef as af, createEmptyActor as ag, toGuardDefinition as ah, constantPrefixes as ai, after as aj, done as ak, error as al, escalate as am, formatTransition as b, memo as c, flatten as d, evaluateGuard as e, formatTransitions as f, createInvokeId as g, getDelayedTransitions as h, formatInitialTransition as i, getCandidates as j, toInvokeConfig as k, getConfiguration as l, mapValues as m, getStateNodes as n, isInFinalState as o, State as p, isErrorEvent as q, resolveStateValue as r, cloneState as s, toArray as t, macrostep as u, transitionNode as v, getInitialConfiguration as w, resolveActionsAndContext as x, assign as y, createInitEvent as z };
|
|
@@ -922,7 +922,7 @@ function toActorRef(actorRefLike) {
|
|
|
922
922
|
}
|
|
923
923
|
const emptyLogic = fromTransition(_ => undefined, undefined);
|
|
924
924
|
function createEmptyActor() {
|
|
925
|
-
return
|
|
925
|
+
return createActor(emptyLogic);
|
|
926
926
|
}
|
|
927
927
|
|
|
928
928
|
/**
|
|
@@ -978,6 +978,11 @@ let ActorStatus = /*#__PURE__*/function (ActorStatus) {
|
|
|
978
978
|
ActorStatus[ActorStatus["Stopped"] = 2] = "Stopped";
|
|
979
979
|
return ActorStatus;
|
|
980
980
|
}({});
|
|
981
|
+
|
|
982
|
+
/**
|
|
983
|
+
* @deprecated Use `ActorStatus` instead.
|
|
984
|
+
*/
|
|
985
|
+
const InterpreterStatus = ActorStatus;
|
|
981
986
|
const defaultOptions = {
|
|
982
987
|
deferEvents: true,
|
|
983
988
|
clock: {
|
|
@@ -991,9 +996,9 @@ const defaultOptions = {
|
|
|
991
996
|
logger: console.log.bind(console),
|
|
992
997
|
devTools: false
|
|
993
998
|
};
|
|
994
|
-
class
|
|
999
|
+
class Actor {
|
|
995
1000
|
/**
|
|
996
|
-
* The current state of the
|
|
1001
|
+
* The current internal state of the actor.
|
|
997
1002
|
*/
|
|
998
1003
|
|
|
999
1004
|
/**
|
|
@@ -1017,10 +1022,10 @@ class Interpreter {
|
|
|
1017
1022
|
*/
|
|
1018
1023
|
|
|
1019
1024
|
/**
|
|
1020
|
-
* Creates a new
|
|
1025
|
+
* Creates a new actor instance for the given logic with the provided options, if any.
|
|
1021
1026
|
*
|
|
1022
|
-
* @param logic The logic to
|
|
1023
|
-
* @param options
|
|
1027
|
+
* @param logic The logic to create an actor from
|
|
1028
|
+
* @param options Actor options
|
|
1024
1029
|
*/
|
|
1025
1030
|
constructor(logic, options) {
|
|
1026
1031
|
this.logic = logic;
|
|
@@ -1084,7 +1089,7 @@ class Interpreter {
|
|
|
1084
1089
|
}
|
|
1085
1090
|
};
|
|
1086
1091
|
|
|
1087
|
-
// Ensure that the send method is bound to this
|
|
1092
|
+
// Ensure that the send method is bound to this Actor instance
|
|
1088
1093
|
// if destructured
|
|
1089
1094
|
this.send = this.send.bind(this);
|
|
1090
1095
|
this._initState();
|
|
@@ -1147,7 +1152,7 @@ class Interpreter {
|
|
|
1147
1152
|
}
|
|
1148
1153
|
|
|
1149
1154
|
/**
|
|
1150
|
-
* Starts the
|
|
1155
|
+
* Starts the Actor from the initial state
|
|
1151
1156
|
*/
|
|
1152
1157
|
start() {
|
|
1153
1158
|
if (this.status === ActorStatus.Running) {
|
|
@@ -1234,7 +1239,7 @@ class Interpreter {
|
|
|
1234
1239
|
}
|
|
1235
1240
|
|
|
1236
1241
|
/**
|
|
1237
|
-
* Stops the
|
|
1242
|
+
* Stops the Actor and unsubscribe all listeners.
|
|
1238
1243
|
*/
|
|
1239
1244
|
stop() {
|
|
1240
1245
|
if (this._parent) {
|
|
@@ -1276,7 +1281,7 @@ class Interpreter {
|
|
|
1276
1281
|
}
|
|
1277
1282
|
_stopProcedure() {
|
|
1278
1283
|
if (this.status !== ActorStatus.Running) {
|
|
1279
|
-
//
|
|
1284
|
+
// Actor already stopped; do nothing
|
|
1280
1285
|
return this;
|
|
1281
1286
|
}
|
|
1282
1287
|
|
|
@@ -1298,7 +1303,7 @@ class Interpreter {
|
|
|
1298
1303
|
}
|
|
1299
1304
|
|
|
1300
1305
|
/**
|
|
1301
|
-
* Sends an event to the running
|
|
1306
|
+
* Sends an event to the running Actor to trigger a transition.
|
|
1302
1307
|
*
|
|
1303
1308
|
* @param event The event to send
|
|
1304
1309
|
*/
|
|
@@ -1369,17 +1374,28 @@ class Interpreter {
|
|
|
1369
1374
|
}
|
|
1370
1375
|
|
|
1371
1376
|
/**
|
|
1372
|
-
* Creates a new
|
|
1377
|
+
* Creates a new `ActorRef` instance for the given machine with the provided options, if any.
|
|
1373
1378
|
*
|
|
1374
|
-
* @param machine The machine to
|
|
1375
|
-
* @param options
|
|
1379
|
+
* @param machine The machine to create an actor from
|
|
1380
|
+
* @param options `ActorRef` options
|
|
1376
1381
|
*/
|
|
1377
1382
|
|
|
1378
|
-
function
|
|
1379
|
-
const interpreter = new
|
|
1383
|
+
function createActor(logic, options) {
|
|
1384
|
+
const interpreter = new Actor(logic, options);
|
|
1380
1385
|
return interpreter;
|
|
1381
1386
|
}
|
|
1382
1387
|
|
|
1388
|
+
/**
|
|
1389
|
+
* Creates a new Interpreter instance for the given machine with the provided options, if any.
|
|
1390
|
+
*
|
|
1391
|
+
* @deprecated Use `createActor` instead
|
|
1392
|
+
*/
|
|
1393
|
+
const interpret = createActor;
|
|
1394
|
+
|
|
1395
|
+
/**
|
|
1396
|
+
* @deprecated Use `Actor` instead.
|
|
1397
|
+
*/
|
|
1398
|
+
|
|
1383
1399
|
function resolve$6(actorContext, state, actionArgs, {
|
|
1384
1400
|
id,
|
|
1385
1401
|
systemId,
|
|
@@ -1391,7 +1407,7 @@ function resolve$6(actorContext, state, actionArgs, {
|
|
|
1391
1407
|
if (referenced) {
|
|
1392
1408
|
// TODO: inline `input: undefined` should win over the referenced one
|
|
1393
1409
|
const configuredInput = input || referenced.input;
|
|
1394
|
-
actorRef =
|
|
1410
|
+
actorRef = createActor(referenced.src, {
|
|
1395
1411
|
id,
|
|
1396
1412
|
src,
|
|
1397
1413
|
parent: actorContext?.self,
|
|
@@ -2384,7 +2400,12 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
2384
2400
|
_internalQueue: []
|
|
2385
2401
|
});
|
|
2386
2402
|
for (const action of actions) {
|
|
2387
|
-
const
|
|
2403
|
+
const isInline = typeof action === 'function';
|
|
2404
|
+
const resolved = isInline ? action :
|
|
2405
|
+
// the existing type of `.actions` assumes non-nullable `TExpressionAction`
|
|
2406
|
+
// it's fine to cast this here to get a common type and lack of errors in the rest of the code
|
|
2407
|
+
// our logic below makes sure that we call those 2 "variants" correctly
|
|
2408
|
+
machine.implementations.actions[typeof action === 'string' ? action : action.type];
|
|
2388
2409
|
if (!resolved) {
|
|
2389
2410
|
continue;
|
|
2390
2411
|
}
|
|
@@ -2393,12 +2414,7 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
2393
2414
|
event,
|
|
2394
2415
|
self: actorCtx?.self,
|
|
2395
2416
|
system: actorCtx?.system,
|
|
2396
|
-
|
|
2397
|
-
// what those ones should receive?
|
|
2398
|
-
//
|
|
2399
|
-
// entry: ({ action }) => {}
|
|
2400
|
-
// exit: assign(({ action }) => {})
|
|
2401
|
-
action: typeof action === 'string' ? {
|
|
2417
|
+
action: isInline ? undefined : typeof action === 'string' ? {
|
|
2402
2418
|
type: action
|
|
2403
2419
|
} : action
|
|
2404
2420
|
};
|
|
@@ -2535,9 +2551,8 @@ class State {
|
|
|
2535
2551
|
*/
|
|
2536
2552
|
|
|
2537
2553
|
/**
|
|
2538
|
-
* The
|
|
2554
|
+
* The output data of the top-level finite state.
|
|
2539
2555
|
*/
|
|
2540
|
-
// TODO: add an explicit type for `output`
|
|
2541
2556
|
|
|
2542
2557
|
/**
|
|
2543
2558
|
* The enabled state nodes representative of the state value.
|
|
@@ -2817,7 +2832,7 @@ function createSpawner(actorContext, {
|
|
|
2817
2832
|
const input = 'input' in options ? options.input : referenced.input;
|
|
2818
2833
|
|
|
2819
2834
|
// TODO: this should also receive `src`
|
|
2820
|
-
const actor =
|
|
2835
|
+
const actor = createActor(referenced.src, {
|
|
2821
2836
|
id: options.id,
|
|
2822
2837
|
parent: actorContext.self,
|
|
2823
2838
|
input: typeof input === 'function' ? input({
|
|
@@ -2831,7 +2846,7 @@ function createSpawner(actorContext, {
|
|
|
2831
2846
|
return actor;
|
|
2832
2847
|
} else {
|
|
2833
2848
|
// TODO: this should also receive `src`
|
|
2834
|
-
return
|
|
2849
|
+
return createActor(src, {
|
|
2835
2850
|
id: options.id,
|
|
2836
2851
|
parent: actorContext.self,
|
|
2837
2852
|
input: options.input,
|
|
@@ -2978,7 +2993,7 @@ function resolve(_, state, args, {
|
|
|
2978
2993
|
get
|
|
2979
2994
|
}) {
|
|
2980
2995
|
return [state, undefined, toArray(get({
|
|
2981
|
-
context:
|
|
2996
|
+
context: args.context,
|
|
2982
2997
|
event: args.event
|
|
2983
2998
|
}))];
|
|
2984
2999
|
}
|
|
@@ -3054,9 +3069,10 @@ function createInitEvent(input) {
|
|
|
3054
3069
|
};
|
|
3055
3070
|
}
|
|
3056
3071
|
|
|
3072
|
+
exports.Actor = Actor;
|
|
3057
3073
|
exports.ActorStatus = ActorStatus;
|
|
3058
3074
|
exports.ConstantPrefix = ConstantPrefix;
|
|
3059
|
-
exports.
|
|
3075
|
+
exports.InterpreterStatus = InterpreterStatus;
|
|
3060
3076
|
exports.NULL_EVENT = NULL_EVENT;
|
|
3061
3077
|
exports.STATE_DELIMITER = STATE_DELIMITER;
|
|
3062
3078
|
exports.SpecialTargets = SpecialTargets;
|
|
@@ -3068,6 +3084,7 @@ exports.cancel = cancel;
|
|
|
3068
3084
|
exports.choose = choose;
|
|
3069
3085
|
exports.cloneState = cloneState;
|
|
3070
3086
|
exports.constantPrefixes = constantPrefixes;
|
|
3087
|
+
exports.createActor = createActor;
|
|
3071
3088
|
exports.createEmptyActor = createEmptyActor;
|
|
3072
3089
|
exports.createInitEvent = createInitEvent;
|
|
3073
3090
|
exports.createInvokeId = createInvokeId;
|