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