xstate 4.18.0 → 4.20.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.
package/es/interpreter.js CHANGED
@@ -1,4 +1,4 @@
1
- import { __values, __assign, __spread } from './_virtual/_tslib.js';
1
+ import { __values, __assign, __spreadArray, __read } from './_virtual/_tslib.js';
2
2
  import { IS_PRODUCTION } from './environment.js';
3
3
  import { warn, mapContext, isFunction, keys, toSCXMLEvent, toInvokeSource, isPromiseLike, isObservable, isMachine, reportUnhandledExceptionOnInvocation, symbolObservable, isArray, toEventObject, isString, isActor, uniqueId, toObserver } from './utils.js';
4
4
  import { ActionTypes, SpecialTargets } from './types.js';
@@ -636,9 +636,9 @@ function () {
636
636
  nextState = provide(_this, function () {
637
637
  return _this.machine.transition(nextState, _event);
638
638
  });
639
- batchedActions.push.apply(batchedActions, __spread(nextState.actions.map(function (a) {
639
+ batchedActions.push.apply(batchedActions, __spreadArray([], __read(nextState.actions.map(function (a) {
640
640
  return bindActionToState(a, nextState);
641
- })));
641
+ }))));
642
642
  batchChanged = batchChanged || !!nextState.changed;
643
643
  };
644
644
 
