xstate 4.28.0 → 4.30.1

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 (57) hide show
  1. package/CHANGELOG.md +216 -91
  2. package/README.md +5 -5
  3. package/dist/xstate.interpreter.js +1 -1
  4. package/dist/xstate.js +1 -1
  5. package/dist/xstate.web.js +2 -2
  6. package/es/Actor.d.ts +1 -2
  7. package/es/Machine.d.ts +5 -4
  8. package/es/State.d.ts +17 -14
  9. package/es/State.js +4 -4
  10. package/es/StateNode.d.ts +22 -17
  11. package/es/StateNode.js +21 -25
  12. package/es/actions.d.ts +3 -4
  13. package/es/actions.js +8 -3
  14. package/es/behaviors.d.ts +1 -1
  15. package/es/devTools.d.ts +3 -4
  16. package/es/each.d.ts +1 -1
  17. package/es/index.d.ts +10 -22
  18. package/es/index.js +11 -23
  19. package/es/interpreter.d.ts +34 -27
  20. package/es/interpreter.js +7 -4
  21. package/es/model.d.ts +2 -2
  22. package/es/model.types.d.ts +8 -9
  23. package/es/schema.d.ts +1 -0
  24. package/es/schema.js +2 -1
  25. package/es/scxml.d.ts +2 -2
  26. package/es/stateUtils.d.ts +6 -5
  27. package/es/typegenTypes.d.ts +121 -0
  28. package/es/types.d.ts +122 -61
  29. package/es/utils.d.ts +4 -4
  30. package/es/utils.js +1 -1
  31. package/lib/Actor.d.ts +1 -2
  32. package/lib/Machine.d.ts +5 -4
  33. package/lib/State.d.ts +17 -14
  34. package/lib/State.js +4 -4
  35. package/lib/StateNode.d.ts +22 -17
  36. package/lib/StateNode.js +21 -25
  37. package/lib/actions.d.ts +3 -4
  38. package/lib/actions.js +5 -0
  39. package/lib/behaviors.d.ts +1 -1
  40. package/lib/devTools.d.ts +3 -4
  41. package/lib/each.d.ts +1 -1
  42. package/lib/index.d.ts +10 -22
  43. package/lib/index.js +15 -27
  44. package/lib/interpreter.d.ts +34 -27
  45. package/lib/interpreter.js +5 -2
  46. package/lib/model.d.ts +2 -2
  47. package/lib/model.types.d.ts +8 -9
  48. package/lib/schema.d.ts +1 -0
  49. package/lib/schema.js +2 -0
  50. package/lib/scxml.d.ts +2 -2
  51. package/lib/stateUtils.d.ts +6 -5
  52. package/lib/typegenTypes.d.ts +121 -0
  53. package/lib/typegenTypes.js +2 -0
  54. package/lib/types.d.ts +122 -61
  55. package/lib/utils.d.ts +4 -4
  56. package/lib/utils.js +1 -1
  57. package/package.json +5 -5
package/lib/State.d.ts CHANGED
@@ -1,19 +1,22 @@
1
1
  import { StateValue, ActivityMap, EventObject, HistoryValue, ActionObject, EventType, StateConfig, SCXML, StateSchema, TransitionDefinition, Typestate, ActorRef, StateMachine, SimpleEventsOf } from './types';
2
2
  import { StateNode } from './StateNode';
3
+ import { TypegenDisabled, TypegenEnabled } from './typegenTypes';
4
+ import { BaseActionObject, Prop } from './types';
3
5
  export declare function stateValuesEqual(a: StateValue | undefined, b: StateValue | undefined): boolean;
4
- export declare function isState<TContext, TEvent extends EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
5
- value: any;
6
- context: TContext;
7
- }>(state: object | string): state is State<TContext, TEvent, TStateSchema, TTypestate>;
8
- export declare function bindActionToState<TC, TE extends EventObject>(action: ActionObject<TC, TE>, state: State<TC, TE, any, any>): ActionObject<TC, TE>;
6
+ export declare function isStateConfig<TContext, TEvent extends EventObject>(state: any): state is StateConfig<TContext, TEvent>;
7
+ /**
8
+ * @deprecated Use `isStateConfig(object)` or `state instanceof State` instead.
9
+ */
10
+ export declare const isState: typeof isStateConfig;
11
+ export declare function bindActionToState<TC, TE extends EventObject>(action: ActionObject<TC, TE>, state: State<TC, TE, any, any, any>): ActionObject<TC, TE>;
9
12
  export declare class State<TContext, TEvent extends EventObject = EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
10
13
  value: any;
11
14
  context: TContext;
