xstate 4.19.1 → 4.19.2

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/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
@@ -87,7 +87,7 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
87
87
  * @param delimiter The character(s) that separate each subpath in the string state node path.
88
88
  */
89
89
  toStrings(stateValue?: StateValue, delimiter?: string): string[];
90
- toJSON(): Pick<this, Exclude<keyof this, "configuration" | "transitions" | "tags">> & {
90
+ toJSON(): Omit<this, "configuration" | "transitions" | "tags"> & {
91
91
  tags: string[];
92
92
  };
93
93
  /**
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;
@@ -217,9 +218,9 @@ var State = /** @class */ (function () {
217
218
  return [stateValue];
218
219
  }
219
220
  var valueKeys = utils_1.keys(stateValue);
220
- return valueKeys.concat.apply(valueKeys, __spread(valueKeys.map(function (key) {
221
+ return valueKeys.concat.apply(valueKeys, __spreadArray([], __read(valueKeys.map(function (key) {
221
222
  return _this.toStrings(stateValue[key], delimiter).map(function (s) { return key + delimiter + s; });
222
- })));
223
+ }))));
223
224
  };
224
225
  State.prototype.toJSON = function () {
225
226
  var _a = this, configuration = _a.configuration, transitions = _a.transitions, tags = _a.tags, jsonValues = __rest(_a, ["configuration", "transitions", "tags"]);
@@ -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;
@@ -161,7 +161,7 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
161
161
  *
162
162
  * @param state The state value or State instance
163
163
  */
164
- 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>>;
165
165
  /**
166
166
  * Returns `true` if this state node explicitly handles the given event.
167
167
  *
@@ -195,13 +195,13 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
195
195
  * @param event The event that was sent at the current state
196
196
  * @param context The current context (extended state) of the current state
197
197
  */
198
- 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>;
199
199
  private resolveRaisedTransition;
200
200
  private resolveTransition;
201
201
  /**
202
202
  * Returns the child state node from its relative `stateKey`, or throws.
203
203
  */
204
- getStateNode(stateKey: string): StateNode<TContext, any, TEvent>;
204
+ getStateNode(stateKey: string): StateNode<TContext, any, TEvent, TTypestate>;
205
205
  /**
206
206
  * Returns the state node with the given `stateId`, or throws.
207
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;
@@ -132,7 +133,7 @@ var StateNode = /** @class */ (function () {
132
133
  this.config.delimiter ||
133
134
  (this.parent ? this.parent.delimiter : constants_1.STATE_DELIMITER);
134
135
  this.id =
135
- 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);
136
137
  this.version = this.parent
137
138
  ? this.parent.version
138
139
  : this.config.version;
@@ -410,10 +411,11 @@ var StateNode = /** @class */ (function () {
410
411
  var initialStateValue = this.getStateNode(stateValue).initial;
411
412
  return initialStateValue !== undefined
412
413
  ? this.getStateNodes((_a = {}, _a[stateValue] = initialStateValue, _a))
413
- : [this.states[stateValue]];
414
+ : [this, this.states[stateValue]];
414
415
  }
415
416
  var subStateKeys = utils_1.keys(stateValue);
416
417
  var subStateNodes = subStateKeys.map(function (subStateKey) { return _this.getStateNode(subStateKey); });
418
+ subStateNodes.push(this);
417
419
  return subStateNodes.concat(subStateKeys.reduce(function (allSubStateNodes, subStateKey) {
418
420
  var subStateNode = _this.getStateNode(subStateKey).getStateNodes(stateValue[subStateKey]);
419
421
  return allSubStateNodes.concat(subStateNode);
@@ -543,7 +545,7 @@ var StateNode = /** @class */ (function () {
543
545
  if (candidate.target !== undefined) {
544
546
  nextStateNodes = candidate.target;
545
547
  }
546
- actions.push.apply(actions, __spread(candidate.actions));
548
+ actions.push.apply(actions, __spreadArray([], __read(candidate.actions)));
547
549
  selectedTransition = candidate;
548
550
  break;
549
551
  }
@@ -685,9 +687,9 @@ var StateNode = /** @class */ (function () {
685
687
  var exitStates = new Set(transition.exitSet);
686
688
  var _c = __read([
687
689
  utils_1.flatten(Array.from(entryStates).map(function (stateNode) {
688
- 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));
689
691
  })).concat(doneEvents.map(actions_1.raise)),
690
- 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); }))); }))
691
693
  ], 2), entryActions = _c[0], exitActions = _c[1];
