xstate 5.0.0-beta.16 → 5.0.0-beta.18

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 (55) 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.cjs.mjs +19 -0
  5. package/actions/dist/xstate-actions.development.esm.js +1 -1
  6. package/actions/dist/xstate-actions.esm.js +1 -1
  7. package/actions/dist/xstate-actions.umd.min.js +1 -1
  8. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  9. package/actors/dist/xstate-actors.cjs.js +1 -1
  10. package/actors/dist/xstate-actors.development.cjs.js +1 -1
  11. package/actors/dist/xstate-actors.development.cjs.mjs +15 -0
  12. package/actors/dist/xstate-actors.development.esm.js +1 -1
  13. package/actors/dist/xstate-actors.esm.js +1 -1
  14. package/actors/dist/xstate-actors.umd.min.js +1 -1
  15. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  16. package/dev/dist/xstate-dev.development.cjs.mjs +5 -0
  17. package/dist/{actions-6f7fbc84.development.esm.js → actions-13190b25.development.esm.js} +677 -844
  18. package/dist/{actions-0f903c0d.development.cjs.js → actions-40bd643f.development.cjs.js} +678 -850
  19. package/dist/{actions-0386b622.esm.js → actions-4d6514d2.esm.js} +653 -847
  20. package/dist/{actions-6b9073db.cjs.js → actions-5fb9f10d.cjs.js} +654 -853
  21. package/dist/declarations/src/State.d.ts +1 -1
  22. package/dist/declarations/src/StateNode.d.ts +4 -4
  23. package/dist/declarations/src/actions/assign.d.ts +11 -2
  24. package/dist/declarations/src/actions/cancel.d.ts +14 -3
  25. package/dist/declarations/src/actions/choose.d.ts +11 -3
  26. package/dist/declarations/src/actions/log.d.ts +22 -3
  27. package/dist/declarations/src/actions/pure.d.ts +17 -3
  28. package/dist/declarations/src/actions/raise.d.ts +5 -2
  29. package/dist/declarations/src/actions/send.d.ts +58 -6
  30. package/dist/declarations/src/actions/stop.d.ts +14 -2
  31. package/dist/declarations/src/actions.d.ts +4 -7
  32. package/dist/declarations/src/constantPrefixes.d.ts +6 -0
  33. package/dist/declarations/src/interpreter.d.ts +8 -3
  34. package/dist/declarations/src/stateUtils.d.ts +4 -8
  35. package/dist/declarations/src/types.d.ts +22 -187
  36. package/dist/declarations/src/utils.d.ts +1 -6
  37. package/dist/xstate.cjs.js +42 -19
  38. package/dist/xstate.cjs.mjs +1 -1
  39. package/dist/xstate.development.cjs.js +42 -19
  40. package/dist/xstate.development.cjs.mjs +38 -0
  41. package/dist/xstate.development.esm.js +42 -19
  42. package/dist/xstate.esm.js +42 -19
  43. package/dist/xstate.umd.min.js +1 -1
  44. package/dist/xstate.umd.min.js.map +1 -1
  45. package/guards/dist/xstate-guards.cjs.js +1 -1
  46. package/guards/dist/xstate-guards.development.cjs.js +1 -1
  47. package/guards/dist/xstate-guards.development.cjs.mjs +8 -0
  48. package/guards/dist/xstate-guards.development.esm.js +1 -1
  49. package/guards/dist/xstate-guards.esm.js +1 -1
  50. package/guards/dist/xstate-guards.umd.min.js +1 -1
  51. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  52. package/package.json +1 -1
  53. package/actions/dynamicAction.ts +0 -42
  54. package/dist/declarations/src/actionTypes.d.ts +0 -16
  55. package/dist/declarations/src/constants.d.ts +0 -5
@@ -15,12 +15,6 @@ import { devToolsAdapter } from '../dev/dist/xstate-dev.development.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.development.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,20 @@ 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;
138
+ function sendTo(to, eventOrExpr, options) {
139
+ function sendTo(_) {
140
+ {
141
+ throw new Error(`This isn't supposed to be called`);
375
142
  }
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
- });
143
+ }
144
+ sendTo.type = 'xstate.sendTo';
145
+ sendTo.to = to;
146
+ sendTo.event = eventOrExpr;
147
+ sendTo.id = options?.id;
148
+ sendTo.delay = options?.delay;
149
+ sendTo.resolve = resolve$8;
150
+ sendTo.execute = execute$5;
151
+ return sendTo;
403
152
  }
404
153
 
405
154
  /**
@@ -444,7 +193,7 @@ function escalate(errorData, options) {
444
193
  return sendParent(arg => {
445
194
  return {
446
195
  type: error$1,
447
- data: isFunction(errorData) ? errorData(arg) : errorData
196
+ data: typeof errorData === 'function' ? errorData(arg) : errorData
448
197
  };
449
198
  }, options);
450
199
  }
@@ -463,6 +212,16 @@ function memo(object, key, fn) {
463
212
  return memoizedData[key];
464
213
  }
465
214
 
215
+ function resolve$7(_, state, actionArgs, {
216
+ sendId
217
+ }) {
218
+ const resolvedSendId = typeof sendId === 'function' ? sendId(actionArgs) : sendId;
219
+ return [state, resolvedSendId];
220
+ }
221
+ function execute$4(actorContext, resolvedSendId) {
222
+ actorContext.self.cancel(resolvedSendId);
223
+ }
224
+
466
225
  /**
467
226
  * Cancels an in-flight `send(...)` action. A canceled sent action will not
468
227
  * be executed, nor will its event be sent, unless it has already been sent
@@ -470,34 +229,17 @@ function memo(object, key, fn) {
470
229
  *
471
230
  * @param sendId The `id` of the `send(...)` action to cancel.
472
231
  */
473
-
474
232
  function cancel(sendId) {
475
- return createDynamicAction({
476
- type: cancel$1,
477
- params: {
478
- sendId
233
+ function cancel(_) {
234
+ {
235
+ throw new Error(`This isn't supposed to be called`);
479
236
  }
480
- }, (event, {
481
- state,
482
- actorContext
483
- }) => {
484
- const resolvedSendId = isFunction(sendId) ? sendId({
485
- context: state.context,
486
- event,
487
- self: actorContext?.self ?? {},
488
- system: actorContext?.system
489
- }) : sendId;
490
- return [state, {
491
- type: 'xstate.cancel',
492
- params: {
493
- sendId: resolvedSendId
494
- },
495
- execute: actorCtx => {
496
- const interpreter = actorCtx.self;
497
- interpreter.cancel(resolvedSendId);
498
- }
499
- }];
500
- });
237
+ }
238
+ cancel.type = 'xstate.cancel';
239
+ cancel.sendId = sendId;
240
+ cancel.resolve = resolve$7;
241
+ cancel.execute = execute$4;
242
+ return cancel;
501
243
  }
502
244
 
503
245
  class Mailbox {
@@ -897,7 +639,186 @@ function fromEventObservable(lazyObservable) {
897
639
  subscription: undefined
898
640
  })
899
641
  };