12
- }> {
15
+ }, TResolvedTypesMeta = TypegenDisabled> {
13
16
  value: StateValue;
14
17
  context: TContext;
15
18
  historyValue?: HistoryValue | undefined;
16
- history?: State<TContext, TEvent, TStateSchema, TTypestate>;
19
+ history?: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
17
20
  actions: Array<ActionObject<TContext, TEvent>>;
18
21
  activities: ActivityMap;
19
22
  meta: any;
@@ -37,7 +40,7 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
37
40
  /**
38
41
  * The enabled state nodes representative of the state value.
39
42
  */
40
- configuration: Array<StateNode<TContext, any, TEvent, any>>;
43
+ configuration: Array<StateNode<TContext, any, TEvent, any, any>>;
41
44
  /**
42
45
  * The next events that will cause a transition from the current state.
43
46
  */
@@ -51,18 +54,18 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
51
54
  */
52
55
  children: Record<string, ActorRef<any>>;
53
56
  tags: Set<string>;
54
- machine: StateMachine<TContext, any, TEvent, TTypestate> | undefined;
57
+ machine: StateMachine<TContext, any, TEvent, TTypestate, BaseActionObject, any, TResolvedTypesMeta> | undefined;
55
58
  /**
56
59
  * Creates a new State instance for the given `stateValue` and `context`.
57
60
  * @param stateValue
58
61
  * @param context
59
62
  */
60
- static from<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE, any, any> | StateValue, context?: TC | undefined): State<TC, TE, any, any>;
63
+ static from<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE, any, any, any> | StateValue, context?: TC | undefined): State<TC, TE, any, any, any>;
61
64
  /**
62
65
  * Creates a new State instance for the given `config`.
63
66
  * @param config The state config
64
67
  */
65
- static create<TC, TE extends EventObject = EventObject>(config: StateConfig<TC, TE>): State<TC, TE>;
68
+ static create<TC, TE extends EventObject = EventObject>(config: StateConfig<TC, TE>): State<TC, TE, any, any, any>;
66
69
  /**
67
70
  * Creates a new `State` instance for the given `stateValue` and `context` with no actions (side-effects).
68
71
  * @param stateValue
@@ -95,17 +98,17 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
95
98
  * Whether the current state value is a subset of the given parent state value.
96
99
  * @param parentStateValue
97
100
  */
98
- matches<TSV extends TTypestate['value']>(parentStateValue: TSV): this is State<(TTypestate extends any ? {
101
+ matches<TSV extends TResolvedTypesMeta extends TypegenEnabled ? Prop<TResolvedTypesMeta, 'matchesStates'> : TTypestate['value']>(parentStateValue: TSV): this is State<(TTypestate extends any ? {
99
102
  value: TSV;
100
103
  context: any;
101
- } extends TTypestate ? TTypestate : never : never)['context'], TEvent, TStateSchema, TTypestate> & {
104
+ } extends TTypestate ? TTypestate : never : never)['context'], TEvent, TStateSchema, TTypestate, TResolvedTypesMeta> & {
102
105
  value: TSV;
103
106
  };
104
107
  /**
105
108
  * Whether the current state configuration has a state node with the specified `tag`.
106
109
  * @param tag
107
110
  */
108
- hasTag(tag: string): boolean;
111
+ hasTag(tag: TResolvedTypesMeta extends TypegenEnabled ? Prop<TResolvedTypesMeta, 'tags'> : string): boolean;
109
112
  /**
110
113
  * Determines whether sending the `event` will cause a non-forbidden transition
111
114
  * to be selected, even if the transitions have no actions nor
package/lib/State.js CHANGED
@@ -28,12 +28,12 @@ function stateValuesEqual(a, b) {
28
28
  return stateValuesEqual(a[key], b[key]);
29
29
  });
30
30
  }
31
- function isState(state) {
32
- if (utils.isString(state)) {
31
+ function isStateConfig(state) {
32
+ if (typeof state !== 'object' || state === null) {
33
33
  return false;
34
34
  }
35
35
 
36
- return 'value' in state && 'history' in state;
36
+ return 'value' in state && '_event' in state;
37
37
  }
38
38
  function bindActionToState(action, state) {
39
39
  var exec = action.exec;
@@ -277,5 +277,5 @@ function () {
277
277
 
278
278
  exports.State = State;
279
279
  exports.bindActionToState = bindActionToState;
280
- exports.isState = isState;
280
+ exports.isStateConfig = isStateConfig;
281
281
  exports.stateValuesEqual = stateValuesEqual;
@@ -1,9 +1,10 @@
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';
1
+ import { Event, StateValue, StateTransition, MachineOptions, EventObject, HistoryValue, StateNodeDefinition, TransitionDefinition, DelayedTransitionDefinition, ActivityDefinition, StateNodeConfig, StateSchema, StateNodesConfig, InvokeDefinition, ActionObject, Mapper, PropertyMapper, SCXML, Typestate, TransitionDefinitionMap, MachineSchema, InternalMachineOptions, ServiceMap, StateConfig } from './types';
2
2
  import { State } from './State';
3
+ import { TypegenDisabled } from './typegenTypes';
3
4
  declare class StateNode<TContext = any, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
4
5
  value: any;
5
6
  context: TContext;
6
- }> {
7
+ }, TServiceMap extends ServiceMap = ServiceMap, TResolvedTypesMeta = TypegenDisabled> {
7
8
  /**
8
9
  * The raw config used to create the machine.
9
10
  */
@@ -81,7 +82,7 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
81
82
  /**
82
83
  * The parent state node.
83
84
  */
84
- parent?: StateNode<TContext, any, TEvent, any>;
85
+ parent?: StateNode<TContext, any, TEvent, any, any, any>;
85
86
  /**
86
87
  * The root machine node.
87
88
  */
@@ -119,11 +120,15 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
119
120
  /**
120
121
  * The raw config used to create the machine.
121
122
  */
122
- config: StateNodeConfig<TContext, TStateSchema, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>,
123
+ config: StateNodeConfig<TContext, TStateSchema, TEvent>, options?: MachineOptions<TContext, TEvent>,
123
124
  /**
124
125
  * The initial extended state
125
126
  */
126
- _context?: Readonly<TContext> | (() => Readonly<TContext>));
127
+ _context?: Readonly<TContext> | (() => Readonly<TContext>), // TODO: this is unsafe, but we're removing it in v5 anyway
128
+ _stateInfo?: {
129
+ parent: StateNode<any, any, any, any, any, any>;
130
+ key: string;
131
+ });
127
132
  private _init;
