xstate 4.26.0 → 4.28.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.
Files changed (50) hide show
  1. package/CHANGELOG.md +78 -1
  2. package/dist/xstate.interpreter.js +1 -1
  3. package/dist/xstate.js +1 -1
  4. package/dist/xstate.web.js +2 -2
  5. package/es/Actor.js +5 -5
  6. package/es/State.d.ts +5 -2
  7. package/es/State.js +10 -3
  8. package/es/StateNode.d.ts +2 -1
  9. package/es/StateNode.js +54 -59
  10. package/es/_virtual/_tslib.js +8 -4
  11. package/es/actions.d.ts +18 -2
  12. package/es/actions.js +22 -8
  13. package/es/devTools.d.ts +1 -2
  14. package/es/devTools.js +4 -0
  15. package/es/index.d.ts +2 -1
  16. package/es/index.js +2 -1
  17. package/es/interpreter.d.ts +0 -5
  18. package/es/interpreter.js +35 -25
  19. package/es/registry.js +1 -1
  20. package/es/stateUtils.d.ts +1 -1
  21. package/es/stateUtils.js +1 -1
  22. package/es/types.d.ts +10 -14
  23. package/es/utils.d.ts +7 -1
  24. package/es/utils.js +17 -10
  25. package/lib/Actor.js +4 -4
  26. package/lib/SimulatedClock.js +9 -5
  27. package/lib/State.d.ts +5 -2
  28. package/lib/State.js +10 -3
  29. package/lib/StateNode.d.ts +2 -1
  30. package/lib/StateNode.js +52 -57
  31. package/lib/_virtual/_tslib.js +8 -4
  32. package/lib/actions.d.ts +18 -2
  33. package/lib/actions.js +22 -7
  34. package/lib/devTools.d.ts +1 -2
  35. package/lib/devTools.js +4 -0
  36. package/lib/index.d.ts +2 -1
  37. package/lib/index.js +1 -0
  38. package/lib/interpreter.d.ts +0 -5
  39. package/lib/interpreter.js +34 -24
  40. package/lib/json.js +7 -7
  41. package/lib/model.js +14 -10
  42. package/lib/patterns.js +2 -2
  43. package/lib/registry.js +1 -1
  44. package/lib/scxml.js +29 -25
  45. package/lib/stateUtils.d.ts +1 -1
  46. package/lib/stateUtils.js +1 -1
  47. package/lib/types.d.ts +10 -14
  48. package/lib/utils.d.ts +7 -1
  49. package/lib/utils.js +18 -9
  50. package/package.json +3 -3