900
- return logic;
642
+ return logic;
643
+ }
644
+
645
+ function matchesState(parentStateId, childStateId) {
646
+ const parentStateValue = toStateValue(parentStateId);
647
+ const childStateValue = toStateValue(childStateId);
648
+ if (typeof childStateValue === 'string') {
649
+ if (typeof parentStateValue === 'string') {
650
+ return childStateValue === parentStateValue;
651
+ }
652
+
653
+ // Parent more specific than child
654
+ return false;
655
+ }
656
+ if (typeof parentStateValue === 'string') {
657
+ return parentStateValue in childStateValue;
658
+ }
659
+ return Object.keys(parentStateValue).every(key => {
660
+ if (!(key in childStateValue)) {
661
+ return false;
662
+ }
663
+ return matchesState(parentStateValue[key], childStateValue[key]);
664
+ });
665
+ }
666
+ function toStatePath(stateId) {
667
+ try {
668
+ if (isArray(stateId)) {
669
+ return stateId;
670
+ }
671
+ return stateId.toString().split(STATE_DELIMITER);
672
+ } catch (e) {
673
+ throw new Error(`'${stateId}' is not a valid state path.`);
674
+ }
675
+ }
676
+ function isStateLike(state) {
677
+ return typeof state === 'object' && 'value' in state && 'context' in state && 'event' in state;
678
+ }
679
+ function toStateValue(stateValue) {
680
+ if (isStateLike(stateValue)) {
681
+ return stateValue.value;
682
+ }
683
+ if (isArray(stateValue)) {
684
+ return pathToStateValue(stateValue);
685
+ }
686
+ if (typeof stateValue !== 'string') {
687
+ return stateValue;
688
+ }
689
+ const statePath = toStatePath(stateValue);
690
+ return pathToStateValue(statePath);
691
+ }
692
+ function pathToStateValue(statePath) {
693
+ if (statePath.length === 1) {
694
+ return statePath[0];
695
+ }
696
+ const value = {};
697
+ let marker = value;
698
+ for (let i = 0; i < statePath.length - 1; i++) {
699
+ if (i === statePath.length - 2) {
700
+ marker[statePath[i]] = statePath[i + 1];
701
+ } else {
702
+ const previous = marker;
703
+ marker = {};
704
+ previous[statePath[i]] = marker;
705
+ }
706
+ }
707
+ return value;
708
+ }
709
+ function mapValues(collection, iteratee) {
710
+ const result = {};
711
+ const collectionKeys = Object.keys(collection);
712
+ for (let i = 0; i < collectionKeys.length; i++) {
713
+ const key = collectionKeys[i];
714
+ result[key] = iteratee(collection[key], key, collection, i);
715
+ }
716
+ return result;
717
+ }
718
+ function flatten(array) {
719
+ return [].concat(...array);
720
+ }
721
+ function toArrayStrict(value) {
722
+ if (isArray(value)) {
723
+ return value;
724
+ }
725
+ return [value];
726
+ }
727
+ function toArray(value) {
728
+ if (value === undefined) {
729
+ return [];
730
+ }
731
+ return toArrayStrict(value);
732
+ }
733
+ function mapContext(mapper, context, event) {
734
+ if (typeof mapper === 'function') {
735
+ return mapper({
736
+ context,
737
+ event
738
+ });
739
+ }
740
+ const result = {};
741
+ const args = {
742
+ context,
743
+ event
744
+ };
745
+ for (const key of Object.keys(mapper)) {
746
+ const subMapper = mapper[key];
747
+ if (typeof subMapper === 'function') {
748
+ result[key] = subMapper(args);
749
+ } else {
750
+ result[key] = subMapper;
751
+ }
752
+ }
753
+ return result;
754
+ }
755
+ function isPromiseLike(value) {
756
+ if (value instanceof Promise) {
757
+ return true;
758
+ }
759
+ // Check if shape matches the Promise/A+ specification for a "thenable".
760
+ if (value !== null && (typeof value === 'function' || typeof value === 'object') && typeof value.then === 'function') {
761
+ return true;
762
+ }
763
+ return false;
764
+ }
765
+ function isArray(value) {
766
+ return Array.isArray(value);
767
+ }
768
+ function isErrorEvent(event) {
769
+ return typeof event.type === 'string' && (event.type === errorExecution || event.type.startsWith(errorPlatform));
770
+ }
771
+ function toTransitionConfigArray(configLike) {
772
+ return toArrayStrict(configLike).map(transitionLike => {
773
+ if (typeof transitionLike === 'undefined' || typeof transitionLike === 'string') {
774
+ return {
775
+ target: transitionLike
776
+ };
777
+ }
778
+ return transitionLike;
779
+ });
780
+ }
781
+ function normalizeTarget(target) {
782
+ if (target === undefined || target === TARGETLESS_KEY) {
783
+ return undefined;
784
+ }
785
+ return toArray(target);
786
+ }
787
+ function toInvokeConfig(invocable, id) {
788
+ if (typeof invocable === 'object') {
789
+ if ('src' in invocable) {
790
+ return invocable;
791
+ }
792
+ if ('transition' in invocable) {
793
+ return {
794
+ id,
795
+ src: invocable
796
+ };
797
+ }
798
+ }
799
+ return {
800
+ id,
801
+ src: invocable
802
+ };
803
+ }
804
+ function toObserver(nextHandler, errorHandler, completionHandler) {
805
+ const noop = () => {};
806
+ const isObserver = typeof nextHandler === 'object';
807
+ const self = isObserver ? nextHandler : null;
808
+ return {
809
+ next: ((isObserver ? nextHandler.next : nextHandler) || noop).bind(self),
810
+ error: ((isObserver ? nextHandler.error : errorHandler) || noop).bind(self),
811
+ complete: ((isObserver ? nextHandler.complete : completionHandler) || noop).bind(self)
812
+ };
813
+ }
814
+ function createInvokeId(stateNodeId, index) {
815
+ return `${stateNodeId}:invocation[${index}]`;
816
+ }
817
+ function resolveReferencedActor(referenced) {
818
+ return referenced ? 'transition' in referenced ? {
819
+ src: referenced,
820
+ input: undefined
821
+ } : referenced : undefined;
901
822
  }
902
823
 
