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
package/es/interpreter.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { __values, __assign, __spreadArray, __read } from './_virtual/_tslib.js';
2
2
  import { IS_PRODUCTION } from './environment.js';
3
- import { warn, mapContext, isFunction, keys, toSCXMLEvent, toInvokeSource, isMachine, isPromiseLike, isObservable, isBehavior, reportUnhandledExceptionOnInvocation, symbolObservable, isArray, toEventObject, isString, isActor, uniqueId, toObserver } from './utils.js';
3
+ import { warn, mapContext, isFunction, keys, toSCXMLEvent, toInvokeSource, isMachine, isPromiseLike, isObservable, isBehavior, reportUnhandledExceptionOnInvocation, interopSymbols, symbolObservable, isArray, toEventObject, isString, isActor, toObserver, uniqueId } from './utils.js';
4
4
  import { ActionTypes, SpecialTargets } from './types.js';
5
5
  import { isInFinalState } from './stateUtils.js';
6
6
  import { errorPlatform, log, stop, start, cancel, send, update, error as error$1 } from './actionTypes.js';
@@ -87,14 +87,15 @@ function () {
87
87
  if (_this.status === InterpreterStatus.Stopped) {
88
88
  // do nothing
89
89
  if (!IS_PRODUCTION) {
90
- 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));
90
+ 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)));
91
91
  }
92
92
 
93
93
  return _this.state;
94
94
  }
95
95
 
96
96
  if (_this.status !== InterpreterStatus.Running && !_this.options.deferEvents) {
97
- 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));
97
+ throw new Error("Event \"".concat(_event.name, "\" was sent to uninitialized service \"").concat(_this.machine.id // tslint:disable-next-line:max-line-length
98
+ , "\". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: ").concat(JSON.stringify(_event.data)));
98
99
  }
99
100
 