@@ -90,14 +90,15 @@ function () {
90
90
  if (_this.status === exports.InterpreterStatus.Stopped) {
91
91
  // do nothing
92
92
  if (!environment.IS_PRODUCTION) {
93
- utils.warn(false, "Event \"" + _event.name + "\" was sent to stopped service \"" + _this.machine.id + "\". This service has already reached its final state, and will not transition.\nEvent: " + JSON.stringify(_event.data));
93
+ utils.warn(false, "Event \"".concat(_event.name, "\" was sent to stopped service \"").concat(_this.machine.id, "\". This service has already reached its final state, and will not transition.\nEvent: ").concat(JSON.stringify(_event.data)));
94
94
  }
95
95
 
96
96
  return _this.state;
97
97
  }
98
98
 
99
99
  if (_this.status !== exports.InterpreterStatus.Running && !_this.options.deferEvents) {
100
- throw new Error("Event \"" + _event.name + "\" was sent to uninitialized service \"" + _this.machine.id + "\". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: " + JSON.stringify(_event.data));
100
+ throw new Error("Event \"".concat(_event.name, "\" was sent to uninitialized service \"").concat(_this.machine.id // tslint:disable-next-line:max-line-length
101
+ , "\". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: ").concat(JSON.stringify(_event.data)));
101
102
  }
102
103
 
103
104
  _this.scheduler.schedule(function () {
@@ -119,12 +120,12 @@ function () {
119
120
 
120
121
  if (!target) {
121
122
  if (!isParent) {
122
- throw new Error("Unable to send event to child '" + to + "' from service '" + _this.id + "'.");
123
+ throw new Error("Unable to send event to child '".concat(to, "' from service '").concat(_this.id, "'."));
123
124
  } // tslint:disable-next-line:no-console
124
125
 
125
126
 
126
127
  if (!environment.IS_PRODUCTION) {
127
- utils.warn(false, "Service '" + _this.id + "' has no parent: unable to send event " + event.type);
128
+ utils.warn(false, "Service '".concat(_this.id, "' has no parent: unable to send event ").concat(event.type));
128
129
  }
129
130
 
130
131
  return;
@@ -133,7 +134,7 @@ function () {
133
134
  if ('machine' in target) {
134
135
  // Send SCXML events to machines
135
136
  target.send(_tslib.__assign(_tslib.__assign({}, event), {
136
- name: event.name === actionTypes.error ? "" + actions.error(_this.id) : event.name,
137
+ name: event.name === actionTypes.error ? "".concat(actions.error(_this.id)) : event.name,
137
138
  origin: _this.sessionId
138
139
  }));
139
140
  } else {
@@ -179,7 +180,7 @@ function () {
179
180
  Object.defineProperty(Interpreter.prototype, "state", {
180
181
  get: function () {
181
182
  if (!environment.IS_PRODUCTION) {
182
- utils.warn(this.status !== exports.InterpreterStatus.NotStarted, "Attempted to read state from uninitialized service '" + this.id + "'. Make sure the service is started first.");
183
+ utils.warn(this.status !== exports.InterpreterStatus.NotStarted, "Attempted to read state from uninitialized service '".concat(this.id, "'. Make sure the service is started first."));
183
184
  }
184
185
 
185
186
  return this._state;
@@ -619,11 +620,11 @@ function () {
619
620
  if (this.status === exports.InterpreterStatus.NotStarted && this.options.deferEvents) {
620
621
  // tslint:disable-next-line:no-console
621
622
  if (!environment.IS_PRODUCTION) {
622
- utils.warn(false, events.length + " event(s) were sent to uninitialized service \"" + this.machine.id + "\" and are deferred. Make sure .start() is called for this service.\nEvent: " + JSON.stringify(event));
623
+ utils.warn(false, "".concat(events.length, " event(s) were sent to uninitialized service \"").concat(this.machine.id, "\" and are deferred. Make sure .start() is called for this service.\nEvent: ").concat(JSON.stringify(event)));
623
624
  }
624
625
  } else if (this.status !== exports.InterpreterStatus.Running) {
625
626
  throw new Error( // tslint:disable-next-line:max-line-length
626
- events.length + " event(s) were sent to uninitialized service \"" + this.machine.id + "\". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.");
627
+ "".concat(events.length, " event(s) were sent to uninitialized service \"").concat(this.machine.id, "\". Make sure .start() is called for this service, or set { deferEvents: true } in the service options."));
627
628
  }
628
629
 
629
630
  this.scheduler.schedule(function () {
@@ -643,7 +644,7 @@ function () {
643
644
  });
644
645
  batchedActions.push.apply(batchedActions, _tslib.__spreadArray([], _tslib.__read(nextState.actions.map(function (a) {
645
646
  return State.bindActionToState(a, nextState);
646
- }))));
647
+ })), false));
647
648
  batchChanged = batchChanged || !!nextState.changed;
648
649
  };
649
650
 
@@ -716,7 +717,7 @@ function () {
716
717
  var child = this.children.get(id);
717
718
 
718
719
  if (!child) {
719
- throw new Error("Unable to forward event '" + event + "' from interpreter '" + this.id + "' to nonexistant child '" + id + "'.");
720
+ throw new Error("Unable to forward event '".concat(event, "' from interpreter '").concat(this.id, "' to nonexistant child '").concat(id, "'."));
720
721
  }
721
722
 
722
723
  child.send(event);
@@ -803,6 +804,10 @@ function () {
803
804
 
804
805
  case actionTypes.start:
805
806
  {
807
+ if (this.status !== exports.InterpreterStatus.Running) {
808
+ return;
809
+ }
810
+
806
811
  var activity = action.activity; // If the activity will be stopped right after it's started
807
812
  // (such as in transient states)
808
813
  // don't bother starting the activity.
@@ -820,7 +825,7 @@ function () {
820
825
 
821
826
  if (!environment.IS_PRODUCTION) {
822
827
  utils.warn(!('forward' in activity), // tslint:disable-next-line:max-line-length
823
- "`forward` property is deprecated (found in invocation of '" + activity.src + "' in in machine '" + this.machine.id + "'). " + "Please use `autoForward` instead.");
828
+ "`forward` property is deprecated (found in invocation of '".concat(activity.src, "' in in machine '").concat(this.machine.id, "'). ") + "Please use `autoForward` instead.");
824
829
  }
825
830
 
826
831
  var autoForward = 'autoForward' in activity ? activity.autoForward : !!activity.forward;
@@ -828,7 +833,7 @@ function () {
828
833
  if (!serviceCreator) {
829
834
  // tslint:disable-next-line:no-console
830
835
  if (!environment.IS_PRODUCTION) {
831
- utils.warn(false, "No service found for invocation '" + activity.src + "' in machine '" + this.machine.id + "'.");
836
+ utils.warn(false, "No service found for invocation '".concat(activity.src, "' in machine '").concat(this.machine.id, "'."));
832
837
  }
833
838
 
834
839
  return;
@@ -889,7 +894,7 @@ function () {
889
894
 
890
895
  default:
891
896
  if (!environment.IS_PRODUCTION) {
892
- utils.warn(false, "No implementation found for action type '" + action.type + "'");
897
+ utils.warn(false, "No implementation found for action type '".concat(action.type, "'"));
893
898
  }
894
899
 
895
900
  break;
@@ -938,7 +943,7 @@ function () {
938
943
  } else if (utils.isBehavior(entity)) {
939
944
  return this.spawnBehavior(entity, name);
940
945
  } else {
941
- throw new Error("Unable to spawn entity \"" + name + "\" of type \"" + typeof entity + "\".");
946
+ throw new Error("Unable to spawn entity \"".concat(name, "\" of type \"").concat(typeof entity, "\"."));
942
947
  }
943
948
  };
944
949
 
@@ -1034,7 +1039,8 @@ function () {
1034
1039
  }
1035
1040
  }
1036
1041
  });
1037
- var actor = {
1042
+
1043
+ var actor = _tslib.__assign({
1038
1044
  id: id,
1039
1045
  send: function () {
1040
1046
  return void 0;
@@ -1078,7 +1084,8 @@ function () {
1078
1084
  getSnapshot: function () {
1079
1085
  return resolvedData;
1080
1086
  }
1081
- };
1087
+ }, utils.interopSymbols);
1088
+
1082
1089
  this.children.set(id, actor);
1083
1090
  return actor;
1084
1091
  };
@@ -1122,7 +1129,7 @@ function () {
1122
1129
  return this.spawnPromise(callbackStop, id);
1123
1130
  }
1124
1131
 
1125
- var actor = {
1132
+ var actor = _tslib.__assign({
1126
1133
  id: id,
1127
1134
  send: function (event) {
1128
1135
  return receivers.forEach(function (receiver) {
@@ -1152,7 +1159,8 @@ function () {
1152
1159
  getSnapshot: function () {
1153
1160
  return emitted;
1154
1161
  }
1155
- };
1162
+ }, utils.interopSymbols);
1163
+
1156
1164
  this.children.set(id, actor);
1157
1165
  return actor;
1158
1166
  };
@@ -1180,7 +1188,8 @@ function () {
1180
1188
  origin: id
1181
1189
  }));
1182
1190
  });
1183
- var actor = {
1191
+
1192
+ var actor = _tslib.__assign({
1184
1193
  id: id,
1185
1194
  send: function () {
1186
1195
  return void 0;
@@ -1199,7 +1208,8 @@ function () {
1199
1208
  id: id
1200
1209
  };
1201
1210
  }
1202
- };
1211
+ }, utils.interopSymbols);
1212
+
1203
1213
  this.children.set(id, actor);
1204
1214
  return actor;
1205
1215
  };
@@ -1214,7 +1224,7 @@ function () {
1214
1224
 
1215
1225
  if (!implementation) {
1216
1226
  if (!environment.IS_PRODUCTION) {
1217
- utils.warn(false, "No implementation found for activity '" + activity.type + "'");
1227
+ utils.warn(false, "No implementation found for activity '".concat(activity.type, "'"));
1218
1228
  } // tslint:disable-next-line:no-console
1219
1229
 
1220
1230
 
@@ -1227,7 +1237,7 @@ function () {
1227
1237
  };
1228
1238
 
1229
1239
  Interpreter.prototype.spawnEffect = function (id, dispose) {
1230
- this.children.set(id, {
1240
+ this.children.set(id, _tslib.__assign({
1231
1241
  id: id,
1232
1242
  send: function () {
1233
1243
  return void 0;
@@ -1248,7 +1258,7 @@ function () {
1248
1258
  id: id
1249
1259
  };
1250
1260
  }
1251
- });
1261
+ }, utils.interopSymbols));
1252
1262
  };
1253
1263
 
1254
1264
  Interpreter.prototype.attachDev = function () {
@@ -1346,7 +1356,7 @@ function spawn(entity, nameOrOptions) {
1346
1356
  return serviceScope.consume(function (service) {
1347
1357
  if (!environment.IS_PRODUCTION) {
1348
1358
  var isLazyEntity = utils.isMachine(entity) || utils.isFunction(entity);
1349
- utils.warn(!!service || isLazyEntity, "Attempted to spawn an Actor (ID: \"" + (utils.isMachine(entity) ? entity.id : 'undefined') + "\") outside of a service. This will have no effect.");
1359
+ utils.warn(!!service || isLazyEntity, "Attempted to spawn an Actor (ID: \"".concat(utils.isMachine(entity) ? entity.id : 'undefined', "\") outside of a service. This will have no effect."));
1350
1360
  }
1351
1361
 
1352
1362
  if (service) {
package/lib/json.js CHANGED
@@ -10,7 +10,7 @@ function stringifyFunction(fn) {
10
10
  }
11
11
  exports.stringifyFunction = stringifyFunction;
12
12
  function getStateNodeId(stateNode) {
13
- return "#" + stateNode.id;
13
+ return "#".concat(stateNode.id);
14
14
  }
15
15
  // derive config from machine
16
16
  function machineToJSON(stateNode) {
@@ -21,7 +21,7 @@ function machineToJSON(stateNode) {
21
21
  key: stateNode.key,
22
22
  entry: stateNode.onEntry,
23
23
  exit: stateNode.onExit,
24
- on: utils_1.mapValues(stateNode.on, function (transition) {
24
+ on: (0, utils_1.mapValues)(stateNode.on, function (transition) {
25
25
  return transition.map(function (t) {
26
26
  return {
27
27
  target: t.target ? t.target.map(getStateNodeId) : [],
@@ -43,7 +43,7 @@ function machineToJSON(stateNode) {
43
43
  exports.machineToJSON = machineToJSON;
44
44
  function stringify(machine) {
45
45
  return JSON.stringify(machineToJSON(machine), function (_, value) {
46
- if (utils_1.isFunction(value)) {
46
+ if ((0, utils_1.isFunction)(value)) {
47
47
  return { $function: value.toString() };
48
48
  }
49
49
  return value;
@@ -63,14 +63,14 @@ exports.parse = parse;
63
63
  function jsonify(value) {
64
64
  Object.defineProperty(value, 'toJSON', {
65
65
  value: function () {
66
- return utils_1.mapValues(value, function (subValue) {
67
- if (utils_1.isFunction(subValue)) {
66
+ return (0, utils_1.mapValues)(value, function (subValue) {
67
+ if ((0, utils_1.isFunction)(subValue)) {
68
68
  return stringifyFunction(subValue);
69
69
  }
70
70
  else if (typeof subValue === 'object' && !Array.isArray(subValue)) {
71
71
  // mostly for assignments
72
- return utils_1.mapValues(subValue, function (subSubValue) {
73
- if (utils_1.isFunction(subSubValue)) {
72
+ return (0, utils_1.mapValues)(subValue, function (subSubValue) {
73
+ if ((0, utils_1.isFunction)(subSubValue)) {
74
74
  return stringifyFunction(subSubValue);
75
75
  }
76
76
  return subSubValue;
package/lib/model.js CHANGED
@@ -26,10 +26,14 @@ var __read = (this && this.__read) || function (o, n) {
26
26
  }
27
27
  return ar;
28
28
  };
29
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
30
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
31
- to[j] = from[i];
32
- return to;
29
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
30
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
31
+ if (ar || !(i in from)) {
32
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
33
+ ar[i] = from[i];
34
+ }
35
+ }
36
+ return to.concat(ar || Array.prototype.slice.call(from));
33
37
  };
34
38
  Object.defineProperty(exports, "__esModule", { value: true });
35
39
  exports.createModel = void 0;
@@ -43,26 +47,26 @@ function createModel(initialContext, creators) {
43
47
  initialContext: initialContext,
44
48
  assign: actions_1.assign,
45
49
  events: (eventCreators
46
- ? utils_1.mapValues(eventCreators, function (fn, eventType) { return function () {
50
+ ? (0, utils_1.mapValues)(eventCreators, function (fn, eventType) { return function () {
47
51
  var args = [];
48
52
  for (var _i = 0; _i < arguments.length; _i++) {
49
53
  args[_i] = arguments[_i];
50
54
  }
51
- return (__assign(__assign({}, fn.apply(void 0, __spreadArray([], __read(args)))), { type: eventType }));
55
+ return (__assign(__assign({}, fn.apply(void 0, __spreadArray([], __read(args), false))), { type: eventType }));
52
56
  }; })
53
57
  : undefined),
54
58
  actions: actionCreators
55
- ? utils_1.mapValues(actionCreators, function (fn, actionType) { return function () {
59
+ ? (0, utils_1.mapValues)(actionCreators, function (fn, actionType) { return function () {
56
60
  var args = [];
57
61
  for (var _i = 0; _i < arguments.length; _i++) {
58
62
  args[_i] = arguments[_i];
59
63
  }
60
- return (__assign(__assign({}, fn.apply(void 0, __spreadArray([], __read(args)))), { type: actionType }));
64
+ return (__assign(__assign({}, fn.apply(void 0, __spreadArray([], __read(args), false))), { type: actionType }));
61
65
  }; })
62
66
  : undefined,
63
- reset: function () { return actions_1.assign(initialContext); },
67
+ reset: function () { return (0, actions_1.assign)(initialContext); },
64
68
  createMachine: function (config, implementations) {
65
- return Machine_1.createMachine('context' in config ? config : __assign(__assign({}, config), { context: initialContext }), implementations);
69
+ return (0, Machine_1.createMachine)('context' in config ? config : __assign(__assign({}, config), { context: initialContext }), implementations);
66
70
  }
67
71
  };
68
72
  return model;
package/lib/patterns.js CHANGED
@@ -34,10 +34,10 @@ function sequence(items, options) {
34
34
  var states = {};
35
35
  var nextEventObject = resolvedOptions.nextEvent === undefined
36
36
  ? undefined
37
- : utils_1.toEventObject(resolvedOptions.nextEvent);
37
+ : (0, utils_1.toEventObject)(resolvedOptions.nextEvent);
38
38
  var prevEventObject = resolvedOptions.prevEvent === undefined
39
39
  ? undefined
40
- : utils_1.toEventObject(resolvedOptions.prevEvent);
40
+ : (0, utils_1.toEventObject)(resolvedOptions.prevEvent);
41
41
  items.forEach(function (item, i) {
42
42
  var state = {
43
43
  on: {}
package/lib/registry.js CHANGED
@@ -6,7 +6,7 @@ var children = /*#__PURE__*/new Map();
6
6
  var sessionIdIndex = 0;
7
7
  var registry = {
8
8
  bookId: function () {
9
- return "x:" + sessionIdIndex++;
9
+ return "x:".concat(sessionIdIndex++);
10
10
  },
11
11
  register: function (id, actor) {
12
12
  children.set(id, actor);
package/lib/scxml.js CHANGED
@@ -26,10 +26,14 @@ var __read = (this && this.__read) || function (o, n) {
26
26
  }
27
27
  return ar;
28
28
  };
29
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
30
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
31
- to[j] = from[i];
32
- return to;
29
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
30
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
31
+ if (ar || !(i in from)) {
32
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
33
+ ar[i] = from[i];
34
+ }
35
+ }
36
+ return to.concat(ar || Array.prototype.slice.call(from));
33
37
  };
34
38
  var __values = (this && this.__values) || function(o) {
35
39
  var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
@@ -53,7 +57,7 @@ function getAttribute(element, attribute) {
53
57
  }
54
58
  function indexedRecord(items, identifier) {
55
59
  var record = {};
56
- var identifierFn = utils_1.isString(identifier)
60
+ var identifierFn = (0, utils_1.isString)(identifier)
57
61
  ? function (item) { return item[identifier]; }
58
62
  : identifier;
59
63
  items.forEach(function (item) {
@@ -71,7 +75,7 @@ function executableContent(elements) {
71
75
  function getTargets(targetAttr) {
72
76
  // return targetAttr ? [`#${targetAttr}`] : undefined;
73
77
  return targetAttr
74
- ? ("" + targetAttr).split(/\s+/).map(function (target) { return "#" + target; })
78
+ ? "".concat(targetAttr).split(/\s+/).map(function (target) { return "#".concat(target); })
75
79
  : undefined;
76
80
  }
77
81
  function delayToMs(delay) {
@@ -96,29 +100,29 @@ function delayToMs(delay) {
96
100
  : 0;
97
101
  var millisecondsPart = parseInt(secondsMatch[3].padEnd(3, '0'), 10);
98
102
  if (millisecondsPart >= 1000) {
99
- throw new Error("Can't parse \"" + delay + " delay.\"");
103
+ throw new Error("Can't parse \"".concat(delay, " delay.\""));
100
104
  }
101
105
  return secondsPart + millisecondsPart;
102
106
  }
103
- throw new Error("Can't parse \"" + delay + " delay.\"");
107
+ throw new Error("Can't parse \"".concat(delay, " delay.\""));
104
108
  }
105
109
  var evaluateExecutableContent = function (context, _ev, meta, body) {
106
110
  var datamodel = context
107
- ? utils_1.keys(context)
108
- .map(function (key) { return "const " + key + " = context['" + key + "'];"; })
111
+ ? (0, utils_1.keys)(context)
112
+ .map(function (key) { return "const ".concat(key, " = context['").concat(key, "'];"); })
109
113
  .join('\n')
110
114
  : '';
111
115
  var scope = ['const _sessionid = "NOT_IMPLEMENTED";', datamodel]
112
116
  .filter(Boolean)
113
117
  .join('\n');
114
118
  var args = ['context', '_event'];
115
- var fnBody = "\n " + scope + "\n " + body + "\n ";
116
- var fn = new (Function.bind.apply(Function, __spreadArray(__spreadArray([void 0], __read(args)), [fnBody])))();
119
+ var fnBody = "\n ".concat(scope, "\n ").concat(body, "\n ");
120
+ var fn = new (Function.bind.apply(Function, __spreadArray(__spreadArray([void 0], __read(args), false), [fnBody], false)))();
117
121
  return fn(context, meta._event);
118
122
  };
119
123
  function createCond(cond) {
120
124
  return function (context, _event, meta) {
121
- return evaluateExecutableContent(context, _event, meta, "return " + cond + ";");
125
+ return evaluateExecutableContent(context, _event, meta, "return ".concat(cond, ";"));
122
126
  };
123
127
  }
124
128
  function mapAction(element) {
@@ -129,7 +133,7 @@ function mapAction(element) {
129
133
  }
130
134
  case 'assign': {
131
135
  return actions.assign(function (context, e, meta) {
132
- var fnBody = "\n return {'" + element.attributes.location + "': " + element.attributes.expr + "};\n ";
136
+ var fnBody = "\n return {'".concat(element.attributes.location, "': ").concat(element.attributes.expr, "};\n ");
133
137
  return evaluateExecutableContent(context, e, meta, fnBody);
134
138
  });
135
139
  }
@@ -142,14 +146,14 @@ function mapAction(element) {
142
146
  if (child.name === 'content') {
143
147
  throw new Error('Conversion of <content/> inside <send/> not implemented.');
144
148
  }
145
- return "" + acc + child.attributes.name + ":" + child.attributes.expr + ",\n";
149
+ return "".concat(acc).concat(child.attributes.name, ":").concat(child.attributes.expr, ",\n");
146
150
  }, '');
147
151
  if (event_1 && !params_1) {
148
152
  convertedEvent = event_1;
149
153
  }
150
154
  else {
151
155
  convertedEvent = function (context, _ev, meta) {
152
- var fnBody = "\n return { type: " + (event_1 ? "\"" + event_1 + "\"" : eventexpr_1) + ", " + (params_1 ? params_1 : '') + " }\n ";
156
+ var fnBody = "\n return { type: ".concat(event_1 ? "\"".concat(event_1, "\"") : eventexpr_1, ", ").concat(params_1 ? params_1 : '', " }\n ");
153
157
  return evaluateExecutableContent(context, _ev, meta, fnBody);
154
158
  };
155
159
  }
@@ -158,7 +162,7 @@ function mapAction(element) {
158
162
  }
159
163
  else if (element.attributes.delayexpr) {
160
164
  convertedDelay = function (context, _ev, meta) {
161
- var fnBody = "\n return (" + delayToMs + ")(" + element.attributes.delayexpr + ");\n ";
165
+ var fnBody = "\n return (".concat(delayToMs, ")(").concat(element.attributes.delayexpr, ");\n ");
162
166
  return evaluateExecutableContent(context, _ev, meta, fnBody);
163
167
  };
164
168
  }
@@ -170,7 +174,7 @@ function mapAction(element) {
170
174
  case 'log': {
171
175
  var label = element.attributes.label;
172
176
  return actions.log(function (context, e, meta) {
173
- var fnBody = "\n return " + element.attributes.expr + ";\n ";
177
+ var fnBody = "\n return ".concat(element.attributes.expr, ";\n ");
174
178
  return evaluateExecutableContent(context, e, meta, fnBody);
175
179
  }, label !== undefined ? String(label) : undefined);
176
180
  }
@@ -215,7 +219,7 @@ function mapAction(element) {
215
219
  return actions.choose(conds);
216
220
  }
217
221
  default:
218
- throw new Error("Conversion of \"" + element.name + "\" elements is not implemented yet.");
222
+ throw new Error("Conversion of \"".concat(element.name, "\" elements is not implemented yet."));
219
223
  }
220
224
  }
221
225
  function mapActions(elements) {
@@ -257,7 +261,7 @@ function toConfig(nodeJson, id, options) {
257
261
  return {
258
262
  id: id,
259
263
  history: history_1,
260
- target: target ? "#" + target : undefined
264
+ target: target ? "#".concat(target) : undefined
261
265
  };
262
266
  }
263
267
  case 'final': {
@@ -277,7 +281,7 @@ function toConfig(nodeJson, id, options) {
277
281
  var invokeElements = nodeJson.elements.filter(function (element) { return element.name === 'invoke'; });
278
282
  var onEntryElement = nodeJson.elements.find(function (element) { return element.name === 'onentry'; });
279
283
  var onExitElement = nodeJson.elements.find(function (element) { return element.name === 'onexit'; });
280
- var states = indexedRecord(stateElements, function (item) { return "" + item.attributes.id; });
284
+ var states = indexedRecord(stateElements, function (item) { return "".concat(item.attributes.id); });
281
285
  var initialElement = !initial
282
286
  ? nodeJson.elements.find(function (element) { return element.name === 'initial'; })
283
287
  : undefined;
@@ -312,7 +316,7 @@ function toConfig(nodeJson, id, options) {
312
316
  });
313
317
  return __assign(__assign(__assign(__assign(__assign(__assign(__assign({ id: id }, (initial ? { initial: initial } : undefined)), (parallel ? { type: 'parallel' } : undefined)), (stateElements.length
314
318
  ? {
315
- states: utils_1.mapValues(states, function (state, key) {
319
+ states: (0, utils_1.mapValues)(states, function (state, key) {
316
320
  return toConfig(state, key, options);
317
321
  })
318
322
  }
@@ -332,15 +336,15 @@ function scxmlToMachine(scxmlJson, options) {
332
336
  }
333
337
  acc[element.attributes.id] = element.attributes.expr
334
338
  ? // tslint:disable-next-line:no-eval
335
- eval("(" + element.attributes.expr + ")")
339
+ eval("(".concat(element.attributes.expr, ")"))
336
340
  : undefined;
337
341
  return acc;
338
342
  }, {})
339
343
  : undefined;
340
- return index_1.Machine(__assign(__assign({}, toConfig(machineElement, '(machine)', options)), { context: extState, delimiter: options.delimiter }));
344
+ return (0, index_1.Machine)(__assign(__assign({}, toConfig(machineElement, '(machine)', options)), { context: extState, delimiter: options.delimiter }));
341
345
  }
342
346
  function toMachine(xml, options) {
343
- var json = xml_js_1.xml2js(xml);
347
+ var json = (0, xml_js_1.xml2js)(xml);
344
348
  return scxmlToMachine(json, options);
345
349
  }
346
350
  exports.toMachine = toMachine;
@@ -4,7 +4,7 @@ declare type AdjList<TC, TE extends EventObject> = Map<StateNode<TC, any, TE>, A
4
4
  export declare const isLeafNode: (stateNode: StateNode<any, any, any, any>) => boolean;
5
5
  export declare function getChildren<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE>): Array<StateNode<TC, any, TE>>;
6
6
  export declare function getAllStateNodes<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE, any>): Array<StateNode<TC, any, TE, any>>;
7
- export declare function getConfiguration<TC, TE extends EventObject>(prevStateNodes: Iterable<StateNode<TC, any, TE, any>>, stateNodes: Iterable<StateNode<TC, any, TE, any>>): Iterable<StateNode<TC, any, TE, any>>;
7
+ export declare function getConfiguration<TC, TE extends EventObject>(prevStateNodes: Iterable<StateNode<TC, any, TE, any>>, stateNodes: Iterable<StateNode<TC, any, TE, any>>): Set<StateNode<TC, any, TE, any>>;
8
8
  export declare function getAdjList<TC, TE extends EventObject>(configuration: Configuration<TC, TE>): AdjList<TC, TE>;
9
9
  export declare function getValue<TC, TE extends EventObject>(rootNode: StateNode<TC, any, TE, any>, configuration: Configuration<TC, TE>): StateValue;
10
10
  export declare function has<T>(iterable: Iterable<T>, item: T): boolean;
package/lib/stateUtils.js CHANGED
@@ -226,7 +226,7 @@ function has(iterable, item) {
226
226
  function nextEvents(configuration) {
227
227
  return _tslib.__spreadArray([], _tslib.__read(new Set(utils.flatten(_tslib.__spreadArray([], _tslib.__read(configuration.map(function (sn) {
228
228
  return sn.ownEvents;
229
- })))))));
229
+ })), false)))), false);
230
230
  }
231
231
  function isInFinalState(configuration, stateNode) {
232
232
  if (stateNode.type === 'compound') {
package/lib/types.d.ts CHANGED
@@ -4,6 +4,7 @@ import { Interpreter, Clock } from './interpreter';
4
4
  import { IsNever, Model, Prop } from './model.types';
5
5
  declare type AnyFunction = (...args: any[]) => any;
6
6
  declare type ReturnTypeOrValue<T> = T extends AnyFunction ? ReturnType<T> : T;
7
+ export declare type Cast<A, B> = A extends B ? A : B;
7
8
  export declare type EventType = string;
8
9
  export declare type ActionType = string;
9
10
  export declare type MetaObject = Record<string, any>;
@@ -34,7 +35,7 @@ export interface ActionObject<TContext, TEvent extends EventObject> extends Base
34
35
  /**
35
36
  * The implementation for executing the action.
36
37
  */
37
- exec?: ActionFunction<TContext, TEvent>;
38
+ exec?: ActionFunction<TContext, TEvent> | undefined;
38
39
  }
39
40
  export declare type DefaultContext = Record<string, any> | undefined;
40
41
  export declare type EventData = Record<string, any> & {
@@ -81,14 +82,6 @@ export interface StateValueMap {
81
82
  * - For complex state nodes, this is an object, e.g., `{ success: "someChildState" }`.
82
83
  */
83
84
  export declare type StateValue = string | StateValueMap;
84
- declare type KeysWithStates<TStates extends Record<string, StateSchema> | undefined> = TStates extends object ? {
85
- [K in keyof TStates]-?: TStates[K] extends {
86
- states: object;
87
- } ? K : never;
88
- }[keyof TStates] : never;
89
- export declare type ExtractStateValue<TSchema extends Required<Pick<StateSchema<any>, 'states'>>> = keyof TSchema['states'] | (KeysWithStates<TSchema['states']> extends never ? never : {
90
- [K in KeysWithStates<TSchema['states']>]?: ExtractStateValue<TSchema['states'][K]>;
91
- });
92
85
  export interface HistoryValue {
93
86
  states: Record<string, HistoryValue | undefined>;
94
87
  current: StateValue | undefined;
@@ -114,7 +107,7 @@ export interface TransitionConfig<TContext, TEvent extends EventObject> {
114
107
  actions?: Actions<TContext, TEvent>;
115
108
  in?: StateValue;
116
109
  internal?: boolean;
117
- target?: TransitionTarget<TContext, TEvent>;
110
+ target?: TransitionTarget<TContext, TEvent> | undefined;
118
111
  meta?: Record<string, any>;
119
112
  description?: string;
120
113
  }
@@ -353,7 +346,7 @@ export interface StateNodeConfig<TContext, TStateSchema extends StateSchema, TEv
353
346
  *
354
347
  * This is equivalent to defining a `[done(id)]` transition on this state node's `on` property.
355
348
  */
356
- onDone?: string | SingleOrArray<TransitionConfig<TContext, DoneEventObject>>;
349
+ onDone?: string | SingleOrArray<TransitionConfig<TContext, DoneEventObject>> | undefined;
357
350
  /**
358
351
  * The mapping (or array) of delays (in milliseconds) to their potential transition(s).
359
352
  * The delayed transitions are taken after the specified delay in an interpreter.
@@ -923,18 +916,21 @@ export interface Observer<T> {
923
916
  export interface Subscription {
924
917
  unsubscribe(): void;
925
918
  }
919
+ export interface InteropObservable<T> {
920
+ [Symbol.observable]: () => Subscribable<T>;
921
+ }
926
922
  export interface Subscribable<T> {
927
923
  subscribe(next: (value: T) => void, error?: (error: any) => void, complete?: () => void): Subscription;
928
924
  subscribe(observer: Observer<T>): Subscription;
929
925
  }
930
- export declare type Spawnable = StateMachine<any, any, any> | PromiseLike<any> | InvokeCallback | Subscribable<any> | Behavior<any>;
926
+ export declare type Spawnable = StateMachine<any, any, any> | PromiseLike<any> | InvokeCallback | InteropObservable<any> | Subscribable<any> | Behavior<any>;
931
927
  export declare type ExtractEvent<TEvent extends EventObject, TEventType extends TEvent['type']> = TEvent extends {
932
928
  type: TEventType;
933
929
  } ? TEvent : never;
934
930
  export interface BaseActorRef<TEvent extends EventObject> {
935
931
  send: (event: TEvent) => void;
936
932
  }
937
- export interface ActorRef<TEvent extends EventObject, TEmitted = any> extends Subscribable<TEmitted> {
933
+ export interface ActorRef<TEvent extends EventObject, TEmitted = any> extends Subscribable<TEmitted>, InteropObservable<TEmitted> {
938
934
  send: Sender<TEvent>;
939
935
  id: string;
940
936
  getSnapshot: () => TEmitted | undefined;
@@ -966,7 +962,7 @@ export interface Behavior<TEvent extends EventObject, TEmitted = any> {
966
962
  start?: (actorCtx: ActorContext<TEvent, TEmitted>) => TEmitted;
967
963
  }
968
964
  export declare type EmittedFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends ActorRef<infer _, infer TEmitted> ? TEmitted : R extends Behavior<infer _, infer TEmitted> ? TEmitted : R extends ActorContext<infer _, infer TEmitted> ? TEmitted : never : never;
969
- declare type ResolveEventType<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer _, infer __, infer TEvent, infer ____> ? TEvent : R extends Model<infer _, infer TEvent, infer ___, infer ____> ? TEvent : R extends State<infer _, infer TEvent, infer ___, infer ____> ? TEvent : R extends Interpreter<infer _, infer __, infer TEvent, infer ____> ? TEvent : never : never;
965
+ declare type ResolveEventType<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer _, infer __, infer TEvent, infer ____> ? TEvent : R extends Model<infer _, infer TEvent, infer ___, infer ____> ? TEvent : R extends State<infer _, infer TEvent, infer ___, infer ____> ? TEvent : R extends Interpreter<infer _, infer __, infer TEvent, infer ____> ? TEvent : R extends ActorRef<infer TEvent, infer _> ? TEvent : never : never;
970
966
  export declare type EventFrom<T, K extends Prop<TEvent, 'type'> = never, TEvent = ResolveEventType<T>> = IsNever<K> extends true ? TEvent : Extract<TEvent, {
971
967
  type: K;
972
968
  }>;
package/lib/utils.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import { Event, StateValue, ActionType, Action, EventObject, PropertyMapper, Mapper, EventType, HistoryValue, AssignAction, Condition, Subscribable, StateMachine, ConditionPredicate, SCXML, StateLike, EventData, TransitionConfig, TransitionConfigTarget, NullEvent, SingleOrArray, Guard, InvokeSourceDefinition, Observer, Behavior } from './types';
2
3
  import { StateNode } from './StateNode';
3
4
  import { State } from './State';
@@ -52,7 +53,11 @@ export declare function isFunction(value: any): value is Function;
52
53
  export declare function isString(value: any): value is string;
53
54
  export declare function toGuard<TContext, TEvent extends EventObject>(condition?: Condition<TContext, TEvent>, guardMap?: Record<string, ConditionPredicate<TContext, TEvent>>): Guard<TContext, TEvent> | undefined;
54
55
  export declare function isObservable<T>(value: any): value is Subscribable<T>;
55
- export declare const symbolObservable: any;
56
+ export declare const symbolObservable: string | typeof Symbol.observable;
57
+ export declare const interopSymbols: {
58
+ [x: string]: () => any;
59
+ [Symbol.observable]: () => any;
60
+ };
56
61
  export declare function isMachine(value: any): value is StateMachine<any, any, any>;
57
62
  export declare function isActor(value: any): value is Actor;
58
63
  export declare const uniqueId: () => string;
@@ -66,4 +71,5 @@ export declare function reportUnhandledExceptionOnInvocation(originalError: any,
66
71
  export declare function evaluateGuard<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any>, guard: Guard<TContext, TEvent>, context: TContext, _event: SCXML.Event<TEvent>, state: State<TContext, TEvent>): boolean;
67
72
  export declare function toInvokeSource(src: string | InvokeSourceDefinition): InvokeSourceDefinition;
68
73
  export declare function toObserver<T>(nextHandler: Observer<T> | ((value: T) => void), errorHandler?: (error: any) => void, completionHandler?: () => void): Observer<T>;
74
+ export declare function createInvokeId(stateNodeId: string, index: number): string;
69
75
  //# sourceMappingURL=utils.d.ts.map