xstate 6.0.0-alpha.36 → 6.0.0-alpha.38
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/dist/{StateMachine-c6fc9d29.cjs.js → StateMachine-18e71e29.cjs.js} +95 -74
- package/dist/{StateMachine-9d68f525.esm.js → StateMachine-812087bb.esm.js} +23 -2
- package/dist/{StateMachine-8dd1e4a0.development.esm.js → StateMachine-d344b16c.development.esm.js} +23 -2
- package/dist/{StateMachine-41dc03be.development.cjs.js → StateMachine-f4ddc94b.development.cjs.js} +95 -74
- package/dist/{index-9d364b4a.development.esm.js → createActor-164c86f5.development.esm.js} +15 -988
- package/dist/{index-9146dea1.esm.js → createActor-19e83fb9.esm.js} +15 -988
- package/dist/{index-0acba787.development.cjs.js → createActor-8462b9cc.development.cjs.js} +16 -995
- package/dist/{index-9683e24d.cjs.js → createActor-fd53ec92.cjs.js} +16 -995
- package/dist/declarations/src/State.d.ts +1 -1
- package/dist/declarations/src/durable/index.d.ts +66 -0
- package/dist/declarations/src/setup.d.ts +7 -3
- package/dist/declarations/src/types.v6.d.ts +31 -2
- package/dist/index-13e54113.cjs.js +985 -0
- package/dist/index-14478488.development.cjs.js +985 -0
- package/dist/index-abf9ab72.esm.js +976 -0
- package/dist/index-acf2bd02.development.esm.js +976 -0
- package/dist/transition-169651ca.cjs.js +148 -0
- package/dist/transition-61a126e0.development.esm.js +142 -0
- package/dist/transition-760b0fc6.esm.js +142 -0
- package/dist/transition-a306226e.development.cjs.js +148 -0
- package/dist/xstate-actors.cjs.js +6 -5
- package/dist/xstate-actors.development.cjs.js +6 -5
- package/dist/xstate-actors.development.esm.js +2 -1
- package/dist/xstate-actors.esm.js +2 -1
- package/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/xstate-durable.cjs.d.mts +2 -0
- package/dist/xstate-durable.cjs.d.ts +2 -0
- package/dist/xstate-durable.cjs.js +106 -0
- package/dist/xstate-durable.cjs.mjs +5 -0
- package/dist/xstate-durable.development.cjs.js +106 -0
- package/dist/xstate-durable.development.cjs.mjs +5 -0
- package/dist/xstate-durable.development.esm.js +100 -0
- package/dist/xstate-durable.esm.js +100 -0
- package/dist/xstate-durable.umd.min.js +2 -0
- package/dist/xstate-durable.umd.min.js.map +1 -0
- package/dist/xstate-graph.cjs.js +13 -12
- package/dist/xstate-graph.development.cjs.js +13 -12
- package/dist/xstate-graph.development.esm.js +5 -4
- package/dist/xstate-graph.esm.js +5 -4
- package/dist/xstate-graph.umd.min.js +1 -1
- package/dist/xstate-graph.umd.min.js.map +1 -1
- package/dist/xstate-validation.cjs.js +1 -1
- package/dist/xstate-validation.development.cjs.js +1 -1
- package/dist/xstate-validation.development.esm.js +1 -1
- package/dist/xstate-validation.esm.js +1 -1
- package/dist/xstate-validation.umd.min.js +1 -1
- package/dist/xstate-validation.umd.min.js.map +1 -1
- package/dist/xstate.cjs.js +53 -190
- package/dist/xstate.development.cjs.js +53 -190
- package/dist/xstate.development.esm.js +12 -149
- package/dist/xstate.esm.js +12 -149
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/durable/package.json +8 -0
- package/package.json +18 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var createActor = require('./createActor-fd53ec92.cjs.js');
|
|
4
|
+
var dist_xstateActors = require('./index-13e54113.cjs.js');
|
|
4
5
|
|
|
5
6
|
function createSpawner(actorScope, actors, spawnedChildren) {
|
|
6
7
|
return (src, options) => {
|
|
@@ -105,14 +106,14 @@ class StateNode {
|
|
|
105
106
|
this.machine = options._machine;
|
|
106
107
|
this.path = this.parent ? this.parent.path.concat(this.key) : [];
|
|
107
108
|
const firstStateKey = this.config.states ? Object.keys(this.config.states)[0] : undefined;
|
|
108
|
-
this.id = this.config.id || [this.machine.id, ...this.path].join(
|
|
109
|
+
this.id = this.config.id || [this.machine.id, ...this.path].join(createActor.STATE_DELIMITER);
|
|
109
110
|
this.type = this.config.type || (firstStateKey !== undefined ? 'compound' : this.config.history ? 'history' : 'atomic');
|
|
110
111
|
this.description = this.config.description;
|
|
111
112
|
this.schemas = this.config.schemas;
|
|
112
113
|
validateStateNodeConfig(this);
|
|
113
114
|
this.order = this.machine.idMap.size;
|
|
114
115
|
this.machine.idMap.set(this.id, this);
|
|
115
|
-
this.states = this.config.states ?
|
|
116
|
+
this.states = this.config.states ? createActor.mapValues(this.config.states, (stateConfig, key) => {
|
|
116
117
|
const stateNode = new StateNode(stateConfig, {
|
|
117
118
|
_parent: this,
|
|
118
119
|
_key: key,
|
|
@@ -138,13 +139,13 @@ class StateNode {
|
|
|
138
139
|
}
|
|
139
140
|
this.meta = this.config.meta;
|
|
140
141
|
this.output = this.type === 'final' || !this.parent ? this.config.output : undefined;
|
|
141
|
-
this.tags =
|
|
142
|
-
this.invoke =
|
|
142
|
+
this.tags = createActor.toArray(config.tags).slice();
|
|
143
|
+
this.invoke = createActor.toArray(this.config.invoke).map((invokeConfig, i) => {
|
|
143
144
|
const {
|
|
144
145
|
src,
|
|
145
146
|
registryKey
|
|
146
147
|
} = invokeConfig;
|
|
147
|
-
const invokeId =
|
|
148
|
+
const invokeId = createActor.createInvokeId(this.id, i);
|
|
148
149
|
const resolvedId = invokeConfig.id ?? invokeId;
|
|
149
150
|
// Referenced (string) actors keep their logical name so persisted
|
|
150
151
|
// snapshots reference `src: 'fetchUser'` rather than a positional id;
|
|
@@ -162,12 +163,12 @@ class StateNode {
|
|
|
162
163
|
|
|
163
164
|
/** @internal */
|
|
164
165
|
_initialize() {
|
|
165
|
-
this.after =
|
|
166
|
+
this.after = createActor.getDelayedTransitions(this);
|
|
166
167
|
this.transitions = formatTransitions(this);
|
|
167
168
|
if (this.type === 'choice') {
|
|
168
169
|
this.always = formatChoiceTransitions(this);
|
|
169
170
|
} else if (this.config.always) {
|
|
170
|
-
this.always = mapTransitionConfigs(this.config.always, transition =>
|
|
171
|
+
this.always = mapTransitionConfigs(this.config.always, transition => createActor.formatTransition(this, createActor.NULL_EVENT, transition));
|
|
171
172
|
}
|
|
172
173
|
for (const key of Object.keys(this.states)) {
|
|
173
174
|
this.states[key]._initialize();
|
|
@@ -201,14 +202,14 @@ class StateNode {
|
|
|
201
202
|
|
|
202
203
|
/** @internal */
|
|
203
204
|
next(snapshot, event, actorScope, selectionResults) {
|
|
204
|
-
const descriptorKey =
|
|
205
|
+
const descriptorKey = createActor.getEventDescriptorKey(event);
|
|
205
206
|
let candidates = this._candidateCache?.get(descriptorKey);
|
|
206
207
|
if (!candidates) {
|
|
207
|
-
candidates =
|
|
208
|
+
candidates = createActor.getCandidates(this, event);
|
|
208
209
|
(this._candidateCache ??= new Map()).set(descriptorKey, candidates);
|
|
209
210
|
}
|
|
210
211
|
for (const candidate of candidates) {
|
|
211
|
-
const guardPassed =
|
|
212
|
+
const guardPassed = createActor.evaluateCandidate(candidate, event, snapshot, this, actorScope, selectionResults);
|
|
212
213
|
if (guardPassed) {
|
|
213
214
|
return [candidate];
|
|
214
215
|
}
|
|
@@ -236,12 +237,12 @@ function formatChoiceTransitions(stateNode) {
|
|
|
236
237
|
}
|
|
237
238
|
return result;
|
|
238
239
|
};
|
|
239
|
-
return [
|
|
240
|
+
return [createActor.formatTransition(stateNode, createActor.NULL_EVENT, {
|
|
240
241
|
to: args => validateChoiceResult(choice(args))
|
|
241
242
|
})];
|
|
242
243
|
}
|
|
243
244
|
function mapTransitionConfigs(transitionsConfig, mapper) {
|
|
244
|
-
const transitionConfigs =
|
|
245
|
+
const transitionConfigs = createActor.toTransitionConfigArray(transitionsConfig);
|
|
245
246
|
const transitions = new Array(transitionConfigs.length);
|
|
246
247
|
for (let i = 0; i < transitionConfigs.length; i++) {
|
|
247
248
|
transitions[i] = mapper(transitionConfigs[i]);
|
|
@@ -255,16 +256,16 @@ function formatTransitions(stateNode) {
|
|
|
255
256
|
};
|
|
256
257
|
if (stateNode.config.on) {
|
|
257
258
|
for (const descriptor of Object.keys(stateNode.config.on)) {
|
|
258
|
-
if (descriptor ===
|
|
259
|
+
if (descriptor === createActor.NULL_EVENT) {
|
|
259
260
|
throw new Error('Null event transition key');
|
|
260
261
|
}
|
|
261
262
|
const transitionsConfig = stateNode.config.on[descriptor];
|
|
262
|
-
transitions.set(descriptor, mapTransitionConfigs(transitionsConfig, transition =>
|
|
263
|
+
transitions.set(descriptor, mapTransitionConfigs(transitionsConfig, transition => createActor.formatTransition(stateNode, descriptor, transition)));
|
|
263
264
|
}
|
|
264
265
|
}
|
|
265
266
|
if (stateNode.config.onDone) {
|
|
266
267
|
const descriptor = 'xstate.done.state';
|
|
267
|
-
addTransitions(descriptor, mapTransitionConfigs(stateNode.config.onDone, transition =>
|
|
268
|
+
addTransitions(descriptor, mapTransitionConfigs(stateNode.config.onDone, transition => createActor.formatTransition(stateNode, descriptor, {
|
|
268
269
|
...transition,
|
|
269
270
|
matches: {
|
|
270
271
|
...transition.matches,
|
|
@@ -274,13 +275,13 @@ function formatTransitions(stateNode) {
|
|
|
274
275
|
}
|
|
275
276
|
if (stateNode.config.onError) {
|
|
276
277
|
const descriptor = 'xstate.error.*';
|
|
277
|
-
transitions.set(descriptor, mapTransitionConfigs(stateNode.config.onError, transition =>
|
|
278
|
+
transitions.set(descriptor, mapTransitionConfigs(stateNode.config.onError, transition => createActor.formatTransition(stateNode, descriptor, transition)));
|
|
278
279
|
}
|
|
279
|
-
const createCancelInvokeTimeoutTransition = (descriptor, timeoutEventId, actorId) =>
|
|
280
|
+
const createCancelInvokeTimeoutTransition = (descriptor, timeoutEventId, actorId) => createActor.formatTransition(stateNode, descriptor, {
|
|
280
281
|
matches: {
|
|
281
282
|
actorId
|
|
282
283
|
},
|
|
283
|
-
_eventMatcher: (event, snapshot) =>
|
|
284
|
+
_eventMatcher: (event, snapshot) => createActor.matchesActorSession(event, snapshot, actorId),
|
|
284
285
|
to: (_args, enq) => {
|
|
285
286
|
enq.cancel(timeoutEventId);
|
|
286
287
|
return {};
|
|
@@ -293,7 +294,7 @@ function formatTransitions(stateNode) {
|
|
|
293
294
|
reenter,
|
|
294
295
|
...rest
|
|
295
296
|
} = transitionConfig;
|
|
296
|
-
return
|
|
297
|
+
return createActor.formatTransition(stateNode, descriptor, {
|
|
297
298
|
...rest,
|
|
298
299
|
reenter,
|
|
299
300
|
to: (args, enq) => {
|
|
@@ -336,14 +337,14 @@ function formatTransitions(stateNode) {
|
|
|
336
337
|
...transition.matches,
|
|
337
338
|
actorId: invokeDef.id
|
|
338
339
|
},
|
|
339
|
-
_eventMatcher: (event, snapshot) =>
|
|
340
|
+
_eventMatcher: (event, snapshot) => createActor.matchesActorSession(event, snapshot, invokeDef.id)
|
|
340
341
|
});
|
|
341
|
-
const invokeTimeoutEventId = invokeDef.timeout !== undefined ?
|
|
342
|
+
const invokeTimeoutEventId = invokeDef.timeout !== undefined ? createActor.createInvokeTimeoutEventId(invokeDef.id) : undefined;
|
|
342
343
|
if (invokeDef.onDone) {
|
|
343
344
|
const descriptor = 'xstate.done.actor';
|
|
344
345
|
const invokeDoneTransitions = mapTransitionConfigs(invokeDef.onDone, rawTransition => {
|
|
345
346
|
const transition = withInvokeMatch(rawTransition);
|
|
346
|
-
return invokeTimeoutEventId ? formatInvokeCompletionTransition(descriptor, transition, invokeTimeoutEventId) :
|
|
347
|
+
return invokeTimeoutEventId ? formatInvokeCompletionTransition(descriptor, transition, invokeTimeoutEventId) : createActor.formatTransition(stateNode, descriptor, transition);
|
|
347
348
|
});
|
|
348
349
|
if (invokeTimeoutEventId) {
|
|
349
350
|
invokeDoneTransitions.push(createCancelInvokeTimeoutTransition(descriptor, invokeTimeoutEventId, invokeDef.id));
|
|
@@ -357,12 +358,12 @@ function formatTransitions(stateNode) {
|
|
|
357
358
|
const descriptor = 'xstate.error.actor';
|
|
358
359
|
addTransitions(descriptor, mapTransitionConfigs(invokeDef.onError, rawTransition => {
|
|
359
360
|
const transition = withInvokeMatch(rawTransition);
|
|
360
|
-
return invokeTimeoutEventId ? formatInvokeCompletionTransition(descriptor, transition, invokeTimeoutEventId) :
|
|
361
|
+
return invokeTimeoutEventId ? formatInvokeCompletionTransition(descriptor, transition, invokeTimeoutEventId) : createActor.formatTransition(stateNode, descriptor, transition);
|
|
361
362
|
}));
|
|
362
363
|
}
|
|
363
364
|
if (invokeDef.onSnapshot) {
|
|
364
365
|
const descriptor = 'xstate.snapshot.actor';
|
|
365
|
-
addTransitions(descriptor, mapTransitionConfigs(invokeDef.onSnapshot, transition =>
|
|
366
|
+
addTransitions(descriptor, mapTransitionConfigs(invokeDef.onSnapshot, transition => createActor.formatTransition(stateNode, descriptor, withInvokeMatch(transition))));
|
|
366
367
|
}
|
|
367
368
|
}
|
|
368
369
|
for (const delayedTransition of stateNode.after) {
|
|
@@ -397,7 +398,7 @@ function getEmptyCanActor() {
|
|
|
397
398
|
// A minimal inert actor used purely as the `self`/`parent` argument when
|
|
398
399
|
// dry-running transitions for `snapshot.can(...)`. Intentionally not built
|
|
399
400
|
// on `createLogic` so `can()` does not pull that machinery into bundles.
|
|
400
|
-
return emptyCanActor ??=
|
|
401
|
+
return emptyCanActor ??= createActor.createActor({
|
|
401
402
|
transition: snapshot => [snapshot, []],
|
|
402
403
|
initialTransition: () => [{
|
|
403
404
|
status: 'active',
|
|
@@ -484,7 +485,7 @@ class StateMachine {
|
|
|
484
485
|
_machine: this
|
|
485
486
|
});
|
|
486
487
|
this.root._initialize();
|
|
487
|
-
|
|
488
|
+
createActor.formatRouteTransitions(this.root);
|
|
488
489
|
this.root._refreshEventMetadata();
|
|
489
490
|
this._hasEventlessTransitions = Array.from(this.idMap.values()).some(stateNode => !!stateNode.always?.length);
|
|
490
491
|
this.states = this.root.states; // TODO: remove!
|
|
@@ -528,15 +529,15 @@ class StateMachine {
|
|
|
528
529
|
return provided;
|
|
529
530
|
}
|
|
530
531
|
resolveState(config) {
|
|
531
|
-
const resolvedStateValue =
|
|
532
|
-
const nodeSet =
|
|
532
|
+
const resolvedStateValue = createActor.resolveStateValue(this.root, config.value);
|
|
533
|
+
const nodeSet = createActor.getAllStateNodes(createActor.getStateNodes(this.root, resolvedStateValue));
|
|
533
534
|
const nodes = [...nodeSet];
|
|
534
|
-
return
|
|
535
|
+
return createActor.createMachineSnapshot({
|
|
535
536
|
_nodes: nodes,
|
|
536
537
|
value: resolvedStateValue,
|
|
537
538
|
context: config.context || {},
|
|
538
539
|
children: {},
|
|
539
|
-
status:
|
|
540
|
+
status: createActor.isInFinalState(nodeSet, this.root) ? 'done' : config.status || 'active',
|
|
540
541
|
output: config.output,
|
|
541
542
|
error: config.error,
|
|
542
543
|
historyValue: config.historyValue
|
|
@@ -552,7 +553,7 @@ class StateMachine {
|
|
|
552
553
|
*/
|
|
553
554
|
transition(snapshot, event, actorScope) {
|
|
554
555
|
const usesInertScope = !actorScope;
|
|
555
|
-
const resolvedActorScope = actorScope ??
|
|
556
|
+
const resolvedActorScope = actorScope ?? createActor.createInertActorScope(this, snapshot);
|
|
556
557
|
if (this.validator) {
|
|
557
558
|
dist_xstateActors.assertValid(this.validator, {
|
|
558
559
|
kind: 'event',
|
|
@@ -562,14 +563,14 @@ class StateMachine {
|
|
|
562
563
|
});
|
|
563
564
|
}
|
|
564
565
|
if (usesInertScope) {
|
|
565
|
-
|
|
566
|
+
createActor.setInertActorScopeSnapshot(resolvedActorScope, snapshot, false);
|
|
566
567
|
}
|
|
567
568
|
const fastSnapshot = this._transitionFast(snapshot, event, resolvedActorScope);
|
|
568
569
|
if (fastSnapshot) {
|
|
569
570
|
if (usesInertScope) {
|
|
570
|
-
|
|
571
|
+
createActor.setInertActorScopeSnapshot(resolvedActorScope, fastSnapshot, false);
|
|
571
572
|
}
|
|
572
|
-
const returnedSnapshot = usesInertScope && fastSnapshot !== snapshot ?
|
|
573
|
+
const returnedSnapshot = usesInertScope && fastSnapshot !== snapshot ? createActor.attachSnapshotActorRef(resolvedActorScope, fastSnapshot) : this._attachPureActorRef(fastSnapshot, resolvedActorScope);
|
|
573
574
|
if (this.validator) {
|
|
574
575
|
dist_xstateActors.assertValid(this.validator, {
|
|
575
576
|
kind: 'result',
|
|
@@ -583,11 +584,11 @@ class StateMachine {
|
|
|
583
584
|
const {
|
|
584
585
|
snapshot: nextSnapshot,
|
|
585
586
|
microsteps
|
|
586
|
-
} =
|
|
587
|
+
} = createActor.macrostep(snapshot, event, resolvedActorScope, []);
|
|
587
588
|
if (usesInertScope) {
|
|
588
|
-
|
|
589
|
+
createActor.setInertActorScopeSnapshot(resolvedActorScope, nextSnapshot, false);
|
|
589
590
|
}
|
|
590
|
-
const returnedSnapshot = usesInertScope ? nextSnapshot === snapshot ? nextSnapshot :
|
|
591
|
+
const returnedSnapshot = usesInertScope ? nextSnapshot === snapshot ? nextSnapshot : createActor.attachSnapshotActorRef(resolvedActorScope, nextSnapshot) : this._attachPureActorRef(nextSnapshot, resolvedActorScope);
|
|
591
592
|
const effects = this._collectEffects(microsteps);
|
|
592
593
|
if (this.validator) {
|
|
593
594
|
dist_xstateActors.assertValid(this.validator, {
|
|
@@ -603,13 +604,13 @@ class StateMachine {
|
|
|
603
604
|
return microsteps.flatMap(([, actions]) => actions);
|
|
604
605
|
}
|
|
605
606
|
_attachPureActorRef(snapshot, actorScope, skipInitializingActor = false) {
|
|
606
|
-
if (
|
|
607
|
+
if (createActor.isInertActorScope(actorScope)) {
|
|
607
608
|
return snapshot;
|
|
608
609
|
}
|
|
609
610
|
if (skipInitializingActor && actorScope.self._actorScope === actorScope && actorScope.self._snapshot === undefined) {
|
|
610
611
|
return snapshot;
|
|
611
612
|
}
|
|
612
|
-
|
|
613
|
+
createActor.setSnapshotActorRef(snapshot, actorScope.self, actorScope.system);
|
|
613
614
|
return snapshot;
|
|
614
615
|
}
|
|
615
616
|
_transitionFast(snapshot, event, actorScope) {
|
|
@@ -637,12 +638,12 @@ class StateMachine {
|
|
|
637
638
|
...snapshot.context,
|
|
638
639
|
...selected.context
|
|
639
640
|
} : snapshot.context;
|
|
640
|
-
if (!
|
|
641
|
+
if (!createActor.isInertActorScope(actorScope) && (actorScope.system._hasInspectionObservers?.() ?? true)) {
|
|
641
642
|
const collectedMicrosteps = actorScope.self._collectedMicrosteps || [];
|
|
642
643
|
collectedMicrosteps.push(selected);
|
|
643
644
|
actorScope.self._collectedMicrosteps = collectedMicrosteps;
|
|
644
645
|
}
|
|
645
|
-
return
|
|
646
|
+
return createActor.cloneMachineSnapshot(snapshot, {
|
|
646
647
|
...(context !== snapshot.context ? {
|
|
647
648
|
context
|
|
648
649
|
} : {}),
|
|
@@ -662,7 +663,7 @@ class StateMachine {
|
|
|
662
663
|
microstep(snapshot, event, actorScope) {
|
|
663
664
|
const {
|
|
664
665
|
microsteps
|
|
665
|
-
} =
|
|
666
|
+
} = createActor.macrostep(snapshot, event, actorScope, []);
|
|
666
667
|
const snapshots = new Array(microsteps.length);
|
|
667
668
|
for (let i = 0; i < microsteps.length; i++) {
|
|
668
669
|
snapshots[i] = microsteps[i][0];
|
|
@@ -670,14 +671,14 @@ class StateMachine {
|
|
|
670
671
|
return snapshots;
|
|
671
672
|
}
|
|
672
673
|
getTransitionData(snapshot, event, actorScope, selectionResults) {
|
|
673
|
-
return
|
|
674
|
+
return createActor.transitionNode(this.root, snapshot.value, snapshot, event, actorScope, selectionResults) || [];
|
|
674
675
|
}
|
|
675
676
|
isInternalEventType(eventType) {
|
|
676
|
-
if (eventType ===
|
|
677
|
+
if (eventType === createActor.XSTATE_TIMER) {
|
|
677
678
|
return true;
|
|
678
679
|
}
|
|
679
680
|
for (const descriptor of this.internalEventDescriptors) {
|
|
680
|
-
if (
|
|
681
|
+
if (createActor.matchesEventDescriptor(eventType, descriptor)) {
|
|
681
682
|
return true;
|
|
682
683
|
}
|
|
683
684
|
}
|
|
@@ -703,10 +704,10 @@ class StateMachine {
|
|
|
703
704
|
if (transition.target !== undefined) {
|
|
704
705
|
return true;
|
|
705
706
|
}
|
|
706
|
-
const res =
|
|
707
|
+
const res = createActor.getTransitionResult(transition, snapshot, event, emptyActorScope, {
|
|
707
708
|
resolveActions: false
|
|
708
709
|
});
|
|
709
|
-
if (res.targets?.length || res.context ||
|
|
710
|
+
if (res.targets?.length || res.context || createActor.hasEffect(transition, snapshot.context, event, snapshot, emptyActorScope)) {
|
|
710
711
|
return true;
|
|
711
712
|
}
|
|
712
713
|
}
|
|
@@ -720,10 +721,10 @@ class StateMachine {
|
|
|
720
721
|
* @internal
|
|
721
722
|
*/
|
|
722
723
|
getExecutionErrorEvent(snapshot, error) {
|
|
723
|
-
if (snapshot?.status !== 'active' || !snapshot.
|
|
724
|
+
if (snapshot?.status !== 'active' || !snapshot.nodes?.some(stateNode => stateNode.config.onError)) {
|
|
724
725
|
return undefined;
|
|
725
726
|
}
|
|
726
|
-
return
|
|
727
|
+
return createActor.createErrorPlatformEvent('execution', error);
|
|
727
728
|
}
|
|
728
729
|
|
|
729
730
|
/**
|
|
@@ -736,7 +737,7 @@ class StateMachine {
|
|
|
736
737
|
const {
|
|
737
738
|
context
|
|
738
739
|
} = this.config;
|
|
739
|
-
const preInitial =
|
|
740
|
+
const preInitial = createActor.createMachineSnapshot({
|
|
740
741
|
context: typeof context !== 'function' && context ? context : {},
|
|
741
742
|
_nodes: [this.root],
|
|
742
743
|
children: {},
|
|
@@ -745,12 +746,12 @@ class StateMachine {
|
|
|
745
746
|
if (typeof context === 'function') {
|
|
746
747
|
const children = {};
|
|
747
748
|
const spawn = createSpawner(actorScope, this.sources.actors, children);
|
|
748
|
-
const resolvedContext = context(
|
|
749
|
+
const resolvedContext = context(createActor.withActorSelf({
|
|
749
750
|
spawn,
|
|
750
751
|
input: initEvent.input,
|
|
751
752
|
actors: this.sources.actors
|
|
752
753
|
}, actorScope));
|
|
753
|
-
const [nextState] =
|
|
754
|
+
const [nextState] = createActor.resolveActionsWithContext(preInitial, initEvent, actorScope, []);
|
|
754
755
|
if (resolvedContext) {
|
|
755
756
|
nextState.context = resolvedContext;
|
|
756
757
|
}
|
|
@@ -781,16 +782,16 @@ class StateMachine {
|
|
|
781
782
|
});
|
|
782
783
|
}
|
|
783
784
|
const usesInertScope = !actorScope;
|
|
784
|
-
const resolvedActorScope = actorScope ??
|
|
785
|
-
const initEvent =
|
|
785
|
+
const resolvedActorScope = actorScope ?? createActor.createInertActorScope(this);
|
|
786
|
+
const initEvent = createActor.createInitEvent(input); // TODO: fix;
|
|
786
787
|
const internalQueue = [];
|
|
787
788
|
const preInitialState = this._getPreInitialState(resolvedActorScope, initEvent);
|
|
788
|
-
const contextSpawnEffects = Object.values(preInitialState.children).filter(Boolean).map(actor =>
|
|
789
|
+
const contextSpawnEffects = Object.values(preInitialState.children).filter(Boolean).map(actor => createActor.createSpawnEffect(actor));
|
|
789
790
|
const finalizeInitialResult = (macroState, microsteps) => {
|
|
790
791
|
if (usesInertScope) {
|
|
791
|
-
|
|
792
|
+
createActor.setInertActorScopeSnapshot(resolvedActorScope, macroState, false);
|
|
792
793
|
}
|
|
793
|
-
const returnedSnapshot = usesInertScope ?
|
|
794
|
+
const returnedSnapshot = usesInertScope ? createActor.attachSnapshotActorRef(resolvedActorScope, macroState) : this._attachPureActorRef(macroState, resolvedActorScope, true);
|
|
794
795
|
const effects = this._collectEffects(microsteps);
|
|
795
796
|
if (this.validator) {
|
|
796
797
|
dist_xstateActors.assertValid(this.validator, {
|
|
@@ -803,18 +804,18 @@ class StateMachine {
|
|
|
803
804
|
return [returnedSnapshot, effects];
|
|
804
805
|
};
|
|
805
806
|
try {
|
|
806
|
-
const [nextState, initialActions] =
|
|
807
|
+
const [nextState, initialActions] = createActor.initialMicrostep(this.root, preInitialState, resolvedActorScope, initEvent, internalQueue);
|
|
807
808
|
const {
|
|
808
809
|
snapshot: macroState,
|
|
809
810
|
microsteps
|
|
810
|
-
} =
|
|
811
|
+
} = createActor.macrostep(nextState, initEvent, resolvedActorScope, internalQueue, [[nextState, [...contextSpawnEffects, ...initialActions]]]);
|
|
811
812
|
return finalizeInitialResult(macroState, microsteps);
|
|
812
813
|
} catch (err) {
|
|
813
814
|
if (!this.root.config.onError) {
|
|
814
815
|
throw err;
|
|
815
816
|
}
|
|
816
|
-
const errorEvent =
|
|
817
|
-
const errorMacrostep =
|
|
817
|
+
const errorEvent = createActor.createErrorPlatformEvent('execution', err);
|
|
818
|
+
const errorMacrostep = createActor.macrostep(preInitialState, errorEvent, resolvedActorScope, [], [[preInitialState, contextSpawnEffects]]);
|
|
818
819
|
return finalizeInitialResult(errorMacrostep.snapshot, errorMacrostep.microsteps);
|
|
819
820
|
}
|
|
820
821
|
}
|
|
@@ -837,21 +838,21 @@ class StateMachine {
|
|
|
837
838
|
}
|
|
838
839
|
}
|
|
839
840
|
getStateNodeById(stateId) {
|
|
840
|
-
const fullPath =
|
|
841
|
+
const fullPath = createActor.toStatePath(stateId);
|
|
841
842
|
const relativePath = fullPath.slice(1);
|
|
842
|
-
const resolvedStateId =
|
|
843
|
+
const resolvedStateId = createActor.isStateId(fullPath[0]) ? fullPath[0].slice(STATE_IDENTIFIER.length) : fullPath[0];
|
|
843
844
|
const stateNode = this.idMap.get(resolvedStateId);
|
|
844
845
|
if (!stateNode) {
|
|
845
846
|
throw new Error(`Child state node '#${resolvedStateId}' does not exist on machine '${this.id}'`);
|
|
846
847
|
}
|
|
847
|
-
return
|
|
848
|
+
return createActor.getStateNodeByPath(stateNode, relativePath);
|
|
848
849
|
}
|
|
849
850
|
getPersistedSnapshot(snapshot, options) {
|
|
850
|
-
return
|
|
851
|
+
return createActor.getPersistedSnapshot(snapshot, options);
|
|
851
852
|
}
|
|
852
853
|
restoreSnapshot(snapshot, actorScope) {
|
|
853
854
|
const usesInertScope = !actorScope;
|
|
854
|
-
const resolvedActorScope = actorScope ??
|
|
855
|
+
const resolvedActorScope = actorScope ?? createActor.createInertActorScope(this);
|
|
855
856
|
const persistedMachine = snapshot.machine;
|
|
856
857
|
const legacyPersistedVersion = snapshot.version;
|
|
857
858
|
const persistedVersion = typeof persistedMachine?.version === 'string' ? persistedMachine.version : legacyPersistedVersion;
|
|
@@ -875,7 +876,7 @@ class StateMachine {
|
|
|
875
876
|
const actorData = snapshotChildren[actorId];
|
|
876
877
|
const childState = actorData.snapshot;
|
|
877
878
|
const src = actorData.src;
|
|
878
|
-
const logic = typeof src === 'string' ?
|
|
879
|
+
const logic = typeof src === 'string' ? createActor.resolveReferencedActor(this, src) : src;
|
|
879
880
|
if (!logic) {
|
|
880
881
|
const sourceId = typeof src === 'string' ? src : '<unknown>';
|
|
881
882
|
throw new Error(`Unable to restore child actor '${actorId}': child source '${sourceId}' is not provided in machine '${this.id}'.`);
|
|
@@ -901,7 +902,7 @@ class StateMachine {
|
|
|
901
902
|
const actorId = event.actorId;
|
|
902
903
|
const child = children[actorId];
|
|
903
904
|
if (child) {
|
|
904
|
-
event =
|
|
905
|
+
event = createActor.createInvokeTimeoutEvent(actorId, child.sessionId);
|
|
905
906
|
}
|
|
906
907
|
}
|
|
907
908
|
const target = typeof timer.target === 'string' ? timer.target === 'self' ? 'self' : children[timer.target] : resolvedActorScope.self._parent;
|
|
@@ -942,12 +943,32 @@ class StateMachine {
|
|
|
942
943
|
return revived;
|
|
943
944
|
};
|
|
944
945
|
const revivedHistoryValue = reviveHistoryValue(snapshotData.historyValue);
|
|
945
|
-
const
|
|
946
|
+
const validateStateValue = (stateValue, node, path) => {
|
|
947
|
+
const missingStateError = statePath => new Error(`Persisted snapshot references state '${statePath.join('.')}' which does not exist on machine '${this.id}'.`);
|
|
948
|
+
if (typeof stateValue === 'string') {
|
|
949
|
+
if (!node.states[stateValue]) {
|
|
950
|
+
throw missingStateError(path.concat(stateValue));
|
|
951
|
+
}
|
|
952
|
+
return;
|
|
953
|
+
}
|
|
954
|
+
if (!stateValue || typeof stateValue !== 'object') {
|
|
955
|
+
return;
|
|
956
|
+
}
|
|
957
|
+
for (const key of Object.keys(stateValue)) {
|
|
958
|
+
const childNode = node.states[key];
|
|
959
|
+
if (!childNode) {
|
|
960
|
+
throw missingStateError(path.concat(key));
|
|
961
|
+
}
|
|
962
|
+
validateStateValue(stateValue[key], childNode, path.concat(key));
|
|
963
|
+
}
|
|
964
|
+
};
|
|
965
|
+
validateStateValue(snapshotData.value, this.root, []);
|
|
966
|
+
const nodes = Array.from(createActor.getAllStateNodes(createActor.getStateNodes(this.root, snapshotData.value)));
|
|
946
967
|
const {
|
|
947
968
|
version: _persistedSnapshotVersion,
|
|
948
969
|
...persistedRest
|
|
949
970
|
} = snapshot;
|
|
950
|
-
const restoredSnapshot =
|
|
971
|
+
const restoredSnapshot = createActor.createMachineSnapshot({
|
|
951
972
|
...persistedRest,
|
|
952
973
|
children,
|
|
953
974
|
timers,
|
|
@@ -965,7 +986,7 @@ class StateMachine {
|
|
|
965
986
|
for (const key of Object.keys(contextPart)) {
|
|
966
987
|
const value = contextPart[key];
|
|
967
988
|
if (value && typeof value === 'object') {
|
|
968
|
-
if ('xstate$$type' in value && value.xstate$$type ===
|
|
989
|
+
if ('xstate$$type' in value && value.xstate$$type === createActor.$$ACTOR_TYPE) {
|
|
969
990
|
contextPart[key] = children[value.id];
|
|
970
991
|
continue;
|
|
971
992
|
}
|
|
@@ -975,8 +996,8 @@ class StateMachine {
|
|
|
975
996
|
}
|
|
976
997
|
reviveContext(restoredSnapshot.context);
|
|
977
998
|
if (usesInertScope) {
|
|
978
|
-
|
|
979
|
-
return
|
|
999
|
+
createActor.setInertActorScopeSnapshot(resolvedActorScope, restoredSnapshot, false);
|
|
1000
|
+
return createActor.attachSnapshotActorRef(resolvedActorScope, restoredSnapshot);
|
|
980
1001
|
}
|
|
981
1002
|
return this._attachPureActorRef(restoredSnapshot, resolvedActorScope);
|
|
982
1003
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { S as STATE_DELIMITER, I as mapValues, t as toArray, J as createInvokeId, K as getDelayedTransitions, L as getEventDescriptorKey, M as getCandidates, N as evaluateCandidate, O as formatTransition, P as NULL_EVENT, Q as toTransitionConfigArray, R as createInvokeTimeoutEventId, T as matchesActorSession, U as formatRouteTransitions, V as resolveStateValue, W as getAllStateNodes, o as getStateNodes, Y as createMachineSnapshot, Z as isInFinalState, _ as createInertActorScope, $ as setInertActorScopeSnapshot, a0 as attachSnapshotActorRef, a1 as macrostep, a2 as isInertActorScope, a3 as setSnapshotActorRef, a4 as cloneMachineSnapshot, a5 as transitionNode, e as XSTATE_TIMER, m as matchesEventDescriptor, a6 as getTransitionResult, a7 as hasEffect, a8 as createErrorPlatformEvent, a9 as withActorSelf, r as resolveActionsWithContext, F as createInitEvent, aa as createSpawnEffect, ab as initialMicrostep, ac as toStatePath, ad as isStateId, ae as getStateNodeByPath, af as getPersistedSnapshot, ag as resolveReferencedActor, ah as createInvokeTimeoutEvent, ai as $$ACTOR_TYPE, j as createActor } from './createActor-19e83fb9.esm.js';
|
|
2
|
+
import { g as assertValid } from './index-abf9ab72.esm.js';
|
|
2
3
|
|
|
3
4
|
function createSpawner(actorScope, actors, spawnedChildren) {
|
|
4
5
|
return (src, options) => {
|
|
@@ -718,7 +719,7 @@ class StateMachine {
|
|
|
718
719
|
* @internal
|
|
719
720
|
*/
|
|
720
721
|
getExecutionErrorEvent(snapshot, error) {
|
|
721
|
-
if (snapshot?.status !== 'active' || !snapshot.
|
|
722
|
+
if (snapshot?.status !== 'active' || !snapshot.nodes?.some(stateNode => stateNode.config.onError)) {
|
|
722
723
|
return undefined;
|
|
723
724
|
}
|
|
724
725
|
return createErrorPlatformEvent('execution', error);
|
|
@@ -940,6 +941,26 @@ class StateMachine {
|
|
|
940
941
|
return revived;
|
|
941
942
|
};
|
|
942
943
|
const revivedHistoryValue = reviveHistoryValue(snapshotData.historyValue);
|
|
944
|
+
const validateStateValue = (stateValue, node, path) => {
|
|
945
|
+
const missingStateError = statePath => new Error(`Persisted snapshot references state '${statePath.join('.')}' which does not exist on machine '${this.id}'.`);
|
|
946
|
+
if (typeof stateValue === 'string') {
|
|
947
|
+
if (!node.states[stateValue]) {
|
|
948
|
+
throw missingStateError(path.concat(stateValue));
|
|
949
|
+
}
|
|
950
|
+
return;
|
|
951
|
+
}
|
|
952
|
+
if (!stateValue || typeof stateValue !== 'object') {
|
|
953
|
+
return;
|
|
954
|
+
}
|
|
955
|
+
for (const key of Object.keys(stateValue)) {
|
|
956
|
+
const childNode = node.states[key];
|
|
957
|
+
if (!childNode) {
|
|
958
|
+
throw missingStateError(path.concat(key));
|
|
959
|
+
}
|
|
960
|
+
validateStateValue(stateValue[key], childNode, path.concat(key));
|
|
961
|
+
}
|
|
962
|
+
};
|
|
963
|
+
validateStateValue(snapshotData.value, this.root, []);
|
|
943
964
|
const nodes = Array.from(getAllStateNodes(getStateNodes(this.root, snapshotData.value)));
|
|
944
965
|
const {
|
|
945
966
|
version: _persistedSnapshotVersion,
|
package/dist/{StateMachine-8dd1e4a0.development.esm.js → StateMachine-d344b16c.development.esm.js}
RENAMED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { S as STATE_DELIMITER, I as mapValues, t as toArray, J as createInvokeId, K as getDelayedTransitions, L as getEventDescriptorKey, M as getCandidates, N as evaluateCandidate, O as formatTransition, P as NULL_EVENT, Q as toTransitionConfigArray, R as createInvokeTimeoutEventId, T as matchesActorSession, U as formatRouteTransitions, V as resolveStateValue, W as getAllStateNodes, o as getStateNodes, Y as createMachineSnapshot, Z as isInFinalState, _ as createInertActorScope, $ as setInertActorScopeSnapshot, a0 as attachSnapshotActorRef, a1 as macrostep, a2 as isInertActorScope, a3 as setSnapshotActorRef, a4 as cloneMachineSnapshot, a5 as transitionNode, e as XSTATE_TIMER, m as matchesEventDescriptor, a6 as getTransitionResult, a7 as hasEffect, a8 as createErrorPlatformEvent, a9 as withActorSelf, r as resolveActionsWithContext, F as createInitEvent, aa as createSpawnEffect, ab as initialMicrostep, ac as toStatePath, ad as isStateId, ae as getStateNodeByPath, af as getPersistedSnapshot, ag as resolveReferencedActor, ah as createInvokeTimeoutEvent, ai as $$ACTOR_TYPE, j as createActor } from './createActor-164c86f5.development.esm.js';
|
|
2
|
+
import { g as assertValid } from './index-acf2bd02.development.esm.js';
|
|
2
3
|
|
|
3
4
|
function createSpawner(actorScope, actors, spawnedChildren) {
|
|
4
5
|
return (src, options) => {
|
|
@@ -747,7 +748,7 @@ class StateMachine {
|
|
|
747
748
|
* @internal
|
|
748
749
|
*/
|
|
749
750
|
getExecutionErrorEvent(snapshot, error) {
|
|
750
|
-
if (snapshot?.status !== 'active' || !snapshot.
|
|
751
|
+
if (snapshot?.status !== 'active' || !snapshot.nodes?.some(stateNode => stateNode.config.onError)) {
|
|
751
752
|
return undefined;
|
|
752
753
|
}
|
|
753
754
|
return createErrorPlatformEvent('execution', error);
|
|
@@ -972,6 +973,26 @@ class StateMachine {
|
|
|
972
973
|
return revived;
|
|
973
974
|
};
|
|
974
975
|
const revivedHistoryValue = reviveHistoryValue(snapshotData.historyValue);
|
|
976
|
+
const validateStateValue = (stateValue, node, path) => {
|
|
977
|
+
const missingStateError = statePath => new Error(`Persisted snapshot references state '${statePath.join('.')}' which does not exist on machine '${this.id}'.`);
|
|
978
|
+
if (typeof stateValue === 'string') {
|
|
979
|
+
if (!node.states[stateValue]) {
|
|
980
|
+
throw missingStateError(path.concat(stateValue));
|
|
981
|
+
}
|
|
982
|
+
return;
|
|
983
|
+
}
|
|
984
|
+
if (!stateValue || typeof stateValue !== 'object') {
|
|
985
|
+
return;
|
|
986
|
+
}
|
|
987
|
+
for (const key of Object.keys(stateValue)) {
|
|
988
|
+
const childNode = node.states[key];
|
|
989
|
+
if (!childNode) {
|
|
990
|
+
throw missingStateError(path.concat(key));
|
|
991
|
+
}
|
|
992
|
+
validateStateValue(stateValue[key], childNode, path.concat(key));
|
|
993
|
+
}
|
|
994
|
+
};
|
|
995
|
+
validateStateValue(snapshotData.value, this.root, []);
|
|
975
996
|
const nodes = Array.from(getAllStateNodes(getStateNodes(this.root, snapshotData.value)));
|
|
976
997
|
const {
|
|
977
998
|
version: _persistedSnapshotVersion,
|