903
824
  function fromCallback(invokeCallback) {
@@ -942,7 +863,7 @@ function fromCallback(invokeCallback) {
942
863
  }
943
864
  if (event.type === stopSignalType) {
944
865
  state.canceled = true;
945
- if (isFunction(state.dispose)) {
866
+ if (typeof state.dispose === 'function') {
946
867
  state.dispose();
947
868
  }
948
869
  return state;
@@ -1348,14 +1269,24 @@ class Interpreter {
1348
1269
  }
1349
1270
 
1350
1271
  // TODO: make private (and figure out a way to do this within the machine)
1351
- delaySend(sendAction) {
1352
- this.delayedEventsMap[sendAction.params.id] = this.clock.setTimeout(() => {
1353
- if ('to' in sendAction.params && sendAction.params.to) {
1354
- sendAction.params.to.send(sendAction.params.event);
1272
+ delaySend({
1273
+ event,
1274
+ id,
1275
+ delay,
1276
+ to
1277
+ }) {
1278
+ const timerId = this.clock.setTimeout(() => {
1279
+ if (to) {
1280
+ to.send(event);
1355
1281
  } else {
1356
- this.send(sendAction.params.event);
1282
+ this.send(event);
1357
1283
  }
1358
- }, sendAction.params.delay);
1284
+ }, delay);
1285
+
1286
+ // TODO: consider the rehydration story here
1287
+ if (id) {
1288
+ this.delayedEventsMap[id] = timerId;
1289
+ }
1359
1290
  }
1360
1291
 
1361
1292
  // TODO: make private (and figure out a way to do this within the machine)
@@ -1400,81 +1331,81 @@ function interpret(logic, options) {
1400
1331
  return interpreter;
1401
1332
  }
1402
1333
 
1403
- function invoke(invokeDef) {
1404
- return createDynamicAction({
1405
- type: invoke$1,
1406
- params: invokeDef
1407
- }, (event, {
1408
- state,
1409
- actorContext
1410
- }) => {
1411
- const type = invoke$1;
1412
- const {
1334
+ function resolve$6(actorContext, state, actionArgs, {
1335
+ id,
1336
+ systemId,
1337
+ src,
1338
+ input
1339
+ }) {
1340
+ const referenced = resolveReferencedActor(state.machine.implementations.actors[src]);
1341
+ let actorRef;
1342
+ if (referenced) {
1343
+ // TODO: inline `input: undefined` should win over the referenced one
1344
+ const configuredInput = input || referenced.input;
1345
+ actorRef = interpret(referenced.src, {
1413
1346
  id,
1414
- src
1415
- } = invokeDef;
1416
- let resolvedInvokeAction;
1417
- const referenced = resolveReferencedActor(state.machine.implementations.actors[src]);
1418
- if (!referenced) {
1419
- resolvedInvokeAction = {
1420
- type,
1421
- params: invokeDef
1422
- };
1423
- } else {
1424
- const input = 'input' in invokeDef ? invokeDef.input : referenced.input;
1425
- const ref = interpret(referenced.src, {
1426
- id,
1427
- src,
1428
- parent: actorContext?.self,
1429
- systemId: invokeDef.systemId,
1430
- input: typeof input === 'function' ? input({
1431
- context: state.context,
1432
- event,
1433
- self: actorContext?.self
1434
- }) : input
1435
- });
1436
- resolvedInvokeAction = {
1437
- type,
1438
- params: {
1439
- ...invokeDef,
1440
- ref
1441
- }
1442
- };
1443
- }
1444
- const actorRef = resolvedInvokeAction.params.ref;
1445
- const invokedState = cloneState(state, {
1446
- children: {
1447
- ...state.children,
1448
- [id]: actorRef
1449
- }
1347
+ src,
1348
+ parent: actorContext?.self,
1349
+ systemId,
1350
+ input: typeof configuredInput === 'function' ? configuredInput({
1351
+ context: state.context,
1352
+ event: actionArgs.event,
1353
+ self: actorContext?.self
1354
+ }) : configuredInput
1450
1355
  });
1451
- resolvedInvokeAction.execute = actorCtx => {
1452
- const parent = actorCtx.self;
1453
- const {
1454
- id,
1455
- ref
1456
- } = resolvedInvokeAction.params;
1457
- if (!ref) {
1458
- {
1459
- console.warn(`Actor type '${resolvedInvokeAction.params.src}' not found in machine '${actorCtx.id}'.`);
1460
- }
1461
- return;
1462
- }
1463
- actorCtx.defer(() => {
1464
- if (actorRef.status === ActorStatus.Stopped) {
1465
- return;
1466
- }
1467
- try {
1468
- actorRef.start?.();
1469
- } catch (err) {
1470
- parent.send(error(id, err));
1471
- return;
1472
- }
1473
- });
1474
- };
1475
- return [invokedState, resolvedInvokeAction];
1356
+ }
1357
+ if (!actorRef) {
1358
+ console.warn(`Actor type '${src}' not found in machine '${actorContext.id}'.`);
1359
+ }
1360
+ return [cloneState(state, {
1361
+ children: {
1362
+ ...state.children,
1363
+ [id]: actorRef
1364
+ }
1365
+ }), {
1366
+ id,
1367
+ actorRef
1368
+ }];
1369
+ }
1370
+ function execute$3(actorContext, {
1371
+ id,
1372
+ actorRef
1373
+ }) {
1374
+ if (!actorRef) {
1375
+ return;
1376
+ }
1377
+ actorContext.defer(() => {
1378
+ if (actorRef.status === ActorStatus.Stopped) {
1379
+ return;
1380
+ }
1381
+ try {
1382
+ actorRef.start?.();
1383
+ } catch (err) {
1384
+ actorContext.self.send(error(id, err));
1385
+ return;
1386
+ }
1476
1387
  });
1477
1388
  }
1389
+ function invoke({
1390
+ id,
1391
+ systemId,
1392
+ src,
1393
+ input
1394
+ }) {
1395
+ function invoke(_) {
1396
+ {
1397
+ throw new Error(`This isn't supposed to be called`);
1398
+ }
1399
+ }
1400
+ invoke.type = 'xstate.invoke';
1401
+ invoke.id = id;
1402
+ invoke.systemId = systemId;
1403
+ invoke.src = src;
1404
+ invoke.input = input;
1405
+ invoke.resolve = resolve$6;
1406
+ invoke.execute = execute$3;
1407
+ return invoke;
1408
+ }
1478
1409
 
1479
1410
  function stateIn(stateValue) {
1480
1411
  return {
@@ -1485,7 +1416,7 @@ function stateIn(stateValue) {
1485
1416
  predicate: ({
1486
1417
  state
1487
1418
  }) => {
1488
- if (isString(stateValue) && isStateId(stateValue)) {
1419
+ if (typeof stateValue === 'string' && isStateId(stateValue)) {
1489
1420
  return state.configuration.some(sn => sn.id === stateValue.slice(1));
1490
1421
  }
1491
1422
  return state.matches(stateValue);
@@ -1569,9 +1500,9 @@ function evaluateGuard(guard, context, event, state) {
1569
1500
  function toGuardDefinition(guardConfig, getPredicate) {
1570
1501
  // TODO: check for cycles and consider a refactor to more lazily evaluated guards
1571
1502
  // TODO: resolve this more recursively: https://github.com/statelyai/xstate/pull/4064#discussion_r1229915724
1572
- if (isString(guardConfig)) {
1503
+ if (typeof guardConfig === 'string') {
1573
1504
  const predicateOrDef = getPredicate?.(guardConfig);
1574
- if (isFunction(predicateOrDef)) {
1505
+ if (typeof predicateOrDef === 'function') {
1575
1506
  return {
1576
1507
  type: guardConfig,
1577
1508
  predicate: predicateOrDef,
@@ -1590,7 +1521,7 @@ function toGuardDefinition(guardConfig, getPredicate) {
1590
1521
  };
1591
1522
  }
1592
1523
  }
1593
- if (isFunction(guardConfig)) {
1524
+ if (typeof guardConfig === 'function') {
1594
1525
  return {
1595
1526
  type: guardConfig.name,
1596
1527
  predicate: guardConfig,
@@ -1601,7 +1532,7 @@ function toGuardDefinition(guardConfig, getPredicate) {
1601
1532
  };
1602
1533
  }
1603
1534
  const predicateOrDef = getPredicate?.(guardConfig.type);
1604
- if (isFunction(predicateOrDef)) {
1535
+ if (typeof predicateOrDef === 'function') {
1605
1536
  return {
1606
1537
  type: guardConfig.type,
1607
1538
  params: guardConfig.params || guardConfig,
@@ -1728,27 +1659,19 @@ function isInFinalState(configuration, stateNode = configuration[0].machine.root
1728
1659
  }
1729
1660
  const isStateId = str => str[0] === STATE_IDENTIFIER;
1730
1661
  function getCandidates(stateNode, receivedEventType) {
1731
- const candidates = stateNode.transitions.filter(transition => {
1732
- const {
1733
- eventType
1734
- } = transition;
1735
- // First, check the trivial case: event names are exactly equal
1736
- if (eventType === receivedEventType) {
1737
- return true;
1738
- }
1739
-
1740
- // Then, check if transition is a wildcard transition,
1662
+ const candidates = stateNode.transitions.get(receivedEventType) || [...stateNode.transitions.keys()].filter(descriptor => {
1663
+ // check if transition is a wildcard transition,
1741
1664
  // which matches any non-transient events
1742
- if (eventType === WILDCARD) {
1665
+ if (descriptor === WILDCARD) {
1743
1666
  return true;
1744
1667
  }
1745
- if (!eventType.endsWith('.*')) {
1668
+ if (!descriptor.endsWith('.*')) {
1746
1669
  return false;
1747
1670
  }
1748
- if (/.*\*.+/.test(eventType)) {
1749
- console.warn(`Wildcards can only be the last token of an event descriptor (e.g., "event.*") or the entire event descriptor ("*"). Check the "${eventType}" event.`);
1671
+ if (/.*\*.+/.test(descriptor)) {
1672
+ console.warn(`Wildcards can only be the last token of an event descriptor (e.g., "event.*") or the entire event descriptor ("*"). Check the "${descriptor}" event.`);
1750
1673
  }
1751
- const partialEventTokens = eventType.split('.');
1674
+ const partialEventTokens = descriptor.split('.');
1752
1675
  const eventTokens = receivedEventType.split('.');
1753
1676
  for (let tokenIndex = 0; tokenIndex < partialEventTokens.length; tokenIndex++) {
1754
1677
  const partialEventToken = partialEventTokens[tokenIndex];
@@ -1756,7 +1679,7 @@ function getCandidates(stateNode, receivedEventType) {
1756
1679
  if (partialEventToken === '*') {
1757
1680
  const isLastToken = tokenIndex === partialEventTokens.length - 1;
1758
1681
  if (!isLastToken) {
1759
- console.warn(`Infix wildcards in transition events are not allowed. Check the "${eventType}" event.`);
1682
+ console.warn(`Infix wildcards in transition events are not allowed. Check the "${descriptor}" transition.`);
1760
1683
  }
1761
1684
  return isLastToken;
1762
1685
  }
@@ -1765,7 +1688,7 @@ function getCandidates(stateNode, receivedEventType) {
1765
1688
  }
1766
1689
  }
1767
1690
  return true;
1768
- });
1691
+ }).sort((a, b) => b.length - a.length).flatMap(key => stateNode.transitions.get(key));
1769
1692
  return candidates;
1770
1693
  }
1771
1694
 
@@ -1778,11 +1701,12 @@ function getDelayedTransitions(stateNode) {
1778
1701
  return [];
1779
1702
  }
1780
1703
  const mutateEntryExit = (delay, i) => {
1781
- const delayRef = isFunction(delay) ? `${stateNode.id}:delay[${i}]` : delay;
1704
+ const delayRef = typeof delay === 'function' ? `${stateNode.id}:delay[${i}]` : delay;
1782
1705
  const eventType = after(delayRef, stateNode.id);
1783
1706
  stateNode.entry.push(raise({
1784
1707
  type: eventType
1785
1708
  }, {
1709
+ id: eventType,
1786
1710
  delay
1787
1711
  }));
1788
1712
  stateNode.exit.push(cancel(eventType));
@@ -1796,7 +1720,7 @@ function getDelayedTransitions(stateNode) {
1796
1720
  };
1797
1721
  }) : Object.keys(afterConfig).flatMap((delay, i) => {
1798
1722
  const configTransition = afterConfig[delay];
1799
- const resolvedTransition = isString(configTransition) ? {
1723
+ const resolvedTransition = typeof configTransition === 'string' ? {
1800
1724
  target: configTransition
1801
1725
  } : configTransition;
1802
1726
  const resolvedDelay = !isNaN(+delay) ? +delay : delay;
@@ -1812,12 +1736,12 @@ function getDelayedTransitions(stateNode) {
1812
1736
  delay
1813
1737
  } = delayedTransition;
1814
1738
  return {
1815
- ...formatTransition(stateNode, delayedTransition),
1739
+ ...formatTransition(stateNode, delayedTransition.event, delayedTransition),
1816
1740
  delay
1817
1741
  };
1818
1742
  });
1819
1743
  }
1820
- function formatTransition(stateNode, transitionConfig) {
1744
+ function formatTransition(stateNode, descriptor, transitionConfig) {
1821
1745
  const normalizedTarget = normalizeTarget(transitionConfig.target);
1822
1746
  const reenter = transitionConfig.reenter ?? false;
1823
1747
  const {
@@ -1831,12 +1755,12 @@ function formatTransition(stateNode, transitionConfig) {
1831
1755
  }
1832
1756
  const transition = {
1833
1757
  ...transitionConfig,
1834
- actions: toActionObjects(toArray(transitionConfig.actions)),
1758
+ actions: toArray(transitionConfig.actions),
1835
1759
  guard: transitionConfig.guard ? toGuardDefinition(transitionConfig.guard, guardType => guards[guardType]) : undefined,
1836
1760
  target,
1837
1761
  source: stateNode,
1838
1762
  reenter,
1839
- eventType: transitionConfig.event,
1763
+ eventType: descriptor,
1840
1764
  toJSON: () => ({
1841
1765
  ...transition,
1842
1766
  source: `#${stateNode.id}`,
@@ -1846,52 +1770,50 @@ function formatTransition(stateNode, transitionConfig) {
1846
1770
  return transition;
1847
1771
  }
1848
1772
  function formatTransitions(stateNode) {
1849
- const transitionConfigs = [];
1850
- if (Array.isArray(stateNode.config.on)) {
1851
- transitionConfigs.push(...stateNode.config.on);
1852
- } else if (stateNode.config.on) {
1853
- const {
1854
- [WILDCARD]: wildcardConfigs = [],
1855
- ...namedTransitionConfigs
1856
- } = stateNode.config.on;
1857
- for (const eventType of Object.keys(namedTransitionConfigs)) {
1858
- if (eventType === NULL_EVENT) {
1773
+ const transitions = new Map();
1774
+ if (stateNode.config.on) {
1775
+ for (const descriptor of Object.keys(stateNode.config.on)) {
1776
+ if (descriptor === NULL_EVENT) {
1859
1777
  throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');
1860
1778
  }
1861
- const eventTransitionConfigs = toTransitionConfigArray(eventType, namedTransitionConfigs[eventType]);
1862
- transitionConfigs.push(...eventTransitionConfigs);
1863
- // TODO: add dev-mode validation for unreachable transitions
1779
+ const transitionsConfig = stateNode.config.on[descriptor];
1780
+ transitions.set(descriptor, toTransitionConfigArray(transitionsConfig).map(t => formatTransition(stateNode, descriptor, t)));
1864
1781
  }
1865
-
1866
- transitionConfigs.push(...toTransitionConfigArray(WILDCARD, wildcardConfigs));
1867
1782
  }
1868
- const doneConfig = stateNode.config.onDone ? toTransitionConfigArray(String(done(stateNode.id)), stateNode.config.onDone) : [];
1869
- const invokeConfig = stateNode.invoke.flatMap(invokeDef => {
1870
- const settleTransitions = [];
1783
+ if (stateNode.config.onDone) {
1784
+ const descriptor = String(done(stateNode.id));
1785
+ transitions.set(descriptor, toTransitionConfigArray(stateNode.config.onDone).map(t => formatTransition(stateNode, descriptor, t)));
1786
+ }
1787
+ for (const invokeDef of stateNode.invoke) {
1871
1788
  if (invokeDef.onDone) {
1872
- settleTransitions.push(...toTransitionConfigArray(`done.invoke.${invokeDef.id}`, invokeDef.onDone));
1789
+ const descriptor = `done.invoke.${invokeDef.id}`;
1790
+ transitions.set(descriptor, toTransitionConfigArray(invokeDef.onDone).map(t => formatTransition(stateNode, descriptor, t)));
1873
1791
  }
1874
1792
  if (invokeDef.onError) {
1875
- settleTransitions.push(...toTransitionConfigArray(`error.platform.${invokeDef.id}`, invokeDef.onError));
1793
+ const descriptor = `error.platform.${invokeDef.id}`;
1794
+ transitions.set(descriptor, toTransitionConfigArray(invokeDef.onError).map(t => formatTransition(stateNode, descriptor, t)));
1876
1795
  }
1877
1796
  if (invokeDef.onSnapshot) {
1878
- settleTransitions.push(...toTransitionConfigArray(`xstate.snapshot.${invokeDef.id}`, invokeDef.onSnapshot));
1797
+ const descriptor = `xstate.snapshot.${invokeDef.id}`;
1798
+ transitions.set(descriptor, toTransitionConfigArray(invokeDef.onSnapshot).map(t => formatTransition(stateNode, descriptor, t)));
1879
1799
  }
1880
- return settleTransitions;
1881
- });
1882
- const delayedTransitions = stateNode.after;
1883
- const formattedTransitions = [...doneConfig, ...invokeConfig, ...transitionConfigs].flatMap(transitionConfig => toArray(transitionConfig).map(transition => formatTransition(stateNode, transition)));
1884
- for (const delayedTransition of delayedTransitions) {
1885
- formattedTransitions.push(delayedTransition);
1886
1800
  }
1887
- return formattedTransitions;
1801
+ for (const delayedTransition of stateNode.after) {
1802
+ let existing = transitions.get(delayedTransition.eventType);
1803
+ if (!existing) {
1804
+ existing = [];
1805
+ transitions.set(delayedTransition.eventType, existing);
1806
+ }
1807
+ existing.push(delayedTransition);
1808
+ }
1809
+ return transitions;
1888
1810
  }
1889
1811
  function formatInitialTransition(stateNode, _target) {
1890
- if (isString(_target) || isArray(_target)) {
1812
+ if (typeof _target === 'string' || isArray(_target)) {
1891
1813
  const targets = toArray(_target).map(t => {
1892
1814
  // Resolve state string keys (which represent children)
1893
1815
  // to their state node
1894
- const descStateNode = isString(t) ? isStateId(t) ? stateNode.machine.getStateNodeById(t) : stateNode.states[t] : t;
1816
+ const descStateNode = typeof t === 'string' ? isStateId(t) ? stateNode.machine.getStateNodeById(t) : stateNode.states[t] : t;
1895
1817
  if (!descStateNode) {
1896
1818
  throw new Error(`Initial state node "${t}" not found on parent state node #${stateNode.id}`);
1897
1819
  }
@@ -1915,15 +1837,14 @@ function formatInitialTransition(stateNode, _target) {
1915
1837
  };
1916
1838
  return transition;
1917
1839
  }
1918
- return formatTransition(stateNode, {
1840
+ return formatTransition(stateNode, '__INITIAL__', {
1919
1841
  target: toArray(_target.target).map(t => {
1920
- if (isString(t)) {
1842
+ if (typeof t === 'string') {
1921
1843
  return isStateId(t) ? t : `${STATE_DELIMITER}${t}`;
1922
1844
  }
1923
1845
  return t;
1924
1846
  }),
1925
- actions: _target.actions,
1926
- event: null
1847
+ actions: _target.actions
1927
1848
  });
1928
1849
  }
1929
1850
  function resolveTarget(stateNode, targets) {
@@ -1932,7 +1853,7 @@ function resolveTarget(stateNode, targets) {
1932
1853
  return undefined;
1933
1854
  }
1934
1855
  return targets.map(target => {
1935
- if (!isString(target)) {
1856
+ if (typeof target !== 'string') {
1936
1857
  return target;
1937
1858
  }
1938
1859
  if (isStateId(target)) {
@@ -2040,7 +1961,7 @@ function getStateNodeByPath(stateNode, statePath) {
2040
1961
  */
2041
1962
  function getStateNodes(stateNode, state) {
2042
1963
  const stateValue = state instanceof State ? state.value : toStateValue(state);
2043
- if (isString(stateValue)) {
1964
+ if (typeof stateValue === 'string') {
2044
1965
  return [stateNode, stateNode.states[stateValue]];
2045
1966
  }
2046
1967
  const childStateKeys = Object.keys(stateValue);
@@ -2091,7 +2012,7 @@ function transitionParallelNode(stateNode, stateValue, state, event) {
2091
2012
  }
2092
2013
  function transitionNode(stateNode, stateValue, state, event) {
2093
2014
  // leaf node
2094
- if (isString(stateValue)) {
2015
+ if (typeof stateValue === 'string') {
2095
2016
  return transitionAtomicNode(stateNode, stateValue, state, event);
2096
2017
  }
2097
2018
 
@@ -2425,44 +2346,55 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
2425
2346
  const {
2426
2347
  machine
2427
2348
  } = currentState;
2428
- const raiseActions = [];
2429
- let intermediateState = currentState;
2430
- function handleAction(action) {
2431
- if (actorCtx?.self.status === ActorStatus.Running) {
2432
- action.execute?.(actorCtx);
2433
- } else {
2434
- actorCtx?.defer(() => action.execute?.(actorCtx));
2349
+ // TODO: this `cloneState` is really just a hack to prevent infinite loops
2350
+ // we need to take another look at how internal queue is managed
2351
+ let intermediateState = cloneState(currentState, {
2352
+ _internalQueue: []
2353
+ });
2354
+ for (const action of actions) {
2355
+ const resolved = typeof action === 'function' ? action : machine.implementations.actions[typeof action === 'string' ? action : action.type];
2356
+ if (!resolved) {
2357
+ continue;
2435
2358
  }
2436
- }
2437
- function resolveAction(actionObject) {
2438
- const executableActionObject = resolveActionObject(actionObject, machine.implementations.actions);
2439
- if (isDynamicAction(executableActionObject)) {
2440
- const [nextState, resolvedAction] = executableActionObject.resolve(event, {
2441
- state: intermediateState,
2442
- action: actionObject,
2443
- actorContext: actorCtx
2444
- });
2445
- const matchedActions = resolvedAction.params?.actions;
2446
- intermediateState = nextState;
2447
- if (resolvedAction.type === raise$1 && typeof resolvedAction.params.delay !== 'number') {
2448
- raiseActions.push(resolvedAction);
2359
+ const args = {
2360
+ context: intermediateState.context,
2361
+ event,
2362
+ self: actorCtx?.self,
2363
+ system: actorCtx?.system,
2364
+ // TODO: figure out story for `action` and inline actions
2365
+ // what those ones should receive?
2366
+ //
2367
+ // entry: ({ action }) => {}
2368
+ // exit: assign(({ action }) => {})
2369
+ action: typeof action === 'string' ? {
2370
+ type: action
2371
+ } : action
2372
+ };
2373
+ if (!('resolve' in resolved)) {
2374
+ if (actorCtx?.self.status === ActorStatus.Running) {
2375
+ resolved(args);
2376
+ } else {
2377
+ actorCtx?.defer(() => resolved(args));
2449
2378
  }
2379
+ continue;
2380
+ }
2381
+ const builtinAction = resolved;
2382
+ const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, args, resolved // this holds all params
2383
+ );
2450
2384
 
2451
- // TODO: remove the check; just handleAction
2452
- if (resolvedAction.type !== pure$1) {
2453
- handleAction(resolvedAction);
2385
+ intermediateState = nextState;
2386
+ if ('execute' in resolved) {
2387
+ if (actorCtx?.self.status === ActorStatus.Running) {
2388
+ builtinAction.execute(actorCtx, params);
2389
+ } else {
2390
+ actorCtx?.defer(builtinAction.execute.bind(null, actorCtx, params));
2454
2391
  }
2455
- toActionObjects(matchedActions).forEach(resolveAction);
2456
- return;
2457
2392
  }
2458
- handleAction(executableActionObject);
2459
- }
2460
- for (const actionObject of actions) {
2461
- resolveAction(actionObject);
2393
+ if (actions) {
2394
+ intermediateState = resolveActionsAndContext(actions, event, intermediateState, actorCtx);
2395
+ }
2462
2396
  }
2463
- return cloneState(intermediateState, {
2464
- _internalQueue: raiseActions.map(a => a.params.event)
2465
- });
2397
+ return intermediateState;
2466
2398
  }
2467
2399
  function macrostep(state, event, actorCtx) {
2468
2400
  if (event.type === WILDCARD) {
@@ -2484,7 +2416,7 @@ function macrostep(state, event, actorCtx) {
2484
2416
 
2485
2417
  // Assume the state is at rest (no raised events)
2486
2418
  // Determine the next state based on the next microstep
2487
- if (nextEvent.type !== init) {
2419
+ if (nextEvent.type !== INIT_TYPE) {
2488
2420
  const transitions = selectTransitions(nextEvent, nextState);
2489
2421
  nextState = microstep(transitions, state, actorCtx, nextEvent, false);
2490
2422
  states.push(nextState);
@@ -2650,7 +2582,7 @@ class State {
2650
2582
  * @param delimiter The character(s) that separate each subpath in the string state node path.
2651
2583
  */
2652
2584
  toStrings(stateValue = this.value) {
2653
- if (isString(stateValue)) {
2585
+ if (typeof stateValue === 'string') {
2654
2586
  return [stateValue];
2655
2587
  }
2656
2588
  const valueKeys = Object.keys(stateValue);
@@ -2748,6 +2680,36 @@ function getPersistedState(state) {
2748
2680
  };
2749
2681
  }
2750
2682
 
2683
+ function resolve$5(_, state, args, {
2684
+ actorRef
2685
+ }) {
2686
+ const actorRefOrString = typeof actorRef === 'function' ? actorRef(args) : actorRef;
2687
+ const resolvedActorRef = typeof actorRefOrString === 'string' ? state.children[actorRefOrString] : actorRefOrString;
2688
+ let children = state.children;
2689
+ if (resolvedActorRef) {
2690
+ children = {
2691
+ ...children
2692
+ };
2693
+ delete children[resolvedActorRef.id];
2694
+ }
2695
+ return [cloneState(state, {
2696
+ children
2697
+ }), resolvedActorRef];
2698
+ }
2699
+ function execute$2(actorContext, actorRef) {
2700
+ if (!actorRef) {
2701
+ return;
2702
+ }
2703
+ if (actorRef.status !== ActorStatus.Running) {
2704
+ actorContext.stopChild(actorRef);
2705
+ return;
2706
+ }
2707
+ // TODO: recheck why this one has to be deferred
2708
+ actorContext.defer(() => {
2709
+ actorContext.stopChild(actorRef);
2710
+ });
2711
+ }
2712
+
2751
2713
  /**
2752
2714
  * Stops an actor.
2753
2715
  *
@@ -2755,61 +2717,40 @@ function getPersistedState(state) {
2755
2717
  */
2756
2718
 
2757
2719
  function stop(actorRef) {
2758
- const actor = actorRef;
2759
- return createDynamicAction({
2760
- type: stop$1,
2761
- params: {
2762
- actor
2763
- }
2764
- }, (event, {
2765
- state,
2766
- actorContext
2767
- }) => {
2768
- const actorRefOrString = isFunction(actor) ? actor({
2769
- context: state.context,
2770
- event,
2771
- self: actorContext?.self ?? {},
2772
- system: actorContext?.system
2773
- }) : actor;
2774
- const actorRef = typeof actorRefOrString === 'string' ? state.children[actorRefOrString] : actorRefOrString;
2775
- let children = state.children;
2776
- if (actorRef) {
2777
- children = {
2778
- ...children
2779
- };
2780
- delete children[actorRef.id];
2781
- }
2782
- return [cloneState(state, {
2783
- children
2784
- }), {
2785
- type: 'xstate.stop',
2786
- params: {
2787
- actor: actorRef
2788
- },
2789
- execute: actorCtx => {
2790
- if (!actorRef) {
2791
- return;
2792
- }
2793
- if (actorRef.status !== ActorStatus.Running) {
2794
- actorCtx.stopChild(actorRef);
2795
- return;
2796
- }
2797
- actorCtx.defer(() => {
2798
- actorCtx.stopChild(actorRef);
2799
- });
2800
- }
2801
- }];
2802
- });
2720
+ function stop(_) {
2721
+ {
2722
+ throw new Error(`This isn't supposed to be called`);
2723
+ }
2724
+ }
2725
+ stop.type = 'xstate.stop';
2726
+ stop.actorRef = actorRef;
2727
+ stop.resolve = resolve$5;
2728
+ stop.execute = execute$2;
2729
+ return stop;
2730
+ }
2731
+
2732
+ function resolve$4(_, state, actionArgs, {
2733
+ value,
2734
+ label
2735
+ }) {
2736
+ return [state, {
2737
+ value: typeof value === 'function' ? value(actionArgs) : value,
2738
+ label
2739
+ }];
2740
+ }
2741
+ function execute$1({
2742
+ logger
2743
+ }, {
2744
+ value,
2745
+ label
2746
+ }) {
2747
+ if (label) {
2748
+ logger(label, value);
2749
+ } else {
2750
+ logger(value);
2751
+ }
2803
2752
  }
2804
2753
 
2805
- const defaultLogExpr = ({
2806
- context,
2807
- event
2808
- }) => ({
2809
- context,
2810
- event
2811
- });
2812
-
2813
2754
  /**
2814
2755
  *
2815
2756
  * @param expr The expression function to evaluate which will be logged.
@@ -2818,39 +2759,24 @@ const defaultLogExpr = ({
2818
2759
  * - `event` - the event that caused this action to be executed.
2819
2760
  * @param label The label to give to the logged expression.
2820
2761
  */
2821
-
2822
- function log(expr = defaultLogExpr, label) {
2823
- return createDynamicAction({
2824
- type: log$1,
2825
- params: {
2826
- label,
2827
- expr
2762
+ function log(value = ({
2763
+ context,
2764
+ event
2765
+ }) => ({
2766
+ context,
2767
+ event
2768
+ }), label) {
2769
+ function log(_) {
2770
+ {
2771
+ throw new Error(`This isn't supposed to be called`);
2828
2772
  }
2829
- }, (event, {
2830
- state,
2831
- actorContext
2832
- }) => {
2833
- const resolvedValue = typeof expr === 'function' ? expr({
2834
- context: state.context,
2835
- event,
2836
- self: actorContext?.self ?? {},
2837
- system: actorContext?.system
2838
- }) : expr;
2839
- return [state, {
2840
- type: 'xstate.log',
2841
- params: {
2842
- label,
2843
- value: resolvedValue
2844
- },
2845
- execute: actorCtx => {
2846
- if (label) {
2847
- actorCtx.logger?.(label, resolvedValue);
2848
- } else {
2849
- actorCtx.logger?.(resolvedValue);
2850
- }
2851
- }
2852
- }];
2853
- });
2773
+ }
2774
+ log.type = 'xstate.log';
2775
+ log.value = value;
2776
+ log.label = label;
2777
+ log.resolve = resolve$4;
2778
+ log.execute = execute$1;
2779
+ return log;
2854
2780
  }
2855
2781
 
2856
2782
  function createSpawner(actorContext, {
@@ -2909,57 +2835,87 @@ function createSpawner(actorContext, {
2909
2835
  };
2910
2836
  }
2911
2837
 
2838
+ function resolve$3(actorContext, state, actionArgs, {
2839
+ assignment
2840
+ }) {
2841
+ if (!state.context) {
2842
+ throw new Error('Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.');
2843
+ }
2844
+ const spawnedChildren = {};
2845
+ const assignArgs = {
2846
+ context: state.context,
2847
+ event: actionArgs.event,
2848
+ action: actionArgs.action,
2849
+ spawn: createSpawner(actorContext, state, actionArgs.event, spawnedChildren),
2850
+ self: actorContext?.self,
2851
+ system: actorContext?.system
2852
+ };
2853
+ let partialUpdate = {};
2854
+ if (typeof assignment === 'function') {
2855
+ partialUpdate = assignment(assignArgs);
2856
+ } else {
2857
+ for (const key of Object.keys(assignment)) {
2858
+ const propAssignment = assignment[key];
2859
+ partialUpdate[key] = typeof propAssignment === 'function' ? propAssignment(assignArgs) : propAssignment;
2860
+ }
2861
+ }
2862
+ const updatedContext = Object.assign({}, state.context, partialUpdate);
2863
+ return [cloneState(state, {
2864
+ context: updatedContext,
2865
+ children: Object.keys(spawnedChildren).length ? {
2866
+ ...state.children,
2867
+ ...spawnedChildren
2868
+ } : state.children
2869
+ })];
2870
+ }
2871
+
2912
2872
  /**
2913
2873
  * Updates the current context of the machine.
2914
2874
  *
2915
2875
  * @param assignment An object that represents the partial context to update.
2916
2876
  */
2917
2877
  function assign(assignment) {
2918
- return createDynamicAction({
2919
- type: assign$1,
2920
- params: {
2921
- assignment
2922
- }
2923
- }, (event, {
2924
- state,
2925
- action,
2926
- actorContext
2927
- }) => {
2928
- if (!state.context) {
2929
- throw new Error('Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.');
2930
- }
2931
- const spawnedChildren = {};
2932
- const args = {
2933
- context: state.context,
2934
- event,
2935
- action,
2936
- spawn: createSpawner(actorContext, state, event, spawnedChildren),
2937
- self: actorContext?.self ?? {},
2938
- system: actorContext?.system
2939
- };
2940
- let partialUpdate = {};
2941
- if (isFunction(assignment)) {
2942
- partialUpdate = assignment(args);
2943
- } else {
2944
- for (const key of Object.keys(assignment)) {
2945
- const propAssignment = assignment[key];
2946
- partialUpdate[key] = isFunction(propAssignment) ? propAssignment(args) : propAssignment;
2947
- }
2948
- }
2949
- const updatedContext = Object.assign({}, state.context, partialUpdate);
2950
- return [cloneState(state, {
2951
- context: updatedContext,
2952
- children: Object.keys(spawnedChildren).length ? {
2953
- ...state.children,
2954
- ...spawnedChildren
2955
- } : state.children
2956
- }), {
2957
- type: assign$1,
2958
- params: {
2959
- context: updatedContext
2960
- }
2961
- }];
2962
- });
2878
+ function assign(_) {
2879
+ {
2880
+ throw new Error(`This isn't supposed to be called`);
2881
+ }
2882
+ }
2883
+ assign.type = 'xstate.assign';
2884
+ assign.assignment = assignment;
2885
+ assign.resolve = resolve$3;
2886
+ return assign;
2887
+ }
2888
+
2889
+ function resolve$2(_, state, args, {
2890
+ event: eventOrExpr,
2891
+ id,
2892
+ delay
2893
+ }) {
2894
+ const delaysMap = state.machine.implementations.delays;
2895
+ if (typeof eventOrExpr === 'string') {
2896
+ throw new Error(`Only event objects may be used with raise; use raise({ type: "${eventOrExpr}" }) instead`);
2897
+ }
2898
+ const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args) : eventOrExpr;
2899
+ let resolvedDelay;
2900
+ if (typeof delay === 'string') {
2901
+ const configDelay = delaysMap && delaysMap[delay];
2902
+ resolvedDelay = typeof configDelay === 'function' ? configDelay(args) : configDelay;
2903
+ } else {
2904
+ resolvedDelay = typeof delay === 'function' ? delay(args) : delay;
2905
+ }
2906
+ return [typeof resolvedDelay !== 'number' ? cloneState(state, {
2907
+ _internalQueue: state._internalQueue.concat(resolvedEvent)
2908
+ }) : state, {
2909
+ event: resolvedEvent,
2910
+ id,
2911
+ delay: resolvedDelay
2912
+ }];
2913
+ }
2914
+ function execute(actorContext, params) {
2915
+ if (typeof params.delay === 'number') {
2916
+ actorContext.self.delaySend(params);
2917
+ return;
2918
+ }
2963
2919
  }
2964
2920
 
2965
2921
  /**
@@ -2970,183 +2926,60 @@ function assign(assignment) {
2970
2926
  */
2971
2927
 
2972
2928
  function raise(eventOrExpr, options) {
2973
- return createDynamicAction({
2974
- type: raise$1,
2975
- params: {
2976
- delay: options ? options.delay : undefined,
2977
- event: eventOrExpr,
2978
- id: options && options.id !== undefined ? options.id : typeof eventOrExpr === 'function' ? eventOrExpr.name : eventOrExpr.type
2979
- }
2980
- }, (event, {
2981
- state,
2982
- actorContext
2983
- }) => {
2984
- const params = {
2985
- delay: options ? options.delay : undefined,
2986
- event: eventOrExpr,
2987
- id: options && options.id !== undefined ? options.id : typeof eventOrExpr === 'function' ? eventOrExpr.name : eventOrExpr.type
2988
- };
2989
- const args = {
2990
- context: state.context,
2991
- event,
2992
- self: actorContext?.self ?? {},
2993
- system: actorContext?.system
2994
- };
2995
- const delaysMap = state.machine.implementations.delays;
2996
-
2997
- // TODO: helper function for resolving Expr
2998
- if (typeof eventOrExpr === 'string') {
2999
- throw new Error(`Only event objects may be used with raise; use raise({ type: "${eventOrExpr}" }) instead`);
2929
+ function raise(_) {
2930
+ {
2931
+ throw new Error(`This isn't supposed to be called`);
3000
2932
  }
3001
- const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args) : eventOrExpr;
3002
- let resolvedDelay;
3003
- if (typeof params.delay === 'string') {
3004
- const configDelay = delaysMap && delaysMap[params.delay];
3005
- resolvedDelay = typeof configDelay === 'function' ? configDelay(args) : configDelay;
3006
- } else {
3007
- resolvedDelay = typeof params.delay === 'function' ? params.delay(args) : params.delay;
3008
- }
3009
- const resolvedAction = {
3010
- type: raise$1,
3011
- params: {
3012
- ...params,
3013
- event: resolvedEvent,
3014
- delay: resolvedDelay
3015
- },
3016
- execute: actorCtx => {
3017
- if (typeof resolvedAction.params.delay === 'number') {
3018
- actorCtx.self.delaySend(resolvedAction);
3019
- return;
3020
- }
3021
- }
3022
- };
3023
- return [state, resolvedAction];
3024
- });
2933
+ }
2934
+ raise.type = 'xstate.raise';
2935
+ raise.event = eventOrExpr;
2936
+ raise.id = options?.id;
2937
+ raise.delay = options?.delay;
2938
+ raise.resolve = resolve$2;
2939
+ raise.execute = execute;
2940
+ return raise;
3025
2941
  }
3026
2942
 
3027
- function choose(guards) {
3028
- return createDynamicAction({
3029
- type: choose$1,
3030
- params: {
3031
- guards
3032
- }
3033
- }, (event, {
3034
- state
3035
- }) => {
3036
- const matchedActions = guards.find(condition => {
3037
- const guard = condition.guard && toGuardDefinition(condition.guard, guardType => state.machine.implementations.guards[guardType]);
3038
- return !guard || evaluateGuard(guard, state.context, event, state);
3039
- })?.actions;
3040
- return [state, {
3041
- type: choose$1,
3042
- params: {
3043
- actions: toActionObjects(matchedActions)
3044
- }
3045
- }];
3046
- });
2943
+ function resolve$1(_, state, actionArgs, {
2944
+ branches
2945
+ }) {
2946
+ const matchedActions = branches.find(condition => {
2947
+ const guard = condition.guard && toGuardDefinition(condition.guard, guardType => state.machine.implementations.guards[guardType]);
2948
+ return !guard || evaluateGuard(guard, state.context, actionArgs.event, state);
2949
+ })?.actions;
2950
+ return [state, undefined, toArray(matchedActions)];
3047
2951
  }
3048
-
3049
- function pure(getActions) {
3050
- return createDynamicAction({
3051
- type: pure$1,
3052
- params: {
3053
- get: getActions
2952
+ function choose(branches) {
2953
+ function choose(_) {
2954
+ {
2955
+ throw new Error(`This isn't supposed to be called`);
3054
2956
  }
3055
- }, (event, {
3056
- state
3057
- }) => {
3058
- return [state, {
3059
- type: pure$1,
3060
- params: {
3061
- actions: toArray(toActionObjects(getActions({
3062
- context: state.context,
3063
- event
3064
- }))) ?? []
3065
- }
3066
- }];
3067
- });
3068
- }
3069
-
3070
- function resolveActionObject(actionObject, actionFunctionMap) {
3071
- if (isDynamicAction(actionObject)) {
3072
- return actionObject;
3073
- }
3074
- const dereferencedAction = actionFunctionMap[actionObject.type];
3075
- if (typeof dereferencedAction === 'function') {
3076
- return createDynamicAction({
3077
- type: 'xstate.function',
3078
- params: actionObject.params ?? {}
3079
- }, (event, {
3080
- state
3081
- }) => {
3082
- const a = {
3083
- type: actionObject.type,
3084
- params: actionObject.params,
3085
- execute: actorCtx => {
3086
- return dereferencedAction({
3087
- context: state.context,
3088
- event,
3089
- action: a,
3090
- system: actorCtx.system,
3091
- self: actorCtx.self
3092
- });
3093
- }
3094
- };
3095
- return [state, a];
3096
- });
3097
- } else if (dereferencedAction) {
3098
- return dereferencedAction;
3099
- } else {
3100
- return actionObject;
3101
2957
  }
2958
+ choose.type = 'xstate.choose';
2959
+ choose.branches = branches;
2960
+ choose.resolve = resolve$1;
2961
+ return choose;
3102
2962
  }
3103
- function toActionObject(action) {
3104
- if (isDynamicAction(action)) {
3105
- return action;
3106
- }
3107
- if (typeof action === 'string') {
3108
- return {
3109
- type: action,
3110
- params: {}
3111
- };
3112
- }
3113
- if (typeof action === 'function') {
3114
- const type = 'xstate.function';
3115
- return createDynamicAction({
3116
- type,
3117
- params: {}
3118
- }, (event, {
3119
- state
3120
- }) => {
3121
- const actionObject = {
3122
- type,
3123
- params: {
3124
- function: action
3125
- },
3126
- execute: actorCtx => {
3127
- return action({
3128
- context: state.context,
3129
- event: event,
3130
- action: actionObject,
3131
- self: actorCtx.self,
3132
- system: actorCtx.system
3133
- });
3134
- }
3135
- };
3136
- return [state, actionObject];
3137
- });
3138
- }
3139
2963
 
3140
- // action is already a BaseActionObject
3141
- return action;
2964
+ function resolve(_, state, args, {
2965
+ get
2966
+ }) {
2967
+ return [state, undefined, toArray(get({
2968
+ context: state.context,
2969
+ event: args.event
2970
+ }))];
3142
2971
  }
3143
- const toActionObjects = action => {
3144
- if (!action) {
3145
- return [];
2972
+ function pure(getActions) {
2973
+ function pure(_) {
2974
+ {
2975
+ throw new Error(`This isn't supposed to be called`);
2976
+ }
3146
2977
  }
3147
- const actions = isArray(action) ? action : [action];
3148
- return actions.map(toActionObject);
3149
- };
2978
+ pure.type = 'xstate.pure';
2979
+ pure.get = getActions;
2980
+ pure.resolve = resolve;
2981
+ return pure;
2982
+ }
3150
2983
 
3151
2984
  /**
3152
2985
  * Returns an event type that represents an implicit event that
@@ -3157,7 +2990,7 @@ const toActionObjects = action => {
3157
2990
  */
3158
2991
  function after(delayRef, id) {
3159
2992
  const idSuffix = id ? `#${id}` : '';
3160
- return `${ActionTypes.After}(${delayRef})${idSuffix}`;
2993
+ return `${ConstantPrefix.After}(${delayRef})${idSuffix}`;
3161
2994
  }
3162
2995
 
3163
2996
  /**
@@ -3168,7 +3001,7 @@ function after(delayRef, id) {
3168
3001
  * @param output The data to pass into the event
3169
3002
  */
3170
3003
  function done(id, output) {
3171
- const type = `${ActionTypes.DoneState}.${id}`;
3004
+ const type = `${ConstantPrefix.DoneState}.${id}`;
3172
3005
  const eventObject = {
3173
3006
  type,
3174
3007
  output
@@ -3187,7 +3020,7 @@ function done(id, output) {
3187
3020
  * @param output The data to pass into the event
3188
3021
  */
3189
3022
  function doneInvoke(invokeId, output) {
3190
- const type = `${ActionTypes.DoneInvoke}.${invokeId}`;
3023
+ const type = `${ConstantPrefix.DoneInvoke}.${invokeId}`;
3191
3024
  const eventObject = {
3192
3025
  type,
3193
3026
  output
@@ -3196,7 +3029,7 @@ function doneInvoke(invokeId, output) {
3196
3029
  return eventObject;
3197
3030
  }
3198
3031
  function error(id, data) {
3199
- const type = `${ActionTypes.ErrorPlatform}.${id}`;
3032
+ const type = `${ConstantPrefix.ErrorPlatform}.${id}`;
3200
3033
  const eventObject = {
3201
3034
  type,
3202
3035
  data
@@ -3206,9 +3039,9 @@ function error(id, data) {
3206
3039
  }
3207
3040
  function createInitEvent(input) {
3208
3041
  return {
3209
- type: init,
3042
+ type: INIT_TYPE,
3210
3043
  input
3211
3044
  };
3212
3045
  }
3213
3046
 
3214
- 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 };
3047
+ 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 };