692
694
  var actions = actions_1.toActionObjects(exitActions.concat(transition.actions).concat(entryActions), this.machine.options.actions);
693
695
  return actions;
@@ -737,7 +739,7 @@ var StateNode = /** @class */ (function () {
737
739
  var resolvedConfig = stateTransition.configuration.length
738
740
  ? stateUtils_1.getConfiguration(prevConfig, stateTransition.configuration)
739
741
  : prevConfig;
740
- stateTransition.configuration = __spread(resolvedConfig);
742
+ stateTransition.configuration = __spreadArray([], __read(resolvedConfig));
741
743
  return this.resolveTransition(stateTransition, currentState, _event);
742
744
  };
743
745
  StateNode.prototype.resolveRaisedTransition = function (state, _event, originalEvent) {
@@ -748,7 +750,7 @@ var StateNode = /** @class */ (function () {
748
750
  // TODO: this should be the raised event! Delete in V5 (breaking)
749
751
  state._event = originalEvent;
750
752
  state.event = originalEvent.data;
751
- (_a = state.actions).unshift.apply(_a, __spread(currentActions));
753
+ (_a = state.actions).unshift.apply(_a, __spreadArray([], __read(currentActions)));
752
754
  return state;
753
755
  };
754
756
  StateNode.prototype.resolveTransition = function (stateTransition, currentState, _event, context) {
@@ -1356,15 +1358,15 @@ var StateNode = /** @class */ (function () {
1356
1358
  var invokeConfig = utils_1.flatten(this.invoke.map(function (invokeDef) {
1357
1359
  var settleTransitions = [];
1358
1360
  if (invokeDef.onDone) {
1359
- 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))));
1360
1362
  }
1361
1363
  if (invokeDef.onError) {
1362
- 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))));
1363
1365
  }
1364
1366
  return settleTransitions;
1365
1367
  }));
1366
1368
  var delayedTransitions = this.after;