128
133
  /**
129
134
  * Clones this state machine with custom options and context.
@@ -131,7 +136,7 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
131
136
  * @param options Options (actions, guards, activities, services) to recursively merge with the existing options.
132
137
  * @param context Custom context (will override predefined context)
133
138
  */
134
- withConfig(options: Partial<MachineOptions<TContext, TEvent>>, context?: TContext | (() => TContext)): StateNode<TContext, TStateSchema, TEvent, TTypestate>;
139
+ withConfig(options: InternalMachineOptions<TContext, TEvent, TResolvedTypesMeta, true>, context?: TContext | (() => TContext)): StateNode<TContext, TStateSchema, TEvent, TTypestate, TServiceMap, TResolvedTypesMeta>;
135
140
  /**
136
141
  * Clones this state machine with custom context.
137
142
  *
@@ -163,7 +168,7 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
163
168
  *
164
169
  * @param state The state value or State instance
165
170
  */
166
- getStateNodes(state: StateValue | State<TContext, TEvent, any, TTypestate>): Array<StateNode<TContext, any, TEvent, TTypestate>>;
171
+ getStateNodes(state: StateValue | State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta>): Array<StateNode<TContext, any, TEvent, TTypestate, TServiceMap, TResolvedTypesMeta>>;
167
172
  /**
168
173
  * Returns `true` if this state node explicitly handles the given event.
169
174
  *
@@ -177,12 +182,12 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
177
182
  *
178
183
  * @param state The state to resolve
179
184
  */
180
- resolveState(state: State<TContext, TEvent, any, any>): State<TContext, TEvent, TStateSchema, TTypestate>;
185
+ resolveState(state: State<TContext, TEvent, any, any> | StateConfig<TContext, TEvent>): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
181
186
  private transitionLeafNode;
182
187
  private transitionCompoundNode;
183
188
  private transitionParallelNode;
184
189
  private _transition;
185
- getTransitionData(state: State<TContext, TEvent, any, any>, event: Event<TEvent> | SCXML.Event<TEvent>): StateTransition<TContext, TEvent> | undefined;
190
+ getTransitionData(state: State<TContext, TEvent, any, any, any>, event: Event<TEvent> | SCXML.Event<TEvent>): StateTransition<TContext, TEvent> | undefined;
186
191
  private next;
187
192
  private nodesFromChild;
188
193
  /**
@@ -198,25 +203,25 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
198
203
  * @param event The event that was sent at the current state
199
204
  * @param context The current context (extended state) of the current state
200
205
  */
