xstate 5.0.0-beta.51 → 5.0.0-beta.53

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 (48) hide show
  1. package/actions/dist/xstate-actions.cjs.js +9 -11
  2. package/actions/dist/xstate-actions.cjs.mjs +0 -2
  3. package/actions/dist/xstate-actions.development.cjs.js +9 -11
  4. package/actions/dist/xstate-actions.development.cjs.mjs +0 -2
  5. package/actions/dist/xstate-actions.development.esm.js +2 -2
  6. package/actions/dist/xstate-actions.esm.js +2 -2
  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 +17 -17
  10. package/actors/dist/xstate-actors.development.cjs.js +17 -17
  11. package/actors/dist/xstate-actors.development.esm.js +17 -17
  12. package/actors/dist/xstate-actors.esm.js +17 -17
  13. package/actors/dist/xstate-actors.umd.min.js +1 -1
  14. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  15. package/dist/declarations/src/State.d.ts +2 -2
  16. package/dist/declarations/src/StateMachine.d.ts +6 -6
  17. package/dist/declarations/src/StateNode.d.ts +4 -4
  18. package/dist/declarations/src/actions.d.ts +0 -2
  19. package/dist/declarations/src/actors/index.d.ts +1 -1
  20. package/dist/declarations/src/actors/transition.d.ts +1 -1
  21. package/dist/declarations/src/guards.d.ts +1 -1
  22. package/dist/declarations/src/interpreter.d.ts +7 -7
  23. package/dist/declarations/src/stateUtils.d.ts +9 -9
  24. package/dist/declarations/src/types.d.ts +23 -19
  25. package/dist/{pure-296f8ebd.development.esm.js → log-1fd7d00a.development.esm.js} +24 -61
  26. package/dist/{pure-aefddc19.esm.js → log-60ab9eaf.esm.js} +24 -58
  27. package/dist/{pure-c5f1b46c.cjs.js → log-717bb5a1.cjs.js} +23 -59
  28. package/dist/{pure-a0f16134.development.cjs.js → log-c8797128.development.cjs.js} +23 -62
  29. package/dist/{raise-acaa3884.development.esm.js → raise-953b1eb5.development.esm.js} +136 -136
  30. package/dist/{raise-d5633a02.cjs.js → raise-a8367773.cjs.js} +136 -136
  31. package/dist/{raise-4742bf04.esm.js → raise-be2f20bc.esm.js} +136 -136
  32. package/dist/{raise-528386de.development.cjs.js → raise-d9fd8932.development.cjs.js} +136 -136
  33. package/dist/xstate.cjs.js +28 -30
  34. package/dist/xstate.cjs.mjs +0 -2
  35. package/dist/xstate.development.cjs.js +28 -30
  36. package/dist/xstate.development.cjs.mjs +0 -2
  37. package/dist/xstate.development.esm.js +21 -21
  38. package/dist/xstate.esm.js +21 -21
  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.map +1 -1
  46. package/package.json +1 -1
  47. package/dist/declarations/src/actions/choose.d.ts +0 -9
  48. package/dist/declarations/src/actions/pure.d.ts +0 -10
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var guards_dist_xstateGuards = require('./raise-d5633a02.cjs.js');
3
+ var guards_dist_xstateGuards = require('./raise-a8367773.cjs.js');
4
4
 