100
101
  _this.scheduler.schedule(function () {
@@ -116,12 +117,12 @@ function () {
116
117
 
117
118
  if (!target) {
118
119
  if (!isParent) {
119
- throw new Error("Unable to send event to child '" + to + "' from service '" + _this.id + "'.");
120
+ throw new Error("Unable to send event to child '".concat(to, "' from service '").concat(_this.id, "'."));
120
121
  } // tslint:disable-next-line:no-console
121
122
 
122
123
 
123
124
  if (!IS_PRODUCTION) {
124
- warn(false, "Service '" + _this.id + "' has no parent: unable to send event " + event.type);
125
+ warn(false, "Service '".concat(_this.id, "' has no parent: unable to send event ").concat(event.type));
125
126
  }
126
127
 
127
128
  return;
@@ -130,7 +131,7 @@ function () {
130
131
  if ('machine' in target) {
131
132
  // Send SCXML events to machines
132
133
  target.send(__assign(__assign({}, event), {
133
- name: event.name === error$1 ? "" + error(_this.id) : event.name,
134
+ name: event.name === error$1 ? "".concat(error(_this.id)) : event.name,
134
135
  origin: _this.sessionId
135
136
  }));
136
137
  } else {
@@ -176,7 +177,7 @@ function () {
176
177
  Object.defineProperty(Interpreter.prototype, "state", {
177
178
  get: function () {
178
179
  if (!IS_PRODUCTION) {
179
- warn(this.status !== InterpreterStatus.NotStarted, "Attempted to read state from uninitialized service '" + this.id + "'. Make sure the service is started first.");
180
+ warn(this.status !== InterpreterStatus.NotStarted, "Attempted to read state from uninitialized service '".concat(this.id, "'. Make sure the service is started first."));
180
181
  }
181
182
 
182
183
  return this._state;
@@ -616,11 +617,11 @@ function () {
616
617
  if (this.status === InterpreterStatus.NotStarted && this.options.deferEvents) {
617
618
  // tslint:disable-next-line:no-console
618
619
  if (!IS_PRODUCTION) {
619
- 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));
620
+ 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)));
620
621
  }
621
622
  } else if (this.status !== InterpreterStatus.Running) {
622
623
  throw new Error( // tslint:disable-next-line:max-line-length
623
- 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.");
624
+ "".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."));
624
625
  }
625
626
 
626
627
  this.scheduler.schedule(function () {
@@ -640,7 +641,7 @@ function () {
640
641
  });
641
642
  batchedActions.push.apply(batchedActions, __spreadArray([], __read(nextState.actions.map(function (a) {
642
643
  return bindActionToState(a, nextState);
643
- }))));
644
+ })), false));
644
645
  batchChanged = batchChanged || !!nextState.changed;
645
646
  };
646
647
 
@@ -713,7 +714,7 @@ function () {
713
714
  var child = this.children.get(id);
714
715
 
715
716
  if (!child) {
716
- throw new Error("Unable to forward event '" + event + "' from interpreter '" + this.id + "' to nonexistant child '" + id + "'.");
717
+ throw new Error("Unable to forward event '".concat(event, "' from interpreter '").concat(this.id, "' to nonexistant child '").concat(id, "'."));
717
718
  }
718
719
 
719
720
  child.send(event);
@@ -800,6 +801,10 @@ function () {
800
801
 
801
802
  case start:
802
803
  {
804
+ if (this.status !== InterpreterStatus.Running) {
805
+ return;
806
+ }
807
+
803
808
  var activity = action.activity; // If the activity will be stopped right after it's started
804
809
  // (such as in transient states)
805
810
  // don't bother starting the activity.
@@ -817,7 +822,7 @@ function () {
817
822
 
818
823
  if (!IS_PRODUCTION) {
819
824
  warn(!('forward' in activity), // tslint:disable-next-line:max-line-length
820
- "`forward` property is deprecated (found in invocation of '" + activity.src + "' in in machine '" + this.machine.id + "'). " + "Please use `autoForward` instead.");
825
+ "`forward` property is deprecated (found in invocation of '".concat(activity.src, "' in in machine '").concat(this.machine.id, "'). ") + "Please use `autoForward` instead.");
821
826
  }
822
827
 
823
828
  var autoForward = 'autoForward' in activity ? activity.autoForward : !!activity.forward;
@@ -825,7 +830,7 @@ function () {
825
830
  if (!serviceCreator) {
826
831
  // tslint:disable-next-line:no-console
827
832
  if (!IS_PRODUCTION) {
828
- warn(false, "No service found for invocation '" + activity.src + "' in machine '" + this.machine.id + "'.");
833
+ warn(false, "No service found for invocation '".concat(activity.src, "' in machine '").concat(this.machine.id, "'."));
829
834
  }
830
835
 
831
836
  return;
@@ -886,7 +891,7 @@ function () {
886
891
 
887
892
  default:
888
893
  if (!IS_PRODUCTION) {
889
- warn(false, "No implementation found for action type '" + action.type + "'");
894
+ warn(false, "No implementation found for action type '".concat(action.type, "'"));
890
895
  }
891
896
 
892
897
  break;
@@ -935,7 +940,7 @@ function () {
935
940
  } else if (isBehavior(entity)) {
936
941
  return this.spawnBehavior(entity, name);
937
942
  } else {
938
- throw new Error("Unable to spawn entity \"" + name + "\" of type \"" + typeof entity + "\".");
943
+ throw new Error("Unable to spawn entity \"".concat(name, "\" of type \"").concat(typeof entity, "\"."));
939
944
  }
940
945
  };
941
946
 
@@ -1031,7 +1036,8 @@ function () {
1031
1036
  }
1032
1037
  }
1033
1038
  });
1034
- var actor = {
1039
+
1040
+ var actor = __assign({
1035
1041
  id: id,
1036
1042
  send: function () {
1037
1043
  return void 0;
@@ -1075,7 +1081,8 @@ function () {
1075
1081
  getSnapshot: function () {
1076
1082
  return resolvedData;
1077
1083
  }
1078
- };
1084
+ }, interopSymbols);
1085
+
1079
1086
  this.children.set(id, actor);
1080
1087
  return actor;
1081
1088
  };
@@ -1119,7 +1126,7 @@ function () {
1119
1126
  return this.spawnPromise(callbackStop, id);
1120
1127
  }
1121
1128
 
1122
- var actor = {
1129
+ var actor = __assign({
1123
1130
  id: id,
1124
1131
  send: function (event) {
1125
1132
  return receivers.forEach(function (receiver) {
@@ -1149,7 +1156,8 @@ function () {
1149
1156
  getSnapshot: function () {
1150
1157
  return emitted;
1151
1158
  }
1152
- };
1159
+ }, interopSymbols);
1160
+
1153
1161
  this.children.set(id, actor);
1154
1162
  return actor;
1155
1163
  };
@@ -1177,7 +1185,8 @@ function () {
1177
1185
  origin: id
1178
1186
  }));
1179
1187
  });
1180
- var actor = {
1188
+
1189
+ var actor = __assign({
1181
1190
  id: id,
1182
1191
  send: function () {
1183
1192
  return void 0;
@@ -1196,7 +1205,8 @@ function () {
1196
1205
  id: id
1197
1206
  };
1198
1207
  }
1199
- };
1208
+ }, interopSymbols);
1209
+
1200
1210
  this.children.set(id, actor);
1201
1211
  return actor;
1202
1212
  };
@@ -1211,7 +1221,7 @@ function () {
1211
1221
 
1212
1222
  if (!implementation) {
1213
1223
  if (!IS_PRODUCTION) {
1214
- warn(false, "No implementation found for activity '" + activity.type + "'");
1224
+ warn(false, "No implementation found for activity '".concat(activity.type, "'"));
1215
1225
  } // tslint:disable-next-line:no-console
1216
1226
 
1217
1227
 
@@ -1224,7 +1234,7 @@ function () {
1224
1234
  };
1225
1235
 
1226
1236
  Interpreter.prototype.spawnEffect = function (id, dispose) {
1227
- this.children.set(id, {
1237
+ this.children.set(id, __assign({
1228
1238
  id: id,
1229
1239
  send: function () {
1230
1240
  return void 0;
@@ -1245,7 +1255,7 @@ function () {
1245
1255
  id: id
1246
1256
  };
1247
1257
  }
1248
- });
1258
+ }, interopSymbols));
1249
1259
  };
1250
1260
 
1251
1261
  Interpreter.prototype.attachDev = function () {
@@ -1343,7 +1353,7 @@ function spawn(entity, nameOrOptions) {
1343
1353
  return consume(function (service) {
1344
1354
  if (!IS_PRODUCTION) {
1345
1355
  var isLazyEntity = isMachine(entity) || isFunction(entity);
1346
- warn(!!service || isLazyEntity, "Attempted to spawn an Actor (ID: \"" + (isMachine(entity) ? entity.id : 'undefined') + "\") outside of a service. This will have no effect.");
1356
+ warn(!!service || isLazyEntity, "Attempted to spawn an Actor (ID: \"".concat(isMachine(entity) ? entity.id : 'undefined', "\") outside of a service. This will have no effect."));
1347
1357
  }
1348
1358
 
1349
1359
  if (service) {
package/es/registry.js CHANGED
@@ -2,7 +2,7 @@ var children = /*#__PURE__*/new Map();
2
2
  var sessionIdIndex = 0;
3
3
  var registry = {
4
4
  bookId: function () {
5
- return "x:" + sessionIdIndex++;
5
+ return "x:".concat(sessionIdIndex++);
6
6
  },
7
7
  register: function (id, actor) {
8
8
  children.set(id, actor);
@@ -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/es/stateUtils.js CHANGED
@@ -222,7 +222,7 @@ function has(iterable, item) {
222
222
  function nextEvents(configuration) {
223
223
  return __spreadArray([], __read(new Set(flatten(__spreadArray([], __read(configuration.map(function (sn) {
224
224
  return sn.ownEvents;
225
- })))))));
225
+ })), false)))), false);
226
226
  }
227
227
  function isInFinalState(configuration, stateNode) {
228
228
  if (stateNode.type === 'compound') {
package/es/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/es/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
package/es/utils.js CHANGED
@@ -2,6 +2,7 @@ import { __spreadArray, __read, __values, __assign } from './_virtual/_tslib.js'
2
2
  import { DEFAULT_GUARD_TYPE, TARGETLESS_KEY, STATE_DELIMITER } from './constants.js';
3
3
  import { IS_PRODUCTION } from './environment.js';
4
4
 
5
+ var _a;
5
6
  function keys(value) {
6
7
  return Object.keys(value);
7
8
  }
@@ -36,7 +37,7 @@ function matchesState(parentStateId, childStateId, delimiter) {
36
37
  }
37
38
  function getEventType(event) {
38
39
  try {
39
- return isString(event) || typeof event === 'number' ? "" + event : event.type;
40
+ return isString(event) || typeof event === 'number' ? "".concat(event) : event.type;
40
41
  } catch (e) {
41
42
  throw new Error('Events must be strings or objects with a string event.type property.');
42
43
  }
@@ -49,7 +50,7 @@ function toStatePath(stateId, delimiter) {
49
50
 
50
51
  return stateId.toString().split(delimiter);
51
52
  } catch (e) {
52
- throw new Error("'" + stateId + "' is not a valid state path.");
53
+ throw new Error("'".concat(stateId, "' is not a valid state path."));
53
54
  }
54
55
  }
55
56
  function isStateLike(state) {
@@ -218,7 +219,7 @@ function toStatePaths(stateValue) {
218
219
  function flatten(array) {
219
220
  var _a;
220
221
 
221
- return (_a = []).concat.apply(_a, __spreadArray([], __read(array)));
222
+ return (_a = []).concat.apply(_a, __spreadArray([], __read(array), false));
222
223
  }
223
224
  function toArrayStrict(value) {
224
225
  if (isArray(value)) {
@@ -395,7 +396,7 @@ if (!IS_PRODUCTION) {
395
396
  }
396
397
 
397
398
  if (console !== undefined) {
398
- var args = ["Warning: " + message];
399
+ var args = ["Warning: ".concat(message)];
399
400
 
400
401
  if (error) {
401
402
  args.push(error);
@@ -460,6 +461,9 @@ function isObservable(value) {
460
461
  var symbolObservable = /*#__PURE__*/function () {
461
462
  return typeof Symbol === 'function' && Symbol.observable || '@@observable';
462
463
  }();
464
+ var interopSymbols = (_a = {}, _a[symbolObservable] = function () {
465
+ return this;
466
+ }, _a);
463
467
  function isMachine(value) {
464
468
  try {
465
469
  return '__xstatenode' in value;
@@ -524,15 +528,15 @@ function normalizeTarget(target) {
524
528
  }
525
529
  function reportUnhandledExceptionOnInvocation(originalError, currentError, id) {
526
530
  if (!IS_PRODUCTION) {
527
- var originalStackTrace = originalError.stack ? " Stacktrace was '" + originalError.stack + "'" : '';
531
+ var originalStackTrace = originalError.stack ? " Stacktrace was '".concat(originalError.stack, "'") : '';
528
532
 
529
533
  if (originalError === currentError) {
530
534
  // tslint:disable-next-line:no-console
531
- console.error("Missing onError handler for invocation '" + id + "', error was '" + originalError + "'." + originalStackTrace);
535
+ console.error("Missing onError handler for invocation '".concat(id, "', error was '").concat(originalError, "'.").concat(originalStackTrace));
532
536
  } else {
533
- var stackTrace = currentError.stack ? " Stacktrace was '" + currentError.stack + "'" : ''; // tslint:disable-next-line:no-console
537
+ var stackTrace = currentError.stack ? " Stacktrace was '".concat(currentError.stack, "'") : ''; // tslint:disable-next-line:no-console
534
538
 
535
- console.error("Missing onError handler and/or unhandled exception/promise rejection for invocation '" + id + "'. " + ("Original error: '" + originalError + "'. " + originalStackTrace + " Current error is '" + currentError + "'." + stackTrace));
539
+ console.error("Missing onError handler and/or unhandled exception/promise rejection for invocation '".concat(id, "'. ") + "Original error: '".concat(originalError, "'. ").concat(originalStackTrace, " Current error is '").concat(currentError, "'.").concat(stackTrace));
536
540
  }
537
541
  }
538
542
  }
@@ -551,7 +555,7 @@ function evaluateGuard(machine, guard, context, _event, state) {
551
555
  var condFn = guards[guard.type];
552
556
 
553
557
  if (!condFn) {
554
- throw new Error("Guard '" + guard.type + "' is not implemented on machine '" + machine.id + "'.");
558
+ throw new Error("Guard '".concat(guard.type, "' is not implemented on machine '").concat(machine.id, "'."));
555
559
  }
556
560
 
557
561
  return condFn(context, _event.data, guardMeta);
@@ -580,5 +584,8 @@ function toObserver(nextHandler, errorHandler, completionHandler) {
580
584
  complete: completionHandler || noop
581
585
  };
582
586
  }
587
+ function createInvokeId(stateNodeId, index) {
588
+ return "".concat(stateNodeId, ":invocation[").concat(index, "]");
589
+ }
583
590
 
584
- export { evaluateGuard, flatten, getEventType, isActor, isArray, isBehavior, isBuiltInEvent, isFunction, isMachine, isObservable, isPromiseLike, isStateLike, isString, keys, mapContext, mapFilterValues, mapValues, matchesState, nestedPath, normalizeTarget, partition, path, pathToStateValue, reportUnhandledExceptionOnInvocation, symbolObservable, toArray, toArrayStrict, toEventObject, toGuard, toInvokeSource, toObserver, toSCXMLEvent, toStatePath, toStatePaths, toStateValue, toTransitionConfigArray, uniqueId, updateContext, updateHistoryStates, updateHistoryValue, warn };
591
+ export { createInvokeId, evaluateGuard, flatten, getEventType, interopSymbols, isActor, isArray, isBehavior, isBuiltInEvent, isFunction, isMachine, isObservable, isPromiseLike, isStateLike, isString, keys, mapContext, mapFilterValues, mapValues, matchesState, nestedPath, normalizeTarget, partition, path, pathToStateValue, reportUnhandledExceptionOnInvocation, symbolObservable, toArray, toArrayStrict, toEventObject, toGuard, toInvokeSource, toObserver, toSCXMLEvent, toStatePath, toStatePaths, toStateValue, toTransitionConfigArray, uniqueId, updateContext, updateHistoryStates, updateHistoryValue, warn };
package/lib/Actor.js CHANGED
@@ -7,7 +7,7 @@ var utils = require('./utils.js');
7
7
  var serviceScope = require('./serviceScope.js');
8
8
 
9
9
  function createNullActor(id) {
10
- return {
10
+ return _tslib.__assign({
11
11
  id: id,
12
12
  send: function () {
13
13
  return void 0;
@@ -27,7 +27,7 @@ function createNullActor(id) {
27
27
  id: id
28
28
  };
29
29
  }
30
- };
30
+ }, utils.interopSymbols);
31
31
  }
32
32
  /**
33
33
  * Creates a deferred actor that is able to be invoked given the provided
@@ -76,7 +76,7 @@ function isSpawnedActor(item) {
76
76
  return isActor(item) && 'id' in item;
77
77
  }
78
78
  function toActorRef(actorRefLike) {
79
- return _tslib.__assign({
79
+ return _tslib.__assign(_tslib.__assign({
80
80
  subscribe: function () {
81
81
  return {
82
82
  unsubscribe: function () {
@@ -88,7 +88,7 @@ function toActorRef(actorRefLike) {
88
88
  getSnapshot: function () {
89
89
  return undefined;
90
90
  }
91
- }, actorRefLike);
91
+ }, utils.interopSymbols), actorRefLike);
92
92
  }
93
93
 
94
94
  exports.createDeferredActor = createDeferredActor;
@@ -15,10 +15,14 @@ var __read = (this && this.__read) || function (o, n) {
15
15
  }
16
16
  return ar;
17
17
  };
18
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
19
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
20
- to[j] = from[i];
21
- return to;
18
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20
+ if (ar || !(i in from)) {
21
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
+ ar[i] = from[i];
23
+ }
24
+ }
25
+ return to.concat(ar || Array.prototype.slice.call(from));
22
26
  };
23
27
  Object.defineProperty(exports, "__esModule", { value: true });
24
28
  exports.SimulatedClock = void 0;
@@ -55,7 +59,7 @@ var SimulatedClock = /** @class */ (function () {
55
59
  };
56
60
  SimulatedClock.prototype.flushTimeouts = function () {
57
61
  var _this = this;
58
- __spreadArray([], __read(this.timeouts)).sort(function (_a, _b) {
62
+ __spreadArray([], __read(this.timeouts), false).sort(function (_a, _b) {
59
63
  var _c = __read(_a, 2), _idA = _c[0], timeoutA = _c[1];
60
64
  var _d = __read(_b, 2), _idB = _d[0], timeoutB = _d[1];
61
65
  var endA = timeoutA.start + timeoutA.timeout;
package/lib/State.d.ts CHANGED
@@ -88,7 +88,7 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
88
88
  * @param delimiter The character(s) that separate each subpath in the string state node path.
89
89
  */
90
90
  toStrings(stateValue?: StateValue, delimiter?: string): string[];
91
- toJSON(): Omit<this, "configuration" | "transitions" | "tags" | "machine"> & {
91
+ toJSON(): Omit<this, "machine" | "tags" | "transitions" | "configuration"> & {
92
92
  tags: string[];
93
93
  };
94
94
  /**
@@ -107,7 +107,10 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
107
107
  */
108
108
  hasTag(tag: string): boolean;
109
109
  /**
110
- * Determines whether sending the `event` will cause a transition.
110
+ * Determines whether sending the `event` will cause a non-forbidden transition
111
+ * to be selected, even if the transitions have no actions nor
112
+ * change the state value.
113
+ *
111
114
  * @param event The event to test
112
115
  * @returns Whether the event will cause a transition
113
116
  */
package/lib/State.js CHANGED
@@ -215,7 +215,7 @@ function () {
215
215
  return _this.toStrings(stateValue[key], delimiter).map(function (s) {
216
216
  return key + delimiter + s;
217
217
  });
218
- }))));
218
+ })), false));
219
219
  };
220
220
 
221
221
  State.prototype.toJSON = function () {
@@ -249,7 +249,10 @@ function () {
249
249
  return this.tags.has(tag);
250
250
  };
251
251
  /**
252
- * Determines whether sending the `event` will cause a transition.
252
+ * Determines whether sending the `event` will cause a non-forbidden transition
253
+ * to be selected, even if the transitions have no actions nor
254
+ * change the state value.
255
+ *
253
256
  * @param event The event to test
254
257
  * @returns Whether the event will cause a transition
255
258
  */
@@ -262,7 +265,11 @@ function () {
262
265
  utils.warn(!!this.machine, "state.can(...) used outside of a machine-created State object; this will always return false.");
263
266
  }
264
267
 
265
- return !!((_a = this.machine) === null || _a === void 0 ? void 0 : _a.transition(this, event).changed);
268
+ var transitionData = (_a = this.machine) === null || _a === void 0 ? void 0 : _a.getTransitionData(this, event);
269
+ return !!(transitionData === null || transitionData === void 0 ? void 0 : transitionData.transitions.length) && // Check that at least one transition is not forbidden
270
+ transitionData.transitions.some(function (t) {
271
+ return t.target !== undefined || t.actions.length;
272
+ });
266
273
  };
267
274
 
268
275
  return State;
@@ -1,4 +1,4 @@
1
- import { Event, StateValue, MachineOptions, EventObject, HistoryValue, StateNodeDefinition, TransitionDefinition, DelayedTransitionDefinition, ActivityDefinition, StateNodeConfig, StateSchema, StateNodesConfig, InvokeDefinition, ActionObject, Mapper, PropertyMapper, SCXML, Typestate, TransitionDefinitionMap, MachineSchema } from './types';
1
+ import { Event, StateValue, StateTransition, MachineOptions, EventObject, HistoryValue, StateNodeDefinition, TransitionDefinition, DelayedTransitionDefinition, ActivityDefinition, StateNodeConfig, StateSchema, StateNodesConfig, InvokeDefinition, ActionObject, Mapper, PropertyMapper, SCXML, Typestate, TransitionDefinitionMap, MachineSchema } from './types';
2
2
  import { State } from './State';
3
3
  declare class StateNode<TContext = any, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
4
4
  value: any;
@@ -182,6 +182,7 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
182
182
  private transitionCompoundNode;
183
183
  private transitionParallelNode;
184
184
  private _transition;
185
+ getTransitionData(state: State<TContext, TEvent, any, any>, event: Event<TEvent> | SCXML.Event<TEvent>): StateTransition<TContext, TEvent> | undefined;
185
186
  private next;
186
187
  private nodesFromChild;
187
188
  /**