201
- transition(state: StateValue | State<TContext, TEvent, any, TTypestate> | undefined, event: Event<TEvent> | SCXML.Event<TEvent>, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate>;
206
+ transition(state: StateValue | State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta> | undefined, event: Event<TEvent> | SCXML.Event<TEvent>, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
202
207
  private resolveRaisedTransition;
203
208
  private resolveTransition;
204
209
  /**
205
210
  * Returns the child state node from its relative `stateKey`, or throws.
206
211
  */
207
- getStateNode(stateKey: string): StateNode<TContext, any, TEvent, TTypestate>;
212
+ getStateNode(stateKey: string): StateNode<TContext, any, TEvent, TTypestate, TServiceMap, TResolvedTypesMeta>;
208
213
  /**
209
214
  * Returns the state node with the given `stateId`, or throws.
210
215
  *
211
216
  * @param stateId The state ID. The prefix "#" is removed.
212
217
  */
213
- getStateNodeById(stateId: string): StateNode<TContext, any, TEvent, any>;
218
+ getStateNodeById(stateId: string): StateNode<TContext, any, TEvent, any, TServiceMap, TResolvedTypesMeta>;
214
219
  /**
215
220
  * Returns the relative state node from the given `statePath`, or throws.
216
221
  *
217
222
  * @param statePath The string or string array relative path to the state node.
218
223
  */
219
- getStateNodeByPath(statePath: string | string[]): StateNode<TContext, any, TEvent, any>;
224
+ getStateNodeByPath(statePath: string | string[]): StateNode<TContext, any, TEvent, any, any, any>;
220
225
  /**
221
226
  * Resolves a partial state value with its full representation in this machine.
222
227
  *
@@ -225,12 +230,12 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
225
230
  resolve(stateValue: StateValue): StateValue;
226
231
  private getResolvedPath;
227
232
  private get initialStateValue();
228
- getInitialState(stateValue: StateValue, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate>;
233
+ getInitialState(stateValue: StateValue, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
229
234
  /**
230
235
  * The initial State instance, which includes all actions to be executed from
231
236
  * entering the initial state.
232
237
  */
233
- get initialState(): State<TContext, TEvent, TStateSchema, TTypestate>;
238
+ get initialState(): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
234
239
  /**
235
240
  * The target state value of the history state node, if it exists. This represents the
236
241
  * default state value to transition to if no history value exists yet.
@@ -244,14 +249,14 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
244
249
  * @param resolve Whether state nodes should resolve to initial child state nodes
245
250
  */
246
251
  getRelativeStateNodes(relativeStateId: StateNode<TContext, any, TEvent>, historyValue?: HistoryValue, resolve?: boolean): Array<StateNode<TContext, any, TEvent>>;
247
- get initialStateNodes(): Array<StateNode<TContext, any, TEvent, any>>;
252
+ get initialStateNodes(): Array<StateNode<TContext, any, TEvent, any, any, any>>;
248
253
  /**
249
254
  * Retrieves state nodes from a relative path to this state node.
250
255
  *
251
256
  * @param relativePath The relative path from this state node
252
257
  * @param historyValue
253
258
  */
254
- getFromRelativePath(relativePath: string[]): Array<StateNode<TContext, any, TEvent, any>>;
259
+ getFromRelativePath(relativePath: string[]): Array<StateNode<TContext, any, TEvent, any, any, any>>;
255
260
  private historyValue;
256
261
  /**
257
262
  * Resolves to the historical value(s) of the parent state node,
package/lib/StateNode.js CHANGED
@@ -54,8 +54,8 @@ function () {
54
54
  /**
55
55
  * The initial extended state
56
56
  */
57
- _context // TODO: this is unsafe, but we're removing it in v5 anyway
58
- ) {
57
+ _context, // TODO: this is unsafe, but we're removing it in v5 anyway
58
+ _stateInfo) {
59
59
  var _this = this;
60
60
 
61
61
  if (_context === void 0) {
@@ -85,8 +85,8 @@ function () {
85
85
  this.idMap = {};
86
86
  this.tags = [];
87
87
  this.options = Object.assign(createDefaultOptions(), options);
88
- this.parent = this.options._parent;
89
- this.key = this.config.key || this.options._key || this.config.id || '(machine)';
88
+ this.parent = _stateInfo === null || _stateInfo === void 0 ? void 0 : _stateInfo.parent;
89
+ this.key = this.config.key || (_stateInfo === null || _stateInfo === void 0 ? void 0 : _stateInfo.key) || this.config.id || '(machine)';
90
90
  this.machine = this.parent ? this.parent.machine : this;
91
91
  this.path = this.parent ? this.parent.path.concat(this.key) : [];
92
92
  this.delimiter = this.config.delimiter || (this.parent ? this.parent.delimiter : constants.STATE_DELIMITER);
@@ -104,9 +104,9 @@ function () {
104
104
  this.states = this.config.states ? utils.mapValues(this.config.states, function (stateConfig, key) {
105
105
  var _a;
106
106
 
107
- var stateNode = new StateNode(stateConfig, {
108
- _parent: _this,
109
- _key: key
107
+ var stateNode = new StateNode(stateConfig, {}, undefined, {
108
+ parent: _this,
109
+ key: key
110
110
  });
111
111
  Object.assign(_this.idMap, _tslib.__assign((_a = {}, _a[stateNode.id] = stateNode, _a), stateNode.idMap));
112
112
  return stateNode;
@@ -441,9 +441,10 @@ function () {
441
441
 
442
442
 
443
443
  StateNode.prototype.resolveState = function (state) {
444
- var configuration = Array.from(stateUtils.getConfiguration([], this.getStateNodes(state.value)));
445
- return new State.State(_tslib.__assign(_tslib.__assign({}, state), {
446
- value: this.resolve(state.value),
444
+ var stateFromConfig = state instanceof State.State ? state : State.State.create(state);
445
+ var configuration = Array.from(stateUtils.getConfiguration([], this.getStateNodes(stateFromConfig.value)));
446
+ return new State.State(_tslib.__assign(_tslib.__assign({}, stateFromConfig), {
447
+ value: this.resolve(stateFromConfig.value),
447
448
  configuration: configuration,
448
449
  done: stateUtils.isInFinalState(configuration, this),
449
450
  tags: stateUtils.getTagsFromConfiguration(configuration)
@@ -827,7 +828,7 @@ function () {
827
828
  var prevConfig = stateUtils.getConfiguration([], this.getStateNodes(currentState.value));
828
829
  var resolvedConfig = stateTransition.configuration.length ? stateUtils.getConfiguration(prevConfig, stateTransition.configuration) : prevConfig;
829
830
  stateTransition.configuration = _tslib.__spreadArray([], _tslib.__read(resolvedConfig), false);
830
- return this.resolveTransition(stateTransition, currentState, _event);
831
+ return this.resolveTransition(stateTransition, currentState, currentState.context, _event);
831
832
  };
832
833
 
833
834
  StateNode.prototype.resolveRaisedTransition = function (state, _event, originalEvent) {
@@ -845,7 +846,7 @@ function () {
845
846
  return state;
846
847
  };
847
848
 
848
- StateNode.prototype.resolveTransition = function (stateTransition, currentState, _event, context) {
849
+ StateNode.prototype.resolveTransition = function (stateTransition, currentState, context, _event) {
849
850
  var e_6, _a;
850
851
 
851
852
  var _this = this;
@@ -854,10 +855,6 @@ function () {
854
855
  _event = actions.initEvent;
855
856
  }
856
857
 
857
- if (context === void 0) {
858
- context = this.machine.context;
859
- }
860
-
861
858
  var configuration = stateTransition.configuration; // Transition will "apply" if:
862
859
  // - this is the initial state (there is no current state)
863
860
  // - OR there are transitions
@@ -865,8 +862,7 @@ function () {
865
862
  var willTransition = !currentState || stateTransition.transitions.length > 0;
866
863
  var resolvedStateValue = willTransition ? stateUtils.getValue(this.machine, configuration) : undefined;
867
864
  var historyValue = currentState ? currentState.historyValue ? currentState.historyValue : stateTransition.source ? this.machine.historyValue(currentState.value) : undefined : undefined;
868
- var currentContext = currentState ? currentState.context : context;
869
- var actions$1 = this.getActions(stateTransition, currentContext, _event, currentState);
865
+ var actions$1 = this.getActions(stateTransition, context, _event, currentState);
870
866
  var activities = currentState ? _tslib.__assign({}, currentState.activities) : {};
871
867
 
872
868
  try {
@@ -891,7 +887,7 @@ function () {
891
887
  }
892
888
  }
893
889
 
894
- var _b = _tslib.__read(actions.resolveActions(this, currentState, currentContext, _event, actions$1, this.machine.config.preserveActionOrder), 2),
890
+ var _b = _tslib.__read(actions.resolveActions(this, currentState, context, _event, actions$1, this.machine.config.preserveActionOrder), 2),
895
891
  resolvedActions = _b[0],
896
892
  updatedContext = _b[1];
897
893
 
@@ -910,7 +906,7 @@ function () {
910
906
  acc[action.activity.id] = Actor.createInvocableActor(action.activity, _this.machine, updatedContext, _event);
911
907
  return acc;
912
908
  }, currentState ? _tslib.__assign({}, currentState.children) : {});
913
- var resolvedConfiguration = resolvedStateValue ? stateTransition.configuration : currentState ? currentState.configuration : [];
909
+ var resolvedConfiguration = willTransition ? stateTransition.configuration : currentState ? currentState.configuration : [];
914
910
  var isDone = stateUtils.isInFinalState(resolvedConfiguration, this);
915
911
  var nextState = new State.State({
916
912
  value: resolvedStateValue || currentState.value,
@@ -930,7 +926,7 @@ function () {
930
926
  tags: currentState === null || currentState === void 0 ? void 0 : currentState.tags,
931
927
  machine: this
932
928
  });
933
- var didUpdateContext = currentContext !== updatedContext;
929
+ var didUpdateContext = context !== updatedContext;
934
930
  nextState.changed = _event.name === actionTypes.update || didUpdateContext; // Dispose of penultimate histories to prevent memory leaks
935
931
 
936
932
  var history = nextState.history;
@@ -1150,6 +1146,9 @@ function () {
1150
1146
  });
1151
1147
 
1152
1148
  StateNode.prototype.getInitialState = function (stateValue, context) {
1149
+ this._init(); // TODO: this should be in the constructor (see note in constructor)
1150
+
1151
+
1153
1152
  var configuration = this.getStateNodes(stateValue);
1154
1153
  return this.resolveTransition({
1155
1154
  configuration: configuration,
@@ -1158,7 +1157,7 @@ function () {
1158
1157
  transitions: [],
1159
1158
  source: undefined,
1160
1159
  actions: []
1161
- }, undefined, undefined, context);
1160
+ }, undefined, context !== null && context !== void 0 ? context : this.machine.context, undefined);
1162
1161
  };
1163
1162
 
1164
1163
  Object.defineProperty(StateNode.prototype, "initialState", {
@@ -1167,9 +1166,6 @@ function () {
1167
1166
  * entering the initial state.
1168
1167
  */
1169
1168
  get: function () {
1170
- this._init(); // TODO: this should be in the constructor (see note in constructor)
1171
-
1172
-
1173
1169
  var initialStateValue = this.initialStateValue;
1174
1170
 
1175
1171
  if (!initialStateValue) {
package/lib/actions.d.ts CHANGED
@@ -1,15 +1,14 @@
1
- import { Action, Event, EventObject, SingleOrArray, SendAction, SendActionOptions, CancelAction, ActionObject, ActionType, Assigner, PropertyAssigner, AssignAction, ActionFunction, ActionFunctionMap, ActivityActionObject, ActionTypes, ActivityDefinition, RaiseAction, RaiseActionObject, DoneEvent, ErrorPlatformEvent, DoneEventObject, SendExpr, SendActionObject, PureAction, LogExpr, LogAction, LogActionObject, DelayFunctionMap, SCXML, ExprWithMeta, ChooseCondition, ChooseAction, AnyEventObject, Expr, Cast } from './types';
1
+ import { Action, Event, EventObject, SingleOrArray, SendAction, SendActionOptions, CancelAction, ActionObject, ActionType, Assigner, PropertyAssigner, AssignAction, ActionFunction, ActionFunctionMap, ActivityActionObject, ActionTypes, ActivityDefinition, RaiseAction, RaiseActionObject, DoneEvent, ErrorPlatformEvent, DoneEventObject, SendExpr, SendActionObject, PureAction, LogExpr, LogAction, LogActionObject, DelayFunctionMap, SCXML, ExprWithMeta, ChooseCondition, ChooseAction, AnyEventObject, Expr, StopAction, StopActionObject, Cast, ActorRef, EventFrom } from './types';
2
2
  import * as actionTypes from './actionTypes';
3
3
  import { State } from './State';
4
4
  import { StateNode } from './StateNode';
5
- import { ActorRef, EventFrom, StopAction, StopActionObject } from '.';
6
5
  export { actionTypes };
7
6
  export declare const initEvent: SCXML.Event<{
8
7
  type: ActionTypes;
9
8
  }>;
10
9
  export declare function getActionFunction<TContext, TEvent extends EventObject>(actionType: ActionType, actionFunctionMap?: ActionFunctionMap<TContext, TEvent>): ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent> | undefined;
11
10
  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?: SingleOrArray<Action<TContext, TEvent>> | undefined, actionFunctionMap?: ActionFunctionMap<TContext, TEvent, ActionObject<TContext, TEvent>> | undefined) => ActionObject<TContext, TEvent>[];
11
+ export declare const toActionObjects: <TContext, TEvent extends EventObject>(action?: SingleOrArray<Action<TContext, TEvent>> | undefined, actionFunctionMap?: ActionFunctionMap<TContext, TEvent, import("./types").BaseActionObject> | undefined) => ActionObject<TContext, TEvent>[];
13
12
  export declare function toActivityDefinition<TContext, TEvent extends EventObject>(action: string | ActivityDefinition<TContext, TEvent>): ActivityDefinition<TContext, TEvent>;
14
13
  /**
15
14
  * Raises an event. This places the event in the internal event queue, so that
@@ -151,5 +150,5 @@ export declare function forwardTo<TContext, TEvent extends EventObject>(target:
151
150
  */
152
151
  export declare function escalate<TContext, TEvent extends EventObject, TErrorData = any>(errorData: TErrorData | ExprWithMeta<TContext, TEvent, TErrorData>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, AnyEventObject>;
153
152
  export declare function choose<TContext, TEvent extends EventObject>(conds: Array<ChooseCondition<TContext, TEvent>>): ChooseAction<TContext, TEvent>;
154
- export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any>, currentState: State<TContext, TEvent> | undefined, currentContext: TContext, _event: SCXML.Event<TEvent>, actions: Array<ActionObject<TContext, TEvent>>, preserveActionOrder?: boolean): [Array<ActionObject<TContext, TEvent>>, TContext];
153
+ export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any, any, any>, currentState: State<TContext, TEvent> | undefined, currentContext: TContext, _event: SCXML.Event<TEvent>, actions: Array<ActionObject<TContext, TEvent>>, preserveActionOrder?: boolean): [Array<ActionObject<TContext, TEvent>>, TContext];
155
154
  //# sourceMappingURL=actions.d.ts.map
package/lib/actions.js CHANGED
@@ -292,6 +292,9 @@ var assign = function (assignment) {
292
292
  assignment: assignment
293
293
  };
294
294
  };
295
+ function isActionObject(action) {
296
+ return typeof action === 'object' && 'type' in action;
297
+ }
295
298
  /**
296
299
  * Returns an event type that represents an implicit event that
297
300
  * is sent after the specified `delay`.
@@ -516,6 +519,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
516
519
  return [resolvedActions, updatedContext];
517
520
  }
518
521
 
522
+ exports.actionTypes = actionTypes;
519
523
  exports.after = after;
520
524
  exports.assign = assign;
521
525
  exports.cancel = cancel;
@@ -527,6 +531,7 @@ exports.escalate = escalate;
527
531
  exports.forwardTo = forwardTo;
528
532
  exports.getActionFunction = getActionFunction;
529
533
  exports.initEvent = initEvent;
534
+ exports.isActionObject = isActionObject;
530
535
  exports.log = log;
531
536
  exports.pure = pure;
532
537
  exports.raise = raise;
@@ -1,4 +1,4 @@
1
- import { ActorContext, ActorRef, Behavior, EventObject } from '.';
1
+ import { ActorContext, ActorRef, Behavior, EventObject } from './types';
2
2
  /**
3
3
  * Returns an actor behavior from a reducer and its initial state.
4
4
  *
package/lib/devTools.d.ts CHANGED
@@ -1,13 +1,12 @@
1
- import { Interpreter } from '.';
2
1
  import { AnyInterpreter } from './types';
3
2
  declare type ServiceListener = (service: AnyInterpreter) => void;
4
3
  export interface XStateDevInterface {
5
- register: (service: Interpreter<any>) => void;
6
- unregister: (service: Interpreter<any>) => void;
4
+ register: (service: AnyInterpreter) => void;
5
+ unregister: (service: AnyInterpreter) => void;
7
6
  onRegister: (listener: ServiceListener) => {
8
7
  unsubscribe: () => void;
9
8
  };
10
- services: Set<Interpreter<any>>;
9
+ services: Set<AnyInterpreter>;
11
10
  }
12
11
  export declare function getGlobal(): typeof globalThis | undefined;
13
12
  export declare function registerService(service: AnyInterpreter): void;
package/lib/each.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { EventObject, SingleOrArray, ActionObject } from '.';
1
+ import { EventObject, SingleOrArray, ActionObject } from './types';
2
2
  export declare function each<TContext, TEvent extends EventObject>(collection: keyof TContext, item: keyof TContext, actions: SingleOrArray<ActionObject<TContext, TEvent>>): ActionObject<TContext, TEvent>;
3
3
  export declare function each<TContext, TEvent extends EventObject>(collection: keyof TContext, item: keyof TContext, index: keyof TContext, actions: SingleOrArray<ActionObject<TContext, TEvent>>): ActionObject<TContext, TEvent>;
4
4
  //# sourceMappingURL=each.d.ts.map
package/lib/index.d.ts CHANGED
@@ -4,29 +4,17 @@ import { StateNode } from './StateNode';
4
4
  import { State } from './State';
5
5
  import { Machine, createMachine } from './Machine';
6
6
  import { Actor } from './Actor';
7
- import { raise, send, sendParent, sendTo, sendUpdate, log, start, stop, assign, after, done, respond, doneInvoke, forwardTo, escalate, choose, pure } from './actions';
7
+ import * as actions from './actions';
8
8
  import { interpret, Interpreter, spawn, InterpreterStatus } from './interpreter';
9
9
  import { matchState } from './match';
10
- import { createSchema } from './schema';
11
- declare const actions: {
12
- raise: typeof raise;
13
- send: typeof send;
14
- sendParent: typeof sendParent;
15
- sendTo: typeof sendTo;
16
- sendUpdate: typeof sendUpdate;
17
- log: typeof log;
18
- cancel: (sendId: string | number) => import("./types").CancelAction;
19
- start: typeof start;
20
- stop: typeof stop;
21
- assign: <TContext, TEvent extends import("./types").EventObject = import("./types").EventObject>(assignment: import("./types").Assigner<TContext, TEvent> | import("./types").PropertyAssigner<TContext, TEvent>) => import("./types").AssignAction<TContext, TEvent>;
22
- after: typeof after;
23
- done: typeof done;
24
- respond: typeof respond;
25
- forwardTo: typeof forwardTo;
26
- escalate: typeof escalate;
27
- choose: typeof choose;
28
- pure: typeof pure;
29
- };
30
- export { Actor, Machine, StateNode, State, matchesState, mapState, actions, assign, send, sendParent, sendUpdate, forwardTo, interpret, Interpreter, InterpreterStatus, matchState, spawn, doneInvoke, createMachine, createSchema };
10
+ import { createSchema, t } from './schema';
11
+ declare const assign: <TContext, TEvent extends import("./types").EventObject = import("./types").EventObject>(assignment: import("./types").Assigner<TContext, TEvent> | import("./types").PropertyAssigner<TContext, TEvent>) => import("./types").AssignAction<TContext, TEvent>, send: typeof actions.send, sendParent: typeof actions.sendParent, sendUpdate: typeof actions.sendUpdate, forwardTo: typeof actions.forwardTo, doneInvoke: typeof actions.doneInvoke;
12
+ export { Actor, Machine, StateNode, State, matchesState, mapState, actions, assign, send, sendParent, sendUpdate, forwardTo, interpret, Interpreter, InterpreterStatus, matchState, spawn, doneInvoke, createMachine, createSchema, t };
31
13
  export * from './types';
14
+ export * from './typegenTypes';
15
+ declare global {
16
+ interface SymbolConstructor {
17
+ readonly observable: symbol;
18
+ }
19
+ }
32
20
  //# sourceMappingURL=index.d.ts.map
package/lib/index.js CHANGED
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var utils = require('./utils.js');
6
6
  var mapState = require('./mapState.js');
7
7
  var types = require('./types.js');
8
- var actions$1 = require('./actions.js');
8
+ var actions = require('./actions.js');
9
9
  var State = require('./State.js');
10
10
  var StateNode = require('./StateNode.js');
11
11
  var Machine = require('./Machine.js');
@@ -13,25 +13,12 @@ var interpreter = require('./interpreter.js');
13
13
  var match = require('./match.js');
14
14
  var schema = require('./schema.js');
15
15
 
16
- var actions = {
17
- raise: actions$1.raise,
18
- send: actions$1.send,
19
- sendParent: actions$1.sendParent,
20
- sendTo: actions$1.sendTo,
21
- sendUpdate: actions$1.sendUpdate,
22
- log: actions$1.log,
23
- cancel: actions$1.cancel,
24
- start: actions$1.start,
25
- stop: actions$1.stop,
26
- assign: actions$1.assign,
27
- after: actions$1.after,
28
- done: actions$1.done,
29
- respond: actions$1.respond,
30
- forwardTo: actions$1.forwardTo,
31
- escalate: actions$1.escalate,
32
- choose: actions$1.choose,
33
- pure: actions$1.pure
34
- };
16
+ var assign = actions.assign,
17
+ send = actions.send,
18
+ sendParent = actions.sendParent,
19
+ sendUpdate = actions.sendUpdate,
20
+ forwardTo = actions.forwardTo,
21
+ doneInvoke = actions.doneInvoke;
35
22
 
36
23
  exports.matchesState = utils.matchesState;
37
24
  exports.mapState = mapState.mapState;
@@ -47,12 +34,7 @@ Object.defineProperty(exports, 'SpecialTargets', {
47
34
  return types.SpecialTargets;
48
35
  }
49
36
  });
50
- exports.assign = actions$1.assign;
51
- exports.doneInvoke = actions$1.doneInvoke;
52
- exports.forwardTo = actions$1.forwardTo;
53
- exports.send = actions$1.send;
54
- exports.sendParent = actions$1.sendParent;
55
- exports.sendUpdate = actions$1.sendUpdate;
37
+ exports.actions = actions;
56
38
  exports.State = State.State;
57
39
  exports.StateNode = StateNode.StateNode;
58
40
  exports.Machine = Machine.Machine;
@@ -68,4 +50,10 @@ exports.interpret = interpreter.interpret;
68
50
  exports.spawn = interpreter.spawn;
69
51
  exports.matchState = match.matchState;
70
52
  exports.createSchema = schema.createSchema;
71
- exports.actions = actions;
53
+ exports.t = schema.t;
54
+ exports.assign = assign;
55
+ exports.doneInvoke = doneInvoke;
56
+ exports.forwardTo = forwardTo;
57
+ exports.send = send;
58
+ exports.sendParent = sendParent;
59
+ exports.sendUpdate = sendUpdate;