xstate 5.0.0-beta.16 → 5.0.0-beta.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/actions/dist/xstate-actions.cjs.js +2 -5
  2. package/actions/dist/xstate-actions.cjs.mjs +2 -5
  3. package/actions/dist/xstate-actions.development.cjs.js +2 -5
  4. package/actions/dist/xstate-actions.development.esm.js +1 -1
  5. package/actions/dist/xstate-actions.esm.js +1 -1
  6. package/actions/dist/xstate-actions.umd.min.js +1 -1
  7. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  8. package/actors/dist/xstate-actors.cjs.js +1 -1
  9. package/actors/dist/xstate-actors.development.cjs.js +1 -1
  10. package/actors/dist/xstate-actors.development.esm.js +1 -1
  11. package/actors/dist/xstate-actors.esm.js +1 -1
  12. package/actors/dist/xstate-actors.umd.min.js +1 -1
  13. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  14. package/dist/{actions-6f7fbc84.development.esm.js → actions-13190b25.development.esm.js} +677 -844
  15. package/dist/{actions-0f903c0d.development.cjs.js → actions-40bd643f.development.cjs.js} +678 -850
  16. package/dist/{actions-0386b622.esm.js → actions-4d6514d2.esm.js} +653 -847
  17. package/dist/{actions-6b9073db.cjs.js → actions-5fb9f10d.cjs.js} +654 -853
  18. package/dist/declarations/src/State.d.ts +1 -1
  19. package/dist/declarations/src/StateNode.d.ts +4 -4
  20. package/dist/declarations/src/actions/assign.d.ts +11 -2
  21. package/dist/declarations/src/actions/cancel.d.ts +14 -3
  22. package/dist/declarations/src/actions/choose.d.ts +11 -3
  23. package/dist/declarations/src/actions/log.d.ts +22 -3
  24. package/dist/declarations/src/actions/pure.d.ts +17 -3
  25. package/dist/declarations/src/actions/raise.d.ts +5 -2
  26. package/dist/declarations/src/actions/send.d.ts +58 -6
  27. package/dist/declarations/src/actions/stop.d.ts +14 -2
  28. package/dist/declarations/src/actions.d.ts +4 -7
  29. package/dist/declarations/src/constantPrefixes.d.ts +6 -0
  30. package/dist/declarations/src/interpreter.d.ts +8 -3
  31. package/dist/declarations/src/stateUtils.d.ts +4 -8
  32. package/dist/declarations/src/types.d.ts +22 -187
  33. package/dist/declarations/src/utils.d.ts +1 -6
  34. package/dist/xstate.cjs.js +42 -19
  35. package/dist/xstate.cjs.mjs +1 -1
  36. package/dist/xstate.development.cjs.js +42 -19
  37. package/dist/xstate.development.esm.js +42 -19
  38. package/dist/xstate.esm.js +42 -19
  39. package/dist/xstate.umd.min.js +1 -1
  40. package/dist/xstate.umd.min.js.map +1 -1
  41. package/guards/dist/xstate-guards.cjs.js +1 -1
  42. package/guards/dist/xstate-guards.development.cjs.js +1 -1
  43. package/guards/dist/xstate-guards.development.esm.js +1 -1
  44. package/guards/dist/xstate-guards.esm.js +1 -1
  45. package/guards/dist/xstate-guards.umd.min.js +1 -1
  46. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  47. package/package.json +1 -1
  48. package/actions/dynamicAction.ts +0 -42
  49. package/dist/declarations/src/actionTypes.d.ts +0 -16
  50. package/dist/declarations/src/constants.d.ts +0 -5
@@ -17,12 +17,6 @@ var dev_dist_xstateDev = require('../dev/dist/xstate-dev.cjs.js');
17
17
 
18
18
  // TODO: narrow this to logic from machine
19
19
 
20
- // TODO: fix last param
21
-
22
- /**
23
- * Extracts action objects that have no extra properties.
24
- */
25
-
26
20
  /**
27
21
  * The string or object representing the state value relative to the parent state node.
28
22
  *
@@ -34,25 +28,15 @@ var dev_dist_xstateDev = require('../dev/dist/xstate-dev.cjs.js');
34
28
 
35
29
  // TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
36
30
 
37
- let ActionTypes = /*#__PURE__*/function (ActionTypes) {
38
- ActionTypes["Stop"] = "xstate.stop";
39
- ActionTypes["Raise"] = "xstate.raise";
40
- ActionTypes["SendTo"] = "xstate.sendTo";
41
- ActionTypes["Cancel"] = "xstate.cancel";
42
- ActionTypes["Assign"] = "xstate.assign";
43
- ActionTypes["After"] = "xstate.after";
44
- ActionTypes["DoneState"] = "done.state";
45
- ActionTypes["DoneInvoke"] = "done.invoke";
46
- ActionTypes["Log"] = "xstate.log";
47
- ActionTypes["Init"] = "xstate.init";
48
- ActionTypes["Invoke"] = "xstate.invoke";
49
- ActionTypes["ErrorExecution"] = "error.execution";
50
- ActionTypes["ErrorCommunication"] = "error.communication";
51
- ActionTypes["ErrorPlatform"] = "error.platform";
52
- ActionTypes["ErrorCustom"] = "xstate.error";
53
- ActionTypes["Pure"] = "xstate.pure";
54
- ActionTypes["Choose"] = "xstate.choose";
55
- return ActionTypes;
31
+ let ConstantPrefix = /*#__PURE__*/function (ConstantPrefix) {
32
+ ConstantPrefix["After"] = "xstate.after";
33
+ ConstantPrefix["DoneState"] = "done.state";
34
+ ConstantPrefix["DoneInvoke"] = "done.invoke";
35
+ ConstantPrefix["ErrorExecution"] = "error.execution";
36
+ ConstantPrefix["ErrorCommunication"] = "error.communication";
37
+ ConstantPrefix["ErrorPlatform"] = "error.platform";
38
+ ConstantPrefix["ErrorCustom"] = "xstate.error";
39
+ return ConstantPrefix;
56
40
  }({});
57
41
  let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
58
42
  SpecialTargets["Parent"] = "#_parent";
@@ -60,40 +44,19 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
60
44
  return SpecialTargets;
61
45
  }({});
62
46
 