1367
- 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) {
1368
1370
  return utils_1.toArray(transitionConfig).map(function (transition) {
1369
1371
  return _this.formatTransition(transition);
1370
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>;
@@ -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.interpret = exports.spawn = exports.Interpreter = exports.InterpreterStatus = void 0;
@@ -557,9 +558,9 @@ var Interpreter = /** @class */ (function () {
557
558
  nextState = serviceScope.provide(_this, function () {
558
559
  return _this.machine.transition(nextState, _event);
559
560
  });
560
- batchedActions.push.apply(batchedActions, __spread(nextState.actions.map(function (a) {
561
+ batchedActions.push.apply(batchedActions, __spreadArray([], __read(nextState.actions.map(function (a) {
561
562
  return State_1.bindActionToState(a, nextState);
562
- })));
563
+ }))));
563
564
  batchChanged = batchChanged || !!nextState.changed;
564
565
  };
565
566
  try {
@@ -840,8 +841,10 @@ var Interpreter = /** @class */ (function () {
840
841
  Interpreter.prototype.spawnPromise = function (promise, id) {
841
842
  var _this = this;
842
843
  var canceled = false;
844
+ var resolvedData = undefined;
843
845
  promise.then(function (response) {
844
846
  if (!canceled) {
847
+ resolvedData = response;
845
848
  _this.removeChild(id);
846
849
  _this.send(utils_1.toSCXMLEvent(actions_1.doneInvoke(id, response), { origin: id }));
847
850
  }
@@ -898,7 +901,8 @@ var Interpreter = /** @class */ (function () {
898
901
  },
899
902
  toJSON: function () {
900
903
  return { id: id };
901
- }
904
+ },
905
+ getSnapshot: function () { return resolvedData; }
902
906
  };
903
907
  this.children.set(id, actor);
904
908
  return actor;
@@ -908,7 +912,9 @@ var Interpreter = /** @class */ (function () {
908
912
  var canceled = false;
909
913
  var receivers = new Set();
910
914
  var listeners = new Set();
915
+ var emitted = undefined;
911
916
  var receive = function (e) {
917
+ emitted = e;
912
918
  listeners.forEach(function (listener) { return listener(e); });
913
919
  if (canceled) {
914
920
  return;
@@ -948,14 +954,17 @@ var Interpreter = /** @class */ (function () {
948
954
  },
949
955
  toJSON: function () {
950
956
  return { id: id };
951
- }
957
+ },
958
+ getSnapshot: function () { return emitted; }
952
959
  };
953
960
  this.children.set(id, actor);
954
961
  return actor;
955
962
  };
956
963
  Interpreter.prototype.spawnObservable = function (source, id) {
957
964
  var _this = this;
965
+ var emitted = undefined;
958
966
  var subscription = source.subscribe(function (value) {
967
+ emitted = value;
959
968
  _this.send(utils_1.toSCXMLEvent(value, { origin: id }));
960
969
  }, function (err) {
961
970
  _this.removeChild(id);
@@ -971,6 +980,7 @@ var Interpreter = /** @class */ (function () {
971
980
  return source.subscribe(next, handleError, complete);
972
981
  },
973
982
  stop: function () { return subscription.unsubscribe(); },
983
+ getSnapshot: function () { return emitted; },
974
984
  toJSON: function () {
975
985
  return { id: id };
976
986
  }
@@ -1005,6 +1015,7 @@ var Interpreter = /** @class */ (function () {
1005
1015
  return { unsubscribe: function () { return void 0; } };
1006
1016
  },
1007
1017
  stop: dispose || undefined,
1018
+ getSnapshot: function () { return undefined; },
1008
1019
  toJSON: function () {
1009
1020
  return { id: id };
1010
1021
  }
@@ -1040,6 +1051,9 @@ var Interpreter = /** @class */ (function () {
1040
1051
  Interpreter.prototype[utils_1.symbolObservable] = function () {
1041
1052
  return this;
1042
1053
  };
1054
+ Interpreter.prototype.getSnapshot = function () {
1055
+ return this._state;
1056
+ };
1043
1057
  /**
1044
1058
  * The default interpreter options:
1045
1059
  *
package/lib/model.js CHANGED
@@ -26,9 +26,10 @@ var __read = (this && this.__read) || function (o, n) {
26
26
  }
27
27
  return ar;
28
28
  };
29
- var __spread = (this && this.__spread) || function () {
30
- for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
31
- return ar;
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;
32
33
  };
33
34
  Object.defineProperty(exports, "__esModule", { value: true });
34
35
  exports.createModel = void 0;
@@ -45,7 +46,7 @@ function createModel(initialContext, creators) {
45
46
  for (var _i = 0; _i < arguments.length; _i++) {
46
47
  args[_i] = arguments[_i];
47
48
  }
48
- return (__assign(__assign({}, fn.apply(void 0, __spread(args))), { type: eventType }));
49
+ return (__assign(__assign({}, fn.apply(void 0, __spreadArray([], __read(args)))), { type: eventType }));
49
50
  }; })
50
51
  : undefined),
51
52
  reset: function () { return actions_1.assign(initialContext); }
package/lib/scxml.js CHANGED
@@ -26,9 +26,10 @@ var __read = (this && this.__read) || function (o, n) {
26
26
  }
27
27
  return ar;
28
28
  };
29
- var __spread = (this && this.__spread) || function () {
30
- for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
31
- return ar;
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;
32
33
  };
33
34
  var __values = (this && this.__values) || function(o) {
34
35
  var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
@@ -112,7 +113,7 @@ var evaluateExecutableContent = function (context, _ev, meta, body) {
112
113
  .join('\n');
113
114
  var args = ['context', '_event'];
114
115
  var fnBody = "\n " + scope + "\n " + body + "\n ";
115
- var fn = new (Function.bind.apply(Function, __spread([void 0], args, [fnBody])))();
116
+ var fn = new (Function.bind.apply(Function, __spreadArray(__spreadArray([void 0], __read(args)), [fnBody])))();
116
117
  return fn(context, meta._event);
117
118
  };
118
119
  function createCond(cond) {
package/lib/stateUtils.js CHANGED
@@ -26,9 +26,10 @@ var __read = (this && this.__read) || function (o, n) {
26
26
  }
27
27
  return ar;
28
28
  };
29
- var __spread = (this && this.__spread) || function () {
30
- for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
31
- return ar;
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;
32
33
  };
33
34
  Object.defineProperty(exports, "__esModule", { value: true });
34
35
  exports.isInFinalState = exports.nextEvents = exports.has = exports.getValue = exports.getAdjList = exports.getConfiguration = exports.getAllStateNodes = exports.getChildren = exports.isLeafNode = void 0;
@@ -209,7 +210,7 @@ function has(iterable, item) {
209
210
  }
210
211
  exports.has = has;
211
212
  function nextEvents(configuration) {
212
- return utils_1.flatten(__spread(new Set(configuration.map(function (sn) { return sn.ownEvents; }))));
213
+ return __spreadArray([], __read(new Set(utils_1.flatten(__spreadArray([], __read(configuration.map(function (sn) { return sn.ownEvents; })))))));
213
214
  }
214
215
  exports.nextEvents = nextEvents;
215
216
  function isInFinalState(configuration, stateNode) {
package/lib/types.d.ts CHANGED
@@ -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 extends EventObject = AnyEventObject, TFinalContext = any> = (context: TContext, event: TEvent, meta: InvokeMeta) => PromiseLike<TFinalContext> | StateMachine<TFinalContext, any, any> | Subscribable<any> | InvokeCallback<TEvent>;
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.
@@ -885,12 +885,13 @@ export interface ActorRef<TEvent extends EventObject, TEmitted = any> extends Su
885
885
  }
886
886
  export interface SpawnedActorRef<TEvent extends EventObject, TEmitted = any> extends ActorRef<TEvent, TEmitted> {
887
887
  id: string;
888
+ getSnapshot: () => TEmitted | undefined;
888
889
  stop?: () => void;
889
890
  toJSON?: () => any;
890
891
  }
891
- 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>> & {
892
+ 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>> & {
892
893
  state: State<TContext, TEvent, any, TTypestate>;
893
- } : never;
894
+ } : T extends Promise<infer U> ? SpawnedActorRef<never, U> : never;
894
895
  export declare type AnyInterpreter = Interpreter<any, any, any, any>;
895
896
  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;
896
897
  export {};
package/lib/utils.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.toObserver = exports.toInvokeSource = exports.evaluateGuard = exports.reportUnhandledExceptionOnInvocation = exports.normalizeTarget = exports.toTransitionConfigArray = exports.toSCXMLEvent = exports.toEventObject = exports.uniqueId = exports.isActor = exports.isMachine = exports.symbolObservable = exports.isObservable = exports.toGuard = exports.isString = exports.isFunction = exports.isArray = exports.warn = exports.updateContext = exports.updateHistoryValue = exports.updateHistoryStates = exports.partition = exports.isPromiseLike = exports.isBuiltInEvent = exports.mapContext = exports.toArray = exports.toArrayStrict = exports.flatten = exports.pathsToStateValue = exports.toStatePaths = exports.nestedPath = exports.path = exports.mapFilterValues = exports.mapValues = exports.pathToStateValue = exports.toStateValue = exports.isStateLike = exports.toStatePath = exports.getActionType = exports.getEventType = exports.matchesState = exports.keys = void 0;
@@ -282,7 +283,7 @@ function pathsToStateValue(paths) {
282
283
  exports.pathsToStateValue = pathsToStateValue;
283
284
  function flatten(array) {
284
285
  var _a;
285
- return (_a = []).concat.apply(_a, __spread(array));
286
+ return (_a = []).concat.apply(_a, __spreadArray([], __read(array)));
286
287
  }
287
288
  exports.flatten = flatten;
288
289
  function toArrayStrict(value) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xstate",
3
- "version": "4.19.1",
3
+ "version": "4.19.2",
4
4
  "description": "Finite State Machines and Statecharts for the Modern Web.",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -46,13 +46,13 @@
46
46
  "bugs": {
47
47
  "url": "https://github.com/davidkpiano/xstate/issues"
48
48
  },
49
- "homepage": "https://github.com/davidkpiano/xstate/tree/master/packages/core#readme",
49
+ "homepage": "https://github.com/davidkpiano/xstate/tree/main/packages/core#readme",
50
50
  "devDependencies": {
51
51
  "@babel/cli": "^7.10.5",
52
52
  "@babel/core": "^7.10.5",
53
53
  "@scion-scxml/test-framework": "^2.0.15",
54
54
  "babel-plugin-annotate-pure-calls": "^0.4.0",
55
- "jest": "^26.4.2",
55
+ "jest": "^26.6.3",
56
56
  "jsdom": "^14.0.0",
57
57
  "jsdom-global": "^3.0.2",
58
58
  "lerna-alias": "3.0.3-0",
@@ -64,9 +64,9 @@
64
64
  "rollup-plugin-typescript2": "^0.29.0",
65
65
  "rollup-plugin-uglify": "^6.0.2",
66
66
  "rxjs": "^6.5.1",
67
- "ts-jest": "^26.4.0",
68
- "tslib": "^1.10.0",
69
- "typescript": "^4.1.2",
67
+ "ts-jest": "^26.5.6",
68
+ "tslib": "^2.2.0",
69
+ "typescript": "^4.2.4",
70
70
  "xml-js": "^1.6.11"
71
71
  }
72
72
  }