xstate 5.0.0-beta.38 → 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.
- package/actions/dist/xstate-actions.cjs.js +3 -3
- package/actions/dist/xstate-actions.development.cjs.js +3 -3
- package/actions/dist/xstate-actions.development.esm.js +3 -3
- package/actions/dist/xstate-actions.esm.js +3 -3
- package/actions/dist/xstate-actions.umd.min.js +1 -1
- package/actions/dist/xstate-actions.umd.min.js.map +1 -1
- package/actors/dist/xstate-actors.cjs.js +60 -3
- package/actors/dist/xstate-actors.development.cjs.js +60 -3
- package/actors/dist/xstate-actors.development.esm.js +60 -3
- package/actors/dist/xstate-actors.esm.js +60 -3
- package/actors/dist/xstate-actors.umd.min.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/declarations/src/StateMachine.d.ts +5 -5
- package/dist/declarations/src/actors/callback.d.ts +74 -0
- package/dist/declarations/src/actors/transition.d.ts +2 -2
- package/dist/declarations/src/interpreter.d.ts +70 -9
- package/dist/declarations/src/spawn.d.ts +2 -2
- package/dist/declarations/src/stateUtils.d.ts +4 -4
- package/dist/declarations/src/types.d.ts +7 -7
- package/dist/{interpreter-ed3f81f7.development.cjs.js → interpreter-03a5c3f5.development.cjs.js} +90 -11
- package/dist/{interpreter-c80ce92e.esm.js → interpreter-1e8c1c0c.esm.js} +90 -11
- package/dist/{interpreter-b6f22ee2.cjs.js → interpreter-5dfcd203.cjs.js} +90 -11
- package/dist/{interpreter-4005eb36.development.esm.js → interpreter-70cd9217.development.esm.js} +90 -11
- package/dist/{raise-b69a3d16.development.cjs.js → raise-17cb3d9d.development.cjs.js} +84 -81
- package/dist/{raise-7faa9b3b.cjs.js → raise-291d2181.cjs.js} +83 -80
- package/dist/{raise-c989c7fb.esm.js → raise-62de3670.esm.js} +83 -80
- package/dist/{raise-42073973.development.esm.js → raise-e044f460.development.esm.js} +84 -81
- package/dist/{send-4b616da9.esm.js → send-1249d4ac.esm.js} +22 -22
- package/dist/{send-58725522.development.cjs.js → send-33433787.development.cjs.js} +22 -22
- package/dist/{send-34160163.cjs.js → send-af152aca.cjs.js} +22 -22
- package/dist/{send-bff8c910.development.esm.js → send-f1a2a827.development.esm.js} +22 -22
- package/dist/xstate.cjs.js +17 -17
- package/dist/xstate.development.cjs.js +17 -17
- package/dist/xstate.development.esm.js +20 -20
- package/dist/xstate.esm.js +20 -20
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +2 -2
- package/guards/dist/xstate-guards.development.cjs.js +2 -2
- package/guards/dist/xstate-guards.development.esm.js +2 -2
- package/guards/dist/xstate-guards.esm.js +2 -2
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
4
|
-
var interpreter = require('./interpreter-
|
|
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(
|
|
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:
|
|
24
|
+
parent: actorScope.self,
|
|
25
25
|
input: typeof input === 'function' ? input({
|
|
26
26
|
context,
|
|
27
27
|
event,
|
|
28
|
-
self:
|
|
28
|
+
self: actorScope.self
|
|
29
29
|
}) : input,
|
|
30
30
|
src,
|
|
31
31
|
systemId
|
|
@@ -35,7 +35,7 @@ function createSpawner(actorContext, {
|
|
|
35
35
|
actorRef.subscribe({
|
|
36
36
|
next: snapshot => {
|
|
37
37
|
if (snapshot.status === 'active') {
|
|
38
|
-
|
|
38
|
+
actorScope.self.send({
|
|
39
39
|
type: `xstate.snapshot.${actorRef.id}`,
|
|
40
40
|
snapshot
|
|
41
41
|
});
|
|
@@ -49,7 +49,7 @@ function createSpawner(actorContext, {
|
|
|
49
49
|
// TODO: this should also receive `src`
|
|
50
50
|
const actorRef = interpreter.createActor(src, {
|
|
51
51
|
id: options.id,
|
|
52
|
-
parent:
|
|
52
|
+
parent: actorScope.self,
|
|
53
53
|
input: options.input,
|
|
54
54
|
src: undefined,
|
|
55
55
|
systemId
|
|
@@ -58,7 +58,7 @@ function createSpawner(actorContext, {
|
|
|
58
58
|
actorRef.subscribe({
|
|
59
59
|
next: snapshot => {
|
|
60
60
|
if (snapshot.status === 'active') {
|
|
61
|
-
|
|
61
|
+
actorScope.self.send({
|
|
62
62
|
type: `xstate.snapshot.${actorRef.id}`,
|
|
63
63
|
snapshot,
|
|
64
64
|
id: actorRef.id
|
|
@@ -74,14 +74,14 @@ function createSpawner(actorContext, {
|
|
|
74
74
|
return (src, options) => {
|
|
75
75
|
const actorRef = spawn(src, options); // TODO: fix types
|
|
76
76
|
spawnedChildren[actorRef.id] = actorRef;
|
|
77
|
-
|
|
77
|
+
actorScope.defer(() => {
|
|
78
78
|
if (actorRef.status === interpreter.ActorStatus.Stopped) {
|
|
79
79
|
return;
|
|
80
80
|
}
|
|
81
81
|
try {
|
|
82
82
|
actorRef.start?.();
|
|
83
83
|
} catch (err) {
|
|
84
|
-
|
|
84
|
+
actorScope.self.send(interpreter.createErrorActorEvent(actorRef.id, err));
|
|
85
85
|
return;
|
|
86
86
|
}
|
|
87
87
|
});
|
|
@@ -89,7 +89,7 @@ function createSpawner(actorContext, {
|
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
function resolveAssign(
|
|
92
|
+
function resolveAssign(actorScope, state, actionArgs, actionParams, {
|
|
93
93
|
assignment
|
|
94
94
|
}) {
|
|
95
95
|
if (!state.context) {
|
|
@@ -99,9 +99,9 @@ function resolveAssign(actorContext, state, actionArgs, actionParams, {
|
|
|
99
99
|
const assignArgs = {
|
|
100
100
|
context: state.context,
|
|
101
101
|
event: actionArgs.event,
|
|
102
|
-
spawn: createSpawner(
|
|
103
|
-
self:
|
|
104
|
-
system:
|
|
102
|
+
spawn: createSpawner(actorScope, state, actionArgs.event, spawnedChildren),
|
|
103
|
+
self: actorScope?.self,
|
|
104
|
+
system: actorScope?.system
|
|
105
105
|
};
|
|
106
106
|
let partialUpdate = {};
|
|
107
107
|
if (typeof assignment === 'function') {
|
|
@@ -268,7 +268,7 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
|
268
268
|
return SpecialTargets;
|
|
269
269
|
}({});
|
|
270
270
|
|
|
271
|
-
function resolveSendTo(
|
|
271
|
+
function resolveSendTo(actorScope, state, args, actionParams, {
|
|
272
272
|
to,
|
|
273
273
|
event: eventOrExpr,
|
|
274
274
|
id,
|
|
@@ -290,9 +290,9 @@ function resolveSendTo(actorContext, state, args, actionParams, {
|
|
|
290
290
|
let targetActorRef;
|
|
291
291
|
if (typeof resolvedTarget === 'string') {
|
|
292
292
|
if (resolvedTarget === SpecialTargets.Parent) {
|
|
293
|
-
targetActorRef =
|
|
293
|
+
targetActorRef = actorScope?.self._parent;
|
|
294
294
|
} else if (resolvedTarget === SpecialTargets.Internal) {
|
|
295
|
-
targetActorRef =
|
|
295
|
+
targetActorRef = actorScope?.self;
|
|
296
296
|
} else if (resolvedTarget.startsWith('#_')) {
|
|
297
297
|
// SCXML compatibility: https://www.w3.org/TR/scxml/#SCXMLEventProcessor
|
|
298
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.
|
|
@@ -304,7 +304,7 @@ function resolveSendTo(actorContext, state, args, actionParams, {
|
|
|
304
304
|
throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${state.machine.id}'.`);
|
|
305
305
|
}
|
|
306
306
|
} else {
|
|
307
|
-
targetActorRef = resolvedTarget ||
|
|
307
|
+
targetActorRef = resolvedTarget || actorScope?.self;
|
|
308
308
|
}
|
|
309
309
|
return [state, {
|
|
310
310
|
to: targetActorRef,
|
|
@@ -318,20 +318,20 @@ function retryResolveSendTo(_, state, params) {
|
|
|
318
318
|
params.to = state.children[params.to];
|
|
319
319
|
}
|
|
320
320
|
}
|
|
321
|
-
function executeSendTo(
|
|
321
|
+
function executeSendTo(actorScope, params) {
|
|
322
322
|
if (typeof params.delay === 'number') {
|
|
323
|
-
|
|
323
|
+
actorScope.self.delaySend(params);
|
|
324
324
|
return;
|
|
325
325
|
}
|
|
326
326
|
|
|
327
327
|
// this forms an outgoing events queue
|
|
328
328
|
// thanks to that the recipient actors are able to read the *updated* snapshot value of the sender
|
|
329
|
-
|
|
329
|
+
actorScope.defer(() => {
|
|
330
330
|
const {
|
|
331
331
|
to,
|
|
332
332
|
event
|
|
333
333
|
} = params;
|
|
334
|
-
|
|
334
|
+
actorScope?.system._relay(actorScope.self, to, event.type === interpreter.XSTATE_ERROR ? interpreter.createErrorActorEvent(actorScope.self.id, event.data) : event);
|
|
335
335
|
});
|
|
336
336
|
}
|
|
337
337
|
/**
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
4
|
-
var interpreter = require('./interpreter-
|
|
3
|
+
var guards_dist_xstateGuards = require('./raise-291d2181.cjs.js');
|
|
4
|
+
var interpreter = require('./interpreter-5dfcd203.cjs.js');
|
|
5
5
|
|
|
6
|
-
function createSpawner(
|
|
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:
|
|
24
|
+
parent: actorScope.self,
|
|
25
25
|
input: typeof input === 'function' ? input({
|
|
26
26
|
context,
|
|
27
27
|
event,
|
|
28
|
-
self:
|
|
28
|
+
self: actorScope.self
|
|
29
29
|
}) : input,
|
|
30
30
|
src,
|
|
31
31
|
systemId
|
|
@@ -35,7 +35,7 @@ function createSpawner(actorContext, {
|
|
|
35
35
|
actorRef.subscribe({
|
|
36
36
|
next: snapshot => {
|
|
37
37
|
if (snapshot.status === 'active') {
|
|
38
|
-
|
|
38
|
+
actorScope.self.send({
|
|
39
39
|
type: `xstate.snapshot.${actorRef.id}`,
|
|
40
40
|
snapshot
|
|
41
41
|
});
|
|
@@ -49,7 +49,7 @@ function createSpawner(actorContext, {
|
|
|
49
49
|
// TODO: this should also receive `src`
|
|
50
50
|
const actorRef = interpreter.createActor(src, {
|
|
51
51
|
id: options.id,
|
|
52
|
-
parent:
|
|
52
|
+
parent: actorScope.self,
|
|
53
53
|
input: options.input,
|
|
54
54
|
src: undefined,
|
|
55
55
|
systemId
|
|
@@ -58,7 +58,7 @@ function createSpawner(actorContext, {
|
|
|
58
58
|
actorRef.subscribe({
|
|
59
59
|
next: snapshot => {
|
|
60
60
|
if (snapshot.status === 'active') {
|
|
61
|
-
|
|
61
|
+
actorScope.self.send({
|
|
62
62
|
type: `xstate.snapshot.${actorRef.id}`,
|
|
63
63
|
snapshot,
|
|
64
64
|
id: actorRef.id
|
|
@@ -74,14 +74,14 @@ function createSpawner(actorContext, {
|
|
|
74
74
|
return (src, options) => {
|
|
75
75
|
const actorRef = spawn(src, options); // TODO: fix types
|
|
76
76
|
spawnedChildren[actorRef.id] = actorRef;
|
|
77
|
-
|
|
77
|
+
actorScope.defer(() => {
|
|
78
78
|
if (actorRef.status === interpreter.ActorStatus.Stopped) {
|
|
79
79
|
return;
|
|
80
80
|
}
|
|
81
81
|
try {
|
|
82
82
|
actorRef.start?.();
|
|
83
83
|
} catch (err) {
|
|
84
|
-
|
|
84
|
+
actorScope.self.send(interpreter.createErrorActorEvent(actorRef.id, err));
|
|
85
85
|
return;
|
|
86
86
|
}
|
|
87
87
|
});
|
|
@@ -89,7 +89,7 @@ function createSpawner(actorContext, {
|
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
function resolveAssign(
|
|
92
|
+
function resolveAssign(actorScope, state, actionArgs, actionParams, {
|
|
93
93
|
assignment
|
|
94
94
|
}) {
|
|
95
95
|
if (!state.context) {
|
|
@@ -99,9 +99,9 @@ function resolveAssign(actorContext, state, actionArgs, actionParams, {
|
|
|
99
99
|
const assignArgs = {
|
|
100
100
|
context: state.context,
|
|
101
101
|
event: actionArgs.event,
|
|
102
|
-
spawn: createSpawner(
|
|
103
|
-
self:
|
|
104
|
-
system:
|
|
102
|
+
spawn: createSpawner(actorScope, state, actionArgs.event, spawnedChildren),
|
|
103
|
+
self: actorScope?.self,
|
|
104
|
+
system: actorScope?.system
|
|
105
105
|
};
|
|
106
106
|
let partialUpdate = {};
|
|
107
107
|
if (typeof assignment === 'function') {
|
|
@@ -256,7 +256,7 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
|
256
256
|
return SpecialTargets;
|
|
257
257
|
}({});
|
|
258
258
|
|
|
259
|
-
function resolveSendTo(
|
|
259
|
+
function resolveSendTo(actorScope, state, args, actionParams, {
|
|
260
260
|
to,
|
|
261
261
|
event: eventOrExpr,
|
|
262
262
|
id,
|
|
@@ -278,9 +278,9 @@ function resolveSendTo(actorContext, state, args, actionParams, {
|
|
|
278
278
|
let targetActorRef;
|
|
279
279
|
if (typeof resolvedTarget === 'string') {
|
|
280
280
|
if (resolvedTarget === SpecialTargets.Parent) {
|
|
281
|
-
targetActorRef =
|
|
281
|
+
targetActorRef = actorScope?.self._parent;
|
|
282
282
|
} else if (resolvedTarget === SpecialTargets.Internal) {
|
|
283
|
-
targetActorRef =
|
|
283
|
+
targetActorRef = actorScope?.self;
|
|
284
284
|
} else if (resolvedTarget.startsWith('#_')) {
|
|
285
285
|
// SCXML compatibility: https://www.w3.org/TR/scxml/#SCXMLEventProcessor
|
|
286
286
|
// #_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.
|
|
@@ -292,7 +292,7 @@ function resolveSendTo(actorContext, state, args, actionParams, {
|
|
|
292
292
|
throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${state.machine.id}'.`);
|
|
293
293
|
}
|
|
294
294
|
} else {
|
|
295
|
-
targetActorRef = resolvedTarget ||
|
|
295
|
+
targetActorRef = resolvedTarget || actorScope?.self;
|
|
296
296
|
}
|
|
297
297
|
return [state, {
|
|
298
298
|
to: targetActorRef,
|
|
@@ -306,20 +306,20 @@ function retryResolveSendTo(_, state, params) {
|
|
|
306
306
|
params.to = state.children[params.to];
|
|
307
307
|
}
|
|
308
308
|
}
|
|
309
|
-
function executeSendTo(
|
|
309
|
+
function executeSendTo(actorScope, params) {
|
|
310
310
|
if (typeof params.delay === 'number') {
|
|
311
|
-
|
|
311
|
+
actorScope.self.delaySend(params);
|
|
312
312
|
return;
|
|
313
313
|
}
|
|
314
314
|
|
|
315
315
|
// this forms an outgoing events queue
|
|
316
316
|
// thanks to that the recipient actors are able to read the *updated* snapshot value of the sender
|
|
317
|
-
|
|
317
|
+
actorScope.defer(() => {
|
|
318
318
|
const {
|
|
319
319
|
to,
|
|
320
320
|
event
|
|
321
321
|
} = params;
|
|
322
|
-
|
|
322
|
+
actorScope?.system._relay(actorScope.self, to, event.type === interpreter.XSTATE_ERROR ? interpreter.createErrorActorEvent(actorScope.self.id, event.data) : event);
|
|
323
323
|
});
|
|
324
324
|
}
|
|
325
325
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { j as cloneState, e as evaluateGuard } from './raise-
|
|
2
|
-
import { f as ActorStatus, j as createErrorActorEvent, r as resolveReferencedActor, d as createActor, t as toArray, x as XSTATE_ERROR } from './interpreter-
|
|
1
|
+
import { j as cloneState, e as evaluateGuard } from './raise-e044f460.development.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-70cd9217.development.esm.js';
|
|
3
3
|
|
|
4
|
-
function createSpawner(
|
|
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:
|
|
22
|
+
parent: actorScope.self,
|
|
23
23
|
input: typeof input === 'function' ? input({
|
|
24
24
|
context,
|
|
25
25
|
event,
|
|
26
|
-
self:
|
|
26
|
+
self: actorScope.self
|
|
27
27
|
}) : input,
|
|
28
28
|
src,
|
|
29
29
|
systemId
|
|
@@ -33,7 +33,7 @@ function createSpawner(actorContext, {
|
|
|
33
33
|
actorRef.subscribe({
|
|
34
34
|
next: snapshot => {
|
|
35
35
|
if (snapshot.status === 'active') {
|
|
36
|
-
|
|
36
|
+
actorScope.self.send({
|
|
37
37
|
type: `xstate.snapshot.${actorRef.id}`,
|
|
38
38
|
snapshot
|
|
39
39
|
});
|
|
@@ -47,7 +47,7 @@ function createSpawner(actorContext, {
|
|
|
47
47
|
// TODO: this should also receive `src`
|
|
48
48
|
const actorRef = createActor(src, {
|
|
49
49
|
id: options.id,
|
|
50
|
-
parent:
|
|
50
|
+
parent: actorScope.self,
|
|
51
51
|
input: options.input,
|
|
52
52
|
src: undefined,
|
|
53
53
|
systemId
|
|
@@ -56,7 +56,7 @@ function createSpawner(actorContext, {
|
|
|
56
56
|
actorRef.subscribe({
|
|
57
57
|
next: snapshot => {
|
|
58
58
|
if (snapshot.status === 'active') {
|
|
59
|
-
|
|
59
|
+
actorScope.self.send({
|
|
60
60
|
type: `xstate.snapshot.${actorRef.id}`,
|
|
61
61
|
snapshot,
|
|
62
62
|
id: actorRef.id
|
|
@@ -72,14 +72,14 @@ function createSpawner(actorContext, {
|
|
|
72
72
|
return (src, options) => {
|
|
73
73
|
const actorRef = spawn(src, options); // TODO: fix types
|
|
74
74
|
spawnedChildren[actorRef.id] = actorRef;
|
|
75
|
-
|
|
75
|
+
actorScope.defer(() => {
|
|
76
76
|
if (actorRef.status === ActorStatus.Stopped) {
|
|
77
77
|
return;
|
|
78
78
|
}
|
|
79
79
|
try {
|
|
80
80
|
actorRef.start?.();
|
|
81
81
|
} catch (err) {
|
|
82
|
-
|
|
82
|
+
actorScope.self.send(createErrorActorEvent(actorRef.id, err));
|
|
83
83
|
return;
|
|
84
84
|
}
|
|
85
85
|
});
|
|
@@ -87,7 +87,7 @@ function createSpawner(actorContext, {
|
|
|
87
87
|
};
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
function resolveAssign(
|
|
90
|
+
function resolveAssign(actorScope, state, actionArgs, actionParams, {
|
|
91
91
|
assignment
|
|
92
92
|
}) {
|
|
93
93
|
if (!state.context) {
|
|
@@ -97,9 +97,9 @@ function resolveAssign(actorContext, state, actionArgs, actionParams, {
|
|
|
97
97
|
const assignArgs = {
|
|
98
98
|
context: state.context,
|
|
99
99
|
event: actionArgs.event,
|
|
100
|
-
spawn: createSpawner(
|
|
101
|
-
self:
|
|
102
|
-
system:
|
|
100
|
+
spawn: createSpawner(actorScope, state, actionArgs.event, spawnedChildren),
|
|
101
|
+
self: actorScope?.self,
|
|
102
|
+
system: actorScope?.system
|
|
103
103
|
};
|
|
104
104
|
let partialUpdate = {};
|
|
105
105
|
if (typeof assignment === 'function') {
|
|
@@ -266,7 +266,7 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
|
266
266
|
return SpecialTargets;
|
|
267
267
|
}({});
|
|
268
268
|
|
|
269
|
-
function resolveSendTo(
|
|
269
|
+
function resolveSendTo(actorScope, state, args, actionParams, {
|
|
270
270
|
to,
|
|
271
271
|
event: eventOrExpr,
|
|
272
272
|
id,
|
|
@@ -288,9 +288,9 @@ function resolveSendTo(actorContext, state, args, actionParams, {
|
|
|
288
288
|
let targetActorRef;
|
|
289
289
|
if (typeof resolvedTarget === 'string') {
|
|
290
290
|
if (resolvedTarget === SpecialTargets.Parent) {
|
|
291
|
-
targetActorRef =
|
|
291
|
+
targetActorRef = actorScope?.self._parent;
|
|
292
292
|
} else if (resolvedTarget === SpecialTargets.Internal) {
|
|
293
|
-
targetActorRef =
|
|
293
|
+
targetActorRef = actorScope?.self;
|
|
294
294
|
} else if (resolvedTarget.startsWith('#_')) {
|
|
295
295
|
// SCXML compatibility: https://www.w3.org/TR/scxml/#SCXMLEventProcessor
|
|
296
296
|
// #_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.
|
|
@@ -302,7 +302,7 @@ function resolveSendTo(actorContext, state, args, actionParams, {
|
|
|
302
302
|
throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${state.machine.id}'.`);
|
|
303
303
|
}
|
|
304
304
|
} else {
|
|
305
|
-
targetActorRef = resolvedTarget ||
|
|
305
|
+
targetActorRef = resolvedTarget || actorScope?.self;
|
|
306
306
|
}
|
|
307
307
|
return [state, {
|
|
308
308
|
to: targetActorRef,
|
|
@@ -316,20 +316,20 @@ function retryResolveSendTo(_, state, params) {
|
|
|
316
316
|
params.to = state.children[params.to];
|
|
317
317
|
}
|
|
318
318
|
}
|
|
319
|
-
function executeSendTo(
|
|
319
|
+
function executeSendTo(actorScope, params) {
|
|
320
320
|
if (typeof params.delay === 'number') {
|
|
321
|
-
|
|
321
|
+
actorScope.self.delaySend(params);
|
|
322
322
|
return;
|
|
323
323
|
}
|
|
324
324
|
|
|
325
325
|
// this forms an outgoing events queue
|
|
326
326
|
// thanks to that the recipient actors are able to read the *updated* snapshot value of the sender
|
|
327
|
-
|
|
327
|
+
actorScope.defer(() => {
|
|
328
328
|
const {
|
|
329
329
|
to,
|
|
330
330
|
event
|
|
331
331
|
} = params;
|
|
332
|
-
|
|
332
|
+
actorScope?.system._relay(actorScope.self, to, event.type === XSTATE_ERROR ? createErrorActorEvent(actorScope.self.id, event.data) : event);
|
|
333
333
|
});
|
|
334
334
|
}
|
|
335
335
|
/**
|
package/dist/xstate.cjs.js
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var actors_dist_xstateActors = require('../actors/dist/xstate-actors.cjs.js');
|
|
6
|
-
var interpreter = require('./interpreter-
|
|
7
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
8
|
-
var send = require('./send-
|
|
6
|
+
var interpreter = require('./interpreter-5dfcd203.cjs.js');
|
|
7
|
+
var guards_dist_xstateGuards = require('./raise-291d2181.cjs.js');
|
|
8
|
+
var send = require('./send-af152aca.cjs.js');
|
|
9
9
|
require('../dev/dist/xstate-dev.cjs.js');
|
|
10
10
|
|
|
11
11
|
class SimulatedClock {
|
|
@@ -478,7 +478,7 @@ class StateMachine {
|
|
|
478
478
|
* @param state The current State instance or state value
|
|
479
479
|
* @param event The received event
|
|
480
480
|
*/
|
|
481
|
-
transition(state, event,
|
|
481
|
+
transition(state, event, actorScope) {
|
|
482
482
|
// TODO: handle error events in a better way
|
|
483
483
|
if (interpreter.isErrorActorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
|
|
484
484
|
return guards_dist_xstateGuards.cloneState(state, {
|
|
@@ -488,7 +488,7 @@ class StateMachine {
|
|
|
488
488
|
}
|
|
489
489
|
const {
|
|
490
490
|
state: nextState
|
|
491
|
-
} = guards_dist_xstateGuards.macrostep(state, event,
|
|
491
|
+
} = guards_dist_xstateGuards.macrostep(state, event, actorScope);
|
|
492
492
|
return nextState;
|
|
493
493
|
}
|
|
494
494
|
|
|
@@ -499,8 +499,8 @@ class StateMachine {
|
|
|
499
499
|
* @param state The current state
|
|
500
500
|
* @param event The received event
|
|
501
501
|
*/
|
|
502
|
-
microstep(state, event,
|
|
503
|
-
return guards_dist_xstateGuards.macrostep(state, event,
|
|
502
|
+
microstep(state, event, actorScope) {
|
|
503
|
+
return guards_dist_xstateGuards.macrostep(state, event, actorScope).microstates;
|
|
504
504
|
}
|
|
505
505
|
getTransitionData(state, event) {
|
|
506
506
|
return guards_dist_xstateGuards.transitionNode(this.root, state.value, state, event) || [];
|
|
@@ -510,7 +510,7 @@ class StateMachine {
|
|
|
510
510
|
* The initial state _before_ evaluating any microsteps.
|
|
511
511
|
* This "pre-initial" state is provided to initial actions executed in the initial state.
|
|
512
512
|
*/
|
|
513
|
-
getPreInitialState(
|
|
513
|
+
getPreInitialState(actorScope, initEvent, internalQueue) {
|
|
514
514
|
const {
|
|
515
515
|
context
|
|
516
516
|
} = this.config;
|
|
@@ -531,7 +531,7 @@ class StateMachine {
|
|
|
531
531
|
spawn,
|
|
532
532
|
input: event.input
|
|
533
533
|
});
|
|
534
|
-
return guards_dist_xstateGuards.resolveActionsAndContext(preInitial, initEvent,
|
|
534
|
+
return guards_dist_xstateGuards.resolveActionsAndContext(preInitial, initEvent, actorScope, [send.assign(assignment)], internalQueue);
|
|
535
535
|
}
|
|
536
536
|
return preInitial;
|
|
537
537
|
}
|
|
@@ -539,10 +539,10 @@ class StateMachine {
|
|
|
539
539
|
/**
|
|
540
540
|
* Returns the initial `State` instance, with reference to `self` as an `ActorRef`.
|
|
541
541
|
*/
|
|
542
|
-
getInitialState(
|
|
542
|
+
getInitialState(actorScope, input) {
|
|
543
543
|
const initEvent = interpreter.createInitEvent(input); // TODO: fix;
|
|
544
544
|
const internalQueue = [];
|
|
545
|
-
const preInitialState = this.getPreInitialState(
|
|
545
|
+
const preInitialState = this.getPreInitialState(actorScope, initEvent, internalQueue);
|
|
546
546
|
const nextState = guards_dist_xstateGuards.microstep([{
|
|
547
547
|
target: [...guards_dist_xstateGuards.getInitialStateNodes(this.root)],
|
|
548
548
|
source: this.root,
|
|
@@ -550,15 +550,15 @@ class StateMachine {
|
|
|
550
550
|
actions: [],
|
|
551
551
|
eventType: null,
|
|
552
552
|
toJSON: null // TODO: fix
|
|
553
|
-
}], preInitialState,
|
|
553
|
+
}], preInitialState, actorScope, initEvent, true, internalQueue);
|
|
554
554
|
const {
|
|
555
555
|
state: macroState
|
|
556
|
-
} = guards_dist_xstateGuards.macrostep(nextState, initEvent,
|
|
556
|
+
} = guards_dist_xstateGuards.macrostep(nextState, initEvent, actorScope, internalQueue);
|
|
557
557
|
return macroState;
|
|
558
558
|
}
|
|
559
559
|
start(state) {
|
|
560
560
|
Object.values(state.children).forEach(child => {
|
|
561
|
-
if (child.status ===
|
|
561
|
+
if (child.getSnapshot().status === 'active') {
|
|
562
562
|
child.start();
|
|
563
563
|
}
|
|
564
564
|
});
|
|
@@ -585,7 +585,7 @@ class StateMachine {
|
|
|
585
585
|
createState(stateConfig) {
|
|
586
586
|
return stateConfig instanceof guards_dist_xstateGuards.State ? stateConfig : new guards_dist_xstateGuards.State(stateConfig, this);
|
|
587
587
|
}
|
|
588
|
-
restoreState(snapshot,
|
|
588
|
+
restoreState(snapshot, _actorScope) {
|
|
589
589
|
const children = {};
|
|
590
590
|
const snapshotChildren = snapshot.children;
|
|
591
591
|
Object.keys(snapshotChildren).forEach(actorId => {
|
|
@@ -596,10 +596,10 @@ class StateMachine {
|
|
|
596
596
|
if (!logic) {
|
|
597
597
|
return;
|
|
598
598
|
}
|
|
599
|
-
const actorState = logic.restoreState?.(childState,
|
|
599
|
+
const actorState = logic.restoreState?.(childState, _actorScope);
|
|
600
600
|
const actorRef = interpreter.createActor(logic, {
|
|
601
601
|
id: actorId,
|
|
602
|
-
parent:
|
|
602
|
+
parent: _actorScope?.self,
|
|
603
603
|
state: actorState,
|
|
604
604
|
systemId: actorData.systemId
|
|
605
605
|
});
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var actors_dist_xstateActors = require('../actors/dist/xstate-actors.development.cjs.js');
|
|
6
|
-
var interpreter = require('./interpreter-
|
|
7
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
8
|
-
var send = require('./send-
|
|
6
|
+
var interpreter = require('./interpreter-03a5c3f5.development.cjs.js');
|
|
7
|
+
var guards_dist_xstateGuards = require('./raise-17cb3d9d.development.cjs.js');
|
|
8
|
+
var send = require('./send-33433787.development.cjs.js');
|
|
9
9
|
require('../dev/dist/xstate-dev.development.cjs.js');
|
|
10
10
|
|
|
11
11
|
class SimulatedClock {
|
|
@@ -481,7 +481,7 @@ class StateMachine {
|
|
|
481
481
|
* @param state The current State instance or state value
|
|
482
482
|
* @param event The received event
|
|
483
483
|
*/
|
|
484
|
-
transition(state, event,
|
|
484
|
+
transition(state, event, actorScope) {
|
|
485
485
|
// TODO: handle error events in a better way
|
|
486
486
|
if (interpreter.isErrorActorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
|
|
487
487
|
return guards_dist_xstateGuards.cloneState(state, {
|
|
@@ -491,7 +491,7 @@ class StateMachine {
|
|
|
491
491
|
}
|
|
492
492
|
const {
|
|
493
493
|
state: nextState
|
|
494
|
-
} = guards_dist_xstateGuards.macrostep(state, event,
|
|
494
|
+
} = guards_dist_xstateGuards.macrostep(state, event, actorScope);
|
|
495
495
|
return nextState;
|
|
496
496
|
}
|
|
497
497
|
|
|
@@ -502,8 +502,8 @@ class StateMachine {
|
|
|
502
502
|
* @param state The current state
|
|
503
503
|
* @param event The received event
|
|
504
504
|
*/
|
|
505
|
-
microstep(state, event,
|
|
506
|
-
return guards_dist_xstateGuards.macrostep(state, event,
|
|
505
|
+
microstep(state, event, actorScope) {
|
|
506
|
+
return guards_dist_xstateGuards.macrostep(state, event, actorScope).microstates;
|
|
507
507
|
}
|
|
508
508
|
getTransitionData(state, event) {
|
|
509
509
|
return guards_dist_xstateGuards.transitionNode(this.root, state.value, state, event) || [];
|
|
@@ -513,7 +513,7 @@ class StateMachine {
|
|
|
513
513
|
* The initial state _before_ evaluating any microsteps.
|
|
514
514
|
* This "pre-initial" state is provided to initial actions executed in the initial state.
|
|
515
515
|
*/
|
|
516
|
-
getPreInitialState(
|
|
516
|
+
getPreInitialState(actorScope, initEvent, internalQueue) {
|
|
517
517
|
const {
|
|
518
518
|
context
|
|
519
519
|
} = this.config;
|
|
@@ -534,7 +534,7 @@ class StateMachine {
|
|
|
534
534
|
spawn,
|
|
535
535
|
input: event.input
|
|
536
536
|
});
|
|
537
|
-
return guards_dist_xstateGuards.resolveActionsAndContext(preInitial, initEvent,
|
|
537
|
+
return guards_dist_xstateGuards.resolveActionsAndContext(preInitial, initEvent, actorScope, [send.assign(assignment)], internalQueue);
|
|
538
538
|
}
|
|
539
539
|
return preInitial;
|
|
540
540
|
}
|
|
@@ -542,10 +542,10 @@ class StateMachine {
|
|
|
542
542
|
/**
|
|
543
543
|
* Returns the initial `State` instance, with reference to `self` as an `ActorRef`.
|
|
544
544
|
*/
|
|
545
|
-
getInitialState(
|
|
545
|
+
getInitialState(actorScope, input) {
|
|
546
546
|
const initEvent = interpreter.createInitEvent(input); // TODO: fix;
|
|
547
547
|
const internalQueue = [];
|
|
548
|
-
const preInitialState = this.getPreInitialState(
|
|
548
|
+
const preInitialState = this.getPreInitialState(actorScope, initEvent, internalQueue);
|
|
549
549
|
const nextState = guards_dist_xstateGuards.microstep([{
|
|
550
550
|
target: [...guards_dist_xstateGuards.getInitialStateNodes(this.root)],
|
|
551
551
|
source: this.root,
|
|
@@ -553,15 +553,15 @@ class StateMachine {
|
|
|
553
553
|
actions: [],
|
|
554
554
|
eventType: null,
|
|
555
555
|
toJSON: null // TODO: fix
|
|
556
|
-
}], preInitialState,
|
|
556
|
+
}], preInitialState, actorScope, initEvent, true, internalQueue);
|
|
557
557
|
const {
|
|
558
558
|
state: macroState
|
|
559
|
-
} = guards_dist_xstateGuards.macrostep(nextState, initEvent,
|
|
559
|
+
} = guards_dist_xstateGuards.macrostep(nextState, initEvent, actorScope, internalQueue);
|
|
560
560
|
return macroState;
|
|
561
561
|
}
|
|
562
562
|
start(state) {
|
|
563
563
|
Object.values(state.children).forEach(child => {
|
|
564
|
-
if (child.status ===
|
|
564
|
+
if (child.getSnapshot().status === 'active') {
|
|
565
565
|
child.start();
|
|
566
566
|
}
|
|
567
567
|
});
|
|
@@ -588,7 +588,7 @@ class StateMachine {
|
|
|
588
588
|
createState(stateConfig) {
|
|
589
589
|
return stateConfig instanceof guards_dist_xstateGuards.State ? stateConfig : new guards_dist_xstateGuards.State(stateConfig, this);
|
|
590
590
|
}
|
|
591
|
-
restoreState(snapshot,
|
|
591
|
+
restoreState(snapshot, _actorScope) {
|
|
592
592
|
const children = {};
|
|
593
593
|
const snapshotChildren = snapshot.children;
|
|
594
594
|
Object.keys(snapshotChildren).forEach(actorId => {
|
|
@@ -599,10 +599,10 @@ class StateMachine {
|
|
|
599
599
|
if (!logic) {
|
|
600
600
|
return;
|
|
601
601
|
}
|
|
602
|
-
const actorState = logic.restoreState?.(childState,
|
|
602
|
+
const actorState = logic.restoreState?.(childState, _actorScope);
|
|
603
603
|
const actorRef = interpreter.createActor(logic, {
|
|
604
604
|
id: actorId,
|
|
605
|
-
parent:
|
|
605
|
+
parent: _actorScope?.self,
|
|
606
606
|
state: actorState,
|
|
607
607
|
systemId: actorData.systemId
|
|
608
608
|
});
|