xstate 5.0.0-beta.37 → 5.0.0-beta.39

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 (62) hide show
  1. package/actions/dist/xstate-actions.cjs.js +4 -3
  2. package/actions/dist/xstate-actions.cjs.mjs +1 -0
  3. package/actions/dist/xstate-actions.development.cjs.js +4 -3
  4. package/actions/dist/xstate-actions.development.cjs.mjs +1 -0
  5. package/actions/dist/xstate-actions.development.esm.js +3 -3
  6. package/actions/dist/xstate-actions.esm.js +3 -3
  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 +60 -3
  10. package/actors/dist/xstate-actors.development.cjs.js +60 -3
  11. package/actors/dist/xstate-actors.development.esm.js +60 -3
  12. package/actors/dist/xstate-actors.esm.js +60 -3
  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 +7 -7
  17. package/dist/declarations/src/actions/assign.d.ts +4 -4
  18. package/dist/declarations/src/actions/cancel.d.ts +4 -4
  19. package/dist/declarations/src/actions/choose.d.ts +3 -3
  20. package/dist/declarations/src/actions/log.d.ts +4 -4
  21. package/dist/declarations/src/actions/pure.d.ts +4 -4
  22. package/dist/declarations/src/actions/raise.d.ts +3 -3
  23. package/dist/declarations/src/actions/send.d.ts +7 -7
  24. package/dist/declarations/src/actions/spawn.d.ts +34 -0
  25. package/dist/declarations/src/actions/stop.d.ts +4 -4
  26. package/dist/declarations/src/actions.d.ts +1 -0
  27. package/dist/declarations/src/actors/callback.d.ts +76 -2
  28. package/dist/declarations/src/actors/observable.d.ts +2 -3
  29. package/dist/declarations/src/actors/promise.d.ts +0 -1
  30. package/dist/declarations/src/actors/transition.d.ts +3 -3
  31. package/dist/declarations/src/guards.d.ts +9 -10
  32. package/dist/declarations/src/interpreter.d.ts +71 -10
  33. package/dist/declarations/src/spawn.d.ts +3 -4
  34. package/dist/declarations/src/stateUtils.d.ts +4 -9
  35. package/dist/declarations/src/types.d.ts +51 -62
  36. package/dist/{interpreter-e58ca48d.development.cjs.js → interpreter-03a5c3f5.development.cjs.js} +91 -12
  37. package/dist/{interpreter-8def682e.esm.js → interpreter-1e8c1c0c.esm.js} +91 -12
  38. package/dist/{interpreter-97aff8d2.cjs.js → interpreter-5dfcd203.cjs.js} +91 -12
  39. package/dist/{interpreter-1c52b23c.development.esm.js → interpreter-70cd9217.development.esm.js} +91 -12
  40. package/dist/{raise-1fd59c65.development.cjs.js → raise-17cb3d9d.development.cjs.js} +145 -152
  41. package/dist/{raise-800296d7.cjs.js → raise-291d2181.cjs.js} +145 -152
  42. package/dist/{raise-21c417c1.esm.js → raise-62de3670.esm.js} +145 -153
  43. package/dist/{raise-e342a840.development.esm.js → raise-e044f460.development.esm.js} +145 -153
  44. package/dist/{send-92854675.esm.js → send-1249d4ac.esm.js} +45 -44
  45. package/dist/{send-b309ef4e.development.cjs.js → send-33433787.development.cjs.js} +45 -44
  46. package/dist/{send-4cc29786.cjs.js → send-af152aca.cjs.js} +45 -44
  47. package/dist/{send-83ccc98b.development.esm.js → send-f1a2a827.development.esm.js} +45 -44
  48. package/dist/xstate.cjs.js +23 -20
  49. package/dist/xstate.cjs.mjs +1 -0
  50. package/dist/xstate.development.cjs.js +23 -20
  51. package/dist/xstate.development.cjs.mjs +1 -0
  52. package/dist/xstate.development.esm.js +25 -23
  53. package/dist/xstate.esm.js +25 -23
  54. package/dist/xstate.umd.min.js +1 -1
  55. package/dist/xstate.umd.min.js.map +1 -1
  56. package/guards/dist/xstate-guards.cjs.js +2 -2
  57. package/guards/dist/xstate-guards.development.cjs.js +2 -2
  58. package/guards/dist/xstate-guards.development.esm.js +2 -2
  59. package/guards/dist/xstate-guards.esm.js +2 -2
  60. package/guards/dist/xstate-guards.umd.min.js +1 -1
  61. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  62. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