63
- // xstate-specific action types
64
- const stop$1 = ActionTypes.Stop;
65
- const raise$1 = ActionTypes.Raise;
66
- const sendTo$1 = ActionTypes.SendTo;
67
- const cancel$1 = ActionTypes.Cancel;
68
- const assign$1 = ActionTypes.Assign;
69
- const after$1 = ActionTypes.After;
70
- const doneState = ActionTypes.DoneState;
71
- const log$1 = ActionTypes.Log;
72
- const init = ActionTypes.Init;
73
- const invoke$1 = ActionTypes.Invoke;
74
- const errorExecution = ActionTypes.ErrorExecution;
75
- const errorPlatform = ActionTypes.ErrorPlatform;
76
- const error$1 = ActionTypes.ErrorCustom;
77
- const choose$1 = ActionTypes.Choose;
78
- const pure$1 = ActionTypes.Pure;
79
-
80
- var actionTypes = /*#__PURE__*/Object.freeze({
47
+ const after$1 = ConstantPrefix.After;
48
+ const doneState = ConstantPrefix.DoneState;
49
+ const errorExecution = ConstantPrefix.ErrorExecution;
50
+ const errorPlatform = ConstantPrefix.ErrorPlatform;
51
+ const error$1 = ConstantPrefix.ErrorCustom;
52
+
53
+ var constantPrefixes = /*#__PURE__*/Object.freeze({
81
54
  __proto__: null,
82
- stop: stop$1,
83
- raise: raise$1,
84
- sendTo: sendTo$1,
85
- cancel: cancel$1,
86
- assign: assign$1,
87
55
  after: after$1,
88
56
  doneState: doneState,
89
- log: log$1,
90
- init: init,
91
- invoke: invoke$1,
92
57
  errorExecution: errorExecution,
93
58
  errorPlatform: errorPlatform,
94
- error: error$1,
95
- choose: choose$1,
96
- pure: pure$1
59
+ error: error$1
97
60
  });
98
61
 
99
62
  const STATE_DELIMITER = '.';
@@ -101,208 +64,68 @@ const TARGETLESS_KEY = '';
101
64
  const NULL_EVENT = '';
102
65
  const STATE_IDENTIFIER = '#';
103
66
  const WILDCARD = '*';
104
-
105
- function matchesState(parentStateId, childStateId) {
106
- const parentStateValue = toStateValue(parentStateId);
107
- const childStateValue = toStateValue(childStateId);
108
- if (isString(childStateValue)) {
109
- if (isString(parentStateValue)) {
110
- return childStateValue === parentStateValue;
111
- }
112
-
113
- // Parent more specific than child
114
- return false;
115
- }
116
- if (isString(parentStateValue)) {
117
- return parentStateValue in childStateValue;
118
- }
119
- return Object.keys(parentStateValue).every(key => {
120
- if (!(key in childStateValue)) {
121
- return false;
122
- }
123
- return matchesState(parentStateValue[key], childStateValue[key]);
124
- });
125
- }
126
- function toStatePath(stateId) {
127
- try {
128
- if (isArray(stateId)) {
129
- return stateId;
130
- }
131
- return stateId.toString().split(STATE_DELIMITER);
132
- } catch (e) {
133
- throw new Error(`'${stateId}' is not a valid state path.`);
134
- }
135
- }
136
- function isStateLike(state) {
137
- return typeof state === 'object' && 'value' in state && 'context' in state && 'event' in state;
138
- }
139
- function toStateValue(stateValue) {
140
- if (isStateLike(stateValue)) {
141
- return stateValue.value;
142
- }
143
- if (isArray(stateValue)) {
144
- return pathToStateValue(stateValue);
145
- }
146
- if (typeof stateValue !== 'string') {
147
- return stateValue;
148
- }
149
- const statePath = toStatePath(stateValue);
150
- return pathToStateValue(statePath);
151
- }
152
- function pathToStateValue(statePath) {
153
- if (statePath.length === 1) {
154
- return statePath[0];
155
- }
156
- const value = {};
157
- let marker = value;
158
- for (let i = 0; i < statePath.length - 1; i++) {
159
- if (i === statePath.length - 2) {
160
- marker[statePath[i]] = statePath[i + 1];
67
+ const INIT_TYPE = 'xstate.init';
68
+
69
+ function resolve$8(actorContext, state, args, {
70
+ to,
71
+ event: eventOrExpr,
72
+ id,
73
+ delay
74
+ }) {
75
+ const delaysMap = state.machine.implementations.delays;
76
+ if (typeof eventOrExpr === 'string') {
77
+ throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${eventOrExpr}" }) instead`);
78
+ }
79
+ const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args) : eventOrExpr;
80
+ let resolvedDelay;
81
+ if (typeof delay === 'string') {
82
+ const configDelay = delaysMap && delaysMap[delay];
83
+ resolvedDelay = typeof configDelay === 'function' ? configDelay(args) : configDelay;
84
+ } else {
85
+ resolvedDelay = typeof delay === 'function' ? delay(args) : delay;
86
+ }
87
+ const resolvedTarget = typeof to === 'function' ? to(args) : to;
88
+ let targetActorRef;
89
+ if (typeof resolvedTarget === 'string') {
90
+ if (resolvedTarget === SpecialTargets.Parent) {
91
+ targetActorRef = actorContext?.self._parent;
92
+ } else if (resolvedTarget === SpecialTargets.Internal) {
93
+ targetActorRef = actorContext?.self;
94
+ } else if (resolvedTarget.startsWith('#_')) {
95
+ // SCXML compatibility: https://www.w3.org/TR/scxml/#SCXMLEventProcessor
96
+ // #_invokeid. If the target is the special term '#_invokeid', where invokeid is the invokeid of an SCXML session that the sending session has created by <invoke>, the Processor must add the event to the external queue of that session.
97
+ targetActorRef = state.children[resolvedTarget.slice(2)];
161
98
  } else {
162
- const previous = marker;
163
- marker = {};
164
- previous[statePath[i]] = marker;
99
+ targetActorRef = state.children[resolvedTarget];
165
100
  }
166
- }
167
- return value;
168
- }
169
- function mapValues(collection, iteratee) {
170
- const result = {};
171
- const collectionKeys = Object.keys(collection);
172
- for (let i = 0; i < collectionKeys.length; i++) {
173
- const key = collectionKeys[i];
174
- result[key] = iteratee(collection[key], key, collection, i);
175
- }
176
- return result;
177
- }
178
- function flatten(array) {
179
- return [].concat(...array);
180
- }
181
- function toArrayStrict(value) {
182
- if (isArray(value)) {
183
- return value;
184
- }
185
- return [value];
186
- }
187
- function toArray(value) {
188
- if (value === undefined) {
189
- return [];
190
- }
191
- return toArrayStrict(value);
192
- }
193
- function mapContext(mapper, context, event) {
194
- if (isFunction(mapper)) {
195
- return mapper({
196
- context,
197
- event
198
- });
199
- }
200
- const result = {};
201
- const args = {
202
- context,
203
- event
204
- };
205
- for (const key of Object.keys(mapper)) {
206
- const subMapper = mapper[key];
207
- if (isFunction(subMapper)) {
208
- result[key] = subMapper(args);
209
- } else {
210
- result[key] = subMapper;
101
+ if (!targetActorRef) {
102
+ throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${state.machine.id}'.`);
211
103
  }
104
+ } else {
105
+ targetActorRef = resolvedTarget || actorContext?.self;
212
106
  }
213
- return result;
107
+ return [state, {
108
+ to: targetActorRef,
109
+ event: resolvedEvent,
110
+ id,
111
+ delay: resolvedDelay
112
+ }];
214
113
  }
215
- function isPromiseLike(value) {
216
- if (value instanceof Promise) {
217
- return true;
218
- }
219
- // Check if shape matches the Promise/A+ specification for a "thenable".
220
- if (value !== null && (isFunction(value) || typeof value === 'object') && isFunction(value.then)) {
221
- return true;
114
+ function execute$5(actorContext, params) {
115
+ if (typeof params.delay === 'number') {
116
+ actorContext.self.delaySend(params);
117
+ return;
222
118
  }
223
- return false;
224
- }
225
- function isArray(value) {
226
- return Array.isArray(value);
227
- }
228
-
229
- // tslint:disable-next-line:ban-types
230
- function isFunction(value) {
231
- return typeof value === 'function';
232
- }
233
- function isString(value) {
234
- return typeof value === 'string';
235
- }
236
- function isErrorEvent(event) {
237
- return typeof event.type === 'string' && (event.type === errorExecution || event.type.startsWith(errorPlatform));
238
- }
239
- function toTransitionConfigArray(event, configLike) {
240
- const transitions = toArrayStrict(configLike).map(transitionLike => {
241
- if (typeof transitionLike === 'undefined' || typeof transitionLike === 'string') {
242
- return {
243
- target: transitionLike,
244
- event
245
- };
246
- }
247
- return {
248
- ...transitionLike,
249
- event
250
- };
119
+ const {
120
+ to,
121
+ event
122
+ } = params;
123
+ actorContext.defer(() => {
124
+ to.send(event.type === error$1 ? {
125
+ type: `${error(actorContext.self.id)}`,
126
+ data: event.data
127
+ } : event);
251
128
  });
252
- return transitions;
253
- }
254
- function normalizeTarget(target) {
255
- if (target === undefined || target === TARGETLESS_KEY) {
256
- return undefined;
257
- }
258
- return toArray(target);
259
- }
260
- function toInvokeConfig(invocable, id) {
261
- if (typeof invocable === 'object') {
262
- if ('src' in invocable) {
263
- return invocable;
264
- }
265
- if ('transition' in invocable) {
266
- return {
267
- id,
268
- src: invocable
269
- };
270
- }
271
- }
272
- return {
273
- id,
274
- src: invocable
275
- };
276
- }
277
- function toObserver(nextHandler, errorHandler, completionHandler) {
278
- const noop = () => {};
279
- const isObserver = typeof nextHandler === 'object';
280
- const self = isObserver ? nextHandler : null;
281
- return {
282
- next: ((isObserver ? nextHandler.next : nextHandler) || noop).bind(self),
283
- error: ((isObserver ? nextHandler.error : errorHandler) || noop).bind(self),
284
- complete: ((isObserver ? nextHandler.complete : completionHandler) || noop).bind(self)
285
- };
286
- }
287
- function createInvokeId(stateNodeId, index) {
288
- return `${stateNodeId}:invocation[${index}]`;
289
- }
290
- function resolveReferencedActor(referenced) {
291
- return referenced ? 'transition' in referenced ? {
292
- src: referenced,
293
- input: undefined
294
- } : referenced : undefined;
295
- }
296
-
297
- function createDynamicAction(action, resolve) {
298
- return {
299
- type: action.type,
300
- params: action.params,
301
- resolve
302
- };
303
- }
304
- function isDynamicAction(action) {
305
- return typeof action === 'object' && action !== null && 'resolve' in action;
306
129
  }
307
130
 
308
131
  /**
@@ -314,94 +137,17 @@ function isDynamicAction(action) {
314
137
  * - `id` - The unique send event identifier (used with `cancel()`).
315
138
  * - `delay` - The number of milliseconds to delay the sending of the event.
316
139
  */
317
- function sendTo(actor, eventOrExpr, options) {
318
- return createDynamicAction({
319
- type: sendTo$1,
320
- params: {
321
- to: actor,
322
- delay: options ? options.delay : undefined,
323
- event: eventOrExpr,
324
- id: options && options.id !== undefined ? options.id : isFunction(eventOrExpr) ? eventOrExpr.name : eventOrExpr.type
325
- }
326
- }, (event, {
327
- actorContext,
328
- state
329
- }) => {
330
- const params = {
331
- to: actor,
332
- delay: options ? options.delay : undefined,
333
- event: eventOrExpr,
334
- // TODO: don't auto-generate IDs here like that
335
- // there is too big chance of the ID collision
336
- id: options && options.id !== undefined ? options.id : isFunction(eventOrExpr) ? eventOrExpr.name : eventOrExpr.type
337
- };
338
- const args = {
339
- context: state.context,
340
- event,
341
- self: actorContext?.self ?? null,
342
- system: actorContext?.system
343
- };
344
- const delaysMap = state.machine.implementations.delays;
345
-
346
- // TODO: helper function for resolving Expr
347
- if (typeof eventOrExpr === 'string') {
348
- throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${eventOrExpr}" }) instead`);
349
- }
350
- const resolvedEvent = isFunction(eventOrExpr) ? eventOrExpr(args) : eventOrExpr;
351
- let resolvedDelay;
352
- if (isString(params.delay)) {
353
- const configDelay = delaysMap && delaysMap[params.delay];
354
- resolvedDelay = isFunction(configDelay) ? configDelay(args) : configDelay;
355
- } else {
356
- resolvedDelay = isFunction(params.delay) ? params.delay(args) : params.delay;
357
- }
358
- const resolvedTarget = isFunction(params.to) ? params.to(args) : params.to;
359
- let targetActorRef;
360
- if (typeof resolvedTarget === 'string') {
361
- if (resolvedTarget === SpecialTargets.Parent) {
362
- targetActorRef = actorContext?.self._parent;
363
- } else if (resolvedTarget === SpecialTargets.Internal) {
364
- targetActorRef = actorContext?.self;
365
- } else if (resolvedTarget.startsWith('#_')) {
366
- // SCXML compatibility: https://www.w3.org/TR/scxml/#SCXMLEventProcessor
367
- // #_invokeid. If the target is the special term '#_invokeid', where invokeid is the invokeid of an SCXML session that the sending session has created by <invoke>, the Processor must add the event to the external queue of that session.
368
- targetActorRef = state.children[resolvedTarget.slice(2)];
369
- } else {
370
- targetActorRef = state.children[resolvedTarget];
371
- }
372
- if (!targetActorRef) {
373
- throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${state.machine.id}'.`);
374
- }
375
- } else {
376
- targetActorRef = resolvedTarget || actorContext?.self;
377
- }
378
- const resolvedAction = {
379
- type: sendTo$1,
380
- params: {
381
- ...params,
382
- to: targetActorRef,
383
- event: resolvedEvent,
384
- delay: resolvedDelay
385
- },
386
- execute: actorCtx => {
387
- const sendAction = resolvedAction;
388
- if (typeof sendAction.params.delay === 'number') {
389
- actorCtx.self.delaySend(sendAction);
390
- return;
391
- } else {
392
- const target = sendAction.params.to;
393
- const sentEvent = sendAction.params.event;
394
- actorCtx.defer(() => {
395
- target.send(sentEvent.type === error$1 ? {
396
- type: `${error(actorCtx.self.id)}`,
397
- data: sentEvent.data
398
- } : sendAction.params.event);
399
- });
400
- }
401
- }
402
- };
403
- return [state, resolvedAction];
404
- });
140
+ function sendTo(to, eventOrExpr, options) {
141
+ function sendTo(_) {
142
+ }
143
+ sendTo.type = 'xstate.sendTo';
144
+ sendTo.to = to;
145
+ sendTo.event = eventOrExpr;
146
+ sendTo.id = options?.id;
147
+ sendTo.delay = options?.delay;
148
+ sendTo.resolve = resolve$8;
149
+ sendTo.execute = execute$5;
150
+ return sendTo;
405
151
  }
406
152
 
407
153
  /**
@@ -436,7 +182,7 @@ function escalate(errorData, options) {
436
182
  return sendParent(arg => {
437
183
  return {
438
184
  type: error$1,
439
- data: isFunction(errorData) ? errorData(arg) : errorData
185
+ data: typeof errorData === 'function' ? errorData(arg) : errorData
440
186
  };
441
187
  }, options);
442
188
  }
@@ -455,6 +201,16 @@ function memo(object, key, fn) {
455
201
  return memoizedData[key];
456
202
  }
457
203
 
204
+ function resolve$7(_, state, actionArgs, {
205
+ sendId
206
+ }) {
207
+ const resolvedSendId = typeof sendId === 'function' ? sendId(actionArgs) : sendId;
208
+ return [state, resolvedSendId];
209
+ }
210
+ function execute$4(actorContext, resolvedSendId) {
211
+ actorContext.self.cancel(resolvedSendId);
212
+ }
213
+
458
214
  /**
459
215
  * Cancels an in-flight `send(...)` action. A canceled sent action will not
460
216
  * be executed, nor will its event be sent, unless it has already been sent
@@ -462,34 +218,14 @@ function memo(object, key, fn) {
462
218
  *
463
219
  * @param sendId The `id` of the `send(...)` action to cancel.
464
220
  */
465
-
466
221
  function cancel(sendId) {
467
- return createDynamicAction({
468
- type: cancel$1,
469
- params: {
470
- sendId
471
- }
472
- }, (event, {
473
- state,
474
- actorContext
475
- }) => {
476
- const resolvedSendId = isFunction(sendId) ? sendId({
477
- context: state.context,
478
- event,
479
- self: actorContext?.self ?? {},
480
- system: actorContext?.system
481
- }) : sendId;
482
- return [state, {
483
- type: 'xstate.cancel',
484
- params: {
485
- sendId: resolvedSendId
486
- },
487
- execute: actorCtx => {
488
- const interpreter = actorCtx.self;
489
- interpreter.cancel(resolvedSendId);
490
- }
491
- }];
492
- });
222
+ function cancel(_) {
223
+ }
224
+ cancel.type = 'xstate.cancel';
225
+ cancel.sendId = sendId;
226
+ cancel.resolve = resolve$7;
227
+ cancel.execute = execute$4;
228
+ return cancel;
493
229
  }
494
230
 
495
231
  class Mailbox {
@@ -889,7 +625,186 @@ function fromEventObservable(lazyObservable) {
889
625
  subscription: undefined
890
626
  })
891
627
  };
892
- return logic;
628
+ return logic;
629
+ }
630
+
631
+ function matchesState(parentStateId, childStateId) {
632
+ const parentStateValue = toStateValue(parentStateId);
633
+ const childStateValue = toStateValue(childStateId);
634
+ if (typeof childStateValue === 'string') {
635
+ if (typeof parentStateValue === 'string') {
636
+ return childStateValue === parentStateValue;
637
+ }
638
+
639
+ // Parent more specific than child
640
+ return false;
641
+ }
642
+ if (typeof parentStateValue === 'string') {
643
+ return parentStateValue in childStateValue;
644
+ }
645
+ return Object.keys(parentStateValue).every(key => {
646
+ if (!(key in childStateValue)) {
647
+ return false;
648
+ }
649
+ return matchesState(parentStateValue[key], childStateValue[key]);
650
+ });
651
+ }
652
+ function toStatePath(stateId) {
653
+ try {
654
+ if (isArray(stateId)) {
655
+ return stateId;
656
+ }
657
+ return stateId.toString().split(STATE_DELIMITER);
658
+ } catch (e) {
659
+ throw new Error(`'${stateId}' is not a valid state path.`);
660
+ }
661
+ }
662
+ function isStateLike(state) {
663
+ return typeof state === 'object' && 'value' in state && 'context' in state && 'event' in state;
664
+ }
665
+ function toStateValue(stateValue) {
666
+ if (isStateLike(stateValue)) {
667
+ return stateValue.value;
668
+ }
669
+ if (isArray(stateValue)) {
670
+ return pathToStateValue(stateValue);
671
+ }
672
+ if (typeof stateValue !== 'string') {
673
+ return stateValue;
674
+ }
675
+ const statePath = toStatePath(stateValue);
676
+ return pathToStateValue(statePath);
677
+ }
678
+ function pathToStateValue(statePath) {
679
+ if (statePath.length === 1) {
680
+ return statePath[0];
681
+ }
682
+ const value = {};
683
+ let marker = value;
684
+ for (let i = 0; i < statePath.length - 1; i++) {
685
+ if (i === statePath.length - 2) {
686
+ marker[statePath[i]] = statePath[i + 1];
687
+ } else {
688
+ const previous = marker;
689
+ marker = {};
690
+ previous[statePath[i]] = marker;
691
+ }
692
+ }
693
+ return value;
694
+ }
695
+ function mapValues(collection, iteratee) {
696
+ const result = {};
697
+ const collectionKeys = Object.keys(collection);
698
+ for (let i = 0; i < collectionKeys.length; i++) {
699
+ const key = collectionKeys[i];
700
+ result[key] = iteratee(collection[key], key, collection, i);
701
+ }
702
+ return result;
703
+ }
704
+ function flatten(array) {
705
+ return [].concat(...array);
706
+ }
707
+ function toArrayStrict(value) {
708
+ if (isArray(value)) {
709
+ return value;
710
+ }
711
+ return [value];
712
+ }
713
+ function toArray(value) {
714
+ if (value === undefined) {
715
+ return [];
716
+ }
717
+ return toArrayStrict(value);
718
+ }
719
+ function mapContext(mapper, context, event) {
720
+ if (typeof mapper === 'function') {
721
+ return mapper({
722
+ context,
723
+ event
724
+ });
725
+ }
726
+ const result = {};
727
+ const args = {
728
+ context,
729
+ event
730
+ };
731
+ for (const key of Object.keys(mapper)) {
732
+ const subMapper = mapper[key];
733
+ if (typeof subMapper === 'function') {
734
+ result[key] = subMapper(args);
735
+ } else {
736
+ result[key] = subMapper;
737
+ }
738
+ }
739
+ return result;
740
+ }
741
+ function isPromiseLike(value) {
742
+ if (value instanceof Promise) {
743
+ return true;
744
+ }
745
+ // Check if shape matches the Promise/A+ specification for a "thenable".
746
+ if (value !== null && (typeof value === 'function' || typeof value === 'object') && typeof value.then === 'function') {
747
+ return true;
748
+ }
749
+ return false;
750
+ }
751
+ function isArray(value) {
752
+ return Array.isArray(value);
753
+ }
754
+ function isErrorEvent(event) {
755
+ return typeof event.type === 'string' && (event.type === errorExecution || event.type.startsWith(errorPlatform));
756
+ }
757
+ function toTransitionConfigArray(configLike) {
758
+ return toArrayStrict(configLike).map(transitionLike => {
759
+ if (typeof transitionLike === 'undefined' || typeof transitionLike === 'string') {
760
+ return {
761
+ target: transitionLike
762
+ };
763
+ }
764
+ return transitionLike;
765
+ });
766
+ }
767
+ function normalizeTarget(target) {
768
+ if (target === undefined || target === TARGETLESS_KEY) {
769
+ return undefined;
770
+ }
771
+ return toArray(target);
772
+ }
773
+ function toInvokeConfig(invocable, id) {
774
+ if (typeof invocable === 'object') {
775
+ if ('src' in invocable) {
776
+ return invocable;
777
+ }
778
+ if ('transition' in invocable) {
779
+ return {
780
+ id,
781
+ src: invocable
782
+ };
783
+ }
784
+ }
785
+ return {
786
+ id,
787
+ src: invocable
788
+ };
789
+ }
790
+ function toObserver(nextHandler, errorHandler, completionHandler) {
791
+ const noop = () => {};
792
+ const isObserver = typeof nextHandler === 'object';
793
+ const self = isObserver ? nextHandler : null;
794
+ return {
795
+ next: ((isObserver ? nextHandler.next : nextHandler) || noop).bind(self),
796
+ error: ((isObserver ? nextHandler.error : errorHandler) || noop).bind(self),
797
+ complete: ((isObserver ? nextHandler.complete : completionHandler) || noop).bind(self)
798
+ };
799
+ }
800
+ function createInvokeId(stateNodeId, index) {
801
+ return `${stateNodeId}:invocation[${index}]`;
802
+ }
803
+ function resolveReferencedActor(referenced) {
804
+ return referenced ? 'transition' in referenced ? {
805
+ src: referenced,
806
+ input: undefined
807
+ } : referenced : undefined;
893
808
  }
894
809
 
895
810
  function fromCallback(invokeCallback) {
@@ -934,7 +849,7 @@ function fromCallback(invokeCallback) {
934
849
  }
935
850
  if (event.type === stopSignalType) {
936
851
  state.canceled = true;
937
- if (isFunction(state.dispose)) {
852
+ if (typeof state.dispose === 'function') {
938
853
  state.dispose();
939
854
  }
940
855
  return state;
@@ -1335,14 +1250,24 @@ class Interpreter {
1335
1250
  }
1336
1251
 
1337
1252
  // TODO: make private (and figure out a way to do this within the machine)
1338
- delaySend(sendAction) {
1339
- this.delayedEventsMap[sendAction.params.id] = this.clock.setTimeout(() => {
1340
- if ('to' in sendAction.params && sendAction.params.to) {
1341
- sendAction.params.to.send(sendAction.params.event);
1253
+ delaySend({
1254
+ event,
1255
+ id,
1256
+ delay,
1257
+ to
1258
+ }) {
1259
+ const timerId = this.clock.setTimeout(() => {
1260
+ if (to) {
1261
+ to.send(event);
1342
1262
  } else {
1343
- this.send(sendAction.params.event);
1263
+ this.send(event);
1344
1264
  }
1345
- }, sendAction.params.delay);
1265
+ }, delay);
1266
+
1267
+ // TODO: consider the rehydration story here
1268
+ if (id) {
1269
+ this.delayedEventsMap[id] = timerId;
1270
+ }
1346
1271
  }
1347
1272
 
1348
1273
  // TODO: make private (and figure out a way to do this within the machine)
@@ -1387,78 +1312,75 @@ function interpret(logic, options) {
1387
1312
  return interpreter;
1388
1313
  }
1389
1314
 
1390
- function invoke(invokeDef) {
1391
- return createDynamicAction({
1392
- type: invoke$1,
1393
- params: invokeDef
1394
- }, (event, {
1395
- state,
1396
- actorContext
1397
- }) => {
1398
- const type = invoke$1;
1399
- const {
1315
+ function resolve$6(actorContext, state, actionArgs, {
1316
+ id,
1317
+ systemId,
1318
+ src,
1319
+ input
1320
+ }) {
1321
+ const referenced = resolveReferencedActor(state.machine.implementations.actors[src]);
1322
+ let actorRef;
1323
+ if (referenced) {
1324
+ // TODO: inline `input: undefined` should win over the referenced one
1325
+ const configuredInput = input || referenced.input;
1326
+ actorRef = interpret(referenced.src, {
1400
1327
  id,
1401
- src
1402
- } = invokeDef;
1403
- let resolvedInvokeAction;
1404
- const referenced = resolveReferencedActor(state.machine.implementations.actors[src]);
1405
- if (!referenced) {
1406
- resolvedInvokeAction = {
1407
- type,
1408
- params: invokeDef
1409
- };
1410
- } else {
1411
- const input = 'input' in invokeDef ? invokeDef.input : referenced.input;
1412
- const ref = interpret(referenced.src, {
1413
- id,
1414
- src,
1415
- parent: actorContext?.self,
1416
- systemId: invokeDef.systemId,
1417
- input: typeof input === 'function' ? input({
1418
- context: state.context,
1419
- event,
1420
- self: actorContext?.self
1421
- }) : input
1422
- });
1423
- resolvedInvokeAction = {
1424
- type,
1425
- params: {
1426
- ...invokeDef,
1427
- ref
1428
- }
1429
- };
1430
- }
1431
- const actorRef = resolvedInvokeAction.params.ref;
1432
- const invokedState = cloneState(state, {
1433
- children: {
1434
- ...state.children,
1435
- [id]: actorRef
1436
- }
1328
+ src,
1329
+ parent: actorContext?.self,
1330
+ systemId,
1331
+ input: typeof configuredInput === 'function' ? configuredInput({
1332
+ context: state.context,
1333
+ event: actionArgs.event,
1334
+ self: actorContext?.self
1335
+ }) : configuredInput
1437
1336
  });
1438
- resolvedInvokeAction.execute = actorCtx => {
1439
- const parent = actorCtx.self;
1440
- const {
1441
- id,
1442
- ref
1443
- } = resolvedInvokeAction.params;
1444
- if (!ref) {
1445
- return;
1446
- }
1447
- actorCtx.defer(() => {
1448
- if (actorRef.status === ActorStatus.Stopped) {
1449
- return;
1450
- }
1451
- try {
1452
- actorRef.start?.();
1453
- } catch (err) {
1454
- parent.send(error(id, err));
1455
- return;
1456
- }
1457
- });
1458
- };
1459
- return [invokedState, resolvedInvokeAction];
1337
+ }
1338
+ return [cloneState(state, {
1339
+ children: {
1340
+ ...state.children,
1341
+ [id]: actorRef
1342
+ }
1343
+ }), {
1344
+ id,
1345
+ actorRef
1346
+ }];
1347
+ }
1348
+ function execute$3(actorContext, {
1349
+ id,
1350
+ actorRef
1351
+ }) {
1352
+ if (!actorRef) {
1353
+ return;
1354
+ }
1355
+ actorContext.defer(() => {
1356
+ if (actorRef.status === ActorStatus.Stopped) {
1357
+ return;
1358
+ }
1359
+ try {
1360
+ actorRef.start?.();
1361
+ } catch (err) {
1362
+ actorContext.self.send(error(id, err));
1363
+ return;
1364
+ }
1460
1365
  });
1461
1366
  }
1367
+ function invoke({
1368
+ id,
1369
+ systemId,
1370
+ src,
1371
+ input
1372
+ }) {
1373
+ function invoke(_) {
1374
+ }
1375
+ invoke.type = 'xstate.invoke';
1376
+ invoke.id = id;
1377
+ invoke.systemId = systemId;
1378
+ invoke.src = src;
1379
+ invoke.input = input;
1380
+ invoke.resolve = resolve$6;
1381
+ invoke.execute = execute$3;
1382
+ return invoke;
1383
+ }
1462
1384
 
1463
1385
  function stateIn(stateValue) {
1464
1386
  return {
@@ -1469,7 +1391,7 @@ function stateIn(stateValue) {
1469
1391
  predicate: ({
1470
1392
  state
1471
1393
  }) => {
1472
- if (isString(stateValue) && isStateId(stateValue)) {
1394
+ if (typeof stateValue === 'string' && isStateId(stateValue)) {
1473
1395
  return state.configuration.some(sn => sn.id === stateValue.slice(1));
1474
1396
  }
1475
1397
  return state.matches(stateValue);
@@ -1553,9 +1475,9 @@ function evaluateGuard(guard, context, event, state) {
1553
1475
  function toGuardDefinition(guardConfig, getPredicate) {
1554
1476
  // TODO: check for cycles and consider a refactor to more lazily evaluated guards
1555
1477
  // TODO: resolve this more recursively: https://github.com/statelyai/xstate/pull/4064#discussion_r1229915724
1556
- if (isString(guardConfig)) {
1478
+ if (typeof guardConfig === 'string') {
1557
1479
  const predicateOrDef = getPredicate?.(guardConfig);
1558
- if (isFunction(predicateOrDef)) {
1480
+ if (typeof predicateOrDef === 'function') {
1559
1481
  return {
1560
1482
  type: guardConfig,
1561
1483
  predicate: predicateOrDef,
@@ -1574,7 +1496,7 @@ function toGuardDefinition(guardConfig, getPredicate) {
1574
1496
  };
1575
1497
  }
1576
1498
  }
1577
- if (isFunction(guardConfig)) {
1499
+ if (typeof guardConfig === 'function') {
1578
1500
  return {
1579
1501
  type: guardConfig.name,
1580
1502
  predicate: guardConfig,
@@ -1585,7 +1507,7 @@ function toGuardDefinition(guardConfig, getPredicate) {
1585
1507
  };
1586
1508
  }
1587
1509
  const predicateOrDef = getPredicate?.(guardConfig.type);
1588
- if (isFunction(predicateOrDef)) {
1510
+ if (typeof predicateOrDef === 'function') {
1589
1511
  return {
1590
1512
  type: guardConfig.type,
1591
1513
  params: guardConfig.params || guardConfig,
@@ -1712,24 +1634,16 @@ function isInFinalState(configuration, stateNode = configuration[0].machine.root
1712
1634
  }
1713
1635
  const isStateId = str => str[0] === STATE_IDENTIFIER;
1714
1636
  function getCandidates(stateNode, receivedEventType) {
1715
- const candidates = stateNode.transitions.filter(transition => {
1716
- const {
1717
- eventType
1718
- } = transition;
1719
- // First, check the trivial case: event names are exactly equal
1720
- if (eventType === receivedEventType) {
1721
- return true;
1722
- }
1723
-
1724
- // Then, check if transition is a wildcard transition,
1637
+ const candidates = stateNode.transitions.get(receivedEventType) || [...stateNode.transitions.keys()].filter(descriptor => {
1638
+ // check if transition is a wildcard transition,
1725
1639
  // which matches any non-transient events
1726
- if (eventType === WILDCARD) {
1640
+ if (descriptor === WILDCARD) {
1727
1641
  return true;
1728
1642
  }
1729
- if (!eventType.endsWith('.*')) {
1643
+ if (!descriptor.endsWith('.*')) {
1730
1644
  return false;
1731
1645
  }
1732
- const partialEventTokens = eventType.split('.');
1646
+ const partialEventTokens = descriptor.split('.');
1733
1647
  const eventTokens = receivedEventType.split('.');
1734
1648
  for (let tokenIndex = 0; tokenIndex < partialEventTokens.length; tokenIndex++) {
1735
1649
  const partialEventToken = partialEventTokens[tokenIndex];
@@ -1743,7 +1657,7 @@ function getCandidates(stateNode, receivedEventType) {
1743
1657
  }
1744
1658
  }
1745
1659
  return true;
1746
- });
1660
+ }).sort((a, b) => b.length - a.length).flatMap(key => stateNode.transitions.get(key));
1747
1661
  return candidates;
1748
1662
  }
1749
1663
 
@@ -1756,11 +1670,12 @@ function getDelayedTransitions(stateNode) {
1756
1670
  return [];
1757
1671
  }
1758
1672
  const mutateEntryExit = (delay, i) => {
1759
- const delayRef = isFunction(delay) ? `${stateNode.id}:delay[${i}]` : delay;
1673
+ const delayRef = typeof delay === 'function' ? `${stateNode.id}:delay[${i}]` : delay;
1760
1674
  const eventType = after(delayRef, stateNode.id);
1761
1675
  stateNode.entry.push(raise({
1762
1676
  type: eventType
1763
1677
  }, {
1678
+ id: eventType,
1764
1679
  delay
1765
1680
  }));
1766
1681
  stateNode.exit.push(cancel(eventType));
@@ -1774,7 +1689,7 @@ function getDelayedTransitions(stateNode) {
1774
1689
  };
1775
1690
  }) : Object.keys(afterConfig).flatMap((delay, i) => {
1776
1691
  const configTransition = afterConfig[delay];
1777
- const resolvedTransition = isString(configTransition) ? {
1692
+ const resolvedTransition = typeof configTransition === 'string' ? {
1778
1693
  target: configTransition
1779
1694
  } : configTransition;
1780
1695
  const resolvedDelay = !isNaN(+delay) ? +delay : delay;
@@ -1790,12 +1705,12 @@ function getDelayedTransitions(stateNode) {
1790
1705
  delay
1791
1706
  } = delayedTransition;
1792
1707
  return {
1793
- ...formatTransition(stateNode, delayedTransition),
1708
+ ...formatTransition(stateNode, delayedTransition.event, delayedTransition),
1794
1709
  delay
1795
1710
  };
1796
1711
  });
1797
1712
  }
1798
- function formatTransition(stateNode, transitionConfig) {
1713
+ function formatTransition(stateNode, descriptor, transitionConfig) {
1799
1714
  const normalizedTarget = normalizeTarget(transitionConfig.target);
1800
1715
  const reenter = transitionConfig.reenter ?? false;
1801
1716
  const {
@@ -1804,12 +1719,12 @@ function formatTransition(stateNode, transitionConfig) {
1804
1719
  const target = resolveTarget(stateNode, normalizedTarget);
1805
1720
  const transition = {
1806
1721
  ...transitionConfig,
1807
- actions: toActionObjects(toArray(transitionConfig.actions)),
1722
+ actions: toArray(transitionConfig.actions),
1808
1723
  guard: transitionConfig.guard ? toGuardDefinition(transitionConfig.guard, guardType => guards[guardType]) : undefined,
1809
1724
  target,
1810
1725
  source: stateNode,
1811
1726
  reenter,
1812
- eventType: transitionConfig.event,
1727
+ eventType: descriptor,
1813
1728
  toJSON: () => ({
1814
1729
  ...transition,
1815
1730
  source: `#${stateNode.id}`,
@@ -1819,52 +1734,50 @@ function formatTransition(stateNode, transitionConfig) {
1819
1734
  return transition;
1820
1735
  }
1821
1736
  function formatTransitions(stateNode) {
1822
- const transitionConfigs = [];
1823
- if (Array.isArray(stateNode.config.on)) {
1824
- transitionConfigs.push(...stateNode.config.on);
1825
- } else if (stateNode.config.on) {
1826
- const {
1827
- [WILDCARD]: wildcardConfigs = [],
1828
- ...namedTransitionConfigs
1829
- } = stateNode.config.on;
1830
- for (const eventType of Object.keys(namedTransitionConfigs)) {
1831
- if (eventType === NULL_EVENT) {
1737
+ const transitions = new Map();
1738
+ if (stateNode.config.on) {
1739
+ for (const descriptor of Object.keys(stateNode.config.on)) {
1740
+ if (descriptor === NULL_EVENT) {
1832
1741
  throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');
1833
1742
  }
1834
- const eventTransitionConfigs = toTransitionConfigArray(eventType, namedTransitionConfigs[eventType]);
1835
- transitionConfigs.push(...eventTransitionConfigs);
1836
- // TODO: add dev-mode validation for unreachable transitions
1743
+ const transitionsConfig = stateNode.config.on[descriptor];
1744
+ transitions.set(descriptor, toTransitionConfigArray(transitionsConfig).map(t => formatTransition(stateNode, descriptor, t)));
1837
1745
  }
1838
-
1839
- transitionConfigs.push(...toTransitionConfigArray(WILDCARD, wildcardConfigs));
1840
1746
  }
1841
- const doneConfig = stateNode.config.onDone ? toTransitionConfigArray(String(done(stateNode.id)), stateNode.config.onDone) : [];
1842
- const invokeConfig = stateNode.invoke.flatMap(invokeDef => {
1843
- const settleTransitions = [];
1747
+ if (stateNode.config.onDone) {
1748
+ const descriptor = String(done(stateNode.id));
1749
+ transitions.set(descriptor, toTransitionConfigArray(stateNode.config.onDone).map(t => formatTransition(stateNode, descriptor, t)));
1750
+ }
1751
+ for (const invokeDef of stateNode.invoke) {
1844
1752
  if (invokeDef.onDone) {
1845
- settleTransitions.push(...toTransitionConfigArray(`done.invoke.${invokeDef.id}`, invokeDef.onDone));
1753
+ const descriptor = `done.invoke.${invokeDef.id}`;
1754
+ transitions.set(descriptor, toTransitionConfigArray(invokeDef.onDone).map(t => formatTransition(stateNode, descriptor, t)));
1846
1755
  }
1847
1756
  if (invokeDef.onError) {
1848
- settleTransitions.push(...toTransitionConfigArray(`error.platform.${invokeDef.id}`, invokeDef.onError));
1757
+ const descriptor = `error.platform.${invokeDef.id}`;
1758
+ transitions.set(descriptor, toTransitionConfigArray(invokeDef.onError).map(t => formatTransition(stateNode, descriptor, t)));
1849
1759
  }
1850
1760
  if (invokeDef.onSnapshot) {
1851
- settleTransitions.push(...toTransitionConfigArray(`xstate.snapshot.${invokeDef.id}`, invokeDef.onSnapshot));
1761
+ const descriptor = `xstate.snapshot.${invokeDef.id}`;
1762
+ transitions.set(descriptor, toTransitionConfigArray(invokeDef.onSnapshot).map(t => formatTransition(stateNode, descriptor, t)));
1852
1763
  }
1853
- return settleTransitions;
1854
- });
1855
- const delayedTransitions = stateNode.after;
1856
- const formattedTransitions = [...doneConfig, ...invokeConfig, ...transitionConfigs].flatMap(transitionConfig => toArray(transitionConfig).map(transition => formatTransition(stateNode, transition)));
1857
- for (const delayedTransition of delayedTransitions) {
1858
- formattedTransitions.push(delayedTransition);
1859
1764
  }
1860
- return formattedTransitions;
1765
+ for (const delayedTransition of stateNode.after) {
1766
+ let existing = transitions.get(delayedTransition.eventType);
1767
+ if (!existing) {
1768
+ existing = [];
1769
+ transitions.set(delayedTransition.eventType, existing);
1770
+ }
1771
+ existing.push(delayedTransition);
1772
+ }
1773
+ return transitions;
1861
1774
  }
1862
1775
  function formatInitialTransition(stateNode, _target) {
1863
- if (isString(_target) || isArray(_target)) {
1776
+ if (typeof _target === 'string' || isArray(_target)) {
1864
1777
  const targets = toArray(_target).map(t => {
1865
1778
  // Resolve state string keys (which represent children)
1866
1779
  // to their state node
1867
- const descStateNode = isString(t) ? isStateId(t) ? stateNode.machine.getStateNodeById(t) : stateNode.states[t] : t;
1780
+ const descStateNode = typeof t === 'string' ? isStateId(t) ? stateNode.machine.getStateNodeById(t) : stateNode.states[t] : t;
1868
1781
  if (!descStateNode) {
1869
1782
  throw new Error(`Initial state node "${t}" not found on parent state node #${stateNode.id}`);
1870
1783
  }
@@ -1888,15 +1801,14 @@ function formatInitialTransition(stateNode, _target) {
1888
1801
  };
1889
1802
  return transition;
1890
1803
  }
1891
- return formatTransition(stateNode, {
1804
+ return formatTransition(stateNode, '__INITIAL__', {
1892
1805
  target: toArray(_target.target).map(t => {
1893
- if (isString(t)) {
1806
+ if (typeof t === 'string') {
1894
1807
  return isStateId(t) ? t : `${STATE_DELIMITER}${t}`;
1895
1808
  }
1896
1809
  return t;
1897
1810
  }),
1898
- actions: _target.actions,
1899
- event: null
1811
+ actions: _target.actions
1900
1812
  });
1901
1813
  }
1902
1814
  function resolveTarget(stateNode, targets) {
@@ -1905,7 +1817,7 @@ function resolveTarget(stateNode, targets) {
1905
1817
  return undefined;
1906
1818
  }
1907
1819
  return targets.map(target => {
1908
- if (!isString(target)) {
1820
+ if (typeof target !== 'string') {
1909
1821
  return target;
1910
1822
  }
1911
1823
  if (isStateId(target)) {
@@ -2013,7 +1925,7 @@ function getStateNodeByPath(stateNode, statePath) {
2013
1925
  */
2014
1926
  function getStateNodes(stateNode, state) {
2015
1927
  const stateValue = state instanceof State ? state.value : toStateValue(state);
2016
- if (isString(stateValue)) {
1928
+ if (typeof stateValue === 'string') {
2017
1929
  return [stateNode, stateNode.states[stateValue]];
2018
1930
  }
2019
1931
  const childStateKeys = Object.keys(stateValue);
@@ -2064,7 +1976,7 @@ function transitionParallelNode(stateNode, stateValue, state, event) {
2064
1976
  }
2065
1977
  function transitionNode(stateNode, stateValue, state, event) {
2066
1978
  // leaf node
2067
- if (isString(stateValue)) {
1979
+ if (typeof stateValue === 'string') {
2068
1980
  return transitionAtomicNode(stateNode, stateValue, state, event);
2069
1981
  }
2070
1982
 
@@ -2398,44 +2310,55 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
2398
2310
  const {
2399
2311
  machine
2400
2312
  } = currentState;
2401
- const raiseActions = [];
2402
- let intermediateState = currentState;
2403
- function handleAction(action) {
2404
- if (actorCtx?.self.status === ActorStatus.Running) {
2405
- action.execute?.(actorCtx);
2406
- } else {
2407
- actorCtx?.defer(() => action.execute?.(actorCtx));
2313
+ // TODO: this `cloneState` is really just a hack to prevent infinite loops
2314
+ // we need to take another look at how internal queue is managed
2315
+ let intermediateState = cloneState(currentState, {
2316
+ _internalQueue: []
2317
+ });
2318
+ for (const action of actions) {
2319
+ const resolved = typeof action === 'function' ? action : machine.implementations.actions[typeof action === 'string' ? action : action.type];
2320
+ if (!resolved) {
2321
+ continue;
2408
2322
  }
2409
- }
2410
- function resolveAction(actionObject) {
2411
- const executableActionObject = resolveActionObject(actionObject, machine.implementations.actions);
2412
- if (isDynamicAction(executableActionObject)) {
2413
- const [nextState, resolvedAction] = executableActionObject.resolve(event, {
2414
- state: intermediateState,
2415
- action: actionObject,
2416
- actorContext: actorCtx
2417
- });
2418
- const matchedActions = resolvedAction.params?.actions;
2419
- intermediateState = nextState;
2420
- if (resolvedAction.type === raise$1 && typeof resolvedAction.params.delay !== 'number') {
2421
- raiseActions.push(resolvedAction);
2323
+ const args = {
2324
+ context: intermediateState.context,
2325
+ event,
2326
+ self: actorCtx?.self,
2327
+ system: actorCtx?.system,
2328
+ // TODO: figure out story for `action` and inline actions
2329
+ // what those ones should receive?
2330
+ //
2331
+ // entry: ({ action }) => {}
2332
+ // exit: assign(({ action }) => {})
2333
+ action: typeof action === 'string' ? {
2334
+ type: action
2335
+ } : action
2336
+ };
2337
+ if (!('resolve' in resolved)) {
2338
+ if (actorCtx?.self.status === ActorStatus.Running) {
2339
+ resolved(args);
2340
+ } else {
2341
+ actorCtx?.defer(() => resolved(args));
2422
2342
  }
2343
+ continue;
2344
+ }
2345
+ const builtinAction = resolved;
2346
+ const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, args, resolved // this holds all params
2347
+ );
2423
2348
 
2424
- // TODO: remove the check; just handleAction
2425
- if (resolvedAction.type !== pure$1) {
2426
- handleAction(resolvedAction);
2349
+ intermediateState = nextState;
2350
+ if ('execute' in resolved) {
2351
+ if (actorCtx?.self.status === ActorStatus.Running) {
2352
+ builtinAction.execute(actorCtx, params);
2353
+ } else {
2354
+ actorCtx?.defer(builtinAction.execute.bind(null, actorCtx, params));
2427
2355
  }
2428
- toActionObjects(matchedActions).forEach(resolveAction);
2429
- return;
2430
2356
  }
2431
- handleAction(executableActionObject);
2432
- }
2433
- for (const actionObject of actions) {
2434
- resolveAction(actionObject);
2357
+ if (actions) {
2358
+ intermediateState = resolveActionsAndContext(actions, event, intermediateState, actorCtx);
2359
+ }
2435
2360
  }
2436
- return cloneState(intermediateState, {
2437
- _internalQueue: raiseActions.map(a => a.params.event)
2438
- });
2361
+ return intermediateState;
2439
2362
  }
2440
2363
  function macrostep(state, event, actorCtx) {
2441
2364
  let nextState = state;
@@ -2454,7 +2377,7 @@ function macrostep(state, event, actorCtx) {
2454
2377
 
2455
2378
  // Assume the state is at rest (no raised events)
2456
2379
  // Determine the next state based on the next microstep
2457
- if (nextEvent.type !== init) {
2380
+ if (nextEvent.type !== INIT_TYPE) {
2458
2381
  const transitions = selectTransitions(nextEvent, nextState);
2459
2382
  nextState = microstep(transitions, state, actorCtx, nextEvent, false);
2460
2383
  states.push(nextState);
@@ -2620,7 +2543,7 @@ class State {
2620
2543
  * @param delimiter The character(s) that separate each subpath in the string state node path.
2621
2544
  */
2622
2545
  toStrings(stateValue = this.value) {
2623
- if (isString(stateValue)) {
2546
+ if (typeof stateValue === 'string') {
2624
2547
  return [stateValue];
2625
2548
  }
2626
2549
  const valueKeys = Object.keys(stateValue);
@@ -2715,6 +2638,36 @@ function getPersistedState(state) {
2715
2638
  };
2716
2639
  }
2717
2640
 
2641
+ function resolve$5(_, state, args, {
2642
+ actorRef
2643
+ }) {
2644
+ const actorRefOrString = typeof actorRef === 'function' ? actorRef(args) : actorRef;
2645
+ const resolvedActorRef = typeof actorRefOrString === 'string' ? state.children[actorRefOrString] : actorRefOrString;
2646
+ let children = state.children;
2647
+ if (resolvedActorRef) {
2648
+ children = {
2649
+ ...children
2650
+ };
2651
+ delete children[resolvedActorRef.id];
2652
+ }
2653
+ return [cloneState(state, {
2654
+ children
2655
+ }), resolvedActorRef];
2656
+ }
2657
+ function execute$2(actorContext, actorRef) {
2658
+ if (!actorRef) {
2659
+ return;
2660
+ }
2661
+ if (actorRef.status !== ActorStatus.Running) {
2662
+ actorContext.stopChild(actorRef);
2663
+ return;
2664
+ }
2665
+ // TODO: recheck why this one has to be deferred
2666
+ actorContext.defer(() => {
2667
+ actorContext.stopChild(actorRef);
2668
+ });
2669
+ }
2670
+
2718
2671
  /**
2719
2672
  * Stops an actor.
2720
2673
  *
@@ -2722,61 +2675,37 @@ function getPersistedState(state) {
2722
2675
  */
2723
2676
 
2724
2677
  function stop(actorRef) {
2725
- const actor = actorRef;
2726
- return createDynamicAction({
2727
- type: stop$1,
2728
- params: {
2729
- actor
2730
- }
2731
- }, (event, {
2732
- state,
2733
- actorContext
2734
- }) => {
2735
- const actorRefOrString = isFunction(actor) ? actor({
2736
- context: state.context,
2737
- event,
2738
- self: actorContext?.self ?? {},
2739
- system: actorContext?.system
2740
- }) : actor;
2741
- const actorRef = typeof actorRefOrString === 'string' ? state.children[actorRefOrString] : actorRefOrString;
2742
- let children = state.children;
2743
- if (actorRef) {
2744
- children = {
2745
- ...children
2746
- };
2747
- delete children[actorRef.id];
2748
- }
2749
- return [cloneState(state, {
2750
- children
2751
- }), {
2752
- type: 'xstate.stop',
2753
- params: {
2754
- actor: actorRef
2755
- },
2756
- execute: actorCtx => {
2757
- if (!actorRef) {
2758
- return;
2759
- }
2760
- if (actorRef.status !== ActorStatus.Running) {
2761
- actorCtx.stopChild(actorRef);
2762
- return;
2763
- }
2764
- actorCtx.defer(() => {
2765
- actorCtx.stopChild(actorRef);
2766
- });
2767
- }
2768
- }];
2769
- });
2678
+ function stop(_) {
2679
+ }
2680
+ stop.type = 'xstate.stop';
2681
+ stop.actorRef = actorRef;
2682
+ stop.resolve = resolve$5;
2683
+ stop.execute = execute$2;
2684
+ return stop;
2685
+ }
2686
+
2687
+ function resolve$4(_, state, actionArgs, {
2688
+ value,
2689
+ label
2690
+ }) {
2691
+ return [state, {
2692
+ value: typeof value === 'function' ? value(actionArgs) : value,
2693
+ label
2694
+ }];
2695
+ }
2696
+ function execute$1({
2697
+ logger
2698
+ }, {
2699
+ value,
2700
+ label
2701
+ }) {
2702
+ if (label) {
2703
+ logger(label, value);
2704
+ } else {
2705
+ logger(value);
2706
+ }
2770
2707
  }
2771
2708
 
2772
- const defaultLogExpr = ({
2773
- context,
2774
- event
2775
- }) => ({
2776
- context,
2777
- event
2778
- });
2779
-
2780
2709
  /**
2781
2710
  *
2782
2711
  * @param expr The expression function to evaluate which will be logged.
@@ -2785,39 +2714,21 @@ const defaultLogExpr = ({
2785
2714
  * - `event` - the event that caused this action to be executed.
2786
2715
  * @param label The label to give to the logged expression.
2787
2716
  */
2788
-
2789
- function log(expr = defaultLogExpr, label) {
2790
- return createDynamicAction({
2791
- type: log$1,
2792
- params: {
2793
- label,
2794
- expr
2795
- }
2796
- }, (event, {
2797
- state,
2798
- actorContext
2799
- }) => {
2800
- const resolvedValue = typeof expr === 'function' ? expr({
2801
- context: state.context,
2802
- event,
2803
- self: actorContext?.self ?? {},
2804
- system: actorContext?.system
2805
- }) : expr;
2806
- return [state, {
2807
- type: 'xstate.log',
2808
- params: {
2809
- label,
2810
- value: resolvedValue
2811
- },
2812
- execute: actorCtx => {
2813
- if (label) {
2814
- actorCtx.logger?.(label, resolvedValue);
2815
- } else {
2816
- actorCtx.logger?.(resolvedValue);
2817
- }
2818
- }
2819
- }];
2820
- });
2717
+ function log(value = ({
2718
+ context,
2719
+ event
2720
+ }) => ({
2721
+ context,
2722
+ event
2723
+ }), label) {
2724
+ function log(_) {
2725
+ }
2726
+ log.type = 'xstate.log';
2727
+ log.value = value;
2728
+ log.label = label;
2729
+ log.resolve = resolve$4;
2730
+ log.execute = execute$1;
2731
+ return log;
2821
2732
  }
2822
2733
 
2823
2734
  function createSpawner(actorContext, {
@@ -2876,57 +2787,84 @@ function createSpawner(actorContext, {
2876
2787
  };
2877
2788
  }
2878
2789
 
2790
+ function resolve$3(actorContext, state, actionArgs, {
2791
+ assignment
2792
+ }) {
2793
+ if (!state.context) {
2794
+ throw new Error('Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.');
2795
+ }
2796
+ const spawnedChildren = {};
2797
+ const assignArgs = {
2798
+ context: state.context,
2799
+ event: actionArgs.event,
2800
+ action: actionArgs.action,
2801
+ spawn: createSpawner(actorContext, state, actionArgs.event, spawnedChildren),
2802
+ self: actorContext?.self,
2803
+ system: actorContext?.system
2804
+ };
2805
+ let partialUpdate = {};
2806
+ if (typeof assignment === 'function') {
2807
+ partialUpdate = assignment(assignArgs);
2808
+ } else {
2809
+ for (const key of Object.keys(assignment)) {
2810
+ const propAssignment = assignment[key];
2811
+ partialUpdate[key] = typeof propAssignment === 'function' ? propAssignment(assignArgs) : propAssignment;
2812
+ }
2813
+ }
2814
+ const updatedContext = Object.assign({}, state.context, partialUpdate);
2815
+ return [cloneState(state, {
2816
+ context: updatedContext,
2817
+ children: Object.keys(spawnedChildren).length ? {
2818
+ ...state.children,
2819
+ ...spawnedChildren
2820
+ } : state.children
2821
+ })];
2822
+ }
2823
+
2879
2824
  /**
2880
2825
  * Updates the current context of the machine.
2881
2826
  *
2882
2827
  * @param assignment An object that represents the partial context to update.
2883
2828
  */
2884
2829
  function assign(assignment) {
2885
- return createDynamicAction({
2886
- type: assign$1,
2887
- params: {
2888
- assignment
2889
- }
2890
- }, (event, {
2891
- state,
2892
- action,
2893
- actorContext
2894
- }) => {
2895
- if (!state.context) {
2896
- throw new Error('Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.');
2897
- }
2898
- const spawnedChildren = {};
2899
- const args = {
2900
- context: state.context,
2901
- event,
2902
- action,
2903
- spawn: createSpawner(actorContext, state, event, spawnedChildren),
2904
- self: actorContext?.self ?? {},
2905
- system: actorContext?.system
2906
- };
2907
- let partialUpdate = {};
2908
- if (isFunction(assignment)) {
2909
- partialUpdate = assignment(args);
2910
- } else {
2911
- for (const key of Object.keys(assignment)) {
2912
- const propAssignment = assignment[key];
2913
- partialUpdate[key] = isFunction(propAssignment) ? propAssignment(args) : propAssignment;
2914
- }
2915
- }
2916
- const updatedContext = Object.assign({}, state.context, partialUpdate);
2917
- return [cloneState(state, {
2918
- context: updatedContext,
2919
- children: Object.keys(spawnedChildren).length ? {
2920
- ...state.children,
2921
- ...spawnedChildren
2922
- } : state.children
2923
- }), {
2924
- type: assign$1,
2925
- params: {
2926
- context: updatedContext
2927
- }
2928
- }];
2929
- });
2830
+ function assign(_) {
2831
+ }
2832
+ assign.type = 'xstate.assign';
2833
+ assign.assignment = assignment;
2834
+ assign.resolve = resolve$3;
2835
+ return assign;
2836
+ }
2837
+
2838
+ function resolve$2(_, state, args, {
2839
+ event: eventOrExpr,
2840
+ id,
2841
+ delay
2842
+ }) {
2843
+ const delaysMap = state.machine.implementations.delays;
2844
+ if (typeof eventOrExpr === 'string') {
2845
+ throw new Error(`Only event objects may be used with raise; use raise({ type: "${eventOrExpr}" }) instead`);
2846
+ }
2847
+ const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args) : eventOrExpr;
2848
+ let resolvedDelay;
2849
+ if (typeof delay === 'string') {
2850
+ const configDelay = delaysMap && delaysMap[delay];
2851
+ resolvedDelay = typeof configDelay === 'function' ? configDelay(args) : configDelay;
2852
+ } else {
2853
+ resolvedDelay = typeof delay === 'function' ? delay(args) : delay;
2854
+ }
2855
+ return [typeof resolvedDelay !== 'number' ? cloneState(state, {
2856
+ _internalQueue: state._internalQueue.concat(resolvedEvent)
2857
+ }) : state, {
2858
+ event: resolvedEvent,
2859
+ id,
2860
+ delay: resolvedDelay
2861
+ }];
2862
+ }
2863
+ function execute(actorContext, params) {
2864
+ if (typeof params.delay === 'number') {
2865
+ actorContext.self.delaySend(params);
2866
+ return;
2867
+ }
2930
2868
  }
2931
2869
 
2932
2870
  /**
@@ -2937,183 +2875,51 @@ function assign(assignment) {
2937
2875
  */
2938
2876
 
2939
2877
  function raise(eventOrExpr, options) {
2940
- return createDynamicAction({
2941
- type: raise$1,
2942
- params: {
2943
- delay: options ? options.delay : undefined,
2944
- event: eventOrExpr,
2945
- id: options && options.id !== undefined ? options.id : typeof eventOrExpr === 'function' ? eventOrExpr.name : eventOrExpr.type
2946
- }
2947
- }, (event, {
2948
- state,
2949
- actorContext
2950
- }) => {
2951
- const params = {
2952
- delay: options ? options.delay : undefined,
2953
- event: eventOrExpr,
2954
- id: options && options.id !== undefined ? options.id : typeof eventOrExpr === 'function' ? eventOrExpr.name : eventOrExpr.type
2955
- };
2956
- const args = {
2957
- context: state.context,
2958
- event,
2959
- self: actorContext?.self ?? {},
2960
- system: actorContext?.system
2961
- };
2962
- const delaysMap = state.machine.implementations.delays;
2963
-
2964
- // TODO: helper function for resolving Expr
2965
- if (typeof eventOrExpr === 'string') {
2966
- throw new Error(`Only event objects may be used with raise; use raise({ type: "${eventOrExpr}" }) instead`);
2967
- }
2968
- const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args) : eventOrExpr;
2969
- let resolvedDelay;
2970
- if (typeof params.delay === 'string') {
2971
- const configDelay = delaysMap && delaysMap[params.delay];
2972
- resolvedDelay = typeof configDelay === 'function' ? configDelay(args) : configDelay;
2973
- } else {
2974
- resolvedDelay = typeof params.delay === 'function' ? params.delay(args) : params.delay;
2975
- }
2976
- const resolvedAction = {
2977
- type: raise$1,
2978
- params: {
2979
- ...params,
2980
- event: resolvedEvent,
2981
- delay: resolvedDelay
2982
- },
2983
- execute: actorCtx => {
2984
- if (typeof resolvedAction.params.delay === 'number') {
2985
- actorCtx.self.delaySend(resolvedAction);
2986
- return;
2987
- }
2988
- }
2989
- };
2990
- return [state, resolvedAction];
2991
- });
2878
+ function raise(_) {
2879
+ }
2880
+ raise.type = 'xstate.raise';
2881
+ raise.event = eventOrExpr;
2882
+ raise.id = options?.id;
2883
+ raise.delay = options?.delay;
2884
+ raise.resolve = resolve$2;
2885
+ raise.execute = execute;
2886
+ return raise;
2887
+ }
2888
+
2889
+ function resolve$1(_, state, actionArgs, {
2890
+ branches
2891
+ }) {
2892
+ const matchedActions = branches.find(condition => {
2893
+ const guard = condition.guard && toGuardDefinition(condition.guard, guardType => state.machine.implementations.guards[guardType]);
2894
+ return !guard || evaluateGuard(guard, state.context, actionArgs.event, state);
2895
+ })?.actions;
2896
+ return [state, undefined, toArray(matchedActions)];
2897
+ }
2898
+ function choose(branches) {
2899
+ function choose(_) {
2900
+ }
2901
+ choose.type = 'xstate.choose';
2902
+ choose.branches = branches;
2903
+ choose.resolve = resolve$1;
2904
+ return choose;
2905
+ }
2906
+
2907
+ function resolve(_, state, args, {
2908
+ get
2909
+ }) {
2910
+ return [state, undefined, toArray(get({
2911
+ context: state.context,
2912
+ event: args.event
2913
+ }))];
2992
2914
  }
2993
-
2994
- function choose(guards) {
2995
- return createDynamicAction({
2996
- type: choose$1,
2997
- params: {
2998
- guards
2999
- }
3000
- }, (event, {
3001
- state
3002
- }) => {
3003
- const matchedActions = guards.find(condition => {
3004
- const guard = condition.guard && toGuardDefinition(condition.guard, guardType => state.machine.implementations.guards[guardType]);
3005
- return !guard || evaluateGuard(guard, state.context, event, state);
3006
- })?.actions;
3007
- return [state, {
3008
- type: choose$1,
3009
- params: {
3010
- actions: toActionObjects(matchedActions)
3011
- }
3012
- }];
3013
- });
3014
- }
3015
-
3016
2915
  function pure(getActions) {
3017
- return createDynamicAction({
3018
- type: pure$1,
3019
- params: {
3020
- get: getActions
3021
- }
3022
- }, (event, {
3023
- state
3024
- }) => {
3025
- return [state, {
3026
- type: pure$1,
3027
- params: {
3028
- actions: toArray(toActionObjects(getActions({
3029
- context: state.context,
3030
- event
3031
- }))) ?? []
3032
- }
3033
- }];
3034
- });
3035
- }
3036
-
3037
- function resolveActionObject(actionObject, actionFunctionMap) {
3038
- if (isDynamicAction(actionObject)) {
3039
- return actionObject;
3040
- }
3041
- const dereferencedAction = actionFunctionMap[actionObject.type];
3042
- if (typeof dereferencedAction === 'function') {
3043
- return createDynamicAction({
3044
- type: 'xstate.function',
3045
- params: actionObject.params ?? {}
3046
- }, (event, {
3047
- state
3048
- }) => {
3049
- const a = {
3050
- type: actionObject.type,
3051
- params: actionObject.params,
3052
- execute: actorCtx => {
3053
- return dereferencedAction({
3054
- context: state.context,
3055
- event,
3056
- action: a,
3057
- system: actorCtx.system,
3058
- self: actorCtx.self
3059
- });
3060
- }
3061
- };
3062
- return [state, a];
3063
- });
3064
- } else if (dereferencedAction) {
3065
- return dereferencedAction;
3066
- } else {
3067
- return actionObject;
3068
- }
3069
- }
3070
- function toActionObject(action) {
3071
- if (isDynamicAction(action)) {
3072
- return action;
2916
+ function pure(_) {
3073
2917
  }
3074
- if (typeof action === 'string') {
3075
- return {
3076
- type: action,
3077
- params: {}
3078
- };
3079
- }
3080
- if (typeof action === 'function') {
3081
- const type = 'xstate.function';
3082
- return createDynamicAction({
3083
- type,
3084
- params: {}
3085
- }, (event, {
3086
- state
3087
- }) => {
3088
- const actionObject = {
3089
- type,
3090
- params: {
3091
- function: action
3092
- },
3093
- execute: actorCtx => {
3094
- return action({
3095
- context: state.context,
3096
- event: event,
3097
- action: actionObject,
3098
- self: actorCtx.self,
3099
- system: actorCtx.system
3100
- });
3101
- }
3102
- };
3103
- return [state, actionObject];
3104
- });
3105
- }
3106
-
3107
- // action is already a BaseActionObject
3108
- return action;
2918
+ pure.type = 'xstate.pure';
2919
+ pure.get = getActions;
2920
+ pure.resolve = resolve;
2921
+ return pure;
3109
2922
  }
3110
- const toActionObjects = action => {
3111
- if (!action) {
3112
- return [];
3113
- }
3114
- const actions = isArray(action) ? action : [action];
3115
- return actions.map(toActionObject);
3116
- };
3117
2923
 
3118
2924
  /**
3119
2925
  * Returns an event type that represents an implicit event that
@@ -3124,7 +2930,7 @@ const toActionObjects = action => {
3124
2930
  */
3125
2931
  function after(delayRef, id) {
3126
2932
  const idSuffix = id ? `#${id}` : '';
3127
- return `${ActionTypes.After}(${delayRef})${idSuffix}`;
2933
+ return `${ConstantPrefix.After}(${delayRef})${idSuffix}`;
3128
2934
  }
3129
2935
 
3130
2936
  /**
@@ -3135,7 +2941,7 @@ function after(delayRef, id) {
3135
2941
  * @param output The data to pass into the event
3136
2942
  */
3137
2943
  function done(id, output) {
3138
- const type = `${ActionTypes.DoneState}.${id}`;
2944
+ const type = `${ConstantPrefix.DoneState}.${id}`;
3139
2945
  const eventObject = {
3140
2946
  type,
3141
2947
  output
@@ -3154,7 +2960,7 @@ function done(id, output) {
3154
2960
  * @param output The data to pass into the event
3155
2961
  */
3156
2962
  function doneInvoke(invokeId, output) {
3157
- const type = `${ActionTypes.DoneInvoke}.${invokeId}`;
2963
+ const type = `${ConstantPrefix.DoneInvoke}.${invokeId}`;
3158
2964
  const eventObject = {
3159
2965
  type,
3160
2966
  output
@@ -3163,7 +2969,7 @@ function doneInvoke(invokeId, output) {
3163
2969
  return eventObject;
3164
2970
  }
3165
2971
  function error(id, data) {
3166
- const type = `${ActionTypes.ErrorPlatform}.${id}`;
2972
+ const type = `${ConstantPrefix.ErrorPlatform}.${id}`;
3167
2973
  const eventObject = {
3168
2974
  type,
3169
2975
  data
@@ -3173,24 +2979,24 @@ function error(id, data) {
3173
2979
  }
3174
2980
  function createInitEvent(input) {
3175
2981
  return {
3176
- type: init,
2982
+ type: INIT_TYPE,
3177
2983
  input
3178
2984
  };
3179
2985
  }
3180
2986
 
3181
- exports.ActionTypes = ActionTypes;
3182
2987
  exports.ActorStatus = ActorStatus;
2988
+ exports.ConstantPrefix = ConstantPrefix;
3183
2989
  exports.Interpreter = Interpreter;
3184
2990
  exports.NULL_EVENT = NULL_EVENT;
3185
2991
  exports.STATE_DELIMITER = STATE_DELIMITER;
3186
2992
  exports.SpecialTargets = SpecialTargets;
3187
2993
  exports.State = State;
3188
- exports.actionTypes = actionTypes;
3189
2994
  exports.after = after;
3190
2995
  exports.and = and;
3191
2996
  exports.assign = assign;
3192
2997
  exports.cancel = cancel;
3193
2998
  exports.choose = choose;
2999
+ exports.constantPrefixes = constantPrefixes;
3194
3000
  exports.createEmptyActor = createEmptyActor;
3195
3001
  exports.createInitEvent = createInitEvent;
3196
3002
  exports.createInvokeId = createInvokeId;
@@ -3217,14 +3023,12 @@ exports.getPersistedState = getPersistedState;
3217
3023
  exports.getStateNodeByPath = getStateNodeByPath;
3218
3024
  exports.getStateNodes = getStateNodes;
3219
3025
  exports.interpret = interpret;
3220
- exports.invoke = invoke$1;
3221
3026
  exports.isActorRef = isActorRef;
3222
3027
  exports.isAtomicStateNode = isAtomicStateNode;
3223
3028
  exports.isErrorEvent = isErrorEvent;
3224
3029
  exports.isInFinalState = isInFinalState;
3225
3030
  exports.isSignal = isSignal;
3226
3031
  exports.isStateId = isStateId;
3227
- exports.isString = isString;
3228
3032
  exports.log = log;
3229
3033
  exports.macrostep = macrostep;
3230
3034
  exports.mapValues = mapValues;
@@ -3236,7 +3040,6 @@ exports.or = or;
3236
3040
  exports.pathToStateValue = pathToStateValue;
3237
3041
  exports.pure = pure;
3238
3042
  exports.raise = raise;
3239
- exports.resolveActionObject = resolveActionObject;
3240
3043
  exports.resolveActionsAndContext = resolveActionsAndContext;
3241
3044
  exports.resolveReferencedActor = resolveReferencedActor;
3242
3045
  exports.resolveStateValue = resolveStateValue;
@@ -3248,8 +3051,6 @@ exports.stateIn = stateIn;
3248
3051
  exports.stop = stop;
3249
3052
  exports.stopSignal = stopSignal;
3250
3053
  exports.stopSignalType = stopSignalType;
3251
- exports.toActionObject = toActionObject;
3252
- exports.toActionObjects = toActionObjects;
3253
3054
  exports.toActorRef = toActorRef;
3254
3055
  exports.toArray = toArray;
3255
3056
  exports.toGuardDefinition = toGuardDefinition;