@@ -966,8 +966,11 @@ function () {
966
966
  var _this = this;
967
967
 
968
968
  var canceled = false;
969
+ var resolvedData = undefined;
969
970
  promise.then(function (response) {
970
971
  if (!canceled) {
972
+ resolvedData = response;
973
+
971
974
  _this.removeChild(id);
972
975
 
973
976
  _this.send(toSCXMLEvent(doneInvoke(id, response), {
@@ -1042,6 +1045,9 @@ function () {
1042
1045
  return {
1043
1046
  id: id
1044
1047
  };
1048
+ },
1049
+ getSnapshot: function () {
1050
+ return resolvedData;
1045
1051
  }
1046
1052
  };
1047
1053
  this.children.set(id, actor);
@@ -1054,8 +1060,10 @@ function () {
1054
1060
  var canceled = false;
1055
1061
  var receivers = new Set();
1056
1062
  var listeners = new Set();
1063
+ var emitted = undefined;
1057
1064
 
1058
1065
  var receive = function (e) {
1066
+ emitted = e;
1059
1067
  listeners.forEach(function (listener) {
1060
1068
  return listener(e);
1061
1069
  });
@@ -1111,6 +1119,9 @@ function () {
1111
1119
  return {
1112
1120
  id: id
1113
1121
  };
1122
+ },
1123
+ getSnapshot: function () {
1124
+ return emitted;
1114
1125
  }
1115
1126
  };
1116
1127
  this.children.set(id, actor);
@@ -1120,7 +1131,10 @@ function () {
1120
1131
  Interpreter.prototype.spawnObservable = function (source, id) {
1121
1132
  var _this = this;
1122
1133
 
1134
+ var emitted = undefined;
1123
1135
  var subscription = source.subscribe(function (value) {
1136
+ emitted = value;
1137
+
1124
1138
  _this.send(toSCXMLEvent(value, {
1125
1139
  origin: id
1126
1140
  }));
@@ -1148,6 +1162,9 @@ function () {
1148
1162
  stop: function () {
1149
1163
  return subscription.unsubscribe();
1150
1164
  },
1165
+ getSnapshot: function () {
1166
+ return emitted;
1167
+ },
1151
1168
  toJSON: function () {
1152
1169
  return {
1153
1170
  id: id
@@ -1194,6 +1211,9 @@ function () {
1194
1211
  };
1195
1212
  },
1196
1213
  stop: dispose || undefined,
1214
+ getSnapshot: function () {
1215
+ return undefined;
1216
+ },
1197
1217
  toJSON: function () {
1198
1218
  return {
1199
1219
  id: id
@@ -1241,6 +1261,10 @@ function () {
1241
1261
  Interpreter.prototype[symbolObservable] = function () {
1242
1262
  return this;
1243
1263
  };
1264
+
1265
+ Interpreter.prototype.getSnapshot = function () {
1266
+ return this._state;
1267
+ };
1244
1268
  /**
1245
1269
  * The default interpreter options:
1246
1270
  *
package/es/stateUtils.js CHANGED
@@ -1,4 +1,4 @@
1
- import { __values, __spread } from './_virtual/_tslib.js';
1
+ import { __values, __spreadArray, __read } from './_virtual/_tslib.js';
2
2
  import { keys, flatten } from './utils.js';
3
3
 
4
4
  var isLeafNode = function (stateNode) {
@@ -226,9 +226,9 @@ function has(iterable, item) {
226
226
  }
227
227
 
228
228
  function nextEvents(configuration) {
229
- return flatten(__spread(new Set(configuration.map(function (sn) {
229
+ return __spreadArray([], __read(new Set(flatten(__spreadArray([], __read(configuration.map(function (sn) {
230
230
  return sn.ownEvents;
231
- }))));
231
+ })))))));
232
232
  }
233
233
 
234
234
  function isInFinalState(configuration, stateNode) {
package/es/types.d.ts CHANGED
@@ -134,7 +134,7 @@ export interface PayloadSender<TEvent extends EventObject> {
134
134
  <K extends TEvent['type']>(eventType: K, payload: NeverIfEmpty<ExtractExtraParameters<TEvent, K>>): void;
135
135
  }
136
136
  export declare type Receiver<TEvent extends EventObject> = (listener: (event: TEvent) => void) => void;
137
- export declare type InvokeCallback = (callback: Sender<any>, onReceive: Receiver<EventObject>) => any;
137
+ export declare type InvokeCallback<TEvent extends EventObject = AnyEventObject> = (callback: Sender<TEvent>, onReceive: Receiver<TEvent>) => any;
138
138
  export interface InvokeMeta {
139
139
  data: any;
140
140
  src: InvokeSourceDefinition;
@@ -152,7 +152,7 @@ export interface InvokeMeta {
152
152
  * @param context The current machine `context`
153
153
  * @param event The event that invoked the service
154
154
  */
155
- export declare type InvokeCreator<TContext, TEvent = AnyEventObject, TFinalContext = any> = (context: TContext, event: TEvent, meta: InvokeMeta) => PromiseLike<TFinalContext> | StateMachine<TFinalContext, any, any> | Subscribable<any> | InvokeCallback;
155
+ export declare type InvokeCreator<TContext, TEvent extends EventObject = AnyEventObject, TFinalContext = any> = (context: TContext, event: TEvent, meta: InvokeMeta) => PromiseLike<TFinalContext> | StateMachine<TFinalContext, any, any> | Subscribable<EventObject> | InvokeCallback<TEvent>;
156
156
  export interface InvokeDefinition<TContext, TEvent extends EventObject> extends ActivityDefinition<TContext, TEvent> {
157
157
  /**
158
158
  * The source of the machine to be invoked, or the machine itself.
@@ -380,6 +380,10 @@ export interface StateNodeConfig<TContext, TStateSchema extends StateSchema, TEv
380
380
  * The order this state node appears. Corresponds to the implicit SCXML document order.
381
381
  */
382
382
  order?: number;
383
+ /**
384
+ * The tags for this state node, which are accumulated into the `state.tags` property.
385
+ */
386
+ tags?: SingleOrArray<string>;
383
387
  }
384
388
  export interface StateNodeDefinition<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> {
385
389
  id: string;
@@ -486,6 +490,8 @@ export interface StateMachine<TContext, TStateSchema extends StateSchema, TEvent
486
490
  }> extends StateNode<TContext, TStateSchema, TEvent, TTypestate> {
487
491
  id: string;
488
492
  states: StateNode<TContext, TStateSchema, TEvent>['states'];
493
+ withConfig(options: Partial<MachineOptions<TContext, TEvent>>, context?: TContext): StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
494
+ withContext(context: TContext): StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
489
495
  }
490
496
  export declare type StateFrom<TMachine extends StateMachine<any, any, any>> = ReturnType<TMachine['transition']>;
491
497
  export interface ActionMap<TContext, TEvent extends EventObject> {
@@ -761,6 +767,7 @@ export interface StateConfig<TContext, TEvent extends EventObject> {
761
767
  transitions: Array<TransitionDefinition<TContext, TEvent>>;
762
768
  children: Record<string, ActorRef<any>>;
763
769
  done?: boolean;
770
+ tags?: Set<string>;
764
771
  }
765
772
  export interface StateSchema<TC = any> {
766
773
  meta?: any;
@@ -880,12 +887,16 @@ export interface ActorRef<TEvent extends EventObject, TEmitted = any> extends Su
880
887
  }
881
888
  export interface SpawnedActorRef<TEvent extends EventObject, TEmitted = any> extends ActorRef<TEvent, TEmitted> {
882
889
  id: string;
890
+ getSnapshot: () => TEmitted | undefined;
883
891
  stop?: () => void;
884
892
  toJSON?: () => any;
885
893
  }
886
- export declare type ActorRefFrom<T extends StateMachine<any, any, any>> = T extends StateMachine<infer TContext, any, infer TEvent, infer TTypestate> ? SpawnedActorRef<TEvent, State<TContext, TEvent, any, TTypestate>> & {
894
+ export declare type ActorRefFrom<T extends StateMachine<any, any, any> | Promise<any>> = T extends StateMachine<infer TContext, any, infer TEvent, infer TTypestate> ? SpawnedActorRef<TEvent, State<TContext, TEvent, any, TTypestate>> & {
895
+ /**
896
+ * @deprecated
897
+ */
887
898
  state: State<TContext, TEvent, any, TTypestate>;
888
- } : never;
899
+ } : T extends Promise<infer U> ? SpawnedActorRef<never, U> : never;
889
900
  export declare type AnyInterpreter = Interpreter<any, any, any, any>;
890
901
  export declare type InterpreterFrom<T extends StateMachine<any, any, any, any>> = T extends StateMachine<infer TContext, infer TStateSchema, infer TEvent, infer TTypestate> ? Interpreter<TContext, TStateSchema, TEvent, TTypestate> : never;
891
902
  export {};
package/es/utils.js CHANGED
@@ -1,4 +1,4 @@
1
- import { __spread, __values, __read, __assign } from './_virtual/_tslib.js';
1
+ 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
 
@@ -230,7 +230,7 @@ function toStatePaths(stateValue) {
230
230
  function flatten(array) {
231
231
  var _a;
232
232
 
233
- return (_a = []).concat.apply(_a, __spread(array));
233
+ return (_a = []).concat.apply(_a, __spreadArray([], __read(array)));
234
234
  }
235
235
 
236
236
  function toArrayStrict(value) {
package/lib/Actor.d.ts CHANGED
@@ -11,15 +11,15 @@ export interface Actor<TContext = any, TEvent extends EventObject = AnyEventObje
11
11
  state?: any;
12
12
  deferred?: boolean;
13
13
  }
14
- export declare function createNullActor(id: string): Actor;
14
+ export declare function createNullActor(id: string): SpawnedActorRef<any>;
15
15
  /**
16
16
  * Creates a deferred actor that is able to be invoked given the provided
17
17
  * invocation information in its `.meta` value.
18
18
  *
19
19
  * @param invokeDefinition The meta information needed to invoke the actor.
20
20
  */
21
- export declare function createInvocableActor<TC, TE extends EventObject>(invokeDefinition: InvokeDefinition<TC, TE>, machine: StateMachine<TC, any, TE, any>, context: TC, _event: SCXML.Event<TE>): Actor;
22
- export declare function createDeferredActor(entity: Spawnable, id: string, data?: any): Actor;
21
+ export declare function createInvocableActor<TC, TE extends EventObject>(invokeDefinition: InvokeDefinition<TC, TE>, machine: StateMachine<TC, any, TE, any>, context: TC, _event: SCXML.Event<TE>): SpawnedActorRef<any>;
22
+ export declare function createDeferredActor(entity: Spawnable, id: string, data?: any): SpawnedActorRef<any, undefined>;
23
23
  export declare function isActor(item: any): item is ActorRef<any>;
24
24
  export declare function isSpawnedActor(item: any): item is SpawnedActorRef<any>;
25
25
  //# sourceMappingURL=Actor.d.ts.map
package/lib/Actor.js CHANGED
@@ -10,6 +10,7 @@ function createNullActor(id) {
10
10
  subscribe: function () { return ({
11
11
  unsubscribe: function () { return void 0; }
12
12
  }); },
13
+ getSnapshot: function () { return undefined; },
13
14
  toJSON: function () { return ({
14
15
  id: id
15
16
  }); }
@@ -32,15 +33,18 @@ function createInvocableActor(invokeDefinition, machine, context, _event) {
32
33
  var tempActor = serviceCreator
33
34
  ? createDeferredActor(serviceCreator, invokeDefinition.id, resolvedData)
34
35
  : createNullActor(invokeDefinition.id);
36
+ // @ts-ignore
35
37
  tempActor.meta = invokeDefinition;
36
38
  return tempActor;
37
39
  }
38
40
  exports.createInvocableActor = createInvocableActor;
39
41
  function createDeferredActor(entity, id, data) {
40
42
  var tempActor = createNullActor(id);
43
+ // @ts-ignore
41
44
  tempActor.deferred = true;
42
45
  if (utils_1.isMachine(entity)) {
43
46
  // "mute" the existing service scope so potential spawned actors within the `.initialState` stay deferred here
47
+ // @ts-ignore
44
48
  tempActor.state = serviceScope.provide(undefined, function () { return (data ? entity.withContext(data) : entity).initialState; });
45
49
  }
46
50
  return tempActor;
@@ -15,9 +15,10 @@ var __read = (this && this.__read) || function (o, n) {
15
15
  }
16
16
  return ar;
17
17
  };
18
- var __spread = (this && this.__spread) || function () {
19
- for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
20
- return ar;
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;
21
22
  };
22
23
  Object.defineProperty(exports, "__esModule", { value: true });
23
24
  exports.SimulatedClock = void 0;
@@ -54,7 +55,7 @@ var SimulatedClock = /** @class */ (function () {
54
55
  };
55
56
  SimulatedClock.prototype.flushTimeouts = function () {
56
57
  var _this = this;
57
- __spread(this.timeouts).sort(function (_a, _b) {
58
+ __spreadArray([], __read(this.timeouts)).sort(function (_a, _b) {
58
59
  var _c = __read(_a, 2), _idA = _c[0], timeoutA = _c[1];
59
60
  var _d = __read(_b, 2), _idB = _d[0], timeoutB = _d[1];
60
61
  var endA = timeoutA.start + timeoutA.timeout;
package/lib/State.d.ts CHANGED
@@ -50,6 +50,7 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
50
50
  * An object mapping actor IDs to spawned actors/invoked services.
51
51
  */
52
52
  children: Record<string, ActorRef<any>>;
53
+ tags: Set<string>;
53
54
  /**
54
55
  * Creates a new State instance for the given `stateValue` and `context`.
55
56
  * @param stateValue
@@ -86,7 +87,9 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
86
87
  * @param delimiter The character(s) that separate each subpath in the string state node path.
87
88
  */
88
89
  toStrings(stateValue?: StateValue, delimiter?: string): string[];
89
- toJSON(): Pick<this, Exclude<keyof this, "configuration" | "transitions">>;
90
+ toJSON(): Omit<this, "configuration" | "transitions" | "tags"> & {
91
+ tags: string[];
92
+ };
90
93
  /**
91
94
  * Whether the current state value is a subset of the given parent state value.
92
95
  * @param parentStateValue
@@ -97,5 +100,10 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
97
100
  } extends TTypestate ? TTypestate : never : never)['context'], TEvent, TStateSchema, TTypestate> & {
98
101
  value: TSV;
99
102
  };
103
+ /**
104
+ * Whether the current state configuration has a state node with the specified `tag`.
105
+ * @param tag
106
+ */
107
+ hasTag(tag: string): boolean;
100
108
  }
101
109
  //# sourceMappingURL=State.d.ts.map
package/lib/State.js CHANGED
@@ -37,9 +37,10 @@ var __read = (this && this.__read) || function (o, n) {
37
37
  }
38
38
  return ar;
39
39
  };
40
- var __spread = (this && this.__spread) || function () {
41
- for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
42
- return ar;
40
+ var __spreadArray = (this && this.__spreadArray) || function (to, from) {
41
+ for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
42
+ to[j] = from[i];
43
+ return to;
43
44
  };
44
45
  Object.defineProperty(exports, "__esModule", { value: true });
45
46
  exports.State = exports.bindActionToState = exports.isState = exports.stateValuesEqual = void 0;
@@ -99,6 +100,7 @@ var State = /** @class */ (function () {
99
100
  */
100
101
  function State(config) {
101
102
  var _this = this;
103
+ var _a;
102
104
  this.actions = [];
103
105
  this.activities = constants_1.EMPTY_ACTIVITY_MAP;
104
106
  this.meta = {};
@@ -120,6 +122,7 @@ var State = /** @class */ (function () {
120
122
  this.transitions = config.transitions;
121
123
  this.children = config.children;
122
124
  this.done = !!config.done;
125
+ this.tags = (_a = config.tags) !== null && _a !== void 0 ? _a : new Set();
123
126
  Object.defineProperty(this, 'nextEvents', {
124
127
  get: function () {
125
128
  return stateUtils_1.nextEvents(_this.configuration);
@@ -215,13 +218,13 @@ var State = /** @class */ (function () {
215
218
  return [stateValue];
216
219
  }
217
220
  var valueKeys = utils_1.keys(stateValue);
218
- return valueKeys.concat.apply(valueKeys, __spread(valueKeys.map(function (key) {
221
+ return valueKeys.concat.apply(valueKeys, __spreadArray([], __read(valueKeys.map(function (key) {
219
222
  return _this.toStrings(stateValue[key], delimiter).map(function (s) { return key + delimiter + s; });
220
- })));
223
+ }))));
221
224
  };
222
225
  State.prototype.toJSON = function () {
223
- var _a = this, configuration = _a.configuration, transitions = _a.transitions, jsonValues = __rest(_a, ["configuration", "transitions"]);
224
- return jsonValues;
226
+ var _a = this, configuration = _a.configuration, transitions = _a.transitions, tags = _a.tags, jsonValues = __rest(_a, ["configuration", "transitions", "tags"]);
227
+ return __assign(__assign({}, jsonValues), { tags: Array.from(tags) });
225
228
  };
226
229
  /**
227
230
  * Whether the current state value is a subset of the given parent state value.
@@ -230,6 +233,13 @@ var State = /** @class */ (function () {
230
233
  State.prototype.matches = function (parentStateValue) {
231
234
  return utils_1.matchesState(parentStateValue, this.value);
232
235
  };
236
+ /**
237
+ * Whether the current state configuration has a state node with the specified `tag`.
238
+ * @param tag
239
+ */
240
+ State.prototype.hasTag = function (tag) {
241
+ return this.tags.has(tag);
242
+ };
233
243
  return State;
234
244
  }());
235
245
  exports.State = State;
@@ -1,4 +1,4 @@
1
- import { Event, StateValue, StateValueMap, MachineOptions, EventObject, HistoryValue, StateNodeDefinition, TransitionDefinition, DelayedTransitionDefinition, ActivityDefinition, StateNodeConfig, StateSchema, StateNodesConfig, InvokeDefinition, ActionObject, Mapper, PropertyMapper, SCXML, Typestate, TransitionDefinitionMap, MachineSchema } from './types';
1
+ import { Event, StateValue, 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;
@@ -113,6 +113,7 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
113
113
  __xstatenode: true;
114
114
  private __cache;
115
115
  private idMap;
116
+ tags: string[];
116
117
  constructor(
117
118
  /**
118
119
  * The raw config used to create the machine.
@@ -135,7 +136,7 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
135
136
  *
136
137
  * @param context Custom context (will override predefined context, not recursive)
137
138
  */
138
- withContext(context: TContext): StateNode<TContext, TStateSchema, TEvent>;
139
+ withContext(context: TContext): StateNode<TContext, TStateSchema, TEvent, TTypestate>;
139
140
  /**
140
141
  * The well-structured state node definition.
141
142
  */
@@ -160,7 +161,7 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
160
161
  *
161
162
  * @param state The state value or State instance
162
163
  */
163
- getStateNodes(state: StateValue | State<TContext, TEvent, any, TTypestate>): Array<StateNode<TContext, any, TEvent, any>>;
164
+ getStateNodes(state: StateValue | State<TContext, TEvent, any, TTypestate>): Array<StateNode<TContext, any, TEvent, TTypestate>>;
164
165
  /**
165
166
  * Returns `true` if this state node explicitly handles the given event.
166
167
  *
@@ -194,13 +195,13 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
194
195
  * @param event The event that was sent at the current state
195
196
  * @param context The current context (extended state) of the current state
196
197
  */
197
- transition(state: string | StateValueMap | State<TContext, TEvent, any, TTypestate> | undefined, event: Event<TEvent> | SCXML.Event<TEvent>, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate>;
198
+ transition(state: StateValue | State<TContext, TEvent, any, TTypestate> | undefined, event: Event<TEvent> | SCXML.Event<TEvent>, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate>;
198
199
  private resolveRaisedTransition;
199
200
  private resolveTransition;
200
201
  /**
201
202
  * Returns the child state node from its relative `stateKey`, or throws.
202
203
  */
203
- getStateNode(stateKey: string): StateNode<TContext, any, TEvent>;
204
+ getStateNode(stateKey: string): StateNode<TContext, any, TEvent, TTypestate>;
204
205
  /**
205
206
  * Returns the state node with the given `stateId`, or throws.
206
207
  *
package/lib/StateNode.js CHANGED
@@ -37,9 +37,10 @@ var __read = (this && this.__read) || function (o, n) {
37
37
  }
38
38
  return ar;
39
39
  };
40
- var __spread = (this && this.__spread) || function () {
41
- for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
42
- return ar;
40
+ var __spreadArray = (this && this.__spreadArray) || function (to, from) {
41
+ for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
42
+ to[j] = from[i];
43
+ return to;
43
44
  };
44
45
  var __values = (this && this.__values) || function(o) {
45
46
  var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
@@ -121,6 +122,7 @@ var StateNode = /** @class */ (function () {
121
122
  delayedTransitions: undefined
122
123
  };
123
124
  this.idMap = {};
125
+ this.tags = [];
124
126
  this.options = Object.assign(createDefaultOptions(), options);
125
127
  this.parent = this.options._parent;
126
128
  this.key =
@@ -131,7 +133,7 @@ var StateNode = /** @class */ (function () {
131
133
  this.config.delimiter ||
132
134
  (this.parent ? this.parent.delimiter : constants_1.STATE_DELIMITER);
133
135
  this.id =
134
- this.config.id || __spread([this.machine.key], this.path).join(this.delimiter);
136
+ this.config.id || __spreadArray([this.machine.key], __read(this.path)).join(this.delimiter);
135
137
  this.version = this.parent
136
138
  ? this.parent.version
137
139
  : this.config.version;
@@ -233,6 +235,7 @@ var StateNode = /** @class */ (function () {
233
235
  .concat(this.invoke)
234
236
  .map(function (activity) { return actions_1.toActivityDefinition(activity); });
235
237
  this.transition = this.transition.bind(this);
238
+ this.tags = utils_1.toArray(this.config.tags);
236
239
  // TODO: this is the real fix for initialization once
237
240
  // state node getters are deprecated
238
241
  // if (!this.parent) {
@@ -408,10 +411,11 @@ var StateNode = /** @class */ (function () {
408
411
  var initialStateValue = this.getStateNode(stateValue).initial;
409
412
  return initialStateValue !== undefined
410
413
  ? this.getStateNodes((_a = {}, _a[stateValue] = initialStateValue, _a))
411
- : [this.states[stateValue]];
414
+ : [this, this.states[stateValue]];
412
415
  }
413
416
  var subStateKeys = utils_1.keys(stateValue);
414
417
  var subStateNodes = subStateKeys.map(function (subStateKey) { return _this.getStateNode(subStateKey); });
418
+ subStateNodes.push(this);
415
419
  return subStateNodes.concat(subStateKeys.reduce(function (allSubStateNodes, subStateKey) {
416
420
  var subStateNode = _this.getStateNode(subStateKey).getStateNodes(stateValue[subStateKey]);
417
421
  return allSubStateNodes.concat(subStateNode);
@@ -541,7 +545,7 @@ var StateNode = /** @class */ (function () {
541
545
  if (candidate.target !== undefined) {
542
546
  nextStateNodes = candidate.target;
543
547
  }
544
- actions.push.apply(actions, __spread(candidate.actions));
548
+ actions.push.apply(actions, __spreadArray([], __read(candidate.actions)));
545
549
  selectedTransition = candidate;
546
550
  break;
547
551
  }
@@ -683,9 +687,9 @@ var StateNode = /** @class */ (function () {
683
687
  var exitStates = new Set(transition.exitSet);
684
688
  var _c = __read([
685
689
  utils_1.flatten(Array.from(entryStates).map(function (stateNode) {
686
- return __spread(stateNode.activities.map(function (activity) { return actions_1.start(activity); }), stateNode.onEntry);
690
+ return __spreadArray(__spreadArray([], __read(stateNode.activities.map(function (activity) { return actions_1.start(activity); }))), __read(stateNode.onEntry));
687
691
  })).concat(doneEvents.map(actions_1.raise)),
688
- utils_1.flatten(Array.from(exitStates).map(function (stateNode) { return __spread(stateNode.onExit, stateNode.activities.map(function (activity) { return actions_1.stop(activity); })); }))
692
+ utils_1.flatten(Array.from(exitStates).map(function (stateNode) { return __spreadArray(__spreadArray([], __read(stateNode.onExit)), __read(stateNode.activities.map(function (activity) { return actions_1.stop(activity); }))); }))
689
693
  ], 2), entryActions = _c[0], exitActions = _c[1];
690
694
  var actions = actions_1.toActionObjects(exitActions.concat(transition.actions).concat(entryActions), this.machine.options.actions);
691
695
  return actions;
@@ -735,7 +739,7 @@ var StateNode = /** @class */ (function () {
735
739
  var resolvedConfig = stateTransition.configuration.length
736
740
  ? stateUtils_1.getConfiguration(prevConfig, stateTransition.configuration)
737
741
  : prevConfig;
738
- stateTransition.configuration = __spread(resolvedConfig);
742
+ stateTransition.configuration = __spreadArray([], __read(resolvedConfig));
739
743
  return this.resolveTransition(stateTransition, currentState, _event);
740
744
  };
741
745
  StateNode.prototype.resolveRaisedTransition = function (state, _event, originalEvent) {
@@ -746,7 +750,7 @@ var StateNode = /** @class */ (function () {
746
750
  // TODO: this should be the raised event! Delete in V5 (breaking)
747
751
  state._event = originalEvent;
748
752
  state.event = originalEvent.data;
749
- (_a = state.actions).unshift.apply(_a, __spread(currentActions));
753
+ (_a = state.actions).unshift.apply(_a, __spreadArray([], __read(currentActions)));
750
754
  return state;
751
755
  };
752
756
  StateNode.prototype.resolveTransition = function (stateTransition, currentState, _event, context) {
@@ -851,7 +855,8 @@ var StateNode = /** @class */ (function () {
851
855
  configuration: resolvedConfiguration,
852
856
  transitions: stateTransition.transitions,
853
857
  children: children,
854
- done: isDone
858
+ done: isDone,
859
+ tags: currentState === null || currentState === void 0 ? void 0 : currentState.tags
855
860
  });
856
861
  var didUpdateContext = currentContext !== updatedContext;
857
862
  nextState.changed = _event.name === actionTypes.update || didUpdateContext;
@@ -890,6 +895,7 @@ var StateNode = /** @class */ (function () {
890
895
  maybeNextState.changed = changed;
891
896
  // Preserve original history after raised events
892
897
  maybeNextState.history = history;
898
+ maybeNextState.tags = new Set(utils_1.flatten(maybeNextState.configuration.map(function (sn) { return sn.tags; })));
893
899
  return maybeNextState;
894
900
  };
895
901
  /**
@@ -1352,15 +1358,15 @@ var StateNode = /** @class */ (function () {
1352
1358
  var invokeConfig = utils_1.flatten(this.invoke.map(function (invokeDef) {
1353
1359
  var settleTransitions = [];
1354
1360
  if (invokeDef.onDone) {
1355
- settleTransitions.push.apply(settleTransitions, __spread(utils_1.toTransitionConfigArray(String(actions_1.doneInvoke(invokeDef.id)), invokeDef.onDone)));
1361
+ settleTransitions.push.apply(settleTransitions, __spreadArray([], __read(utils_1.toTransitionConfigArray(String(actions_1.doneInvoke(invokeDef.id)), invokeDef.onDone))));
1356
1362
  }
1357
1363
  if (invokeDef.onError) {
1358
- settleTransitions.push.apply(settleTransitions, __spread(utils_1.toTransitionConfigArray(String(actions_1.error(invokeDef.id)), invokeDef.onError)));
1364
+ settleTransitions.push.apply(settleTransitions, __spreadArray([], __read(utils_1.toTransitionConfigArray(String(actions_1.error(invokeDef.id)), invokeDef.onError))));
1359
1365
  }
1360
1366
  return settleTransitions;
1361
1367
  }));
1362
1368
  var delayedTransitions = this.after;
1363
- var formattedTransitions = utils_1.flatten(__spread(doneConfig, invokeConfig, onConfig, eventlessConfig).map(function (transitionConfig) {
1369
+ var formattedTransitions = utils_1.flatten(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(doneConfig)), __read(invokeConfig)), __read(onConfig)), __read(eventlessConfig)).map(function (transitionConfig) {
1364
1370
  return utils_1.toArray(transitionConfig).map(function (transition) {
1365
1371
  return _this.formatTransition(transition);
1366
1372
  });
package/lib/actions.d.ts CHANGED
@@ -9,7 +9,7 @@ export declare const initEvent: SCXML.Event<{
9
9
  }>;
10
10
  export declare function getActionFunction<TContext, TEvent extends EventObject>(actionType: ActionType, actionFunctionMap?: ActionFunctionMap<TContext, TEvent>): ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent> | undefined;
11
11
  export declare function toActionObject<TContext, TEvent extends EventObject>(action: Action<TContext, TEvent>, actionFunctionMap?: ActionFunctionMap<TContext, TEvent>): ActionObject<TContext, TEvent>;
12
- export declare const toActionObjects: <TContext, TEvent extends EventObject>(action?: string | ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent> | Action<TContext, TEvent>[] | undefined, actionFunctionMap?: Record<string, ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent>> | undefined) => ActionObject<TContext, TEvent>[];
12
+ export declare const toActionObjects: <TContext, TEvent extends EventObject>(action?: SingleOrArray<Action<TContext, TEvent>> | undefined, actionFunctionMap?: ActionFunctionMap<TContext, TEvent> | undefined) => ActionObject<TContext, TEvent>[];
13
13
  export declare function toActivityDefinition<TContext, TEvent extends EventObject>(action: string | ActivityDefinition<TContext, TEvent>): ActivityDefinition<TContext, TEvent>;
14
14
  /**
15
15
  * Raises an event. This places the event in the internal event queue, so that
@@ -1,6 +1,5 @@
1
1
  import { StateMachine, Event, EventObject, DefaultContext, StateSchema, StateValue, InterpreterOptions, SingleOrArray, DoneEvent, MachineOptions, SCXML, EventData, Observer, Spawnable, Typestate } from './types';
2
2
  import { State } from './State';
3
- import { Actor } from './Actor';
4
3
  import { ActorRefFrom, SpawnedActorRef, Subscription } from '.';
5
4
  export declare type StateListener<TContext, TEvent extends EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
6
5
  value: any;
@@ -26,7 +25,7 @@ export declare enum InterpreterStatus {
26
25
  export declare class Interpreter<TContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
27
26
  value: any;
28
27
  context: TContext;
29
- }> implements Actor<State<TContext, TEvent, TStateSchema, TTypestate>, TEvent> {
28
+ }> implements SpawnedActorRef<TEvent, State<TContext, TEvent, TStateSchema, TTypestate>> {
30
29
  machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
31
30
  /**
32
31
  * The default interpreter options:
@@ -122,7 +121,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
122
121
  /**
123
122
  * Alias for Interpreter.prototype.start
124
123
  */
125
- init: (initialState?: string | import("./types").StateValueMap | State<TContext, TEvent, TStateSchema, TTypestate> | undefined) => Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
124
+ init: (initialState?: StateValue | State<TContext, TEvent, TStateSchema, TTypestate> | undefined) => Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
126
125
  /**
127
126
  * Starts the interpreter from the given state, or the initial state.
128
127
  * @param initialState The state to start the statechart from
@@ -182,6 +181,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
182
181
  toJSON(): {
183
182
  id: string;
184
183
  };
184
+ getSnapshot(): State<TContext, TEvent, TStateSchema, TTypestate>;
185
185
  }
186
186
  export declare function spawn<TC, TE extends EventObject>(entity: StateMachine<TC, any, TE>, nameOrOptions?: string | SpawnOptions): ActorRefFrom<StateMachine<TC, any, TE>>;
187
187
  export declare function spawn(entity: Spawnable, nameOrOptions?: string | SpawnOptions): SpawnedActorRef<any>;