xstate 4.27.0 → 4.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/CHANGELOG.md +227 -90
  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/Actor.js +5 -5
  8. package/es/Machine.d.ts +5 -4
  9. package/es/State.d.ts +17 -14
  10. package/es/State.js +4 -4
  11. package/es/StateNode.d.ts +22 -17
  12. package/es/StateNode.js +33 -36
  13. package/es/actions.d.ts +3 -4
  14. package/es/actions.js +22 -3
  15. package/es/behaviors.d.ts +1 -1
  16. package/es/devTools.d.ts +3 -4
  17. package/es/each.d.ts +1 -1
  18. package/es/index.d.ts +10 -21
  19. package/es/index.js +11 -22
  20. package/es/interpreter.d.ts +34 -31
  21. package/es/interpreter.js +21 -13
  22. package/es/model.d.ts +2 -2
  23. package/es/model.types.d.ts +8 -9
  24. package/es/schema.d.ts +1 -0
  25. package/es/schema.js +2 -1
  26. package/es/scxml.d.ts +2 -2
  27. package/es/stateUtils.d.ts +6 -5
  28. package/es/typegenTypes.d.ts +121 -0
  29. package/es/types.d.ts +118 -57
  30. package/es/utils.d.ts +7 -2
  31. package/es/utils.js +9 -2
  32. package/lib/Actor.d.ts +1 -2
  33. package/lib/Actor.js +4 -4
  34. package/lib/Machine.d.ts +5 -4
  35. package/lib/State.d.ts +17 -14
  36. package/lib/State.js +4 -4
  37. package/lib/StateNode.d.ts +22 -17
  38. package/lib/StateNode.js +32 -35
  39. package/lib/actions.d.ts +3 -4
  40. package/lib/actions.js +20 -0
  41. package/lib/behaviors.d.ts +1 -1
  42. package/lib/devTools.d.ts +3 -4
  43. package/lib/each.d.ts +1 -1
  44. package/lib/index.d.ts +10 -21
  45. package/lib/index.js +15 -26
  46. package/lib/interpreter.d.ts +34 -31
  47. package/lib/interpreter.js +18 -10
  48. package/lib/model.d.ts +2 -2
  49. package/lib/model.types.d.ts +8 -9
  50. package/lib/schema.d.ts +1 -0
  51. package/lib/schema.js +2 -0
  52. package/lib/scxml.d.ts +2 -2
  53. package/lib/stateUtils.d.ts +6 -5
  54. package/lib/typegenTypes.d.ts +121 -0
  55. package/lib/typegenTypes.js +2 -0
  56. package/lib/types.d.ts +118 -57
  57. package/lib/utils.d.ts +7 -2
  58. package/lib/utils.js +10 -1
  59. package/package.json +5 -5