- import { j as cloneState, e as evaluateGuard } from './raise-21c417c1.esm.js';
2
- import { f as ActorStatus, j as createErrorActorEvent, r as resolveReferencedActor, d as createActor, t as toArray, x as XSTATE_ERROR } from './interpreter-8def682e.esm.js';
1
+ import { j as cloneState, e as evaluateGuard } from './raise-62de3670.esm.js';
2
+ import { f as ActorStatus, j as createErrorActorEvent, r as resolveReferencedActor, d as createActor, t as toArray, x as XSTATE_ERROR } from './interpreter-1e8c1c0c.esm.js';
3
3
 
4
- function createSpawner(actorContext, {
4
+ function createSpawner(actorScope, {
5
5
  machine,
6
6
  context
7
7
  }, event, spawnedChildren) {
@@ -19,11 +19,11 @@ function createSpawner(actorContext, {
19
19
  // TODO: this should also receive `src`
20
20
  const actorRef = createActor(referenced.src, {
21
21
  id: options.id,
22
- parent: actorContext.self,
22
+ parent: actorScope.self,
23
23
  input: typeof input === 'function' ? input({
24
24
  context,
25
25
  event,
26
- self: actorContext.self
26
+ self: actorScope.self
27
27
  }) : input,
28
28
  src,
29
29
  systemId
@@ -33,15 +33,13 @@ function createSpawner(actorContext, {
33
33
  actorRef.subscribe({
34
34
  next: snapshot => {
35
35
  if (snapshot.status === 'active') {
36
- actorContext.self.send({
36
+ actorScope.self.send({
37
37
  type: `xstate.snapshot.${actorRef.id}`,
38
38
  snapshot
39
39
  });
40
40
  }
41
41
  },
42
- error: () => {
43
- /* TODO */
44
- }
42
+ error: () => {}
45
43
  });
46
44
  }
47
45
  return actorRef;
@@ -49,7 +47,7 @@ function createSpawner(actorContext, {
49
47
  // TODO: this should also receive `src`
50
48
  const actorRef = createActor(src, {
51
49
  id: options.id,
52
- parent: actorContext.self,
50
+ parent: actorScope.self,
53
51
  input: options.input,
54
52
  src: undefined,
55
53
  systemId
@@ -58,16 +56,14 @@ function createSpawner(actorContext, {
58
56
  actorRef.subscribe({
59
57
  next: snapshot => {
60
58
  if (snapshot.status === 'active') {
61
- actorContext.self.send({
59
+ actorScope.self.send({
62
60
  type: `xstate.snapshot.${actorRef.id}`,
63
61
  snapshot,
64
62
  id: actorRef.id
65
63
  });
66
64
  }
67
65
  },
68
- error: () => {
69
- /* TODO */
70
- }
66
+ error: () => {}
71
67
  });
72
68
  }
73
69
  return actorRef;
@@ -76,14 +72,14 @@ function createSpawner(actorContext, {
76
72
  return (src, options) => {
77
73
  const actorRef = spawn(src, options); // TODO: fix types
78
74
  spawnedChildren[actorRef.id] = actorRef;
79
- actorContext.defer(() => {
75
+ actorScope.defer(() => {
80
76
  if (actorRef.status === ActorStatus.Stopped) {
81
77
  return;
82
78
  }
83
79
  try {
84
80
  actorRef.start?.();
85
81
  } catch (err) {
86
- actorContext.self.send(createErrorActorEvent(actorRef.id, err));
82
+ actorScope.self.send(createErrorActorEvent(actorRef.id, err));
87
83
  return;
88
84
  }
89
85
  });
@@ -91,7 +87,7 @@ function createSpawner(actorContext, {
91
87
  };
92
88
  }
93
89
 
94
- function resolveAssign(actorContext, state, actionArgs, {
90
+ function resolveAssign(actorScope, state, actionArgs, actionParams, {
95
91
  assignment
96
92
  }) {
97
93
  if (!state.context) {
@@ -101,18 +97,17 @@ function resolveAssign(actorContext, state, actionArgs, {
101
97
  const assignArgs = {
102
98
  context: state.context,
103
99
  event: actionArgs.event,
104
- action: actionArgs.action,
105
- spawn: createSpawner(actorContext, state, actionArgs.event, spawnedChildren),
106
- self: actorContext?.self,
107
- system: actorContext?.system
100
+ spawn: createSpawner(actorScope, state, actionArgs.event, spawnedChildren),
101
+ self: actorScope?.self,
102
+ system: actorScope?.system
108
103
  };
109
104
  let partialUpdate = {};
110
105
  if (typeof assignment === 'function') {
111
- partialUpdate = assignment(assignArgs);
106
+ partialUpdate = assignment(assignArgs, actionParams);
112
107
  } else {
113
108
  for (const key of Object.keys(assignment)) {
114
109
  const propAssignment = assignment[key];
115
- partialUpdate[key] = typeof propAssignment === 'function' ? propAssignment(assignArgs) : propAssignment;
110
+ partialUpdate[key] = typeof propAssignment === 'function' ? propAssignment(assignArgs, actionParams) : propAssignment;
116
111
  }
117
112
  }
118
113
  const updatedContext = Object.assign({}, state.context, partialUpdate);
@@ -130,7 +125,7 @@ function resolveAssign(actorContext, state, actionArgs, {
130
125
  * @param assignment An object that represents the partial context to update.
131
126
  */
132
127
  function assign(assignment) {
133
- function assign(_) {
128
+ function assign(args, params) {
134
129
  }
135
130
  assign.type = 'xstate.assign';
136
131
  assign.assignment = assignment;
@@ -138,7 +133,7 @@ function assign(assignment) {
138
133
  return assign;
139
134
  }
140
135
 
141
- function resolveChoose(_, state, actionArgs, {
136
+ function resolveChoose(_, state, actionArgs, _actionParams, {
142
137
  branches
143
138
  }) {
144
139
  const matchedActions = branches.find(condition => {
@@ -147,7 +142,7 @@ function resolveChoose(_, state, actionArgs, {
147
142
  return [state, undefined, toArray(matchedActions)];
148
143
  }
149
144
  function choose(branches) {
150
- function choose(_) {
145
+ function choose(args, params) {
151
146
  }
152
147
  choose.type = 'xstate.choose';
153
148
  choose.branches = branches;
@@ -155,12 +150,12 @@ function choose(branches) {
155
150
  return choose;
156
151
  }
157
152
 
158
- function resolveLog(_, state, actionArgs, {
153
+ function resolveLog(_, state, actionArgs, actionParams, {
159
154
  value,
160
155
  label
161
156
  }) {
162
157
  return [state, {
163
- value: typeof value === 'function' ? value(actionArgs) : value,
158
+ value: typeof value === 'function' ? value(actionArgs, actionParams) : value,
164
159
  label
165
160
  }];
166
161
  }
@@ -191,7 +186,7 @@ function log(value = ({
191
186
  context,
192
187
  event
193
188
  }), label) {
194
- function log(_) {
189
+ function log(args, params) {
195
190
  }
196
191
  log.type = 'xstate.log';
197
192
  log.value = value;
@@ -201,7 +196,7 @@ function log(value = ({
201
196
  return log;
202
197
  }
203
198
 
204
- function resolvePure(_, state, args, {
199
+ function resolvePure(_, state, args, _actionParams, {
205
200
  get
206
201
  }) {
207
202
  return [state, undefined, toArray(get({
@@ -210,7 +205,7 @@ function resolvePure(_, state, args, {
210
205
  }))];
211
206
  }
212
207
  function pure(getActions) {
213
- function pure(_) {
208
+ function pure(args, params) {
214
209
  }
215
210
  pure.type = 'xstate.pure';
216
211
  pure.get = getActions;
@@ -219,6 +214,9 @@ function pure(getActions) {
219
214
  }
220
215
 
221
216
  /**
217
+ *
218
+ * @remarks
219
+ *
222
220
  * `T | unknown` reduces to `unknown` and that can be problematic when it comes to contextual typing.
223
221
  * It especially is a problem when the union has a function member, like here:
224
222
  *
@@ -239,7 +237,10 @@ function pure(getActions) {
239
237
  /**
240
238
  * The string or object representing the state value relative to the parent state node.
241
239
  *
240
+ * @remarks
241
+ *
242
242
  * - For a child atomic state node, this is a string, e.g., `"pending"`.
243
+ *
243
244
  * - For complex state nodes, this is an object, e.g., `{ success: "someChildState" }`.
244
245
  */
245
246
 
@@ -253,7 +254,7 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
253
254
  return SpecialTargets;
254
255
  }({});
255
256
 
256
- function resolveSendTo(actorContext, state, args, {
257
+ function resolveSendTo(actorScope, state, args, actionParams, {
257
258
  to,
258
259
  event: eventOrExpr,
259
260
  id,
@@ -263,21 +264,21 @@ function resolveSendTo(actorContext, state, args, {
263
264
  if (typeof eventOrExpr === 'string') {
264
265
  throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${eventOrExpr}" }) instead`);
265
266
  }
266
- const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args) : eventOrExpr;
267
+ const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args, actionParams) : eventOrExpr;
267
268
  let resolvedDelay;
268
269
  if (typeof delay === 'string') {
269
270
  const configDelay = delaysMap && delaysMap[delay];
270
- resolvedDelay = typeof configDelay === 'function' ? configDelay(args) : configDelay;
271
+ resolvedDelay = typeof configDelay === 'function' ? configDelay(args, actionParams) : configDelay;
271
272
  } else {
272
- resolvedDelay = typeof delay === 'function' ? delay(args) : delay;
273
+ resolvedDelay = typeof delay === 'function' ? delay(args, actionParams) : delay;
273
274
  }
274
- const resolvedTarget = typeof to === 'function' ? to(args) : to;
275
+ const resolvedTarget = typeof to === 'function' ? to(args, actionParams) : to;
275
276
  let targetActorRef;
276
277
  if (typeof resolvedTarget === 'string') {
277
278
  if (resolvedTarget === SpecialTargets.Parent) {
278
- targetActorRef = actorContext?.self._parent;
279
+ targetActorRef = actorScope?.self._parent;
279
280
  } else if (resolvedTarget === SpecialTargets.Internal) {
280
- targetActorRef = actorContext?.self;
281
+ targetActorRef = actorScope?.self;
281
282
  } else if (resolvedTarget.startsWith('#_')) {
282
283
  // SCXML compatibility: https://www.w3.org/TR/scxml/#SCXMLEventProcessor
283
284
  // #_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.
@@ -289,7 +290,7 @@ function resolveSendTo(actorContext, state, args, {
289
290
  throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${state.machine.id}'.`);
290
291
  }
291
292
  } else {
292
- targetActorRef = resolvedTarget || actorContext?.self;
293
+ targetActorRef = resolvedTarget || actorScope?.self;
293
294
  }
294
295
  return [state, {
295
296
  to: targetActorRef,
@@ -303,20 +304,20 @@ function retryResolveSendTo(_, state, params) {
303
304
  params.to = state.children[params.to];
304
305
  }
305
306
  }
306
- function executeSendTo(actorContext, params) {
307
+ function executeSendTo(actorScope, params) {
307
308
  if (typeof params.delay === 'number') {
308
- actorContext.self.delaySend(params);
309
+ actorScope.self.delaySend(params);
309
310
  return;
310
311
  }
311
312
 
312
313
  // this forms an outgoing events queue
313
314
  // thanks to that the recipient actors are able to read the *updated* snapshot value of the sender
314
- actorContext.defer(() => {
315
+ actorScope.defer(() => {
315
316
  const {
316
317
  to,
317
318
  event
318
319
  } = params;
319
- actorContext?.system._relay(actorContext.self, to, event.type === XSTATE_ERROR ? createErrorActorEvent(actorContext.self.id, event.data) : event);
320
+ actorScope?.system._relay(actorScope.self, to, event.type === XSTATE_ERROR ? createErrorActorEvent(actorScope.self.id, event.data) : event);
320
321
  });
321
322
  }
322
323
  /**
@@ -329,7 +330,7 @@ function executeSendTo(actorContext, params) {
329
330
  * - `delay` - The number of milliseconds to delay the sending of the event.
330
331
  */
331
332
  function sendTo(to, eventOrExpr, options) {
332
- function sendTo(_) {
333
+ function sendTo(args, params) {
333
334
  }
334
335
  sendTo.type = 'xstate.sendTo';
335
336
  sendTo.to = to;
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var guards_dist_xstateGuards = require('./raise-1fd59c65.development.cjs.js');
4
- var interpreter = require('./interpreter-e58ca48d.development.cjs.js');
3
+ var guards_dist_xstateGuards = require('./raise-17cb3d9d.development.cjs.js');
4
+ var interpreter = require('./interpreter-03a5c3f5.development.cjs.js');
5
5
 
6
- function createSpawner(actorContext, {
6
+ function createSpawner(actorScope, {
7
7
  machine,
8
8
  context
9
9
  }, event, spawnedChildren) {
@@ -21,11 +21,11 @@ function createSpawner(actorContext, {
21
21
  // TODO: this should also receive `src`
22
22
  const actorRef = interpreter.createActor(referenced.src, {
23
23
  id: options.id,
24
- parent: actorContext.self,
24
+ parent: actorScope.self,
25
25
  input: typeof input === 'function' ? input({
26
26
  context,
27
27
  event,
28
- self: actorContext.self
28
+ self: actorScope.self
29
29
  }) : input,
30
30
  src,
31
31
  systemId
@@ -35,15 +35,13 @@ function createSpawner(actorContext, {
35
35
  actorRef.subscribe({
36
36
  next: snapshot => {
37
37
  if (snapshot.status === 'active') {
38
- actorContext.self.send({
38
+ actorScope.self.send({
39
39
  type: `xstate.snapshot.${actorRef.id}`,
40
40
  snapshot
41
41
  });
42
42
  }
43
43
  },
44
- error: () => {
45
- /* TODO */
46
- }
44
+ error: () => {}
47
45
  });
48
46
  }
49
47
  return actorRef;
@@ -51,7 +49,7 @@ function createSpawner(actorContext, {
51
49
  // TODO: this should also receive `src`
52
50
  const actorRef = interpreter.createActor(src, {
53
51
  id: options.id,
54
- parent: actorContext.self,
52
+ parent: actorScope.self,
55
53
  input: options.input,
56
54
  src: undefined,
57
55
  systemId
@@ -60,16 +58,14 @@ function createSpawner(actorContext, {
60
58
  actorRef.subscribe({
61
59
  next: snapshot => {
62
60
  if (snapshot.status === 'active') {
63
- actorContext.self.send({
61
+ actorScope.self.send({
64
62
  type: `xstate.snapshot.${actorRef.id}`,
65
63
  snapshot,
66
64
  id: actorRef.id
67
65
  });
68
66
  }
69
67
  },
70
- error: () => {
71
- /* TODO */
72
- }
68
+ error: () => {}
73
69
  });
74
70
  }
75
71
  return actorRef;
@@ -78,14 +74,14 @@ function createSpawner(actorContext, {
78
74
  return (src, options) => {
79
75
  const actorRef = spawn(src, options); // TODO: fix types
80
76
  spawnedChildren[actorRef.id] = actorRef;
81
- actorContext.defer(() => {
77
+ actorScope.defer(() => {
82
78
  if (actorRef.status === interpreter.ActorStatus.Stopped) {
83
79
  return;
84
80
  }
85
81
  try {
86
82
  actorRef.start?.();
87
83
  } catch (err) {
88
- actorContext.self.send(interpreter.createErrorActorEvent(actorRef.id, err));
84
+ actorScope.self.send(interpreter.createErrorActorEvent(actorRef.id, err));
89
85
  return;
90
86
  }
91
87
  });
@@ -93,7 +89,7 @@ function createSpawner(actorContext, {
93
89
  };
94
90
  }
95
91
 
96
- function resolveAssign(actorContext, state, actionArgs, {
92
+ function resolveAssign(actorScope, state, actionArgs, actionParams, {
97
93
  assignment
98
94
  }) {
99
95
  if (!state.context) {
@@ -103,18 +99,17 @@ function resolveAssign(actorContext, state, actionArgs, {
103
99
  const assignArgs = {
104
100
  context: state.context,
105
101
  event: actionArgs.event,
106
- action: actionArgs.action,
107
- spawn: createSpawner(actorContext, state, actionArgs.event, spawnedChildren),
108
- self: actorContext?.self,
109
- system: actorContext?.system
102
+ spawn: createSpawner(actorScope, state, actionArgs.event, spawnedChildren),
103
+ self: actorScope?.self,
104
+ system: actorScope?.system
110
105
  };
111
106
  let partialUpdate = {};
112
107
  if (typeof assignment === 'function') {
113
- partialUpdate = assignment(assignArgs);
108
+ partialUpdate = assignment(assignArgs, actionParams);
114
109
  } else {
115
110
  for (const key of Object.keys(assignment)) {
116
111
  const propAssignment = assignment[key];
117
- partialUpdate[key] = typeof propAssignment === 'function' ? propAssignment(assignArgs) : propAssignment;
112
+ partialUpdate[key] = typeof propAssignment === 'function' ? propAssignment(assignArgs, actionParams) : propAssignment;
118
113
  }
119
114
  }
120
115
  const updatedContext = Object.assign({}, state.context, partialUpdate);
@@ -132,7 +127,7 @@ function resolveAssign(actorContext, state, actionArgs, {
132
127
  * @param assignment An object that represents the partial context to update.
133
128
  */
134
129
  function assign(assignment) {
135
- function assign(_) {
130
+ function assign(args, params) {
136
131
  {
137
132
  throw new Error(`This isn't supposed to be called`);
138
133
  }
@@ -143,7 +138,7 @@ function assign(assignment) {
143
138
  return assign;
144
139
  }
145
140
 
146
- function resolveChoose(_, state, actionArgs, {
141
+ function resolveChoose(_, state, actionArgs, _actionParams, {
147
142
  branches
148
143
  }) {
149
144
  const matchedActions = branches.find(condition => {
@@ -152,7 +147,7 @@ function resolveChoose(_, state, actionArgs, {
152
147
  return [state, undefined, interpreter.toArray(matchedActions)];
153
148
  }
154
149
  function choose(branches) {
155
- function choose(_) {
150
+ function choose(args, params) {
156
151
  {
157
152
  throw new Error(`This isn't supposed to be called`);
158
153
  }
@@ -163,12 +158,12 @@ function choose(branches) {
163
158
  return choose;
164
159
  }
165
160
 
166
- function resolveLog(_, state, actionArgs, {
161
+ function resolveLog(_, state, actionArgs, actionParams, {
167
162
  value,
168
163
  label
169
164
  }) {
170
165
  return [state, {
171
- value: typeof value === 'function' ? value(actionArgs) : value,
166
+ value: typeof value === 'function' ? value(actionArgs, actionParams) : value,
172
167
  label
173
168
  }];
174
169
  }
@@ -199,7 +194,7 @@ function log(value = ({
199
194
  context,
200
195
  event
201
196
  }), label) {
202
- function log(_) {
197
+ function log(args, params) {
203
198
  {
204
199
  throw new Error(`This isn't supposed to be called`);
205
200
  }
@@ -212,7 +207,7 @@ function log(value = ({
212
207
  return log;
213
208
  }
214
209
 
215
- function resolvePure(_, state, args, {
210
+ function resolvePure(_, state, args, _actionParams, {
216
211
  get
217
212
  }) {
218
213
  return [state, undefined, interpreter.toArray(get({
@@ -221,7 +216,7 @@ function resolvePure(_, state, args, {
221
216
  }))];
222
217
  }
223
218
  function pure(getActions) {
224
- function pure(_) {
219
+ function pure(args, params) {
225
220
  {
226
221
  throw new Error(`This isn't supposed to be called`);
227
222
  }
@@ -233,6 +228,9 @@ function pure(getActions) {
233
228
  }
234
229
 
235
230
  /**
231
+ *
232
+ * @remarks
233
+ *
236
234
  * `T | unknown` reduces to `unknown` and that can be problematic when it comes to contextual typing.
237
235
  * It especially is a problem when the union has a function member, like here:
238
236
  *
@@ -253,7 +251,10 @@ function pure(getActions) {
253
251
  /**
254
252
  * The string or object representing the state value relative to the parent state node.
255
253
  *
254
+ * @remarks
255
+ *
256
256
  * - For a child atomic state node, this is a string, e.g., `"pending"`.
257
+ *
257
258
  * - For complex state nodes, this is an object, e.g., `{ success: "someChildState" }`.
258
259
  */
259
260
 
@@ -267,7 +268,7 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
267
268
  return SpecialTargets;
268
269
  }({});
269
270
 
270
- function resolveSendTo(actorContext, state, args, {
271
+ function resolveSendTo(actorScope, state, args, actionParams, {
271
272
  to,
272
273
  event: eventOrExpr,
273
274
  id,
@@ -277,21 +278,21 @@ function resolveSendTo(actorContext, state, args, {
277
278
  if (typeof eventOrExpr === 'string') {
278
279
  throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${eventOrExpr}" }) instead`);
279
280
  }
280
- const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args) : eventOrExpr;
281
+ const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args, actionParams) : eventOrExpr;
281
282
  let resolvedDelay;
282
283
  if (typeof delay === 'string') {
283
284
  const configDelay = delaysMap && delaysMap[delay];
284
- resolvedDelay = typeof configDelay === 'function' ? configDelay(args) : configDelay;
285
+ resolvedDelay = typeof configDelay === 'function' ? configDelay(args, actionParams) : configDelay;
285
286
  } else {
286
- resolvedDelay = typeof delay === 'function' ? delay(args) : delay;
287
+ resolvedDelay = typeof delay === 'function' ? delay(args, actionParams) : delay;
287
288
  }
288
- const resolvedTarget = typeof to === 'function' ? to(args) : to;
289
+ const resolvedTarget = typeof to === 'function' ? to(args, actionParams) : to;
289
290
  let targetActorRef;
290
291
  if (typeof resolvedTarget === 'string') {
291
292
  if (resolvedTarget === SpecialTargets.Parent) {
292
- targetActorRef = actorContext?.self._parent;
293
+ targetActorRef = actorScope?.self._parent;
293
294
  } else if (resolvedTarget === SpecialTargets.Internal) {
294
- targetActorRef = actorContext?.self;
295
+ targetActorRef = actorScope?.self;
295
296
  } else if (resolvedTarget.startsWith('#_')) {
296
297
  // SCXML compatibility: https://www.w3.org/TR/scxml/#SCXMLEventProcessor
297
298
  // #_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.
@@ -303,7 +304,7 @@ function resolveSendTo(actorContext, state, args, {
303
304
  throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${state.machine.id}'.`);
304
305
  }
305
306
  } else {
306
- targetActorRef = resolvedTarget || actorContext?.self;
307
+ targetActorRef = resolvedTarget || actorScope?.self;
307
308
  }
308
309
  return [state, {
309
310
  to: targetActorRef,
@@ -317,20 +318,20 @@ function retryResolveSendTo(_, state, params) {
317
318
  params.to = state.children[params.to];
318
319
  }
319
320
  }
320
- function executeSendTo(actorContext, params) {
321
+ function executeSendTo(actorScope, params) {
321
322
  if (typeof params.delay === 'number') {
322
- actorContext.self.delaySend(params);
323
+ actorScope.self.delaySend(params);
323
324
  return;
324
325
  }
325
326
 
326
327
  // this forms an outgoing events queue
327
328
  // thanks to that the recipient actors are able to read the *updated* snapshot value of the sender
328
- actorContext.defer(() => {
329
+ actorScope.defer(() => {
329
330
  const {
330
331
  to,
331
332
  event
332
333
  } = params;
333
- actorContext?.system._relay(actorContext.self, to, event.type === interpreter.XSTATE_ERROR ? interpreter.createErrorActorEvent(actorContext.self.id, event.data) : event);
334
+ actorScope?.system._relay(actorScope.self, to, event.type === interpreter.XSTATE_ERROR ? interpreter.createErrorActorEvent(actorScope.self.id, event.data) : event);
334
335
  });
335
336
  }
336
337
  /**
@@ -343,7 +344,7 @@ function executeSendTo(actorContext, params) {
343
344
  * - `delay` - The number of milliseconds to delay the sending of the event.
344
345
  */
345
346
  function sendTo(to, eventOrExpr, options) {
346
- function sendTo(_) {
347
+ function sendTo(args, params) {
347
348
  {
348
349
  throw new Error(`This isn't supposed to be called`);
349
350
  }