xstate 5.0.0-beta.43 → 5.0.0-beta.44
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 -3
- package/actions/dist/xstate-actions.development.cjs.js +2 -3
- package/actions/dist/xstate-actions.development.esm.js +2 -3
- package/actions/dist/xstate-actions.esm.js +2 -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 +6 -6
- package/actors/dist/xstate-actors.development.cjs.js +6 -6
- package/actors/dist/xstate-actors.development.esm.js +1 -1
- package/actors/dist/xstate-actors.esm.js +1 -1
- 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 +3 -7
- package/dist/declarations/src/actions/spawn.d.ts +11 -16
- package/dist/declarations/src/guards.d.ts +2 -2
- package/dist/declarations/src/index.d.ts +1 -1
- package/dist/declarations/src/spawn.d.ts +9 -13
- package/dist/declarations/src/stateUtils.d.ts +4 -4
- package/dist/declarations/src/types.d.ts +15 -16
- package/dist/declarations/src/utils.d.ts +1 -3
- package/dist/{raise-e0fe5c2d.cjs.js → raise-348cc74e.development.esm.js} +946 -68
- package/dist/{raise-f4ad5a87.development.esm.js → raise-5854eaca.esm.js} +860 -49
- package/dist/{raise-23dea0d7.development.cjs.js → raise-ed700d14.development.cjs.js} +922 -36
- package/dist/{raise-8dc8e1aa.esm.js → raise-fb6f017b.cjs.js} +907 -2
- package/dist/{send-0174c155.development.cjs.js → send-00466e37.development.cjs.js} +11 -12
- package/dist/{send-87bbaaab.cjs.js → send-53e5693c.cjs.js} +11 -12
- package/dist/{send-5d129d95.development.esm.js → send-a0193bdb.development.esm.js} +2 -3
- package/dist/{send-84e2e742.esm.js → send-b7b4befa.esm.js} +2 -3
- package/dist/xstate.cjs.js +25 -25
- package/dist/xstate.cjs.mjs +1 -0
- package/dist/xstate.development.cjs.js +25 -25
- package/dist/xstate.development.cjs.mjs +1 -0
- package/dist/xstate.development.esm.js +4 -6
- package/dist/xstate.esm.js +4 -6
- 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 -2
- package/guards/dist/xstate-guards.development.cjs.js +1 -2
- package/guards/dist/xstate-guards.development.esm.js +1 -2
- package/guards/dist/xstate-guards.esm.js +1 -2
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/dist/interpreter-36d5556e.cjs.js +0 -887
- package/dist/interpreter-4e8e2a0d.development.cjs.js +0 -898
- package/dist/interpreter-63c80754.esm.js +0 -857
- package/dist/interpreter-80eb3bec.development.esm.js +0 -868
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
4
|
-
var interpreter = require('./interpreter-4e8e2a0d.development.cjs.js');
|
|
3
|
+
var guards_dist_xstateGuards = require('./raise-ed700d14.development.cjs.js');
|
|
5
4
|
|
|
6
5
|
function createSpawner(actorScope, {
|
|
7
6
|
machine,
|
|
@@ -13,11 +12,11 @@ function createSpawner(actorScope, {
|
|
|
13
12
|
input
|
|
14
13
|
} = options;
|
|
15
14
|
if (typeof src === 'string') {
|
|
16
|
-
const logic =
|
|
15
|
+
const logic = guards_dist_xstateGuards.resolveReferencedActor(machine, src);
|
|
17
16
|
if (!logic) {
|
|
18
17
|
throw new Error(`Actor logic '${src}' not implemented in machine '${machine.id}'`);
|
|
19
18
|
}
|
|
20
|
-
const actorRef =
|
|
19
|
+
const actorRef = guards_dist_xstateGuards.createActor(logic, {
|
|
21
20
|
id: options.id,
|
|
22
21
|
parent: actorScope.self,
|
|
23
22
|
input: typeof input === 'function' ? input({
|
|
@@ -44,7 +43,7 @@ function createSpawner(actorScope, {
|
|
|
44
43
|
}
|
|
45
44
|
return actorRef;
|
|
46
45
|
} else {
|
|
47
|
-
const actorRef =
|
|
46
|
+
const actorRef = guards_dist_xstateGuards.createActor(src, {
|
|
48
47
|
id: options.id,
|
|
49
48
|
parent: actorScope.self,
|
|
50
49
|
input: options.input,
|
|
@@ -72,13 +71,13 @@ function createSpawner(actorScope, {
|
|
|
72
71
|
const actorRef = spawn(src, options); // TODO: fix types
|
|
73
72
|
spawnedChildren[actorRef.id] = actorRef;
|
|
74
73
|
actorScope.defer(() => {
|
|
75
|
-
if (actorRef._processingStatus ===
|
|
74
|
+
if (actorRef._processingStatus === guards_dist_xstateGuards.ProcessingStatus.Stopped) {
|
|
76
75
|
return;
|
|
77
76
|
}
|
|
78
77
|
try {
|
|
79
78
|
actorRef.start?.();
|
|
80
79
|
} catch (err) {
|
|
81
|
-
actorScope.self.send(
|
|
80
|
+
actorScope.self.send(guards_dist_xstateGuards.createErrorActorEvent(actorRef.id, err));
|
|
82
81
|
return;
|
|
83
82
|
}
|
|
84
83
|
});
|
|
@@ -141,7 +140,7 @@ function resolveChoose(_, state, actionArgs, _actionParams, {
|
|
|
141
140
|
const matchedActions = branches.find(condition => {
|
|
142
141
|
return !condition.guard || guards_dist_xstateGuards.evaluateGuard(condition.guard, state.context, actionArgs.event, state);
|
|
143
142
|
})?.actions;
|
|
144
|
-
return [state, undefined,
|
|
143
|
+
return [state, undefined, guards_dist_xstateGuards.toArray(matchedActions)];
|
|
145
144
|
}
|
|
146
145
|
function choose(branches) {
|
|
147
146
|
function choose(args, params) {
|
|
@@ -207,7 +206,7 @@ function log(value = ({
|
|
|
207
206
|
function resolvePure(_, state, args, _actionParams, {
|
|
208
207
|
get
|
|
209
208
|
}) {
|
|
210
|
-
return [state, undefined,
|
|
209
|
+
return [state, undefined, guards_dist_xstateGuards.toArray(get({
|
|
211
210
|
context: args.context,
|
|
212
211
|
event: args.event
|
|
213
212
|
}))];
|
|
@@ -257,7 +256,7 @@ function pure(getActions) {
|
|
|
257
256
|
|
|
258
257
|
// TODO: remove once TS fixes this type-widening issue
|
|
259
258
|
|
|
260
|
-
|
|
259
|
+
/** @deprecated use `AnyMachineSnapshot` instead */
|
|
261
260
|
|
|
262
261
|
// TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
|
|
263
262
|
|
|
@@ -330,7 +329,7 @@ function executeSendTo(actorScope, params) {
|
|
|
330
329
|
to,
|
|
331
330
|
event
|
|
332
331
|
} = params;
|
|
333
|
-
actorScope?.system._relay(actorScope.self, to, event.type ===
|
|
332
|
+
actorScope?.system._relay(actorScope.self, to, event.type === guards_dist_xstateGuards.XSTATE_ERROR ? guards_dist_xstateGuards.createErrorActorEvent(actorScope.self.id, event.data) : event);
|
|
334
333
|
});
|
|
335
334
|
}
|
|
336
335
|
/**
|
|
@@ -400,7 +399,7 @@ function forwardTo(target, options) {
|
|
|
400
399
|
function escalate(errorData, options) {
|
|
401
400
|
return sendParent(arg => {
|
|
402
401
|
return {
|
|
403
|
-
type:
|
|
402
|
+
type: guards_dist_xstateGuards.XSTATE_ERROR,
|
|
404
403
|
data: typeof errorData === 'function' ? errorData(arg) : errorData
|
|
405
404
|
};
|
|
406
405
|
}, options);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
4
|
-
var interpreter = require('./interpreter-36d5556e.cjs.js');
|
|
3
|
+
var guards_dist_xstateGuards = require('./raise-fb6f017b.cjs.js');
|
|
5
4
|
|
|
6
5
|
function createSpawner(actorScope, {
|
|
7
6
|
machine,
|
|
@@ -13,11 +12,11 @@ function createSpawner(actorScope, {
|
|
|
13
12
|
input
|
|
14
13
|
} = options;
|
|
15
14
|
if (typeof src === 'string') {
|
|
16
|
-
const logic =
|
|
15
|
+
const logic = guards_dist_xstateGuards.resolveReferencedActor(machine, src);
|
|
17
16
|
if (!logic) {
|
|
18
17
|
throw new Error(`Actor logic '${src}' not implemented in machine '${machine.id}'`);
|
|
19
18
|
}
|
|
20
|
-
const actorRef =
|
|
19
|
+
const actorRef = guards_dist_xstateGuards.createActor(logic, {
|
|
21
20
|
id: options.id,
|
|
22
21
|
parent: actorScope.self,
|
|
23
22
|
input: typeof input === 'function' ? input({
|
|
@@ -44,7 +43,7 @@ function createSpawner(actorScope, {
|
|
|
44
43
|
}
|
|
45
44
|
return actorRef;
|
|
46
45
|
} else {
|
|
47
|
-
const actorRef =
|
|
46
|
+
const actorRef = guards_dist_xstateGuards.createActor(src, {
|
|
48
47
|
id: options.id,
|
|
49
48
|
parent: actorScope.self,
|
|
50
49
|
input: options.input,
|
|
@@ -72,13 +71,13 @@ function createSpawner(actorScope, {
|
|
|
72
71
|
const actorRef = spawn(src, options); // TODO: fix types
|
|
73
72
|
spawnedChildren[actorRef.id] = actorRef;
|
|
74
73
|
actorScope.defer(() => {
|
|
75
|
-
if (actorRef._processingStatus ===
|
|
74
|
+
if (actorRef._processingStatus === guards_dist_xstateGuards.ProcessingStatus.Stopped) {
|
|
76
75
|
return;
|
|
77
76
|
}
|
|
78
77
|
try {
|
|
79
78
|
actorRef.start?.();
|
|
80
79
|
} catch (err) {
|
|
81
|
-
actorScope.self.send(
|
|
80
|
+
actorScope.self.send(guards_dist_xstateGuards.createErrorActorEvent(actorRef.id, err));
|
|
82
81
|
return;
|
|
83
82
|
}
|
|
84
83
|
});
|
|
@@ -138,7 +137,7 @@ function resolveChoose(_, state, actionArgs, _actionParams, {
|
|
|
138
137
|
const matchedActions = branches.find(condition => {
|
|
139
138
|
return !condition.guard || guards_dist_xstateGuards.evaluateGuard(condition.guard, state.context, actionArgs.event, state);
|
|
140
139
|
})?.actions;
|
|
141
|
-
return [state, undefined,
|
|
140
|
+
return [state, undefined, guards_dist_xstateGuards.toArray(matchedActions)];
|
|
142
141
|
}
|
|
143
142
|
function choose(branches) {
|
|
144
143
|
function choose(args, params) {
|
|
@@ -198,7 +197,7 @@ function log(value = ({
|
|
|
198
197
|
function resolvePure(_, state, args, _actionParams, {
|
|
199
198
|
get
|
|
200
199
|
}) {
|
|
201
|
-
return [state, undefined,
|
|
200
|
+
return [state, undefined, guards_dist_xstateGuards.toArray(get({
|
|
202
201
|
context: args.context,
|
|
203
202
|
event: args.event
|
|
204
203
|
}))];
|
|
@@ -245,7 +244,7 @@ function pure(getActions) {
|
|
|
245
244
|
|
|
246
245
|
// TODO: remove once TS fixes this type-widening issue
|
|
247
246
|
|
|
248
|
-
|
|
247
|
+
/** @deprecated use `AnyMachineSnapshot` instead */
|
|
249
248
|
|
|
250
249
|
// TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
|
|
251
250
|
|
|
@@ -318,7 +317,7 @@ function executeSendTo(actorScope, params) {
|
|
|
318
317
|
to,
|
|
319
318
|
event
|
|
320
319
|
} = params;
|
|
321
|
-
actorScope?.system._relay(actorScope.self, to, event.type ===
|
|
320
|
+
actorScope?.system._relay(actorScope.self, to, event.type === guards_dist_xstateGuards.XSTATE_ERROR ? guards_dist_xstateGuards.createErrorActorEvent(actorScope.self.id, event.data) : event);
|
|
322
321
|
});
|
|
323
322
|
}
|
|
324
323
|
/**
|
|
@@ -375,7 +374,7 @@ function forwardTo(target, options) {
|
|
|
375
374
|
function escalate(errorData, options) {
|
|
376
375
|
return sendParent(arg => {
|
|
377
376
|
return {
|
|
378
|
-
type:
|
|
377
|
+
type: guards_dist_xstateGuards.XSTATE_ERROR,
|
|
379
378
|
data: typeof errorData === 'function' ? errorData(arg) : errorData
|
|
380
379
|
};
|
|
381
380
|
}, options);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { P as ProcessingStatus, h as createErrorActorEvent, r as resolveReferencedActor, d as createActor, t as toArray, v as XSTATE_ERROR } from './interpreter-80eb3bec.development.esm.js';
|
|
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-348cc74e.development.esm.js';
|
|
3
2
|
|
|
4
3
|
function createSpawner(actorScope, {
|
|
5
4
|
machine,
|
|
@@ -255,7 +254,7 @@ function pure(getActions) {
|
|
|
255
254
|
|
|
256
255
|
// TODO: remove once TS fixes this type-widening issue
|
|
257
256
|
|
|
258
|
-
|
|
257
|
+
/** @deprecated use `AnyMachineSnapshot` instead */
|
|
259
258
|
|
|
260
259
|
// TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
|
|
261
260
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { P as ProcessingStatus, h as createErrorActorEvent, r as resolveReferencedActor, d as createActor, t as toArray, v as XSTATE_ERROR } from './interpreter-63c80754.esm.js';
|
|
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-5854eaca.esm.js';
|
|
3
2
|
|
|
4
3
|
function createSpawner(actorScope, {
|
|
5
4
|
machine,
|
|
@@ -243,7 +242,7 @@ function pure(getActions) {
|
|
|
243
242
|
|
|
244
243
|
// TODO: remove once TS fixes this type-widening issue
|
|
245
244
|
|
|
246
|
-
|
|
245
|
+
/** @deprecated use `AnyMachineSnapshot` instead */
|
|
247
246
|
|
|
248
247
|
// TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
|
|
249
248
|
|
package/dist/xstate.cjs.js
CHANGED
|
@@ -3,9 +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
|
|
7
|
-
var
|
|
8
|
-
var send = require('./send-87bbaaab.cjs.js');
|
|
6
|
+
var guards_dist_xstateGuards = require('./raise-fb6f017b.cjs.js');
|
|
7
|
+
var send = require('./send-53e5693c.cjs.js');
|
|
9
8
|
require('../dev/dist/xstate-dev.cjs.js');
|
|
10
9
|
|
|
11
10
|
class SimulatedClock {
|
|
@@ -165,12 +164,12 @@ class StateNode {
|
|
|
165
164
|
this.key = options._key;
|
|
166
165
|
this.machine = options._machine;
|
|
167
166
|
this.path = this.parent ? this.parent.path.concat(this.key) : [];
|
|
168
|
-
this.id = this.config.id || [this.machine.id, ...this.path].join(
|
|
167
|
+
this.id = this.config.id || [this.machine.id, ...this.path].join(guards_dist_xstateGuards.STATE_DELIMITER);
|
|
169
168
|
this.type = this.config.type || (this.config.states && Object.keys(this.config.states).length ? 'compound' : this.config.history ? 'history' : 'atomic');
|
|
170
169
|
this.description = this.config.description;
|
|
171
170
|
this.order = this.machine.idMap.size;
|
|
172
171
|
this.machine.idMap.set(this.id, this);
|
|
173
|
-
this.states = this.config.states ?
|
|
172
|
+
this.states = this.config.states ? guards_dist_xstateGuards.mapValues(this.config.states, (stateConfig, key) => {
|
|
174
173
|
const stateNode = new StateNode(stateConfig, {
|
|
175
174
|
_parent: this,
|
|
176
175
|
_key: key,
|
|
@@ -184,16 +183,16 @@ class StateNode {
|
|
|
184
183
|
|
|
185
184
|
// History config
|
|
186
185
|
this.history = this.config.history === true ? 'shallow' : this.config.history || false;
|
|
187
|
-
this.entry =
|
|
188
|
-
this.exit =
|
|
186
|
+
this.entry = guards_dist_xstateGuards.toArray(this.config.entry).slice();
|
|
187
|
+
this.exit = guards_dist_xstateGuards.toArray(this.config.exit).slice();
|
|
189
188
|
this.meta = this.config.meta;
|
|
190
189
|
this.output = this.type === 'final' || !this.parent ? this.config.output : undefined;
|
|
191
|
-
this.tags =
|
|
190
|
+
this.tags = guards_dist_xstateGuards.toArray(config.tags).slice();
|
|
192
191
|
}
|
|
193
192
|
_initialize() {
|
|
194
193
|
this.transitions = guards_dist_xstateGuards.formatTransitions(this);
|
|
195
194
|
if (this.config.always) {
|
|
196
|
-
this.always =
|
|
195
|
+
this.always = guards_dist_xstateGuards.toTransitionConfigArray(this.config.always).map(t => guards_dist_xstateGuards.formatTransition(this, guards_dist_xstateGuards.NULL_EVENT, t));
|
|
197
196
|
}
|
|
198
197
|
Object.keys(this.states).forEach(key => {
|
|
199
198
|
this.states[key]._initialize();
|
|
@@ -223,7 +222,7 @@ class StateNode {
|
|
|
223
222
|
})
|
|
224
223
|
} : undefined,
|
|
225
224
|
history: this.history,
|
|
226
|
-
states:
|
|
225
|
+
states: guards_dist_xstateGuards.mapValues(this.states, state => {
|
|
227
226
|
return state.definition;
|
|
228
227
|
}),
|
|
229
228
|
on: this.on,
|
|
@@ -249,13 +248,13 @@ class StateNode {
|
|
|
249
248
|
* The logic invoked as actors by this state node.
|
|
250
249
|
*/
|
|
251
250
|
get invoke() {
|
|
252
|
-
return guards_dist_xstateGuards.memo(this, 'invoke', () =>
|
|
251
|
+
return guards_dist_xstateGuards.memo(this, 'invoke', () => guards_dist_xstateGuards.toArray(this.config.invoke).map((invokeConfig, i) => {
|
|
253
252
|
const {
|
|
254
253
|
src,
|
|
255
254
|
systemId
|
|
256
255
|
} = invokeConfig;
|
|
257
|
-
const resolvedId = invokeConfig.id ||
|
|
258
|
-
const resolvedSrc = typeof src === 'string' ? src : `xstate#${
|
|
256
|
+
const resolvedId = invokeConfig.id || guards_dist_xstateGuards.createInvokeId(this.id, i);
|
|
257
|
+
const resolvedSrc = typeof src === 'string' ? src : `xstate#${guards_dist_xstateGuards.createInvokeId(this.id, i)}`;
|
|
259
258
|
return {
|
|
260
259
|
...invokeConfig,
|
|
261
260
|
src: resolvedSrc,
|
|
@@ -470,7 +469,7 @@ class StateMachine {
|
|
|
470
469
|
*/
|
|
471
470
|
transition(state, event, actorScope) {
|
|
472
471
|
// TODO: handle error events in a better way
|
|
473
|
-
if (
|
|
472
|
+
if (guards_dist_xstateGuards.isErrorActorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
|
|
474
473
|
return guards_dist_xstateGuards.cloneMachineSnapshot(state, {
|
|
475
474
|
status: 'error',
|
|
476
475
|
error: event.data
|
|
@@ -527,7 +526,7 @@ class StateMachine {
|
|
|
527
526
|
* Returns the initial `State` instance, with reference to `self` as an `ActorRef`.
|
|
528
527
|
*/
|
|
529
528
|
getInitialState(actorScope, input) {
|
|
530
|
-
const initEvent =
|
|
529
|
+
const initEvent = guards_dist_xstateGuards.createInitEvent(input); // TODO: fix;
|
|
531
530
|
const internalQueue = [];
|
|
532
531
|
const preInitialState = this.getPreInitialState(actorScope, initEvent, internalQueue);
|
|
533
532
|
const nextState = guards_dist_xstateGuards.microstep([{
|
|
@@ -551,7 +550,7 @@ class StateMachine {
|
|
|
551
550
|
});
|
|
552
551
|
}
|
|
553
552
|
getStateNodeById(stateId) {
|
|
554
|
-
const fullPath = stateId.split(
|
|
553
|
+
const fullPath = stateId.split(guards_dist_xstateGuards.STATE_DELIMITER);
|
|
555
554
|
const relativePath = fullPath.slice(1);
|
|
556
555
|
const resolvedStateId = guards_dist_xstateGuards.isStateId(fullPath[0]) ? fullPath[0].slice(STATE_IDENTIFIER.length) : fullPath[0];
|
|
557
556
|
const stateNode = this.idMap.get(resolvedStateId);
|
|
@@ -576,12 +575,12 @@ class StateMachine {
|
|
|
576
575
|
const actorData = snapshotChildren[actorId];
|
|
577
576
|
const childState = actorData.state;
|
|
578
577
|
const src = actorData.src;
|
|
579
|
-
const logic = typeof src === 'string' ?
|
|
578
|
+
const logic = typeof src === 'string' ? guards_dist_xstateGuards.resolveReferencedActor(this, src) : src;
|
|
580
579
|
if (!logic) {
|
|
581
580
|
return;
|
|
582
581
|
}
|
|
583
582
|
const actorState = logic.restoreState?.(childState, _actorScope);
|
|
584
|
-
const actorRef =
|
|
583
|
+
const actorRef = guards_dist_xstateGuards.createActor(logic, {
|
|
585
584
|
id: actorId,
|
|
586
585
|
parent: _actorScope?.self,
|
|
587
586
|
state: actorState,
|
|
@@ -604,7 +603,7 @@ class StateMachine {
|
|
|
604
603
|
for (let key in contextPart) {
|
|
605
604
|
const value = contextPart[key];
|
|
606
605
|
if (value && typeof value === 'object') {
|
|
607
|
-
if ('xstate$$type' in value && value.xstate$$type ===
|
|
606
|
+
if ('xstate$$type' in value && value.xstate$$type === guards_dist_xstateGuards.$$ACTOR_TYPE) {
|
|
608
607
|
contextPart[key] = children[value.id];
|
|
609
608
|
continue;
|
|
610
609
|
}
|
|
@@ -700,21 +699,22 @@ exports.fromEventObservable = actors_dist_xstateActors.fromEventObservable;
|
|
|
700
699
|
exports.fromObservable = actors_dist_xstateActors.fromObservable;
|
|
701
700
|
exports.fromPromise = actors_dist_xstateActors.fromPromise;
|
|
702
701
|
exports.fromTransition = actors_dist_xstateActors.fromTransition;
|
|
703
|
-
exports.Actor =
|
|
704
|
-
exports.createActor = interpreter.createActor;
|
|
705
|
-
exports.interpret = interpreter.interpret;
|
|
706
|
-
exports.matchesState = interpreter.matchesState;
|
|
707
|
-
exports.pathToStateValue = interpreter.pathToStateValue;
|
|
708
|
-
exports.toObserver = interpreter.toObserver;
|
|
702
|
+
exports.Actor = guards_dist_xstateGuards.Actor;
|
|
709
703
|
exports.and = guards_dist_xstateGuards.and;
|
|
710
704
|
exports.cancel = guards_dist_xstateGuards.cancel;
|
|
705
|
+
exports.createActor = guards_dist_xstateGuards.createActor;
|
|
711
706
|
exports.getStateNodes = guards_dist_xstateGuards.getStateNodes;
|
|
707
|
+
exports.interpret = guards_dist_xstateGuards.interpret;
|
|
708
|
+
exports.isMachineSnapshot = guards_dist_xstateGuards.isMachineSnapshot;
|
|
709
|
+
exports.matchesState = guards_dist_xstateGuards.matchesState;
|
|
712
710
|
exports.not = guards_dist_xstateGuards.not;
|
|
713
711
|
exports.or = guards_dist_xstateGuards.or;
|
|
712
|
+
exports.pathToStateValue = guards_dist_xstateGuards.pathToStateValue;
|
|
714
713
|
exports.raise = guards_dist_xstateGuards.raise;
|
|
715
714
|
exports.spawn = guards_dist_xstateGuards.spawn;
|
|
716
715
|
exports.stateIn = guards_dist_xstateGuards.stateIn;
|
|
717
716
|
exports.stop = guards_dist_xstateGuards.stop;
|
|
717
|
+
exports.toObserver = guards_dist_xstateGuards.toObserver;
|
|
718
718
|
exports.SpecialTargets = send.SpecialTargets;
|
|
719
719
|
exports.assign = send.assign;
|
|
720
720
|
exports.choose = send.choose;
|
package/dist/xstate.cjs.mjs
CHANGED
|
@@ -3,9 +3,8 @@
|
|
|
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
|
|
7
|
-
var
|
|
8
|
-
var send = require('./send-0174c155.development.cjs.js');
|
|
6
|
+
var guards_dist_xstateGuards = require('./raise-ed700d14.development.cjs.js');
|
|
7
|
+
var send = require('./send-00466e37.development.cjs.js');
|
|
9
8
|
require('../dev/dist/xstate-dev.development.cjs.js');
|
|
10
9
|
|
|
11
10
|
class SimulatedClock {
|
|
@@ -165,12 +164,12 @@ class StateNode {
|
|
|
165
164
|
this.key = options._key;
|
|
166
165
|
this.machine = options._machine;
|
|
167
166
|
this.path = this.parent ? this.parent.path.concat(this.key) : [];
|
|
168
|
-
this.id = this.config.id || [this.machine.id, ...this.path].join(
|
|
167
|
+
this.id = this.config.id || [this.machine.id, ...this.path].join(guards_dist_xstateGuards.STATE_DELIMITER);
|
|
169
168
|
this.type = this.config.type || (this.config.states && Object.keys(this.config.states).length ? 'compound' : this.config.history ? 'history' : 'atomic');
|
|
170
169
|
this.description = this.config.description;
|
|
171
170
|
this.order = this.machine.idMap.size;
|
|
172
171
|
this.machine.idMap.set(this.id, this);
|
|
173
|
-
this.states = this.config.states ?
|
|
172
|
+
this.states = this.config.states ? guards_dist_xstateGuards.mapValues(this.config.states, (stateConfig, key) => {
|
|
174
173
|
const stateNode = new StateNode(stateConfig, {
|
|
175
174
|
_parent: this,
|
|
176
175
|
_key: key,
|
|
@@ -184,16 +183,16 @@ class StateNode {
|
|
|
184
183
|
|
|
185
184
|
// History config
|
|
186
185
|
this.history = this.config.history === true ? 'shallow' : this.config.history || false;
|
|
187
|
-
this.entry =
|
|
188
|
-
this.exit =
|
|
186
|
+
this.entry = guards_dist_xstateGuards.toArray(this.config.entry).slice();
|
|
187
|
+
this.exit = guards_dist_xstateGuards.toArray(this.config.exit).slice();
|
|
189
188
|
this.meta = this.config.meta;
|
|
190
189
|
this.output = this.type === 'final' || !this.parent ? this.config.output : undefined;
|
|
191
|
-
this.tags =
|
|
190
|
+
this.tags = guards_dist_xstateGuards.toArray(config.tags).slice();
|
|
192
191
|
}
|
|
193
192
|
_initialize() {
|
|
194
193
|
this.transitions = guards_dist_xstateGuards.formatTransitions(this);
|
|
195
194
|
if (this.config.always) {
|
|
196
|
-
this.always =
|
|
195
|
+
this.always = guards_dist_xstateGuards.toTransitionConfigArray(this.config.always).map(t => guards_dist_xstateGuards.formatTransition(this, guards_dist_xstateGuards.NULL_EVENT, t));
|
|
197
196
|
}
|
|
198
197
|
Object.keys(this.states).forEach(key => {
|
|
199
198
|
this.states[key]._initialize();
|
|
@@ -223,7 +222,7 @@ class StateNode {
|
|
|
223
222
|
})
|
|
224
223
|
} : undefined,
|
|
225
224
|
history: this.history,
|
|
226
|
-
states:
|
|
225
|
+
states: guards_dist_xstateGuards.mapValues(this.states, state => {
|
|
227
226
|
return state.definition;
|
|
228
227
|
}),
|
|
229
228
|
on: this.on,
|
|
@@ -249,13 +248,13 @@ class StateNode {
|
|
|
249
248
|
* The logic invoked as actors by this state node.
|
|
250
249
|
*/
|
|
251
250
|
get invoke() {
|
|
252
|
-
return guards_dist_xstateGuards.memo(this, 'invoke', () =>
|
|
251
|
+
return guards_dist_xstateGuards.memo(this, 'invoke', () => guards_dist_xstateGuards.toArray(this.config.invoke).map((invokeConfig, i) => {
|
|
253
252
|
const {
|
|
254
253
|
src,
|
|
255
254
|
systemId
|
|
256
255
|
} = invokeConfig;
|
|
257
|
-
const resolvedId = invokeConfig.id ||
|
|
258
|
-
const resolvedSrc = typeof src === 'string' ? src : `xstate#${
|
|
256
|
+
const resolvedId = invokeConfig.id || guards_dist_xstateGuards.createInvokeId(this.id, i);
|
|
257
|
+
const resolvedSrc = typeof src === 'string' ? src : `xstate#${guards_dist_xstateGuards.createInvokeId(this.id, i)}`;
|
|
259
258
|
return {
|
|
260
259
|
...invokeConfig,
|
|
261
260
|
src: resolvedSrc,
|
|
@@ -473,7 +472,7 @@ class StateMachine {
|
|
|
473
472
|
*/
|
|
474
473
|
transition(state, event, actorScope) {
|
|
475
474
|
// TODO: handle error events in a better way
|
|
476
|
-
if (
|
|
475
|
+
if (guards_dist_xstateGuards.isErrorActorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
|
|
477
476
|
return guards_dist_xstateGuards.cloneMachineSnapshot(state, {
|
|
478
477
|
status: 'error',
|
|
479
478
|
error: event.data
|
|
@@ -530,7 +529,7 @@ class StateMachine {
|
|
|
530
529
|
* Returns the initial `State` instance, with reference to `self` as an `ActorRef`.
|
|
531
530
|
*/
|
|
532
531
|
getInitialState(actorScope, input) {
|
|
533
|
-
const initEvent =
|
|
532
|
+
const initEvent = guards_dist_xstateGuards.createInitEvent(input); // TODO: fix;
|
|
534
533
|
const internalQueue = [];
|
|
535
534
|
const preInitialState = this.getPreInitialState(actorScope, initEvent, internalQueue);
|
|
536
535
|
const nextState = guards_dist_xstateGuards.microstep([{
|
|
@@ -554,7 +553,7 @@ class StateMachine {
|
|
|
554
553
|
});
|
|
555
554
|
}
|
|
556
555
|
getStateNodeById(stateId) {
|
|
557
|
-
const fullPath = stateId.split(
|
|
556
|
+
const fullPath = stateId.split(guards_dist_xstateGuards.STATE_DELIMITER);
|
|
558
557
|
const relativePath = fullPath.slice(1);
|
|
559
558
|
const resolvedStateId = guards_dist_xstateGuards.isStateId(fullPath[0]) ? fullPath[0].slice(STATE_IDENTIFIER.length) : fullPath[0];
|
|
560
559
|
const stateNode = this.idMap.get(resolvedStateId);
|
|
@@ -579,12 +578,12 @@ class StateMachine {
|
|
|
579
578
|
const actorData = snapshotChildren[actorId];
|
|
580
579
|
const childState = actorData.state;
|
|
581
580
|
const src = actorData.src;
|
|
582
|
-
const logic = typeof src === 'string' ?
|
|
581
|
+
const logic = typeof src === 'string' ? guards_dist_xstateGuards.resolveReferencedActor(this, src) : src;
|
|
583
582
|
if (!logic) {
|
|
584
583
|
return;
|
|
585
584
|
}
|
|
586
585
|
const actorState = logic.restoreState?.(childState, _actorScope);
|
|
587
|
-
const actorRef =
|
|
586
|
+
const actorRef = guards_dist_xstateGuards.createActor(logic, {
|
|
588
587
|
id: actorId,
|
|
589
588
|
parent: _actorScope?.self,
|
|
590
589
|
state: actorState,
|
|
@@ -607,7 +606,7 @@ class StateMachine {
|
|
|
607
606
|
for (let key in contextPart) {
|
|
608
607
|
const value = contextPart[key];
|
|
609
608
|
if (value && typeof value === 'object') {
|
|
610
|
-
if ('xstate$$type' in value && value.xstate$$type ===
|
|
609
|
+
if ('xstate$$type' in value && value.xstate$$type === guards_dist_xstateGuards.$$ACTOR_TYPE) {
|
|
611
610
|
contextPart[key] = children[value.id];
|
|
612
611
|
continue;
|
|
613
612
|
}
|
|
@@ -706,21 +705,22 @@ exports.fromEventObservable = actors_dist_xstateActors.fromEventObservable;
|
|
|
706
705
|
exports.fromObservable = actors_dist_xstateActors.fromObservable;
|
|
707
706
|
exports.fromPromise = actors_dist_xstateActors.fromPromise;
|
|
708
707
|
exports.fromTransition = actors_dist_xstateActors.fromTransition;
|
|
709
|
-
exports.Actor =
|
|
710
|
-
exports.createActor = interpreter.createActor;
|
|
711
|
-
exports.interpret = interpreter.interpret;
|
|
712
|
-
exports.matchesState = interpreter.matchesState;
|
|
713
|
-
exports.pathToStateValue = interpreter.pathToStateValue;
|
|
714
|
-
exports.toObserver = interpreter.toObserver;
|
|
708
|
+
exports.Actor = guards_dist_xstateGuards.Actor;
|
|
715
709
|
exports.and = guards_dist_xstateGuards.and;
|
|
716
710
|
exports.cancel = guards_dist_xstateGuards.cancel;
|
|
711
|
+
exports.createActor = guards_dist_xstateGuards.createActor;
|
|
717
712
|
exports.getStateNodes = guards_dist_xstateGuards.getStateNodes;
|
|
713
|
+
exports.interpret = guards_dist_xstateGuards.interpret;
|
|
714
|
+
exports.isMachineSnapshot = guards_dist_xstateGuards.isMachineSnapshot;
|
|
715
|
+
exports.matchesState = guards_dist_xstateGuards.matchesState;
|
|
718
716
|
exports.not = guards_dist_xstateGuards.not;
|
|
719
717
|
exports.or = guards_dist_xstateGuards.or;
|
|
718
|
+
exports.pathToStateValue = guards_dist_xstateGuards.pathToStateValue;
|
|
720
719
|
exports.raise = guards_dist_xstateGuards.raise;
|
|
721
720
|
exports.spawn = guards_dist_xstateGuards.spawn;
|
|
722
721
|
exports.stateIn = guards_dist_xstateGuards.stateIn;
|
|
723
722
|
exports.stop = guards_dist_xstateGuards.stop;
|
|
723
|
+
exports.toObserver = guards_dist_xstateGuards.toObserver;
|
|
724
724
|
exports.SpecialTargets = send.SpecialTargets;
|
|
725
725
|
exports.assign = send.assign;
|
|
726
726
|
exports.choose = send.choose;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition } from '../actors/dist/xstate-actors.development.esm.js';
|
|
2
|
-
import { S as STATE_DELIMITER, m as mapValues, t as toArray, a as toTransitionConfigArray, N as NULL_EVENT, c as createInvokeId, i as isErrorActorEvent,
|
|
3
|
-
export {
|
|
4
|
-
import {
|
|
5
|
-
export {
|
|
6
|
-
import { a as assign } from './send-5d129d95.development.esm.js';
|
|
7
|
-
export { S as SpecialTargets, a as assign, c as choose, e as escalate, f as forwardTo, l as log, p as pure, s as sendParent, b as sendTo } from './send-5d129d95.development.esm.js';
|
|
2
|
+
import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, c as memo, e as evaluateGuard, d as createInvokeId, g as getDelayedTransitions, h as formatInitialTransition, i as getCandidates, r as resolveStateValue, j as getConfiguration, k as getStateNodes, l as createMachineSnapshot, n as isInFinalState, o as isErrorActorEvent, p as cloneMachineSnapshot, q as macrostep, s as transitionNode, u as resolveActionsAndContext, v as createInitEvent, w as microstep, x as getInitialStateNodes, y as isStateId, z as getStateNodeByPath, A as getPersistedState, B as resolveReferencedActor, C as createActor, $ as $$ACTOR_TYPE } from './raise-348cc74e.development.esm.js';
|
|
3
|
+
export { D as Actor, J as and, O as cancel, C as createActor, k as getStateNodes, E as interpret, F as isMachineSnapshot, G as matchesState, K as not, L as or, H as pathToStateValue, P as raise, R as spawn, M as stateIn, Q as stop, I as toObserver } from './raise-348cc74e.development.esm.js';
|
|
4
|
+
import { a as assign } from './send-a0193bdb.development.esm.js';
|
|
5
|
+
export { S as SpecialTargets, a as assign, c as choose, e as escalate, f as forwardTo, l as log, p as pure, s as sendParent, b as sendTo } from './send-a0193bdb.development.esm.js';
|
|
8
6
|
import '../dev/dist/xstate-dev.development.esm.js';
|
|
9
7
|
|
|
10
8
|
class SimulatedClock {
|
package/dist/xstate.esm.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition } from '../actors/dist/xstate-actors.esm.js';
|
|
2
|
-
import { S as STATE_DELIMITER, m as mapValues, t as toArray, a as toTransitionConfigArray, N as NULL_EVENT, c as createInvokeId, i as isErrorActorEvent,
|
|
3
|
-
export {
|
|
4
|
-
import {
|
|
5
|
-
export {
|
|
6
|
-
import { a as assign } from './send-84e2e742.esm.js';
|
|
7
|
-
export { S as SpecialTargets, a as assign, c as choose, e as escalate, f as forwardTo, l as log, p as pure, s as sendParent, b as sendTo } from './send-84e2e742.esm.js';
|
|
2
|
+
import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, c as memo, e as evaluateGuard, d as createInvokeId, g as getDelayedTransitions, h as formatInitialTransition, i as getCandidates, r as resolveStateValue, j as getConfiguration, k as getStateNodes, l as createMachineSnapshot, n as isInFinalState, o as isErrorActorEvent, p as cloneMachineSnapshot, q as macrostep, s as transitionNode, u as resolveActionsAndContext, v as createInitEvent, w as microstep, x as getInitialStateNodes, y as isStateId, z as getStateNodeByPath, A as getPersistedState, B as resolveReferencedActor, C as createActor, $ as $$ACTOR_TYPE } from './raise-5854eaca.esm.js';
|
|
3
|
+
export { D as Actor, J as and, O as cancel, C as createActor, k as getStateNodes, E as interpret, F as isMachineSnapshot, G as matchesState, K as not, L as or, H as pathToStateValue, P as raise, R as spawn, M as stateIn, Q as stop, I as toObserver } from './raise-5854eaca.esm.js';
|
|
4
|
+
import { a as assign } from './send-b7b4befa.esm.js';
|
|
5
|
+
export { S as SpecialTargets, a as assign, c as choose, e as escalate, f as forwardTo, l as log, p as pure, s as sendParent, b as sendTo } from './send-b7b4befa.esm.js';
|
|
8
6
|
import '../dev/dist/xstate-dev.esm.js';
|
|
9
7
|
|
|
10
8
|
class SimulatedClock {
|