xstate 5.0.0-beta.44 → 5.0.0-beta.46
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 +2 -2
- package/actions/dist/xstate-actions.development.cjs.js +2 -2
- package/actions/dist/xstate-actions.development.esm.js +2 -2
- package/actions/dist/xstate-actions.esm.js +2 -2
- 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 +134 -9
- package/actors/dist/xstate-actors.development.cjs.js +134 -9
- package/actors/dist/xstate-actors.development.esm.js +134 -9
- package/actors/dist/xstate-actors.esm.js +134 -9
- 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/State.d.ts +18 -28
- package/dist/declarations/src/StateMachine.d.ts +11 -29
- package/dist/declarations/src/StateNode.d.ts +8 -6
- package/dist/declarations/src/actions/choose.d.ts +3 -3
- package/dist/declarations/src/actions/pure.d.ts +4 -4
- package/dist/declarations/src/actors/observable.d.ts +80 -4
- package/dist/declarations/src/actors/transition.d.ts +53 -4
- package/dist/declarations/src/createMachine.d.ts +5 -0
- package/dist/declarations/src/guards.d.ts +26 -4
- package/dist/declarations/src/index.d.ts +3 -2
- package/dist/declarations/src/interpreter.d.ts +1 -0
- package/dist/declarations/src/setup.d.ts +35 -0
- package/dist/declarations/src/stateUtils.d.ts +7 -7
- package/dist/declarations/src/types.d.ts +54 -25
- package/dist/declarations/src/utils.d.ts +2 -1
- package/dist/{raise-5854eaca.esm.js → raise-1682abb7.esm.js} +99 -135
- package/dist/{raise-fb6f017b.cjs.js → raise-a1d3d7e9.cjs.js} +100 -136
- package/dist/{raise-ed700d14.development.cjs.js → raise-a9e7e31c.development.cjs.js} +100 -136
- package/dist/{raise-348cc74e.development.esm.js → raise-fa23c2b9.development.esm.js} +99 -135
- package/dist/{send-53e5693c.cjs.js → send-2fa3a204.cjs.js} +24 -28
- package/dist/{send-00466e37.development.cjs.js → send-5b256a89.development.cjs.js} +24 -28
- package/dist/{send-a0193bdb.development.esm.js → send-9acdf858.development.esm.js} +24 -28
- package/dist/{send-b7b4befa.esm.js → send-a237e4e8.esm.js} +24 -28
- package/dist/xstate.cjs.js +102 -92
- package/dist/xstate.cjs.mjs +2 -0
- package/dist/xstate.development.cjs.js +102 -92
- package/dist/xstate.development.cjs.mjs +2 -0
- package/dist/xstate.development.esm.js +97 -89
- package/dist/xstate.esm.js +97 -89
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.esm.js +1 -1
- package/guards/dist/xstate-guards.esm.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/dist/declarations/src/Machine.d.ts +0 -5
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
3
|
+
var guards_dist_xstateGuards = require('./raise-a9e7e31c.development.cjs.js');
|
|
4
4
|
|
|
5
5
|
function createSpawner(actorScope, {
|
|
6
6
|
machine,
|
|
@@ -19,6 +19,7 @@ function createSpawner(actorScope, {
|
|
|
19
19
|
const actorRef = guards_dist_xstateGuards.createActor(logic, {
|
|
20
20
|
id: options.id,
|
|
21
21
|
parent: actorScope.self,
|
|
22
|
+
syncSnapshot: options.syncSnapshot,
|
|
22
23
|
input: typeof input === 'function' ? input({
|
|
23
24
|
context,
|
|
24
25
|
event,
|
|
@@ -28,42 +29,16 @@ function createSpawner(actorScope, {
|
|
|
28
29
|
systemId
|
|
29
30
|
});
|
|
30
31
|
spawnedChildren[actorRef.id] = actorRef;
|
|
31
|
-
if (options.syncSnapshot) {
|
|
32
|
-
actorRef.subscribe({
|
|
33
|
-
next: snapshot => {
|
|
34
|
-
if (snapshot.status === 'active') {
|
|
35
|
-
actorScope.self.send({
|
|
36
|
-
type: `xstate.snapshot.${actorRef.id}`,
|
|
37
|
-
snapshot
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
error: () => {}
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
32
|
return actorRef;
|
|
45
33
|
} else {
|
|
46
34
|
const actorRef = guards_dist_xstateGuards.createActor(src, {
|
|
47
35
|
id: options.id,
|
|
48
36
|
parent: actorScope.self,
|
|
37
|
+
syncSnapshot: options.syncSnapshot,
|
|
49
38
|
input: options.input,
|
|
50
39
|
src,
|
|
51
40
|
systemId
|
|
52
41
|
});
|
|
53
|
-
if (options.syncSnapshot) {
|
|
54
|
-
actorRef.subscribe({
|
|
55
|
-
next: snapshot => {
|
|
56
|
-
if (snapshot.status === 'active') {
|
|
57
|
-
actorScope.self.send({
|
|
58
|
-
type: `xstate.snapshot.${actorRef.id}`,
|
|
59
|
-
snapshot,
|
|
60
|
-
id: actorRef.id
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
error: () => {}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
42
|
return actorRef;
|
|
68
43
|
}
|
|
69
44
|
};
|
|
@@ -266,6 +241,27 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
|
266
241
|
return SpecialTargets;
|
|
267
242
|
}({});
|
|
268
243
|
|
|
244
|
+
/**
|
|
245
|
+
* @deprecated Use `AnyActor` instead.
|
|
246
|
+
*/
|
|
247
|
+
|
|
248
|
+
// Based on RxJS types
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* @deprecated Use `Actor<T>` instead.
|
|
252
|
+
*/
|
|
253
|
+
|
|
254
|
+
// only meant to be used internally for debugging purposes
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Represents logic which can be used by an actor.
|
|
258
|
+
*
|
|
259
|
+
* @template TSnapshot - The type of the snapshot.
|
|
260
|
+
* @template TEvent - The type of the event object.
|
|
261
|
+
* @template TInput - The type of the input.
|
|
262
|
+
* @template TSystem - The type of the actor system.
|
|
263
|
+
*/
|
|
264
|
+
|
|
269
265
|
function resolveSendTo(actorScope, state, args, actionParams, {
|
|
270
266
|
to,
|
|
271
267
|
event: eventOrExpr,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as ProcessingStatus, U as createErrorActorEvent, B as resolveReferencedActor, C as createActor, p as cloneMachineSnapshot, e as evaluateGuard, t as toArray, V as XSTATE_ERROR } from './raise-
|
|
1
|
+
import { T as ProcessingStatus, U as createErrorActorEvent, B as resolveReferencedActor, C as createActor, p as cloneMachineSnapshot, e as evaluateGuard, t as toArray, V as XSTATE_ERROR } from './raise-fa23c2b9.development.esm.js';
|
|
2
2
|
|
|
3
3
|
function createSpawner(actorScope, {
|
|
4
4
|
machine,
|
|
@@ -17,6 +17,7 @@ function createSpawner(actorScope, {
|
|
|
17
17
|
const actorRef = createActor(logic, {
|
|
18
18
|
id: options.id,
|
|
19
19
|
parent: actorScope.self,
|
|
20
|
+
syncSnapshot: options.syncSnapshot,
|
|
20
21
|
input: typeof input === 'function' ? input({
|
|
21
22
|
context,
|
|
22
23
|
event,
|
|
@@ -26,42 +27,16 @@ function createSpawner(actorScope, {
|
|
|
26
27
|
systemId
|
|
27
28
|
});
|
|
28
29
|
spawnedChildren[actorRef.id] = actorRef;
|
|
29
|
-
if (options.syncSnapshot) {
|
|
30
|
-
actorRef.subscribe({
|
|
31
|
-
next: snapshot => {
|
|
32
|
-
if (snapshot.status === 'active') {
|
|
33
|
-
actorScope.self.send({
|
|
34
|
-
type: `xstate.snapshot.${actorRef.id}`,
|
|
35
|
-
snapshot
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
error: () => {}
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
30
|
return actorRef;
|
|
43
31
|
} else {
|
|
44
32
|
const actorRef = createActor(src, {
|
|
45
33
|
id: options.id,
|
|
46
34
|
parent: actorScope.self,
|
|
35
|
+
syncSnapshot: options.syncSnapshot,
|
|
47
36
|
input: options.input,
|
|
48
37
|
src,
|
|
49
38
|
systemId
|
|
50
39
|
});
|
|
51
|
-
if (options.syncSnapshot) {
|
|
52
|
-
actorRef.subscribe({
|
|
53
|
-
next: snapshot => {
|
|
54
|
-
if (snapshot.status === 'active') {
|
|
55
|
-
actorScope.self.send({
|
|
56
|
-
type: `xstate.snapshot.${actorRef.id}`,
|
|
57
|
-
snapshot,
|
|
58
|
-
id: actorRef.id
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
error: () => {}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
40
|
return actorRef;
|
|
66
41
|
}
|
|
67
42
|
};
|
|
@@ -264,6 +239,27 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
|
264
239
|
return SpecialTargets;
|
|
265
240
|
}({});
|
|
266
241
|
|
|
242
|
+
/**
|
|
243
|
+
* @deprecated Use `AnyActor` instead.
|
|
244
|
+
*/
|
|
245
|
+
|
|
246
|
+
// Based on RxJS types
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* @deprecated Use `Actor<T>` instead.
|
|
250
|
+
*/
|
|
251
|
+
|
|
252
|
+
// only meant to be used internally for debugging purposes
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Represents logic which can be used by an actor.
|
|
256
|
+
*
|
|
257
|
+
* @template TSnapshot - The type of the snapshot.
|
|
258
|
+
* @template TEvent - The type of the event object.
|
|
259
|
+
* @template TInput - The type of the input.
|
|
260
|
+
* @template TSystem - The type of the actor system.
|
|
261
|
+
*/
|
|
262
|
+
|
|
267
263
|
function resolveSendTo(actorScope, state, args, actionParams, {
|
|
268
264
|
to,
|
|
269
265
|
event: eventOrExpr,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as ProcessingStatus, U as createErrorActorEvent, B as resolveReferencedActor, C as createActor, p as cloneMachineSnapshot, e as evaluateGuard, t as toArray, V as XSTATE_ERROR } from './raise-
|
|
1
|
+
import { T as ProcessingStatus, U as createErrorActorEvent, B as resolveReferencedActor, C as createActor, p as cloneMachineSnapshot, e as evaluateGuard, t as toArray, V as XSTATE_ERROR } from './raise-1682abb7.esm.js';
|
|
2
2
|
|
|
3
3
|
function createSpawner(actorScope, {
|
|
4
4
|
machine,
|
|
@@ -17,6 +17,7 @@ function createSpawner(actorScope, {
|
|
|
17
17
|
const actorRef = createActor(logic, {
|
|
18
18
|
id: options.id,
|
|
19
19
|
parent: actorScope.self,
|
|
20
|
+
syncSnapshot: options.syncSnapshot,
|
|
20
21
|
input: typeof input === 'function' ? input({
|
|
21
22
|
context,
|
|
22
23
|
event,
|
|
@@ -26,42 +27,16 @@ function createSpawner(actorScope, {
|
|
|
26
27
|
systemId
|
|
27
28
|
});
|
|
28
29
|
spawnedChildren[actorRef.id] = actorRef;
|
|
29
|
-
if (options.syncSnapshot) {
|
|
30
|
-
actorRef.subscribe({
|
|
31
|
-
next: snapshot => {
|
|
32
|
-
if (snapshot.status === 'active') {
|
|
33
|
-
actorScope.self.send({
|
|
34
|
-
type: `xstate.snapshot.${actorRef.id}`,
|
|
35
|
-
snapshot
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
error: () => {}
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
30
|
return actorRef;
|
|
43
31
|
} else {
|
|
44
32
|
const actorRef = createActor(src, {
|
|
45
33
|
id: options.id,
|
|
46
34
|
parent: actorScope.self,
|
|
35
|
+
syncSnapshot: options.syncSnapshot,
|
|
47
36
|
input: options.input,
|
|
48
37
|
src,
|
|
49
38
|
systemId
|
|
50
39
|
});
|
|
51
|
-
if (options.syncSnapshot) {
|
|
52
|
-
actorRef.subscribe({
|
|
53
|
-
next: snapshot => {
|
|
54
|
-
if (snapshot.status === 'active') {
|
|
55
|
-
actorScope.self.send({
|
|
56
|
-
type: `xstate.snapshot.${actorRef.id}`,
|
|
57
|
-
snapshot,
|
|
58
|
-
id: actorRef.id
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
error: () => {}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
40
|
return actorRef;
|
|
66
41
|
}
|
|
67
42
|
};
|
|
@@ -252,6 +227,27 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
|
252
227
|
return SpecialTargets;
|
|
253
228
|
}({});
|
|
254
229
|
|
|
230
|
+
/**
|
|
231
|
+
* @deprecated Use `AnyActor` instead.
|
|
232
|
+
*/
|
|
233
|
+
|
|
234
|
+
// Based on RxJS types
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* @deprecated Use `Actor<T>` instead.
|
|
238
|
+
*/
|
|
239
|
+
|
|
240
|
+
// only meant to be used internally for debugging purposes
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Represents logic which can be used by an actor.
|
|
244
|
+
*
|
|
245
|
+
* @template TSnapshot - The type of the snapshot.
|
|
246
|
+
* @template TEvent - The type of the event object.
|
|
247
|
+
* @template TInput - The type of the input.
|
|
248
|
+
* @template TSystem - The type of the actor system.
|
|
249
|
+
*/
|
|
250
|
+
|
|
255
251
|
function resolveSendTo(actorScope, state, args, actionParams, {
|
|
256
252
|
to,
|
|
257
253
|
event: eventOrExpr,
|
package/dist/xstate.cjs.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
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 guards_dist_xstateGuards = require('./raise-
|
|
7
|
-
var send = require('./send-
|
|
6
|
+
var guards_dist_xstateGuards = require('./raise-a1d3d7e9.cjs.js');
|
|
7
|
+
var send = require('./send-2fa3a204.cjs.js');
|
|
8
8
|
require('../dev/dist/xstate-dev.cjs.js');
|
|
9
9
|
|
|
10
10
|
class SimulatedClock {
|
|
@@ -56,6 +56,20 @@ class SimulatedClock {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
const cache = new WeakMap();
|
|
60
|
+
function memo(object, key, fn) {
|
|
61
|
+
let memoizedData = cache.get(object);
|
|
62
|
+
if (!memoizedData) {
|
|
63
|
+
memoizedData = {
|
|
64
|
+
[key]: fn()
|
|
65
|
+
};
|
|
66
|
+
cache.set(object, memoizedData);
|
|
67
|
+
} else if (!(key in memoizedData)) {
|
|
68
|
+
memoizedData[key] = fn();
|
|
69
|
+
}
|
|
70
|
+
return memoizedData[key];
|
|
71
|
+
}
|
|
72
|
+
|
|
59
73
|
const EMPTY_OBJECT = {};
|
|
60
74
|
const toSerializableAction = action => {
|
|
61
75
|
if (typeof action === 'string') {
|
|
@@ -76,85 +90,72 @@ const toSerializableAction = action => {
|
|
|
76
90
|
return action;
|
|
77
91
|
};
|
|
78
92
|
class StateNode {
|
|
79
|
-
/**
|
|
80
|
-
* The relative key of the state node, which represents its location in the overall state value.
|
|
81
|
-
*/
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* The unique ID of the state node.
|
|
85
|
-
*/
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* The type of this state node:
|
|
89
|
-
*
|
|
90
|
-
* - `'atomic'` - no child state nodes
|
|
91
|
-
* - `'compound'` - nested child state nodes (XOR)
|
|
92
|
-
* - `'parallel'` - orthogonal nested child state nodes (AND)
|
|
93
|
-
* - `'history'` - history state node
|
|
94
|
-
* - `'final'` - final state node
|
|
95
|
-
*/
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* The string path from the root machine node to this node.
|
|
99
|
-
*/
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* The child state nodes.
|
|
103
|
-
*/
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* The type of history on this state node. Can be:
|
|
107
|
-
*
|
|
108
|
-
* - `'shallow'` - recalls only top-level historical state value
|
|
109
|
-
* - `'deep'` - recalls historical state value at all levels
|
|
110
|
-
*/
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* The action(s) to be executed upon entering the state node.
|
|
114
|
-
*/
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* The action(s) to be executed upon exiting the state node.
|
|
118
|
-
*/
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* The parent state node.
|
|
122
|
-
*/
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* The root machine node.
|
|
126
|
-
*/
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* The meta data associated with this state node, which will be returned in State instances.
|
|
130
|
-
*/
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* The output data sent with the "xstate.done.state._id_" event if this is a final state node.
|
|
134
|
-
*/
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* The order this state node appears. Corresponds to the implicit document order.
|
|
138
|
-
*/
|
|
139
|
-
|
|
140
93
|
constructor(
|
|
141
94
|
/**
|
|
142
95
|
* The raw config used to create the machine.
|
|
143
96
|
*/
|
|
144
97
|
config, options) {
|
|
145
98
|
this.config = config;
|
|
99
|
+
/**
|
|
100
|
+
* The relative key of the state node, which represents its location in the overall state value.
|
|
101
|
+
*/
|
|
146
102
|
this.key = void 0;
|
|
103
|
+
/**
|
|
104
|
+
* The unique ID of the state node.
|
|
105
|
+
*/
|
|
147
106
|
this.id = void 0;
|
|
107
|
+
/**
|
|
108
|
+
* The type of this state node:
|
|
109
|
+
*
|
|
110
|
+
* - `'atomic'` - no child state nodes
|
|
111
|
+
* - `'compound'` - nested child state nodes (XOR)
|
|
112
|
+
* - `'parallel'` - orthogonal nested child state nodes (AND)
|
|
113
|
+
* - `'history'` - history state node
|
|
114
|
+
* - `'final'` - final state node
|
|
115
|
+
*/
|
|
148
116
|
this.type = void 0;
|
|
117
|
+
/**
|
|
118
|
+
* The string path from the root machine node to this node.
|
|
119
|
+
*/
|
|
149
120
|
this.path = void 0;
|
|
121
|
+
/**
|
|
122
|
+
* The child state nodes.
|
|
123
|
+
*/
|
|
150
124
|
this.states = void 0;
|
|
125
|
+
/**
|
|
126
|
+
* The type of history on this state node. Can be:
|
|
127
|
+
*
|
|
128
|
+
* - `'shallow'` - recalls only top-level historical state value
|
|
129
|
+
* - `'deep'` - recalls historical state value at all levels
|
|
130
|
+
*/
|
|
151
131
|
this.history = void 0;
|
|
132
|
+
/**
|
|
133
|
+
* The action(s) to be executed upon entering the state node.
|
|
134
|
+
*/
|
|
152
135
|
this.entry = void 0;
|
|
136
|
+
/**
|
|
137
|
+
* The action(s) to be executed upon exiting the state node.
|
|
138
|
+
*/
|
|
153
139
|
this.exit = void 0;
|
|
140
|
+
/**
|
|
141
|
+
* The parent state node.
|
|
142
|
+
*/
|
|
154
143
|
this.parent = void 0;
|
|
144
|
+
/**
|
|
145
|
+
* The root machine node.
|
|
146
|
+
*/
|
|
155
147
|
this.machine = void 0;
|
|
148
|
+
/**
|
|
149
|
+
* The meta data associated with this state node, which will be returned in State instances.
|
|
150
|
+
*/
|
|
156
151
|
this.meta = void 0;
|
|
152
|
+
/**
|
|
153
|
+
* The output data sent with the "xstate.done.state._id_" event if this is a final state node.
|
|
154
|
+
*/
|
|
157
155
|
this.output = void 0;
|
|
156
|
+
/**
|
|
157
|
+
* The order this state node appears. Corresponds to the implicit document order.
|
|
158
|
+
*/
|
|
158
159
|
this.order = -1;
|
|
159
160
|
this.description = void 0;
|
|
160
161
|
this.tags = [];
|
|
@@ -248,7 +249,7 @@ class StateNode {
|
|
|
248
249
|
* The logic invoked as actors by this state node.
|
|
249
250
|
*/
|
|
250
251
|
get invoke() {
|
|
251
|
-
return
|
|
252
|
+
return memo(this, 'invoke', () => guards_dist_xstateGuards.toArray(this.config.invoke).map((invokeConfig, i) => {
|
|
252
253
|
const {
|
|
253
254
|
src,
|
|
254
255
|
systemId
|
|
@@ -281,7 +282,7 @@ class StateNode {
|
|
|
281
282
|
* The mapping of events to transitions.
|
|
282
283
|
*/
|
|
283
284
|
get on() {
|
|
284
|
-
return
|
|
285
|
+
return memo(this, 'on', () => {
|
|
285
286
|
const transitions = this.transitions;
|
|
286
287
|
return [...transitions].flatMap(([descriptor, t]) => t.map(t => [descriptor, t])).reduce((map, [descriptor, transition]) => {
|
|
287
288
|
map[descriptor] = map[descriptor] || [];
|
|
@@ -291,16 +292,16 @@ class StateNode {
|
|
|
291
292
|
});
|
|
292
293
|
}
|
|
293
294
|
get after() {
|
|
294
|
-
return
|
|
295
|
+
return memo(this, 'delayedTransitions', () => guards_dist_xstateGuards.getDelayedTransitions(this));
|
|
295
296
|
}
|
|
296
297
|
get initial() {
|
|
297
|
-
return
|
|
298
|
+
return memo(this, 'initial', () => guards_dist_xstateGuards.formatInitialTransition(this, this.config.initial));
|
|
298
299
|
}
|
|
299
300
|
next(state, event) {
|
|
300
301
|
const eventType = event.type;
|
|
301
302
|
const actions = [];
|
|
302
303
|
let selectedTransition;
|
|
303
|
-
const candidates =
|
|
304
|
+
const candidates = memo(this, `candidates-${eventType}`, () => guards_dist_xstateGuards.getCandidates(this, eventType));
|
|
304
305
|
for (const candidate of candidates) {
|
|
305
306
|
const {
|
|
306
307
|
guard
|
|
@@ -326,7 +327,7 @@ class StateNode {
|
|
|
326
327
|
* All the event types accepted by this state node and its descendants.
|
|
327
328
|
*/
|
|
328
329
|
get events() {
|
|
329
|
-
return
|
|
330
|
+
return memo(this, 'events', () => {
|
|
330
331
|
const {
|
|
331
332
|
states
|
|
332
333
|
} = this;
|
|
@@ -360,16 +361,15 @@ class StateNode {
|
|
|
360
361
|
|
|
361
362
|
const STATE_IDENTIFIER = '#';
|
|
362
363
|
class StateMachine {
|
|
363
|
-
/**
|
|
364
|
-
* The machine's own version.
|
|
365
|
-
*/
|
|
366
|
-
|
|
367
364
|
constructor(
|
|
368
365
|
/**
|
|
369
366
|
* The raw config used to create the machine.
|
|
370
367
|
*/
|
|
371
368
|
config, implementations) {
|
|
372
369
|
this.config = config;
|
|
370
|
+
/**
|
|
371
|
+
* The machine's own version.
|
|
372
|
+
*/
|
|
373
373
|
this.version = void 0;
|
|
374
374
|
this.implementations = void 0;
|
|
375
375
|
this.types = void 0;
|
|
@@ -379,15 +379,7 @@ class StateMachine {
|
|
|
379
379
|
this.id = void 0;
|
|
380
380
|
this.states = void 0;
|
|
381
381
|
this.events = void 0;
|
|
382
|
-
|
|
383
|
-
this.__TEvent = void 0;
|
|
384
|
-
this.__TActor = void 0;
|
|
385
|
-
this.__TAction = void 0;
|
|
386
|
-
this.__TGuard = void 0;
|
|
387
|
-
this.__TDelay = void 0;
|
|
388
|
-
this.__TTag = void 0;
|
|
389
|
-
this.__TInput = void 0;
|
|
390
|
-
this.__TOutput = void 0;
|
|
382
|
+
/** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
|
|
391
383
|
this.__TResolvedTypesMeta = void 0;
|
|
392
384
|
this.id = config.id || '(machine)';
|
|
393
385
|
this.implementations = {
|
|
@@ -448,12 +440,12 @@ class StateMachine {
|
|
|
448
440
|
}
|
|
449
441
|
resolveState(config) {
|
|
450
442
|
const resolvedStateValue = guards_dist_xstateGuards.resolveStateValue(this.root, config.value);
|
|
451
|
-
const
|
|
443
|
+
const nodeSet = guards_dist_xstateGuards.getAllStateNodes(guards_dist_xstateGuards.getStateNodes(this.root, resolvedStateValue));
|
|
452
444
|
return guards_dist_xstateGuards.createMachineSnapshot({
|
|
453
|
-
|
|
445
|
+
_nodes: [...nodeSet],
|
|
454
446
|
context: config.context || {},
|
|
455
447
|
children: {},
|
|
456
|
-
status: guards_dist_xstateGuards.isInFinalState(
|
|
448
|
+
status: guards_dist_xstateGuards.isInFinalState(nodeSet, this.root) ? 'done' : config.status || 'active',
|
|
457
449
|
output: config.output,
|
|
458
450
|
error: config.error,
|
|
459
451
|
historyValue: config.historyValue
|
|
@@ -469,7 +461,7 @@ class StateMachine {
|
|
|
469
461
|
*/
|
|
470
462
|
transition(state, event, actorScope) {
|
|
471
463
|
// TODO: handle error events in a better way
|
|
472
|
-
if (guards_dist_xstateGuards.isErrorActorEvent(event) && !state.
|
|
464
|
+
if (guards_dist_xstateGuards.isErrorActorEvent(event) && !guards_dist_xstateGuards.getAllOwnEventDescriptors(state).some(nextEvent => nextEvent === event.type)) {
|
|
473
465
|
return guards_dist_xstateGuards.cloneMachineSnapshot(state, {
|
|
474
466
|
status: 'error',
|
|
475
467
|
error: event.data
|
|
@@ -505,7 +497,7 @@ class StateMachine {
|
|
|
505
497
|
} = this.config;
|
|
506
498
|
const preInitial = guards_dist_xstateGuards.createMachineSnapshot({
|
|
507
499
|
context: typeof context !== 'function' && context ? context : {},
|
|
508
|
-
|
|
500
|
+
_nodes: [this.root],
|
|
509
501
|
children: {},
|
|
510
502
|
status: 'active'
|
|
511
503
|
}, this);
|
|
@@ -579,11 +571,11 @@ class StateMachine {
|
|
|
579
571
|
if (!logic) {
|
|
580
572
|
return;
|
|
581
573
|
}
|
|
582
|
-
const actorState = logic.restoreState?.(childState, _actorScope);
|
|
583
574
|
const actorRef = guards_dist_xstateGuards.createActor(logic, {
|
|
584
575
|
id: actorId,
|
|
585
576
|
parent: _actorScope?.self,
|
|
586
|
-
|
|
577
|
+
syncSnapshot: actorData.syncSnapshot,
|
|
578
|
+
state: childState,
|
|
587
579
|
src,
|
|
588
580
|
systemId: actorData.systemId
|
|
589
581
|
});
|
|
@@ -592,7 +584,7 @@ class StateMachine {
|
|
|
592
584
|
const restoredSnapshot = guards_dist_xstateGuards.createMachineSnapshot({
|
|
593
585
|
...snapshot,
|
|
594
586
|
children,
|
|
595
|
-
|
|
587
|
+
_nodes: Array.from(guards_dist_xstateGuards.getAllStateNodes(guards_dist_xstateGuards.getStateNodes(this.root, snapshot.value)))
|
|
596
588
|
}, this);
|
|
597
589
|
let seen = new Set();
|
|
598
590
|
function reviveContext(contextPart, children) {
|
|
@@ -614,8 +606,6 @@ class StateMachine {
|
|
|
614
606
|
reviveContext(restoredSnapshot.context, children);
|
|
615
607
|
return restoredSnapshot;
|
|
616
608
|
}
|
|
617
|
-
|
|
618
|
-
/**@deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
|
|
619
609
|
}
|
|
620
610
|
|
|
621
611
|
const defaultWaitForOptions = {
|
|
@@ -693,6 +683,24 @@ function createMachine(config, implementations) {
|
|
|
693
683
|
return new StateMachine(config, implementations);
|
|
694
684
|
}
|
|
695
685
|
|
|
686
|
+
// at the moment we allow extra actors - ones that are not specified by `children`
|
|
687
|
+
// this could be reconsidered in the future
|
|
688
|
+
function setup({
|
|
689
|
+
actors,
|
|
690
|
+
actions,
|
|
691
|
+
guards,
|
|
692
|
+
delays
|
|
693
|
+
}) {
|
|
694
|
+
return {
|
|
695
|
+
createMachine: config => createMachine(config, {
|
|
696
|
+
actors,
|
|
697
|
+
actions,
|
|
698
|
+
guards,
|
|
699
|
+
delays
|
|
700
|
+
})
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
|
|
696
704
|
exports.createEmptyActor = actors_dist_xstateActors.createEmptyActor;
|
|
697
705
|
exports.fromCallback = actors_dist_xstateActors.fromCallback;
|
|
698
706
|
exports.fromEventObservable = actors_dist_xstateActors.fromEventObservable;
|
|
@@ -700,6 +708,7 @@ exports.fromObservable = actors_dist_xstateActors.fromObservable;
|
|
|
700
708
|
exports.fromPromise = actors_dist_xstateActors.fromPromise;
|
|
701
709
|
exports.fromTransition = actors_dist_xstateActors.fromTransition;
|
|
702
710
|
exports.Actor = guards_dist_xstateGuards.Actor;
|
|
711
|
+
exports.__unsafe_getAllOwnEventDescriptors = guards_dist_xstateGuards.getAllOwnEventDescriptors;
|
|
703
712
|
exports.and = guards_dist_xstateGuards.and;
|
|
704
713
|
exports.cancel = guards_dist_xstateGuards.cancel;
|
|
705
714
|
exports.createActor = guards_dist_xstateGuards.createActor;
|
|
@@ -728,4 +737,5 @@ exports.SimulatedClock = SimulatedClock;
|
|
|
728
737
|
exports.StateMachine = StateMachine;
|
|
729
738
|
exports.StateNode = StateNode;
|
|
730
739
|
exports.createMachine = createMachine;
|
|
740
|
+
exports.setup = setup;
|
|
731
741
|
exports.waitFor = waitFor;
|
package/dist/xstate.cjs.mjs
CHANGED