xstate 5.0.0-beta.20 → 5.0.0-beta.22
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 +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-d1c41ed3.development.cjs.js → actions-4b70fc8d.development.cjs.js} +174 -82
- package/dist/{actions-069d9805.cjs.js → actions-8f2e997e.cjs.js} +172 -83
- package/dist/{actions-b299d008.development.esm.js → actions-d4305983.development.esm.js} +171 -82
- package/dist/{actions-a8a9433c.esm.js → actions-fb7384f8.esm.js} +169 -83
- package/dist/declarations/src/Machine.d.ts +2 -2
- package/dist/declarations/src/State.d.ts +4 -7
- package/dist/declarations/src/StateMachine.d.ts +7 -6
- package/dist/declarations/src/StateNode.d.ts +3 -3
- package/dist/declarations/src/actions/send.d.ts +1 -1
- package/dist/declarations/src/actions/stop.d.ts +1 -1
- package/dist/declarations/src/actions.d.ts +2 -2
- package/dist/declarations/src/actors/callback.d.ts +4 -4
- package/dist/declarations/src/actors/observable.d.ts +7 -4
- package/dist/declarations/src/actors/promise.d.ts +4 -4
- 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 +30 -16
- package/dist/declarations/src/types.d.ts +52 -33
- package/dist/declarations/src/utils.d.ts +2 -2
- package/dist/xstate.cjs.js +17 -14
- package/dist/xstate.cjs.mjs +3 -1
- package/dist/xstate.development.cjs.js +17 -14
- package/dist/xstate.development.cjs.mjs +3 -1
- package/dist/xstate.development.esm.js +14 -13
- package/dist/xstate.esm.js +14 -13
- 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
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
var dev_dist_xstateDev = require('../dev/dist/xstate-dev.cjs.js');
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* `T | unknown` reduces to `unknown` and that can be problematic when it comes to contextual typing.
|
|
7
|
+
* It especially is a problem when the union has a function member, like here:
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* declare function test(cbOrVal: ((arg: number) => unknown) | unknown): void;
|
|
11
|
+
* test((arg) => {}) // oops, implicit any
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* This type can be used to avoid this problem. This union represents the same value space as `unknown`.
|
|
15
|
+
*/
|
|
16
|
+
|
|
5
17
|
// https://github.com/microsoft/TypeScript/issues/23182#issuecomment-379091887
|
|
6
18
|
|
|
7
19
|
/**
|
|
@@ -406,27 +418,15 @@ function toArray(value) {
|
|
|
406
418
|
}
|
|
407
419
|
return toArrayStrict(value);
|
|
408
420
|
}
|
|
409
|
-
function mapContext(mapper, context, event) {
|
|
421
|
+
function mapContext(mapper, context, event, self) {
|
|
410
422
|
if (typeof mapper === 'function') {
|
|
411
423
|
return mapper({
|
|
412
424
|
context,
|
|
413
|
-
event
|
|
425
|
+
event,
|
|
426
|
+
self
|
|
414
427
|
});
|
|
415
428
|
}
|
|
416
|
-
|
|
417
|
-
const args = {
|
|
418
|
-
context,
|
|
419
|
-
event
|
|
420
|
-
};
|
|
421
|
-
for (const key of Object.keys(mapper)) {
|
|
422
|
-
const subMapper = mapper[key];
|
|
423
|
-
if (typeof subMapper === 'function') {
|
|
424
|
-
result[key] = subMapper(args);
|
|
425
|
-
} else {
|
|
426
|
-
result[key] = subMapper;
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
return result;
|
|
429
|
+
return mapper;
|
|
430
430
|
}
|
|
431
431
|
function isPromiseLike(value) {
|
|
432
432
|
if (value instanceof Promise) {
|
|
@@ -478,13 +478,12 @@ function toInvokeConfig(invocable, id) {
|
|
|
478
478
|
};
|
|
479
479
|
}
|
|
480
480
|
function toObserver(nextHandler, errorHandler, completionHandler) {
|
|
481
|
-
const noop = () => {};
|
|
482
481
|
const isObserver = typeof nextHandler === 'object';
|
|
483
|
-
const self = isObserver ? nextHandler :
|
|
482
|
+
const self = isObserver ? nextHandler : undefined;
|
|
484
483
|
return {
|
|
485
|
-
next: (
|
|
486
|
-
error: (
|
|
487
|
-
complete: (
|
|
484
|
+
next: (isObserver ? nextHandler.next : nextHandler)?.bind(self),
|
|
485
|
+
error: (isObserver ? nextHandler.error : errorHandler)?.bind(self),
|
|
486
|
+
complete: (isObserver ? nextHandler.complete : completionHandler)?.bind(self)
|
|
488
487
|
};
|
|
489
488
|
}
|
|
490
489
|
function createInvokeId(stateNodeId, index) {
|
|
@@ -498,7 +497,7 @@ function resolveReferencedActor(referenced) {
|
|
|
498
497
|
}
|
|
499
498
|
|
|
500
499
|
function fromCallback(invokeCallback) {
|
|
501
|
-
|
|
500
|
+
return {
|
|
502
501
|
config: invokeCallback,
|
|
503
502
|
start: (_state, {
|
|
504
503
|
self
|
|
@@ -564,19 +563,20 @@ function fromCallback(invokeCallback) {
|
|
|
564
563
|
},
|
|
565
564
|
getSnapshot: () => undefined,
|
|
566
565
|
getPersistedState: ({
|
|
567
|
-
input
|
|
568
|
-
|
|
566
|
+
input,
|
|
567
|
+
canceled
|
|
568
|
+
}) => ({
|
|
569
|
+
input,
|
|
570
|
+
canceled
|
|
571
|
+
})
|
|
569
572
|
};
|
|
570
|
-
return logic;
|
|
571
573
|
}
|
|
572
574
|
|
|
573
575
|
function fromObservable(observableCreator) {
|
|
574
576
|
const nextEventType = '$$xstate.next';
|
|
575
577
|
const errorEventType = '$$xstate.error';
|
|
576
578
|
const completeEventType = '$$xstate.complete';
|
|
577
|
-
|
|
578
|
-
// TODO: add event types
|
|
579
|
-
const logic = {
|
|
579
|
+
return {
|
|
580
580
|
config: observableCreator,
|
|
581
581
|
transition: (state, event, {
|
|
582
582
|
self,
|
|
@@ -606,6 +606,7 @@ function fromObservable(observableCreator) {
|
|
|
606
606
|
status: 'error',
|
|
607
607
|
input: undefined,
|
|
608
608
|
data: event.data,
|
|
609
|
+
// TODO: if we keep this as `data` we should reflect this in the type
|
|
609
610
|
subscription: undefined
|
|
610
611
|
};
|
|
611
612
|
case completeEventType:
|
|
@@ -683,7 +684,6 @@ function fromObservable(observableCreator) {
|
|
|
683
684
|
subscription: undefined
|
|
684
685
|
})
|
|
685
686
|
};
|
|
686
|
-
return logic;
|
|
687
687
|
}
|
|
688
688
|
|
|
689
689
|
/**
|
|
@@ -700,7 +700,7 @@ function fromEventObservable(lazyObservable) {
|
|
|
700
700
|
const completeEventType = '$$xstate.complete';
|
|
701
701
|
|
|
702
702
|
// TODO: event types
|
|
703
|
-
|
|
703
|
+
return {
|
|
704
704
|
config: lazyObservable,
|
|
705
705
|
transition: (state, event) => {
|
|
706
706
|
if (state.status !== 'active') {
|
|
@@ -713,6 +713,7 @@ function fromEventObservable(lazyObservable) {
|
|
|
713
713
|
status: 'error',
|
|
714
714
|
input: undefined,
|
|
715
715
|
data: event.data,
|
|
716
|
+
// TODO: if we keep this as `data` we should reflect this in the type
|
|
716
717
|
subscription: undefined
|
|
717
718
|
};
|
|
718
719
|
case completeEventType:
|
|
@@ -787,7 +788,6 @@ function fromEventObservable(lazyObservable) {
|
|
|
787
788
|
subscription: undefined
|
|
788
789
|
})
|
|
789
790
|
};
|
|
790
|
-
return logic;
|
|
791
791
|
}
|
|
792
792
|
|
|
793
793
|
const resolveEventType = '$$xstate.resolve';
|
|
@@ -815,6 +815,7 @@ promiseCreator) {
|
|
|
815
815
|
...state,
|
|
816
816
|
status: 'error',
|
|
817
817
|
data: event.data,
|
|
818
|
+
// TODO: if we keep this as `data` we should reflect this in the type
|
|
818
819
|
input: undefined
|
|
819
820
|
};
|
|
820
821
|
case stopSignalType:
|
|
@@ -921,7 +922,20 @@ function toActorRef(actorRefLike) {
|
|
|
921
922
|
}
|
|
922
923
|
const emptyLogic = fromTransition(_ => undefined, undefined);
|
|
923
924
|
function createEmptyActor() {
|
|
924
|
-
return
|
|
925
|
+
return createActor(emptyLogic);
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
/**
|
|
929
|
+
* This function makes sure that unhandled errors are thrown in a separate macrotask.
|
|
930
|
+
* It allows those errors to be detected by global error handlers and reported to bug tracking services
|
|
931
|
+
* without interrupting our own stack of execution.
|
|
932
|
+
*
|
|
933
|
+
* @param err error to be thrown
|
|
934
|
+
*/
|
|
935
|
+
function reportUnhandledError(err) {
|
|
936
|
+
setTimeout(() => {
|
|
937
|
+
throw err;
|
|
938
|
+
});
|
|
925
939
|
}
|
|
926
940
|
|
|
927
941
|
function createSystem() {
|
|
@@ -964,6 +978,11 @@ let ActorStatus = /*#__PURE__*/function (ActorStatus) {
|
|
|
964
978
|
ActorStatus[ActorStatus["Stopped"] = 2] = "Stopped";
|
|
965
979
|
return ActorStatus;
|
|
966
980
|
}({});
|
|
981
|
+
|
|
982
|
+
/**
|
|
983
|
+
* @deprecated Use `ActorStatus` instead.
|
|
984
|
+
*/
|
|
985
|
+
const InterpreterStatus = ActorStatus;
|
|
967
986
|
const defaultOptions = {
|
|
968
987
|
deferEvents: true,
|
|
969
988
|
clock: {
|
|
@@ -977,9 +996,9 @@ const defaultOptions = {
|
|
|
977
996
|
logger: console.log.bind(console),
|
|
978
997
|
devTools: false
|
|
979
998
|
};
|
|
980
|
-
class
|
|
999
|
+
class Actor {
|
|
981
1000
|
/**
|
|
982
|
-
* The current state of the
|
|
1001
|
+
* The current internal state of the actor.
|
|
983
1002
|
*/
|
|
984
1003
|
|
|
985
1004
|
/**
|
|
@@ -1003,10 +1022,10 @@ class Interpreter {
|
|
|
1003
1022
|
*/
|
|
1004
1023
|
|
|
1005
1024
|
/**
|
|
1006
|
-
* Creates a new
|
|
1025
|
+
* Creates a new actor instance for the given logic with the provided options, if any.
|
|
1007
1026
|
*
|
|
1008
|
-
* @param logic The logic to
|
|
1009
|
-
* @param options
|
|
1027
|
+
* @param logic The logic to create an actor from
|
|
1028
|
+
* @param options Actor options
|
|
1010
1029
|
*/
|
|
1011
1030
|
constructor(logic, options) {
|
|
1012
1031
|
this.logic = logic;
|
|
@@ -1070,7 +1089,7 @@ class Interpreter {
|
|
|
1070
1089
|
}
|
|
1071
1090
|
};
|
|
1072
1091
|
|
|
1073
|
-
// Ensure that the send method is bound to this
|
|
1092
|
+
// Ensure that the send method is bound to this Actor instance
|
|
1074
1093
|
// if destructured
|
|
1075
1094
|
this.send = this.send.bind(this);
|
|
1076
1095
|
this._initState();
|
|
@@ -1092,29 +1111,38 @@ class Interpreter {
|
|
|
1092
1111
|
deferredFn();
|
|
1093
1112
|
}
|
|
1094
1113
|
for (const observer of this.observers) {
|
|
1095
|
-
|
|
1114
|
+
// TODO: should observers be notified in case of the error?
|
|
1115
|
+
try {
|
|
1116
|
+
observer.next?.(snapshot);
|
|
1117
|
+
} catch (err) {
|
|
1118
|
+
reportUnhandledError(err);
|
|
1119
|
+
}
|
|
1096
1120
|
}
|
|
1097
1121
|
const status = this.logic.getStatus?.(state);
|
|
1098
1122
|
switch (status?.status) {
|
|
1099
1123
|
case 'done':
|
|
1100
1124
|
this._stopProcedure();
|
|
1125
|
+
this._complete();
|
|
1101
1126
|
this._doneEvent = doneInvoke(this.id, status.data);
|
|
1102
1127
|
this._parent?.send(this._doneEvent);
|
|
1103
|
-
this._complete();
|
|
1104
1128
|
break;
|
|
1105
1129
|
case 'error':
|
|
1106
1130
|
this._stopProcedure();
|
|
1107
|
-
this._parent?.send(error(this.id, status.data));
|
|
1108
1131
|
this._error(status.data);
|
|
1132
|
+
this._parent?.send(error(this.id, status.data));
|
|
1109
1133
|
break;
|
|
1110
1134
|
}
|
|
1111
1135
|
}
|
|
1112
1136
|
subscribe(nextListenerOrObserver, errorListener, completeListener) {
|
|
1113
1137
|
const observer = toObserver(nextListenerOrObserver, errorListener, completeListener);
|
|
1114
|
-
this.
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1138
|
+
if (this.status !== ActorStatus.Stopped) {
|
|
1139
|
+
this.observers.add(observer);
|
|
1140
|
+
} else {
|
|
1141
|
+
try {
|
|
1142
|
+
observer.complete?.();
|
|
1143
|
+
} catch (err) {
|
|
1144
|
+
reportUnhandledError(err);
|
|
1145
|
+
}
|
|
1118
1146
|
}
|
|
1119
1147
|
return {
|
|
1120
1148
|
unsubscribe: () => {
|
|
@@ -1124,7 +1152,7 @@ class Interpreter {
|
|
|
1124
1152
|
}
|
|
1125
1153
|
|
|
1126
1154
|
/**
|
|
1127
|
-
* Starts the
|
|
1155
|
+
* Starts the Actor from the initial state
|
|
1128
1156
|
*/
|
|
1129
1157
|
start() {
|
|
1130
1158
|
if (this.status === ActorStatus.Running) {
|
|
@@ -1136,8 +1164,26 @@ class Interpreter {
|
|
|
1136
1164
|
this.system._set(this._systemId, this);
|
|
1137
1165
|
}
|
|
1138
1166
|
this.status = ActorStatus.Running;
|
|
1167
|
+
const status = this.logic.getStatus?.(this._state);
|
|
1168
|
+
switch (status?.status) {
|
|
1169
|
+
case 'done':
|
|
1170
|
+
// a state machine can be "done" upon intialization (it could reach a final state using initial microsteps)
|
|
1171
|
+
// we still need to complete observers, flush deferreds etc
|
|
1172
|
+
this.update(this._state);
|
|
1173
|
+
// fallthrough
|
|
1174
|
+
case 'error':
|
|
1175
|
+
// TODO: rethink cleanup of observers, mailbox, etc
|
|
1176
|
+
return this;
|
|
1177
|
+
}
|
|
1139
1178
|
if (this.logic.start) {
|
|
1140
|
-
|
|
1179
|
+
try {
|
|
1180
|
+
this.logic.start(this._state, this._actorContext);
|
|
1181
|
+
} catch (err) {
|
|
1182
|
+
this._stopProcedure();
|
|
1183
|
+
this._error(err);
|
|
1184
|
+
this._parent?.send(error(this.id, err));
|
|
1185
|
+
return this;
|
|
1186
|
+
}
|
|
1141
1187
|
}
|
|
1142
1188
|
|
|
1143
1189
|
// TODO: this notifies all subscribers but usually this is redundant
|
|
@@ -1151,23 +1197,30 @@ class Interpreter {
|
|
|
1151
1197
|
return this;
|
|
1152
1198
|
}
|
|
1153
1199
|
_process(event) {
|
|
1200
|
+
// TODO: reexamine what happens when an action (or a guard or smth) throws
|
|
1201
|
+
let nextState;
|
|
1202
|
+
let caughtError;
|
|
1154
1203
|
try {
|
|
1155
|
-
|
|
1156
|
-
this.update(nextState);
|
|
1157
|
-
if (event.type === stopSignalType) {
|
|
1158
|
-
this._stopProcedure();
|
|
1159
|
-
this._complete();
|
|
1160
|
-
}
|
|
1204
|
+
nextState = this.logic.transition(this._state, event, this._actorContext);
|
|
1161
1205
|
} catch (err) {
|
|
1162
|
-
//
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
}
|
|
1206
|
+
// we wrap it in a box so we can rethrow it later even if falsy value gets caught here
|
|
1207
|
+
caughtError = {
|
|
1208
|
+
err
|
|
1209
|
+
};
|
|
1210
|
+
}
|
|
1211
|
+
if (caughtError) {
|
|
1212
|
+
const {
|
|
1213
|
+
err
|
|
1214
|
+
} = caughtError;
|
|
1215
|
+
this._stopProcedure();
|
|
1216
|
+
this._error(err);
|
|
1217
|
+
this._parent?.send(error(this.id, err));
|
|
1218
|
+
return;
|
|
1219
|
+
}
|
|
1220
|
+
this.update(nextState);
|
|
1221
|
+
if (event.type === stopSignalType) {
|
|
1222
|
+
this._stopProcedure();
|
|
1223
|
+
this._complete();
|
|
1171
1224
|
}
|
|
1172
1225
|
}
|
|
1173
1226
|
_stop() {
|
|
@@ -1186,7 +1239,7 @@ class Interpreter {
|
|
|
1186
1239
|
}
|
|
1187
1240
|
|
|
1188
1241
|
/**
|
|
1189
|
-
* Stops the
|
|
1242
|
+
* Stops the Actor and unsubscribe all listeners.
|
|
1190
1243
|
*/
|
|
1191
1244
|
stop() {
|
|
1192
1245
|
if (this._parent) {
|
|
@@ -1196,19 +1249,39 @@ class Interpreter {
|
|
|
1196
1249
|
}
|
|
1197
1250
|
_complete() {
|
|
1198
1251
|
for (const observer of this.observers) {
|
|
1199
|
-
|
|
1252
|
+
try {
|
|
1253
|
+
observer.complete?.();
|
|
1254
|
+
} catch (err) {
|
|
1255
|
+
reportUnhandledError(err);
|
|
1256
|
+
}
|
|
1200
1257
|
}
|
|
1201
1258
|
this.observers.clear();
|
|
1202
1259
|
}
|
|
1203
|
-
_error(
|
|
1260
|
+
_error(err) {
|
|
1261
|
+
if (!this.observers.size) {
|
|
1262
|
+
if (!this._parent) {
|
|
1263
|
+
reportUnhandledError(err);
|
|
1264
|
+
}
|
|
1265
|
+
return;
|
|
1266
|
+
}
|
|
1267
|
+
let reportError = false;
|
|
1204
1268
|
for (const observer of this.observers) {
|
|
1205
|
-
observer.error
|
|
1269
|
+
const errorListener = observer.error;
|
|
1270
|
+
reportError ||= !errorListener;
|
|
1271
|
+
try {
|
|
1272
|
+
errorListener?.(err);
|
|
1273
|
+
} catch (err2) {
|
|
1274
|
+
reportUnhandledError(err2);
|
|
1275
|
+
}
|
|
1206
1276
|
}
|
|
1207
1277
|
this.observers.clear();
|
|
1278
|
+
if (reportError) {
|
|
1279
|
+
reportUnhandledError(err);
|
|
1280
|
+
}
|
|
1208
1281
|
}
|
|
1209
1282
|
_stopProcedure() {
|
|
1210
1283
|
if (this.status !== ActorStatus.Running) {
|
|
1211
|
-
//
|
|
1284
|
+
// Actor already stopped; do nothing
|
|
1212
1285
|
return this;
|
|
1213
1286
|
}
|
|
1214
1287
|
|
|
@@ -1230,7 +1303,7 @@ class Interpreter {
|
|
|
1230
1303
|
}
|
|
1231
1304
|
|
|
1232
1305
|
/**
|
|
1233
|
-
* Sends an event to the running
|
|
1306
|
+
* Sends an event to the running Actor to trigger a transition.
|
|
1234
1307
|
*
|
|
1235
1308
|
* @param event The event to send
|
|
1236
1309
|
*/
|
|
@@ -1301,17 +1374,28 @@ class Interpreter {
|
|
|
1301
1374
|
}
|
|
1302
1375
|
|
|
1303
1376
|
/**
|
|
1304
|
-
* Creates a new
|
|
1377
|
+
* Creates a new `ActorRef` instance for the given machine with the provided options, if any.
|
|
1305
1378
|
*
|
|
1306
|
-
* @param machine The machine to
|
|
1307
|
-
* @param options
|
|
1379
|
+
* @param machine The machine to create an actor from
|
|
1380
|
+
* @param options `ActorRef` options
|
|
1308
1381
|
*/
|
|
1309
1382
|
|
|
1310
|
-
function
|
|
1311
|
-
const interpreter = new
|
|
1383
|
+
function createActor(logic, options) {
|
|
1384
|
+
const interpreter = new Actor(logic, options);
|
|
1312
1385
|
return interpreter;
|
|
1313
1386
|
}
|
|
1314
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
|
+
|
|
1315
1399
|
function resolve$6(actorContext, state, actionArgs, {
|
|
1316
1400
|
id,
|
|
1317
1401
|
systemId,
|
|
@@ -1323,7 +1407,7 @@ function resolve$6(actorContext, state, actionArgs, {
|
|
|
1323
1407
|
if (referenced) {
|
|
1324
1408
|
// TODO: inline `input: undefined` should win over the referenced one
|
|
1325
1409
|
const configuredInput = input || referenced.input;
|
|
1326
|
-
actorRef =
|
|
1410
|
+
actorRef = createActor(referenced.src, {
|
|
1327
1411
|
id,
|
|
1328
1412
|
src,
|
|
1329
1413
|
parent: actorContext?.self,
|
|
@@ -1526,10 +1610,10 @@ function toGuardDefinition(guardConfig, getPredicate) {
|
|
|
1526
1610
|
}
|
|
1527
1611
|
}
|
|
1528
1612
|
|
|
1529
|
-
function getOutput(configuration, context, event) {
|
|
1613
|
+
function getOutput(configuration, context, event, self) {
|
|
1530
1614
|
const machine = configuration[0].machine;
|
|
1531
1615
|
const finalChildStateNode = configuration.find(stateNode => stateNode.type === 'final' && stateNode.parent === machine.root);
|
|
1532
|
-
return finalChildStateNode && finalChildStateNode.output ? mapContext(finalChildStateNode.output, context, event) : undefined;
|
|
1616
|
+
return finalChildStateNode && finalChildStateNode.output ? mapContext(finalChildStateNode.output, context, event, self) : undefined;
|
|
1533
1617
|
}
|
|
1534
1618
|
const isAtomicStateNode = stateNode => stateNode.type === 'atomic' || stateNode.type === 'final';
|
|
1535
1619
|
function getChildren(stateNode) {
|
|
@@ -2145,7 +2229,7 @@ function microstepProcedure(transitions, currentState, mutConfiguration, event,
|
|
|
2145
2229
|
actions.push(...filteredTransitions.flatMap(t => t.actions));
|
|
2146
2230
|
|
|
2147
2231
|
// Enter states
|
|
2148
|
-
enterStates(event, filteredTransitions, mutConfiguration, actions, internalQueue, currentState, historyValue, isInitial);
|
|
2232
|
+
enterStates(event, filteredTransitions, mutConfiguration, actions, internalQueue, currentState, historyValue, isInitial, actorCtx);
|
|
2149
2233
|
const nextConfiguration = [...mutConfiguration];
|
|
2150
2234
|
const done = isInFinalState(nextConfiguration);
|
|
2151
2235
|
if (done) {
|
|
@@ -2154,7 +2238,7 @@ function microstepProcedure(transitions, currentState, mutConfiguration, event,
|
|
|
2154
2238
|
}
|
|
2155
2239
|
try {
|
|
2156
2240
|
const nextState = resolveActionsAndContext(actions, event, currentState, actorCtx);
|
|
2157
|
-
const output = done ? getOutput(nextConfiguration, nextState.context, event) : undefined;
|
|
2241
|
+
const output = done ? getOutput(nextConfiguration, nextState.context, event, actorCtx.self) : undefined;
|
|
2158
2242
|
internalQueue.push(...nextState._internalQueue);
|
|
2159
2243
|
return cloneState(currentState, {
|
|
2160
2244
|
configuration: nextConfiguration,
|
|
@@ -2171,7 +2255,7 @@ function microstepProcedure(transitions, currentState, mutConfiguration, event,
|
|
|
2171
2255
|
throw e;
|
|
2172
2256
|
}
|
|
2173
2257
|
}
|
|
2174
|
-
function enterStates(event, filteredTransitions, mutConfiguration, actions, internalQueue, currentState, historyValue, isInitial) {
|
|
2258
|
+
function enterStates(event, filteredTransitions, mutConfiguration, actions, internalQueue, currentState, historyValue, isInitial, actorContext) {
|
|
2175
2259
|
const statesToEnter = new Set();
|
|
2176
2260
|
const statesForDefaultEntry = new Set();
|
|
2177
2261
|
computeEntrySet(filteredTransitions, historyValue, statesForDefaultEntry, statesToEnter);
|
|
@@ -2199,7 +2283,7 @@ function enterStates(event, filteredTransitions, mutConfiguration, actions, inte
|
|
|
2199
2283
|
if (!parent.parent) {
|
|
2200
2284
|
continue;
|
|
2201
2285
|
}
|
|
2202
|
-
internalQueue.push(done(parent.id, stateNodeToEnter.output ? mapContext(stateNodeToEnter.output, currentState.context, event) : undefined));
|
|
2286
|
+
internalQueue.push(done(parent.id, stateNodeToEnter.output ? mapContext(stateNodeToEnter.output, currentState.context, event, actorContext.self) : undefined));
|
|
2203
2287
|
if (parent.parent) {
|
|
2204
2288
|
const grandparent = parent.parent;
|
|
2205
2289
|
if (grandparent.type === 'parallel') {
|
|
@@ -2519,6 +2603,7 @@ class State {
|
|
|
2519
2603
|
this.value = void 0;
|
|
2520
2604
|
this.done = void 0;
|
|
2521
2605
|
this.output = void 0;
|
|
2606
|
+
this.error = void 0;
|
|
2522
2607
|
this.context = void 0;
|
|
2523
2608
|
this.historyValue = {};
|
|
2524
2609
|
this._internalQueue = void 0;
|
|
@@ -2535,6 +2620,7 @@ class State {
|
|
|
2535
2620
|
this.tags = new Set(flatten(this.configuration.map(sn => sn.tags)));
|
|
2536
2621
|
this.done = config.done ?? false;
|
|
2537
2622
|
this.output = config.output;
|
|
2623
|
+
this.error = config.error;
|
|
2538
2624
|
}
|
|
2539
2625
|
|
|
2540
2626
|
/**
|
|
@@ -2747,7 +2833,7 @@ function createSpawner(actorContext, {
|
|
|
2747
2833
|
const input = 'input' in options ? options.input : referenced.input;
|
|
2748
2834
|
|
|
2749
2835
|
// TODO: this should also receive `src`
|
|
2750
|
-
const actor =
|
|
2836
|
+
const actor = createActor(referenced.src, {
|
|
2751
2837
|
id: options.id,
|
|
2752
2838
|
parent: actorContext.self,
|
|
2753
2839
|
input: typeof input === 'function' ? input({
|
|
@@ -2761,7 +2847,7 @@ function createSpawner(actorContext, {
|
|
|
2761
2847
|
return actor;
|
|
2762
2848
|
} else {
|
|
2763
2849
|
// TODO: this should also receive `src`
|
|
2764
|
-
return
|
|
2850
|
+
return createActor(src, {
|
|
2765
2851
|
id: options.id,
|
|
2766
2852
|
parent: actorContext.self,
|
|
2767
2853
|
input: options.input,
|
|
@@ -2984,9 +3070,10 @@ function createInitEvent(input) {
|
|
|
2984
3070
|
};
|
|
2985
3071
|
}
|
|
2986
3072
|
|
|
3073
|
+
exports.Actor = Actor;
|
|
2987
3074
|
exports.ActorStatus = ActorStatus;
|
|
2988
3075
|
exports.ConstantPrefix = ConstantPrefix;
|
|
2989
|
-
exports.
|
|
3076
|
+
exports.InterpreterStatus = InterpreterStatus;
|
|
2990
3077
|
exports.NULL_EVENT = NULL_EVENT;
|
|
2991
3078
|
exports.STATE_DELIMITER = STATE_DELIMITER;
|
|
2992
3079
|
exports.SpecialTargets = SpecialTargets;
|
|
@@ -2996,7 +3083,9 @@ exports.and = and;
|
|
|
2996
3083
|
exports.assign = assign;
|
|
2997
3084
|
exports.cancel = cancel;
|
|
2998
3085
|
exports.choose = choose;
|
|
3086
|
+
exports.cloneState = cloneState;
|
|
2999
3087
|
exports.constantPrefixes = constantPrefixes;
|
|
3088
|
+
exports.createActor = createActor;
|
|
3000
3089
|
exports.createEmptyActor = createEmptyActor;
|
|
3001
3090
|
exports.createInitEvent = createInitEvent;
|
|
3002
3091
|
exports.createInvokeId = createInvokeId;
|