@@ -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;
@@ -159,29 +159,30 @@ function () {
159
159
  var _a, _b;
160
160
 
161
161
  if (utils.isMachine(invokeConfig)) {
162
- _this.machine.options.services = _tslib.__assign((_a = {}, _a[invokeConfig.id] = invokeConfig, _a), _this.machine.options.services);
162
+ var invokeId = utils.createInvokeId(_this.id, i);
163
+ _this.machine.options.services = _tslib.__assign((_a = {}, _a[invokeId] = invokeConfig, _a), _this.machine.options.services);
163
164
  return invokeUtils.toInvokeDefinition({
164
- src: invokeConfig.id,
165
- id: invokeConfig.id
165
+ src: invokeId,
166
+ id: invokeId
166
167
  });
167
168
  } else if (utils.isString(invokeConfig.src)) {
169
+ var invokeId = invokeConfig.id || utils.createInvokeId(_this.id, i);
168
170
  return invokeUtils.toInvokeDefinition(_tslib.__assign(_tslib.__assign({}, invokeConfig), {
169
- id: invokeConfig.id || invokeConfig.src,
171
+ id: invokeId,
170
172
  src: invokeConfig.src
171
173
  }));
172
174
  } else if (utils.isMachine(invokeConfig.src) || utils.isFunction(invokeConfig.src)) {
173
- var invokeSrc = "".concat(_this.id, ":invocation[").concat(i, "]"); // TODO: util function
174
-
175
- _this.machine.options.services = _tslib.__assign((_b = {}, _b[invokeSrc] = invokeConfig.src, _b), _this.machine.options.services);
175
+ var invokeId = invokeConfig.id || utils.createInvokeId(_this.id, i);
176
+ _this.machine.options.services = _tslib.__assign((_b = {}, _b[invokeId] = invokeConfig.src, _b), _this.machine.options.services);
176
177
  return invokeUtils.toInvokeDefinition(_tslib.__assign(_tslib.__assign({
177
- id: invokeSrc
178
+ id: invokeId
178
179
  }, invokeConfig), {
179
- src: invokeSrc
180
+ src: invokeId
180
181
  }));
181
182
  } else {
182
183
  var invokeSource = invokeConfig.src;
183
184
  return invokeUtils.toInvokeDefinition(_tslib.__assign(_tslib.__assign({
184
- id: invokeSource.type
185
+ id: utils.createInvokeId(_this.id, i)
185
186
  }, invokeConfig), {
186
187
  src: invokeSource
187
188
  }));
@@ -440,9 +441,10 @@ function () {
440
441
 
441
442
 
442
443
  StateNode.prototype.resolveState = function (state) {
443
- var configuration = Array.from(stateUtils.getConfiguration([], this.getStateNodes(state.value)));
444
- return new State.State(_tslib.__assign(_tslib.__assign({}, state), {
445
- 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),
446
448
  configuration: configuration,
447
449
  done: stateUtils.isInFinalState(configuration, this),
448
450
  tags: stateUtils.getTagsFromConfiguration(configuration)
@@ -826,7 +828,7 @@ function () {
826
828
  var prevConfig = stateUtils.getConfiguration([], this.getStateNodes(currentState.value));
827
829
  var resolvedConfig = stateTransition.configuration.length ? stateUtils.getConfiguration(prevConfig, stateTransition.configuration) : prevConfig;
828
830
  stateTransition.configuration = _tslib.__spreadArray([], _tslib.__read(resolvedConfig), false);
829
- return this.resolveTransition(stateTransition, currentState, _event);
831
+ return this.resolveTransition(stateTransition, currentState, currentState.context, _event);
830
832
  };
831
833
 
832
834
  StateNode.prototype.resolveRaisedTransition = function (state, _event, originalEvent) {
@@ -844,7 +846,7 @@ function () {
844
846
  return state;
845
847
  };
846
848
 
847
- StateNode.prototype.resolveTransition = function (stateTransition, currentState, _event, context) {
849
+ StateNode.prototype.resolveTransition = function (stateTransition, currentState, context, _event) {
848
850
  var e_6, _a;
849
851
 
850
852
  var _this = this;
@@ -853,10 +855,6 @@ function () {
853
855
  _event = actions.initEvent;
854
856
  }
855
857
 
856
- if (context === void 0) {
857
- context = this.machine.context;
858
- }
859
-
860
858
  var configuration = stateTransition.configuration; // Transition will "apply" if:
861
859
  // - this is the initial state (there is no current state)
862
860
  // - OR there are transitions
@@ -864,8 +862,7 @@ function () {
864
862
  var willTransition = !currentState || stateTransition.transitions.length > 0;
865
863
  var resolvedStateValue = willTransition ? stateUtils.getValue(this.machine, configuration) : undefined;
866
864
  var historyValue = currentState ? currentState.historyValue ? currentState.historyValue : stateTransition.source ? this.machine.historyValue(currentState.value) : undefined : undefined;
867
- var currentContext = currentState ? currentState.context : context;
868
- var actions$1 = this.getActions(stateTransition, currentContext, _event, currentState);
865
+ var actions$1 = this.getActions(stateTransition, context, _event, currentState);
869
866
  var activities = currentState ? _tslib.__assign({}, currentState.activities) : {};
870
867
 
871
868
  try {
@@ -890,7 +887,7 @@ function () {
890
887
  }
891
888
  }
892
889
 
893
- 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),
894
891
  resolvedActions = _b[0],
895
892
  updatedContext = _b[1];
896
893
 
@@ -909,7 +906,7 @@ function () {
909
906
  acc[action.activity.id] = Actor.createInvocableActor(action.activity, _this.machine, updatedContext, _event);
910
907
  return acc;
911
908
  }, currentState ? _tslib.__assign({}, currentState.children) : {});
912
- var resolvedConfiguration = resolvedStateValue ? stateTransition.configuration : currentState ? currentState.configuration : [];
909
+ var resolvedConfiguration = willTransition ? stateTransition.configuration : currentState ? currentState.configuration : [];
913
910
  var isDone = stateUtils.isInFinalState(resolvedConfiguration, this);
914
911
  var nextState = new State.State({
915
912
  value: resolvedStateValue || currentState.value,
@@ -929,7 +926,7 @@ function () {
929
926
  tags: currentState === null || currentState === void 0 ? void 0 : currentState.tags,
930
927
  machine: this
931
928
  });
932
- var didUpdateContext = currentContext !== updatedContext;
929
+ var didUpdateContext = context !== updatedContext;
933
930
  nextState.changed = _event.name === actionTypes.update || didUpdateContext; // Dispose of penultimate histories to prevent memory leaks
934
931
 
935
932
  var history = nextState.history;
@@ -1149,6 +1146,9 @@ function () {
1149
1146
  });
1150
1147
 
1151
1148
  StateNode.prototype.getInitialState = function (stateValue, context) {
1149
+ this._init(); // TODO: this should be in the constructor (see note in constructor)
1150
+
1151
+
1152
1152
  var configuration = this.getStateNodes(stateValue);
1153
1153
  return this.resolveTransition({
1154
1154
  configuration: configuration,
@@ -1157,7 +1157,7 @@ function () {
1157
1157
  transitions: [],
1158
1158
  source: undefined,
1159
1159
  actions: []
1160
- }, undefined, undefined, context);
1160
+ }, undefined, context !== null && context !== void 0 ? context : this.machine.context, undefined);
1161
1161
  };
1162
1162
 
1163
1163
  Object.defineProperty(StateNode.prototype, "initialState", {
@@ -1166,9 +1166,6 @@ function () {
1166
1166
  * entering the initial state.
1167
1167
  */
1168
1168
  get: function () {
1169
- this._init(); // TODO: this should be in the constructor (see note in constructor)
1170
-
1171
-
1172
1169
  var initialStateValue = this.initialStateValue;
1173
1170
 
1174
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
@@ -156,6 +156,20 @@ function sendParent(event, options) {
156
156
  to: types.SpecialTargets.Parent
157
157
  }));
158
158
  }
159
+ /**
160
+ * Sends an event to an actor.
161
+ *
162
+ * @param actor The `ActorRef` to send the event to.
163
+ * @param event The event to send, or an expression that evaluates to the event to send
164
+ * @param options Send action options
165
+ * @returns An XState send action object
166
+ */
167
+
168
+ function sendTo(actor, event, options) {
169
+ return send(event, _tslib.__assign(_tslib.__assign({}, options), {
170
+ to: actor
171
+ }));
172
+ }
159
173
  /**
160
174
  * Sends an update event to this machine's parent.
161
175
  */
@@ -278,6 +292,9 @@ var assign = function (assignment) {
278
292
  assignment: assignment
279
293
  };
280
294
  };
295
+ function isActionObject(action) {
296
+ return typeof action === 'object' && 'type' in action;
297
+ }
281
298
  /**
282
299
  * Returns an event type that represents an implicit event that
283
300
  * is sent after the specified `delay`.
@@ -502,6 +519,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
502
519
  return [resolvedActions, updatedContext];
503
520
  }
504
521
 
522
+ exports.actionTypes = actionTypes;
505
523
  exports.after = after;
506
524
  exports.assign = assign;
507
525
  exports.cancel = cancel;
@@ -513,6 +531,7 @@ exports.escalate = escalate;
513
531
  exports.forwardTo = forwardTo;
514
532
  exports.getActionFunction = getActionFunction;
515
533
  exports.initEvent = initEvent;
534
+ exports.isActionObject = isActionObject;
516
535
  exports.log = log;
517
536
  exports.pure = pure;
518
537
  exports.raise = raise;
@@ -524,6 +543,7 @@ exports.resolveStop = resolveStop;
524
543
  exports.respond = respond;
525
544
  exports.send = send;
526
545
  exports.sendParent = sendParent;
546
+ exports.sendTo = sendTo;
527
547
  exports.sendUpdate = sendUpdate;
528
548
  exports.start = start;
529
549
  exports.stop = stop;
@@ -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,28 +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, 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
- sendUpdate: typeof sendUpdate;
16
- log: typeof log;
17
- cancel: (sendId: string | number) => import("./types").CancelAction;
18
- start: typeof start;
19
- stop: typeof stop;
20
- 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>;
21
- after: typeof after;
22
- done: typeof done;
23
- respond: typeof respond;
24
- forwardTo: typeof forwardTo;
25
- escalate: typeof escalate;
26
- choose: typeof choose;
27
- pure: typeof pure;
28
- };
29
- 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 };
30
13
  export * from './types';
14
+ export * from './typegenTypes';
15
+ declare global {
16
+ interface SymbolConstructor {
17
+ readonly observable: symbol;
18
+ }
19
+ }
31
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,24 +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
- sendUpdate: actions$1.sendUpdate,
21
- log: actions$1.log,
22
- cancel: actions$1.cancel,
23
- start: actions$1.start,
24
- stop: actions$1.stop,
25
- assign: actions$1.assign,
26
- after: actions$1.after,
27
- done: actions$1.done,
28
- respond: actions$1.respond,
29
- forwardTo: actions$1.forwardTo,
30
- escalate: actions$1.escalate,
31
- choose: actions$1.choose,
32
- pure: actions$1.pure
33
- };
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;
34
22
 
35
23
  exports.matchesState = utils.matchesState;
36
24
  exports.mapState = mapState.mapState;
@@ -46,12 +34,7 @@ Object.defineProperty(exports, 'SpecialTargets', {
46
34
  return types.SpecialTargets;
47
35
  }
48
36
  });
49
- exports.assign = actions$1.assign;
50
- exports.doneInvoke = actions$1.doneInvoke;
51
- exports.forwardTo = actions$1.forwardTo;
52
- exports.send = actions$1.send;
53
- exports.sendParent = actions$1.sendParent;
54
- exports.sendUpdate = actions$1.sendUpdate;
37
+ exports.actions = actions;
55
38
  exports.State = State.State;
56
39
  exports.StateNode = StateNode.StateNode;
57
40
  exports.Machine = Machine.Machine;
@@ -67,4 +50,10 @@ exports.interpret = interpreter.interpret;
67
50
  exports.spawn = interpreter.spawn;
68
51
  exports.matchState = match.matchState;
69
52
  exports.createSchema = schema.createSchema;
70
- 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;