5
5
  function createSpawner(actorScope, {
6
6
  machine,
@@ -55,17 +55,17 @@ function createSpawner(actorScope, {
55
55
  };
56
56
  }
57
57
 
58
- function resolveAssign(actorScope, state, actionArgs, actionParams, {
58
+ function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
59
59
  assignment
60
60
  }) {
61
- if (!state.context) {
61
+ if (!snapshot.context) {
62
62
  throw new Error('Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.');
63
63
  }
64
64
  const spawnedChildren = {};
65
65
  const assignArgs = {
66
- context: state.context,
66
+ context: snapshot.context,
67
67
  event: actionArgs.event,
68
- spawn: createSpawner(actorScope, state, actionArgs.event, spawnedChildren),
68
+ spawn: createSpawner(actorScope, snapshot, actionArgs.event, spawnedChildren),
69
69
  self: actorScope?.self,
70
70
  system: actorScope?.system
71
71
  };
@@ -78,13 +78,13 @@ function resolveAssign(actorScope, state, actionArgs, actionParams, {
78
78
  partialUpdate[key] = typeof propAssignment === 'function' ? propAssignment(assignArgs, actionParams) : propAssignment;
79
79
  }
80
80
  }
81
- const updatedContext = Object.assign({}, state.context, partialUpdate);
82
- return [guards_dist_xstateGuards.cloneMachineSnapshot(state, {
81
+ const updatedContext = Object.assign({}, snapshot.context, partialUpdate);
82
+ return [guards_dist_xstateGuards.cloneMachineSnapshot(snapshot, {
83
83
  context: updatedContext,
84
84
  children: Object.keys(spawnedChildren).length ? {
85
- ...state.children,
85
+ ...snapshot.children,
86
86
  ...spawnedChildren
87
- } : state.children
87
+ } : snapshot.children
88
88
  })];
89
89
  }
90
90
  /**
@@ -101,23 +101,6 @@ function assign(assignment) {
101
101
  return assign;
102
102
  }
103
103
 
104
- function resolveChoose(_, state, actionArgs, _actionParams, {
105
- branches
106
- }) {
107
- const matchedActions = branches.find(condition => {
108
- return !condition.guard || guards_dist_xstateGuards.evaluateGuard(condition.guard, state.context, actionArgs.event, state);
109
- })?.actions;
110
- return [state, undefined, guards_dist_xstateGuards.toArray(matchedActions)];
111
- }
112
- function choose(branches) {
113
- function choose(args, params) {
114
- }
115
- choose.type = 'xstate.choose';
116
- choose.branches = branches;
117
- choose.resolve = resolveChoose;
118
- return choose;
119
- }
120
-
121
104
  /**
122
105
  *
123
106
  * @remarks
@@ -182,13 +165,13 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
182
165
  * @template TSystem - The type of the actor system.
183
166
  */
184
167
 
185
- function resolveSendTo(actorScope, state, args, actionParams, {
168
+ function resolveSendTo(actorScope, snapshot, args, actionParams, {
186
169
  to,
187
170
  event: eventOrExpr,
188
171
  id,
189
172
  delay
190
173
  }, extra) {
191
- const delaysMap = state.machine.implementations.delays;
174
+ const delaysMap = snapshot.machine.implementations.delays;
192
175
  if (typeof eventOrExpr === 'string') {
193
176
  throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${eventOrExpr}" }) instead`);
194
177
  }
@@ -210,26 +193,26 @@ function resolveSendTo(actorScope, state, args, actionParams, {
210
193
  } else if (resolvedTarget.startsWith('#_')) {
211
194
  // SCXML compatibility: https://www.w3.org/TR/scxml/#SCXMLEventProcessor
212
195
  // #_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.
213
- targetActorRef = state.children[resolvedTarget.slice(2)];
196
+ targetActorRef = snapshot.children[resolvedTarget.slice(2)];
214
197
  } else {
215
- targetActorRef = extra.deferredActorIds?.includes(resolvedTarget) ? resolvedTarget : state.children[resolvedTarget];
198
+ targetActorRef = extra.deferredActorIds?.includes(resolvedTarget) ? resolvedTarget : snapshot.children[resolvedTarget];
216
199
  }
217
200
  if (!targetActorRef) {
218
- throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${state.machine.id}'.`);
201
+ throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${snapshot.machine.id}'.`);
219
202
  }
220
203
  } else {
221
204
  targetActorRef = resolvedTarget || actorScope?.self;
222
205
  }
223
- return [state, {
206
+ return [snapshot, {
224
207
  to: targetActorRef,
225
208
  event: resolvedEvent,
226
209
  id,
227
210
  delay: resolvedDelay
228
211
  }];
229
212
  }
230
- function retryResolveSendTo(_, state, params) {
213
+ function retryResolveSendTo(_, snapshot, params) {
231
214
  if (typeof params.to === 'string') {
232
- params.to = state.children[params.to];
215
+ params.to = snapshot.children[params.to];
233
216
  }
234
217
  }
235
218
  function executeSendTo(actorScope, params) {
@@ -260,7 +243,7 @@ function executeSendTo(actorScope, params) {
260
243
  function sendTo(to, eventOrExpr, options) {
261
244
  function sendTo(args, params) {
262
245
  }
263
- sendTo.type = 'xstate.sendTo';
246
+ sendTo.type = 'xsnapshot.sendTo';
264
247
  sendTo.to = to;
265
248
  sendTo.event = eventOrExpr;
266
249
  sendTo.id = options?.id;
@@ -308,7 +291,7 @@ function escalate(errorData, options) {
308
291
  }, options);
309
292
  }
310
293
 
311
- function resolveEnqueueActions(_, state, args, _actionParams, {
294
+ function resolveEnqueueActions(_, snapshot, args, _actionParams, {
312
295
  collect
313
296
  }) {
314
297
  const actions = [];
@@ -337,9 +320,9 @@ function resolveEnqueueActions(_, state, args, _actionParams, {
337
320
  context: args.context,
338
321
  event: args.event,
339
322
  enqueue,
340
- check: guard => guards_dist_xstateGuards.evaluateGuard(guard, state.context, args.event, state)
323
+ check: guard => guards_dist_xstateGuards.evaluateGuard(guard, snapshot.context, args.event, snapshot)
341
324
  });
342
- return [state, undefined, actions];
325
+ return [snapshot, undefined, actions];
343
326
  }
344
327
  function enqueueActions(collect) {
345
328
  function enqueueActions(args, params) {
@@ -350,11 +333,11 @@ function enqueueActions(collect) {
350
333
  return enqueueActions;
351
334
  }
352
335
 
353
- function resolveLog(_, state, actionArgs, actionParams, {
336
+ function resolveLog(_, snapshot, actionArgs, actionParams, {
354
337
  value,
355
338
  label
356
339
  }) {
357
- return [state, {
340
+ return [snapshot, {
358
341
  value: typeof value === 'function' ? value(actionArgs, actionParams) : value,
359
342
  label
360
343
  }];
@@ -396,30 +379,11 @@ function log(value = ({
396
379
  return log;
397
380
  }
398
381
 
399
- /**
400
- *
401
- * @deprecated Use `enqueueActions(...)` instead
402
- */
403
- function pure(getActions) {
404
- return enqueueActions(({
405
- context,
406
- event,
407
- enqueue
408
- }) => {
409
- guards_dist_xstateGuards.toArray(getActions({
410
- context,
411
- event
412
- })).forEach(enqueue);
413
- });
414
- }
415
-
416
382
  exports.SpecialTargets = SpecialTargets;
417
383
  exports.assign = assign;
418
- exports.choose = choose;
419
384
  exports.enqueueActions = enqueueActions;
420
385
  exports.escalate = escalate;
421
386
  exports.forwardTo = forwardTo;
422
387
  exports.log = log;
423
- exports.pure = pure;
424
388
  exports.sendParent = sendParent;
425
389
  exports.sendTo = sendTo;
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var guards_dist_xstateGuards = require('./raise-528386de.development.cjs.js');
3
+ var guards_dist_xstateGuards = require('./raise-d9fd8932.development.cjs.js');
4
4
 
5
5
  function createSpawner(actorScope, {
6
6
  machine,
@@ -55,17 +55,17 @@ function createSpawner(actorScope, {
55
55
  };
56
56
  }
57
57
 
58
- function resolveAssign(actorScope, state, actionArgs, actionParams, {
58
+ function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
59
59
  assignment
60
60
  }) {
61
- if (!state.context) {
61
+ if (!snapshot.context) {
62
62
  throw new Error('Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.');
63
63
  }
64
64
  const spawnedChildren = {};
65
65
  const assignArgs = {
66
- context: state.context,
66
+ context: snapshot.context,
67
67
  event: actionArgs.event,
68
- spawn: createSpawner(actorScope, state, actionArgs.event, spawnedChildren),
68
+ spawn: createSpawner(actorScope, snapshot, actionArgs.event, spawnedChildren),
69
69
  self: actorScope?.self,
70
70
  system: actorScope?.system
71
71
  };
@@ -78,13 +78,13 @@ function resolveAssign(actorScope, state, actionArgs, actionParams, {
78
78
  partialUpdate[key] = typeof propAssignment === 'function' ? propAssignment(assignArgs, actionParams) : propAssignment;
79
79
  }
80
80
  }
81
- const updatedContext = Object.assign({}, state.context, partialUpdate);
82
- return [guards_dist_xstateGuards.cloneMachineSnapshot(state, {
81
+ const updatedContext = Object.assign({}, snapshot.context, partialUpdate);
82
+ return [guards_dist_xstateGuards.cloneMachineSnapshot(snapshot, {
83
83
  context: updatedContext,
84
84
  children: Object.keys(spawnedChildren).length ? {
85
- ...state.children,
85
+ ...snapshot.children,
86
86
  ...spawnedChildren
87
- } : state.children
87
+ } : snapshot.children
88
88
  })];
89
89
  }
90
90
  /**
@@ -104,26 +104,6 @@ function assign(assignment) {
104
104
  return assign;
105
105
  }
106
106
 
107
- function resolveChoose(_, state, actionArgs, _actionParams, {
108
- branches
109
- }) {
110
- const matchedActions = branches.find(condition => {
111
- return !condition.guard || guards_dist_xstateGuards.evaluateGuard(condition.guard, state.context, actionArgs.event, state);
112
- })?.actions;
113
- return [state, undefined, guards_dist_xstateGuards.toArray(matchedActions)];
114
- }
115
- function choose(branches) {
116
- function choose(args, params) {
117
- {
118
- throw new Error(`This isn't supposed to be called`);
119
- }
120
- }
121
- choose.type = 'xstate.choose';
122
- choose.branches = branches;
123
- choose.resolve = resolveChoose;
124
- return choose;
125
- }
126
-
127
107
  /**
128
108
  *
129
109
  * @remarks
@@ -188,13 +168,13 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
188
168
  * @template TSystem - The type of the actor system.
189
169
  */
190
170
 
191
- function resolveSendTo(actorScope, state, args, actionParams, {
171
+ function resolveSendTo(actorScope, snapshot, args, actionParams, {
192
172
  to,
193
173
  event: eventOrExpr,
194
174
  id,
195
175
  delay
196
176
  }, extra) {
197
- const delaysMap = state.machine.implementations.delays;
177
+ const delaysMap = snapshot.machine.implementations.delays;
198
178
  if (typeof eventOrExpr === 'string') {
199
179
  throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${eventOrExpr}" }) instead`);
200
180
  }
@@ -216,26 +196,26 @@ function resolveSendTo(actorScope, state, args, actionParams, {
216
196
  } else if (resolvedTarget.startsWith('#_')) {
217
197
  // SCXML compatibility: https://www.w3.org/TR/scxml/#SCXMLEventProcessor
218
198
  // #_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.
219
- targetActorRef = state.children[resolvedTarget.slice(2)];
199
+ targetActorRef = snapshot.children[resolvedTarget.slice(2)];
220
200
  } else {
221
- targetActorRef = extra.deferredActorIds?.includes(resolvedTarget) ? resolvedTarget : state.children[resolvedTarget];
201
+ targetActorRef = extra.deferredActorIds?.includes(resolvedTarget) ? resolvedTarget : snapshot.children[resolvedTarget];
222
202
  }
223
203
  if (!targetActorRef) {
224
- throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${state.machine.id}'.`);
204
+ throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${snapshot.machine.id}'.`);
225
205
  }
226
206
  } else {
227
207
  targetActorRef = resolvedTarget || actorScope?.self;
228
208
  }
229
- return [state, {
209
+ return [snapshot, {
230
210
  to: targetActorRef,
231
211
  event: resolvedEvent,
232
212
  id,
233
213
  delay: resolvedDelay
234
214
  }];
235
215
  }
236
- function retryResolveSendTo(_, state, params) {
216
+ function retryResolveSendTo(_, snapshot, params) {
237
217
  if (typeof params.to === 'string') {
238
- params.to = state.children[params.to];
218
+ params.to = snapshot.children[params.to];
239
219
  }
240
220
  }
241
221
  function executeSendTo(actorScope, params) {
@@ -269,7 +249,7 @@ function sendTo(to, eventOrExpr, options) {
269
249
  throw new Error(`This isn't supposed to be called`);
270
250
  }
271
251
  }
272
- sendTo.type = 'xstate.sendTo';
252
+ sendTo.type = 'xsnapshot.sendTo';
273
253
  sendTo.to = to;
274
254
  sendTo.event = eventOrExpr;
275
255
  sendTo.id = options?.id;
@@ -327,7 +307,7 @@ function escalate(errorData, options) {
327
307
  }, options);
328
308
  }
329
309
 
330
- function resolveEnqueueActions(_, state, args, _actionParams, {
310
+ function resolveEnqueueActions(_, snapshot, args, _actionParams, {
331
311
  collect
332
312
  }) {
333
313
  const actions = [];
@@ -356,9 +336,9 @@ function resolveEnqueueActions(_, state, args, _actionParams, {
356
336
  context: args.context,
357
337
  event: args.event,
358
338
  enqueue,
359
- check: guard => guards_dist_xstateGuards.evaluateGuard(guard, state.context, args.event, state)
339
+ check: guard => guards_dist_xstateGuards.evaluateGuard(guard, snapshot.context, args.event, snapshot)
360
340
  });
361
- return [state, undefined, actions];
341
+ return [snapshot, undefined, actions];
362
342
  }
363
343
  function enqueueActions(collect) {
364
344
  function enqueueActions(args, params) {
@@ -372,11 +352,11 @@ function enqueueActions(collect) {
372
352
  return enqueueActions;
373
353
  }
374
354
 
375
- function resolveLog(_, state, actionArgs, actionParams, {
355
+ function resolveLog(_, snapshot, actionArgs, actionParams, {
376
356
  value,
377
357
  label
378
358
  }) {
379
- return [state, {
359
+ return [snapshot, {
380
360
  value: typeof value === 'function' ? value(actionArgs, actionParams) : value,
381
361
  label
382
362
  }];
@@ -421,30 +401,11 @@ function log(value = ({
421
401
  return log;
422
402
  }
423
403
 
424
- /**
425
- *
426
- * @deprecated Use `enqueueActions(...)` instead
427
- */
428
- function pure(getActions) {
429
- return enqueueActions(({
430
- context,
431
- event,
432
- enqueue
433
- }) => {
434
- guards_dist_xstateGuards.toArray(getActions({
435
- context,
436
- event
437
- })).forEach(enqueue);
438
- });
439
- }
440
-
441
404
  exports.SpecialTargets = SpecialTargets;
442
405
  exports.assign = assign;
443
- exports.choose = choose;
444
406
  exports.enqueueActions = enqueueActions;
445
407
  exports.escalate = escalate;
446
408
  exports.forwardTo = forwardTo;
447
409
  exports.log = log;
448
- exports.pure = pure;
449
410
  exports.sendParent = sendParent;
450
411
  exports.sendTo = sendTo;