xstate 6.0.0-alpha.35 → 6.0.0-alpha.37
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-9d68f525.esm.js → StateMachine-009b5bc4.esm.js} +3 -2
- package/dist/{StateMachine-c6fc9d29.cjs.js → StateMachine-5d0aac92.cjs.js} +75 -74
- package/dist/{StateMachine-41dc03be.development.cjs.js → StateMachine-7197482a.development.cjs.js} +75 -74
- package/dist/{StateMachine-8dd1e4a0.development.esm.js → StateMachine-9da92cbf.development.esm.js} +3 -2
- 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/index.d.ts +1 -1
- package/dist/declarations/src/machineVersions.d.ts +17 -2
- 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 +123 -191
- package/dist/xstate.development.cjs.js +123 -191
- package/dist/xstate.development.esm.js +82 -150
- package/dist/xstate.esm.js +82 -150
- 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
package/dist/{StateMachine-41dc03be.development.cjs.js → StateMachine-7197482a.development.cjs.js}
RENAMED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var createActor = require('./createActor-8462b9cc.development.cjs.js');
|
|
4
|
+
var dist_xstateActors = require('./index-14478488.development.cjs.js');
|
|
4
5
|
|
|
5
6
|
function createSpawner(actorScope, actors, spawnedChildren) {
|
|
6
7
|
return (src, options) => {
|
|
@@ -106,14 +107,14 @@ class StateNode {
|
|
|
106
107
|
this.machine = options._machine;
|
|
107
108
|
this.path = this.parent ? this.parent.path.concat(this.key) : [];
|
|
108
109
|
const firstStateKey = this.config.states ? Object.keys(this.config.states)[0] : undefined;
|
|
109
|
-
this.id = this.config.id || [this.machine.id, ...this.path].join(
|
|
110
|
+
this.id = this.config.id || [this.machine.id, ...this.path].join(createActor.STATE_DELIMITER);
|
|
110
111
|
this.type = this.config.type || (firstStateKey !== undefined ? 'compound' : this.config.history ? 'history' : 'atomic');
|
|
111
112
|
this.description = this.config.description;
|
|
112
113
|
this.schemas = this.config.schemas;
|
|
113
114
|
validateStateNodeConfig(this);
|
|
114
115
|
this.order = this.machine.idMap.size;
|
|
115
116
|
this.machine.idMap.set(this.id, this);
|
|
116
|
-
this.states = this.config.states ?
|
|
117
|
+
this.states = this.config.states ? createActor.mapValues(this.config.states, (stateConfig, key) => {
|
|
117
118
|
const stateNode = new StateNode(stateConfig, {
|
|
118
119
|
_parent: this,
|
|
119
120
|
_key: key,
|
|
@@ -139,13 +140,13 @@ class StateNode {
|
|
|
139
140
|
}
|
|
140
141
|
this.meta = this.config.meta;
|
|
141
142
|
this.output = this.type === 'final' || !this.parent ? this.config.output : undefined;
|
|
142
|
-
this.tags =
|
|
143
|
-
this.invoke =
|
|
143
|
+
this.tags = createActor.toArray(config.tags).slice();
|
|
144
|
+
this.invoke = createActor.toArray(this.config.invoke).map((invokeConfig, i) => {
|
|
144
145
|
const {
|
|
145
146
|
src,
|
|
146
147
|
registryKey
|
|
147
148
|
} = invokeConfig;
|
|
148
|
-
const invokeId =
|
|
149
|
+
const invokeId = createActor.createInvokeId(this.id, i);
|
|
149
150
|
const resolvedId = invokeConfig.id ?? invokeId;
|
|
150
151
|
// Referenced (string) actors keep their logical name so persisted
|
|
151
152
|
// snapshots reference `src: 'fetchUser'` rather than a positional id;
|
|
@@ -163,12 +164,12 @@ class StateNode {
|
|
|
163
164
|
|
|
164
165
|
/** @internal */
|
|
165
166
|
_initialize() {
|
|
166
|
-
this.after =
|
|
167
|
+
this.after = createActor.getDelayedTransitions(this);
|
|
167
168
|
this.transitions = formatTransitions(this);
|
|
168
169
|
if (this.type === 'choice') {
|
|
169
170
|
this.always = formatChoiceTransitions(this);
|
|
170
171
|
} else if (this.config.always) {
|
|
171
|
-
this.always = mapTransitionConfigs(this.config.always, transition =>
|
|
172
|
+
this.always = mapTransitionConfigs(this.config.always, transition => createActor.formatTransition(this, createActor.NULL_EVENT, transition));
|
|
172
173
|
}
|
|
173
174
|
for (const key of Object.keys(this.states)) {
|
|
174
175
|
this.states[key]._initialize();
|
|
@@ -202,14 +203,14 @@ class StateNode {
|
|
|
202
203
|
|
|
203
204
|
/** @internal */
|
|
204
205
|
next(snapshot, event, actorScope, selectionResults) {
|
|
205
|
-
const descriptorKey =
|
|
206
|
+
const descriptorKey = createActor.getEventDescriptorKey(event);
|
|
206
207
|
let candidates = this._candidateCache?.get(descriptorKey);
|
|
207
208
|
if (!candidates) {
|
|
208
|
-
candidates =
|
|
209
|
+
candidates = createActor.getCandidates(this, event);
|
|
209
210
|
(this._candidateCache ??= new Map()).set(descriptorKey, candidates);
|
|
210
211
|
}
|
|
211
212
|
for (const candidate of candidates) {
|
|
212
|
-
const guardPassed =
|
|
213
|
+
const guardPassed = createActor.evaluateCandidate(candidate, event, snapshot, this, actorScope, selectionResults);
|
|
213
214
|
if (guardPassed) {
|
|
214
215
|
return [candidate];
|
|
215
216
|
}
|
|
@@ -254,12 +255,12 @@ function formatChoiceTransitions(stateNode) {
|
|
|
254
255
|
}
|
|
255
256
|
return result;
|
|
256
257
|
};
|
|
257
|
-
return [
|
|
258
|
+
return [createActor.formatTransition(stateNode, createActor.NULL_EVENT, {
|
|
258
259
|
to: args => validateChoiceResult(choice(args))
|
|
259
260
|
})];
|
|
260
261
|
}
|
|
261
262
|
function mapTransitionConfigs(transitionsConfig, mapper) {
|
|
262
|
-
const transitionConfigs =
|
|
263
|
+
const transitionConfigs = createActor.toTransitionConfigArray(transitionsConfig);
|
|
263
264
|
const transitions = new Array(transitionConfigs.length);
|
|
264
265
|
for (let i = 0; i < transitionConfigs.length; i++) {
|
|
265
266
|
transitions[i] = mapper(transitionConfigs[i]);
|
|
@@ -273,16 +274,16 @@ function formatTransitions(stateNode) {
|
|
|
273
274
|
};
|
|
274
275
|
if (stateNode.config.on) {
|
|
275
276
|
for (const descriptor of Object.keys(stateNode.config.on)) {
|
|
276
|
-
if (descriptor ===
|
|
277
|
+
if (descriptor === createActor.NULL_EVENT) {
|
|
277
278
|
throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.' );
|
|
278
279
|
}
|
|
279
280
|
const transitionsConfig = stateNode.config.on[descriptor];
|
|
280
|
-
transitions.set(descriptor, mapTransitionConfigs(transitionsConfig, transition =>
|
|
281
|
+
transitions.set(descriptor, mapTransitionConfigs(transitionsConfig, transition => createActor.formatTransition(stateNode, descriptor, transition)));
|
|
281
282
|
}
|
|
282
283
|
}
|
|
283
284
|
if (stateNode.config.onDone) {
|
|
284
285
|
const descriptor = 'xstate.done.state';
|
|
285
|
-
addTransitions(descriptor, mapTransitionConfigs(stateNode.config.onDone, transition =>
|
|
286
|
+
addTransitions(descriptor, mapTransitionConfigs(stateNode.config.onDone, transition => createActor.formatTransition(stateNode, descriptor, {
|
|
286
287
|
...transition,
|
|
287
288
|
matches: {
|
|
288
289
|
...transition.matches,
|
|
@@ -292,13 +293,13 @@ function formatTransitions(stateNode) {
|
|
|
292
293
|
}
|
|
293
294
|
if (stateNode.config.onError) {
|
|
294
295
|
const descriptor = 'xstate.error.*';
|
|
295
|
-
transitions.set(descriptor, mapTransitionConfigs(stateNode.config.onError, transition =>
|
|
296
|
+
transitions.set(descriptor, mapTransitionConfigs(stateNode.config.onError, transition => createActor.formatTransition(stateNode, descriptor, transition)));
|
|
296
297
|
}
|
|
297
|
-
const createCancelInvokeTimeoutTransition = (descriptor, timeoutEventId, actorId) =>
|
|
298
|
+
const createCancelInvokeTimeoutTransition = (descriptor, timeoutEventId, actorId) => createActor.formatTransition(stateNode, descriptor, {
|
|
298
299
|
matches: {
|
|
299
300
|
actorId
|
|
300
301
|
},
|
|
301
|
-
_eventMatcher: (event, snapshot) =>
|
|
302
|
+
_eventMatcher: (event, snapshot) => createActor.matchesActorSession(event, snapshot, actorId),
|
|
302
303
|
to: (_args, enq) => {
|
|
303
304
|
enq.cancel(timeoutEventId);
|
|
304
305
|
return {};
|
|
@@ -311,7 +312,7 @@ function formatTransitions(stateNode) {
|
|
|
311
312
|
reenter,
|
|
312
313
|
...rest
|
|
313
314
|
} = transitionConfig;
|
|
314
|
-
return
|
|
315
|
+
return createActor.formatTransition(stateNode, descriptor, {
|
|
315
316
|
...rest,
|
|
316
317
|
reenter,
|
|
317
318
|
to: (args, enq) => {
|
|
@@ -354,14 +355,14 @@ function formatTransitions(stateNode) {
|
|
|
354
355
|
...transition.matches,
|
|
355
356
|
actorId: invokeDef.id
|
|
356
357
|
},
|
|
357
|
-
_eventMatcher: (event, snapshot) =>
|
|
358
|
+
_eventMatcher: (event, snapshot) => createActor.matchesActorSession(event, snapshot, invokeDef.id)
|
|
358
359
|
});
|
|
359
|
-
const invokeTimeoutEventId = invokeDef.timeout !== undefined ?
|
|
360
|
+
const invokeTimeoutEventId = invokeDef.timeout !== undefined ? createActor.createInvokeTimeoutEventId(invokeDef.id) : undefined;
|
|
360
361
|
if (invokeDef.onDone) {
|
|
361
362
|
const descriptor = 'xstate.done.actor';
|
|
362
363
|
const invokeDoneTransitions = mapTransitionConfigs(invokeDef.onDone, rawTransition => {
|
|
363
364
|
const transition = withInvokeMatch(rawTransition);
|
|
364
|
-
return invokeTimeoutEventId ? formatInvokeCompletionTransition(descriptor, transition, invokeTimeoutEventId) :
|
|
365
|
+
return invokeTimeoutEventId ? formatInvokeCompletionTransition(descriptor, transition, invokeTimeoutEventId) : createActor.formatTransition(stateNode, descriptor, transition);
|
|
365
366
|
});
|
|
366
367
|
if (invokeTimeoutEventId) {
|
|
367
368
|
invokeDoneTransitions.push(createCancelInvokeTimeoutTransition(descriptor, invokeTimeoutEventId, invokeDef.id));
|
|
@@ -375,12 +376,12 @@ function formatTransitions(stateNode) {
|
|
|
375
376
|
const descriptor = 'xstate.error.actor';
|
|
376
377
|
addTransitions(descriptor, mapTransitionConfigs(invokeDef.onError, rawTransition => {
|
|
377
378
|
const transition = withInvokeMatch(rawTransition);
|
|
378
|
-
return invokeTimeoutEventId ? formatInvokeCompletionTransition(descriptor, transition, invokeTimeoutEventId) :
|
|
379
|
+
return invokeTimeoutEventId ? formatInvokeCompletionTransition(descriptor, transition, invokeTimeoutEventId) : createActor.formatTransition(stateNode, descriptor, transition);
|
|
379
380
|
}));
|
|
380
381
|
}
|
|
381
382
|
if (invokeDef.onSnapshot) {
|
|
382
383
|
const descriptor = 'xstate.snapshot.actor';
|
|
383
|
-
addTransitions(descriptor, mapTransitionConfigs(invokeDef.onSnapshot, transition =>
|
|
384
|
+
addTransitions(descriptor, mapTransitionConfigs(invokeDef.onSnapshot, transition => createActor.formatTransition(stateNode, descriptor, withInvokeMatch(transition))));
|
|
384
385
|
}
|
|
385
386
|
}
|
|
386
387
|
for (const delayedTransition of stateNode.after) {
|
|
@@ -415,7 +416,7 @@ function getEmptyCanActor() {
|
|
|
415
416
|
// A minimal inert actor used purely as the `self`/`parent` argument when
|
|
416
417
|
// dry-running transitions for `snapshot.can(...)`. Intentionally not built
|
|
417
418
|
// on `createLogic` so `can()` does not pull that machinery into bundles.
|
|
418
|
-
return emptyCanActor ??=
|
|
419
|
+
return emptyCanActor ??= createActor.createActor({
|
|
419
420
|
transition: snapshot => [snapshot, []],
|
|
420
421
|
initialTransition: () => [{
|
|
421
422
|
status: 'active',
|
|
@@ -513,7 +514,7 @@ class StateMachine {
|
|
|
513
514
|
_machine: this
|
|
514
515
|
});
|
|
515
516
|
this.root._initialize();
|
|
516
|
-
|
|
517
|
+
createActor.formatRouteTransitions(this.root);
|
|
517
518
|
this.root._refreshEventMetadata();
|
|
518
519
|
this._hasEventlessTransitions = Array.from(this.idMap.values()).some(stateNode => !!stateNode.always?.length);
|
|
519
520
|
this.states = this.root.states; // TODO: remove!
|
|
@@ -557,15 +558,15 @@ class StateMachine {
|
|
|
557
558
|
return provided;
|
|
558
559
|
}
|
|
559
560
|
resolveState(config) {
|
|
560
|
-
const resolvedStateValue =
|
|
561
|
-
const nodeSet =
|
|
561
|
+
const resolvedStateValue = createActor.resolveStateValue(this.root, config.value);
|
|
562
|
+
const nodeSet = createActor.getAllStateNodes(createActor.getStateNodes(this.root, resolvedStateValue));
|
|
562
563
|
const nodes = [...nodeSet];
|
|
563
|
-
return
|
|
564
|
+
return createActor.createMachineSnapshot({
|
|
564
565
|
_nodes: nodes,
|
|
565
566
|
value: resolvedStateValue,
|
|
566
567
|
context: config.context || {},
|
|
567
568
|
children: {},
|
|
568
|
-
status:
|
|
569
|
+
status: createActor.isInFinalState(nodeSet, this.root) ? 'done' : config.status || 'active',
|
|
569
570
|
output: config.output,
|
|
570
571
|
error: config.error,
|
|
571
572
|
historyValue: config.historyValue
|
|
@@ -581,7 +582,7 @@ class StateMachine {
|
|
|
581
582
|
*/
|
|
582
583
|
transition(snapshot, event, actorScope) {
|
|
583
584
|
const usesInertScope = !actorScope;
|
|
584
|
-
const resolvedActorScope = actorScope ??
|
|
585
|
+
const resolvedActorScope = actorScope ?? createActor.createInertActorScope(this, snapshot);
|
|
585
586
|
if (this.validator) {
|
|
586
587
|
dist_xstateActors.assertValid(this.validator, {
|
|
587
588
|
kind: 'event',
|
|
@@ -591,14 +592,14 @@ class StateMachine {
|
|
|
591
592
|
});
|
|
592
593
|
}
|
|
593
594
|
if (usesInertScope) {
|
|
594
|
-
|
|
595
|
+
createActor.setInertActorScopeSnapshot(resolvedActorScope, snapshot, false);
|
|
595
596
|
}
|
|
596
597
|
const fastSnapshot = this._transitionFast(snapshot, event, resolvedActorScope);
|
|
597
598
|
if (fastSnapshot) {
|
|
598
599
|
if (usesInertScope) {
|
|
599
|
-
|
|
600
|
+
createActor.setInertActorScopeSnapshot(resolvedActorScope, fastSnapshot, false);
|
|
600
601
|
}
|
|
601
|
-
const returnedSnapshot = usesInertScope && fastSnapshot !== snapshot ?
|
|
602
|
+
const returnedSnapshot = usesInertScope && fastSnapshot !== snapshot ? createActor.attachSnapshotActorRef(resolvedActorScope, fastSnapshot) : this._attachPureActorRef(fastSnapshot, resolvedActorScope);
|
|
602
603
|
if (this.validator) {
|
|
603
604
|
dist_xstateActors.assertValid(this.validator, {
|
|
604
605
|
kind: 'result',
|
|
@@ -612,11 +613,11 @@ class StateMachine {
|
|
|
612
613
|
const {
|
|
613
614
|
snapshot: nextSnapshot,
|
|
614
615
|
microsteps
|
|
615
|
-
} =
|
|
616
|
+
} = createActor.macrostep(snapshot, event, resolvedActorScope, []);
|
|
616
617
|
if (usesInertScope) {
|
|
617
|
-
|
|
618
|
+
createActor.setInertActorScopeSnapshot(resolvedActorScope, nextSnapshot, false);
|
|
618
619
|
}
|
|
619
|
-
const returnedSnapshot = usesInertScope ? nextSnapshot === snapshot ? nextSnapshot :
|
|
620
|
+
const returnedSnapshot = usesInertScope ? nextSnapshot === snapshot ? nextSnapshot : createActor.attachSnapshotActorRef(resolvedActorScope, nextSnapshot) : this._attachPureActorRef(nextSnapshot, resolvedActorScope);
|
|
620
621
|
const effects = this._collectEffects(microsteps);
|
|
621
622
|
if (this.validator) {
|
|
622
623
|
dist_xstateActors.assertValid(this.validator, {
|
|
@@ -632,13 +633,13 @@ class StateMachine {
|
|
|
632
633
|
return microsteps.flatMap(([, actions]) => actions);
|
|
633
634
|
}
|
|
634
635
|
_attachPureActorRef(snapshot, actorScope, skipInitializingActor = false) {
|
|
635
|
-
if (
|
|
636
|
+
if (createActor.isInertActorScope(actorScope)) {
|
|
636
637
|
return snapshot;
|
|
637
638
|
}
|
|
638
639
|
if (skipInitializingActor && actorScope.self._actorScope === actorScope && actorScope.self._snapshot === undefined) {
|
|
639
640
|
return snapshot;
|
|
640
641
|
}
|
|
641
|
-
|
|
642
|
+
createActor.setSnapshotActorRef(snapshot, actorScope.self, actorScope.system);
|
|
642
643
|
return snapshot;
|
|
643
644
|
}
|
|
644
645
|
_transitionFast(snapshot, event, actorScope) {
|
|
@@ -666,12 +667,12 @@ class StateMachine {
|
|
|
666
667
|
...snapshot.context,
|
|
667
668
|
...selected.context
|
|
668
669
|
} : snapshot.context;
|
|
669
|
-
if (!
|
|
670
|
+
if (!createActor.isInertActorScope(actorScope) && (actorScope.system._hasInspectionObservers?.() ?? true)) {
|
|
670
671
|
const collectedMicrosteps = actorScope.self._collectedMicrosteps || [];
|
|
671
672
|
collectedMicrosteps.push(selected);
|
|
672
673
|
actorScope.self._collectedMicrosteps = collectedMicrosteps;
|
|
673
674
|
}
|
|
674
|
-
return
|
|
675
|
+
return createActor.cloneMachineSnapshot(snapshot, {
|
|
675
676
|
...(context !== snapshot.context ? {
|
|
676
677
|
context
|
|
677
678
|
} : {}),
|
|
@@ -691,7 +692,7 @@ class StateMachine {
|
|
|
691
692
|
microstep(snapshot, event, actorScope) {
|
|
692
693
|
const {
|
|
693
694
|
microsteps
|
|
694
|
-
} =
|
|
695
|
+
} = createActor.macrostep(snapshot, event, actorScope, []);
|
|
695
696
|
const snapshots = new Array(microsteps.length);
|
|
696
697
|
for (let i = 0; i < microsteps.length; i++) {
|
|
697
698
|
snapshots[i] = microsteps[i][0];
|
|
@@ -699,14 +700,14 @@ class StateMachine {
|
|
|
699
700
|
return snapshots;
|
|
700
701
|
}
|
|
701
702
|
getTransitionData(snapshot, event, actorScope, selectionResults) {
|
|
702
|
-
return
|
|
703
|
+
return createActor.transitionNode(this.root, snapshot.value, snapshot, event, actorScope, selectionResults) || [];
|
|
703
704
|
}
|
|
704
705
|
isInternalEventType(eventType) {
|
|
705
|
-
if (eventType ===
|
|
706
|
+
if (eventType === createActor.XSTATE_TIMER) {
|
|
706
707
|
return true;
|
|
707
708
|
}
|
|
708
709
|
for (const descriptor of this.internalEventDescriptors) {
|
|
709
|
-
if (
|
|
710
|
+
if (createActor.matchesEventDescriptor(eventType, descriptor)) {
|
|
710
711
|
return true;
|
|
711
712
|
}
|
|
712
713
|
}
|
|
@@ -732,10 +733,10 @@ class StateMachine {
|
|
|
732
733
|
if (transition.target !== undefined) {
|
|
733
734
|
return true;
|
|
734
735
|
}
|
|
735
|
-
const res =
|
|
736
|
+
const res = createActor.getTransitionResult(transition, snapshot, event, emptyActorScope, {
|
|
736
737
|
resolveActions: false
|
|
737
738
|
});
|
|
738
|
-
if (res.targets?.length || res.context ||
|
|
739
|
+
if (res.targets?.length || res.context || createActor.hasEffect(transition, snapshot.context, event, snapshot, emptyActorScope)) {
|
|
739
740
|
return true;
|
|
740
741
|
}
|
|
741
742
|
}
|
|
@@ -749,10 +750,10 @@ class StateMachine {
|
|
|
749
750
|
* @internal
|
|
750
751
|
*/
|
|
751
752
|
getExecutionErrorEvent(snapshot, error) {
|
|
752
|
-
if (snapshot?.status !== 'active' || !snapshot.
|
|
753
|
+
if (snapshot?.status !== 'active' || !snapshot.nodes?.some(stateNode => stateNode.config.onError)) {
|
|
753
754
|
return undefined;
|
|
754
755
|
}
|
|
755
|
-
return
|
|
756
|
+
return createActor.createErrorPlatformEvent('execution', error);
|
|
756
757
|
}
|
|
757
758
|
|
|
758
759
|
/**
|
|
@@ -765,7 +766,7 @@ class StateMachine {
|
|
|
765
766
|
const {
|
|
766
767
|
context
|
|
767
768
|
} = this.config;
|
|
768
|
-
const preInitial =
|
|
769
|
+
const preInitial = createActor.createMachineSnapshot({
|
|
769
770
|
context: typeof context !== 'function' && context ? context : {},
|
|
770
771
|
_nodes: [this.root],
|
|
771
772
|
children: {},
|
|
@@ -774,12 +775,12 @@ class StateMachine {
|
|
|
774
775
|
if (typeof context === 'function') {
|
|
775
776
|
const children = {};
|
|
776
777
|
const spawn = createSpawner(actorScope, this.sources.actors, children);
|
|
777
|
-
const resolvedContext = context(
|
|
778
|
+
const resolvedContext = context(createActor.withActorSelf({
|
|
778
779
|
spawn,
|
|
779
780
|
input: initEvent.input,
|
|
780
781
|
actors: this.sources.actors
|
|
781
782
|
}, actorScope));
|
|
782
|
-
const [nextState] =
|
|
783
|
+
const [nextState] = createActor.resolveActionsWithContext(preInitial, initEvent, actorScope, []);
|
|
783
784
|
if (resolvedContext) {
|
|
784
785
|
nextState.context = resolvedContext;
|
|
785
786
|
}
|
|
@@ -810,16 +811,16 @@ class StateMachine {
|
|
|
810
811
|
});
|
|
811
812
|
}
|
|
812
813
|
const usesInertScope = !actorScope;
|
|
813
|
-
const resolvedActorScope = actorScope ??
|
|
814
|
-
const initEvent =
|
|
814
|
+
const resolvedActorScope = actorScope ?? createActor.createInertActorScope(this);
|
|
815
|
+
const initEvent = createActor.createInitEvent(input); // TODO: fix;
|
|
815
816
|
const internalQueue = [];
|
|
816
817
|
const preInitialState = this._getPreInitialState(resolvedActorScope, initEvent);
|
|
817
|
-
const contextSpawnEffects = Object.values(preInitialState.children).filter(Boolean).map(actor =>
|
|
818
|
+
const contextSpawnEffects = Object.values(preInitialState.children).filter(Boolean).map(actor => createActor.createSpawnEffect(actor));
|
|
818
819
|
const finalizeInitialResult = (macroState, microsteps) => {
|
|
819
820
|
if (usesInertScope) {
|
|
820
|
-
|
|
821
|
+
createActor.setInertActorScopeSnapshot(resolvedActorScope, macroState, false);
|
|
821
822
|
}
|
|
822
|
-
const returnedSnapshot = usesInertScope ?
|
|
823
|
+
const returnedSnapshot = usesInertScope ? createActor.attachSnapshotActorRef(resolvedActorScope, macroState) : this._attachPureActorRef(macroState, resolvedActorScope, true);
|
|
823
824
|
const effects = this._collectEffects(microsteps);
|
|
824
825
|
if (this.validator) {
|
|
825
826
|
dist_xstateActors.assertValid(this.validator, {
|
|
@@ -832,18 +833,18 @@ class StateMachine {
|
|
|
832
833
|
return [returnedSnapshot, effects];
|
|
833
834
|
};
|
|
834
835
|
try {
|
|
835
|
-
const [nextState, initialActions] =
|
|
836
|
+
const [nextState, initialActions] = createActor.initialMicrostep(this.root, preInitialState, resolvedActorScope, initEvent, internalQueue);
|
|
836
837
|
const {
|
|
837
838
|
snapshot: macroState,
|
|
838
839
|
microsteps
|
|
839
|
-
} =
|
|
840
|
+
} = createActor.macrostep(nextState, initEvent, resolvedActorScope, internalQueue, [[nextState, [...contextSpawnEffects, ...initialActions]]]);
|
|
840
841
|
return finalizeInitialResult(macroState, microsteps);
|
|
841
842
|
} catch (err) {
|
|
842
843
|
if (!this.root.config.onError) {
|
|
843
844
|
throw err;
|
|
844
845
|
}
|
|
845
|
-
const errorEvent =
|
|
846
|
-
const errorMacrostep =
|
|
846
|
+
const errorEvent = createActor.createErrorPlatformEvent('execution', err);
|
|
847
|
+
const errorMacrostep = createActor.macrostep(preInitialState, errorEvent, resolvedActorScope, [], [[preInitialState, contextSpawnEffects]]);
|
|
847
848
|
return finalizeInitialResult(errorMacrostep.snapshot, errorMacrostep.microsteps);
|
|
848
849
|
}
|
|
849
850
|
}
|
|
@@ -866,21 +867,21 @@ class StateMachine {
|
|
|
866
867
|
}
|
|
867
868
|
}
|
|
868
869
|
getStateNodeById(stateId) {
|
|
869
|
-
const fullPath =
|
|
870
|
+
const fullPath = createActor.toStatePath(stateId);
|
|
870
871
|
const relativePath = fullPath.slice(1);
|
|
871
|
-
const resolvedStateId =
|
|
872
|
+
const resolvedStateId = createActor.isStateId(fullPath[0]) ? fullPath[0].slice(STATE_IDENTIFIER.length) : fullPath[0];
|
|
872
873
|
const stateNode = this.idMap.get(resolvedStateId);
|
|
873
874
|
if (!stateNode) {
|
|
874
875
|
throw new Error(`Child state node '#${resolvedStateId}' does not exist on machine '${this.id}'`);
|
|
875
876
|
}
|
|
876
|
-
return
|
|
877
|
+
return createActor.getStateNodeByPath(stateNode, relativePath);
|
|
877
878
|
}
|
|
878
879
|
getPersistedSnapshot(snapshot, options) {
|
|
879
|
-
return
|
|
880
|
+
return createActor.getPersistedSnapshot(snapshot, options);
|
|
880
881
|
}
|
|
881
882
|
restoreSnapshot(snapshot, actorScope) {
|
|
882
883
|
const usesInertScope = !actorScope;
|
|
883
|
-
const resolvedActorScope = actorScope ??
|
|
884
|
+
const resolvedActorScope = actorScope ?? createActor.createInertActorScope(this);
|
|
884
885
|
const persistedMachine = snapshot.machine;
|
|
885
886
|
const legacyPersistedVersion = snapshot.version;
|
|
886
887
|
const persistedVersion = typeof persistedMachine?.version === 'string' ? persistedMachine.version : legacyPersistedVersion;
|
|
@@ -904,7 +905,7 @@ class StateMachine {
|
|
|
904
905
|
const actorData = snapshotChildren[actorId];
|
|
905
906
|
const childState = actorData.snapshot;
|
|
906
907
|
const src = actorData.src;
|
|
907
|
-
const logic = typeof src === 'string' ?
|
|
908
|
+
const logic = typeof src === 'string' ? createActor.resolveReferencedActor(this, src) : src;
|
|
908
909
|
if (!logic) {
|
|
909
910
|
const sourceId = typeof src === 'string' ? src : '<unknown>';
|
|
910
911
|
throw new Error(`Unable to restore child actor '${actorId}': child source '${sourceId}' is not provided in machine '${this.id}'.`);
|
|
@@ -930,7 +931,7 @@ class StateMachine {
|
|
|
930
931
|
const actorId = event.actorId;
|
|
931
932
|
const child = children[actorId];
|
|
932
933
|
if (child) {
|
|
933
|
-
event =
|
|
934
|
+
event = createActor.createInvokeTimeoutEvent(actorId, child.sessionId);
|
|
934
935
|
}
|
|
935
936
|
}
|
|
936
937
|
const target = typeof timer.target === 'string' ? timer.target === 'self' ? 'self' : children[timer.target] : resolvedActorScope.self._parent;
|
|
@@ -974,12 +975,12 @@ class StateMachine {
|
|
|
974
975
|
return revived;
|
|
975
976
|
};
|
|
976
977
|
const revivedHistoryValue = reviveHistoryValue(snapshotData.historyValue);
|
|
977
|
-
const nodes = Array.from(
|
|
978
|
+
const nodes = Array.from(createActor.getAllStateNodes(createActor.getStateNodes(this.root, snapshotData.value)));
|
|
978
979
|
const {
|
|
979
980
|
version: _persistedSnapshotVersion,
|
|
980
981
|
...persistedRest
|
|
981
982
|
} = snapshot;
|
|
982
|
-
const restoredSnapshot =
|
|
983
|
+
const restoredSnapshot = createActor.createMachineSnapshot({
|
|
983
984
|
...persistedRest,
|
|
984
985
|
children,
|
|
985
986
|
timers,
|
|
@@ -997,7 +998,7 @@ class StateMachine {
|
|
|
997
998
|
for (const key of Object.keys(contextPart)) {
|
|
998
999
|
const value = contextPart[key];
|
|
999
1000
|
if (value && typeof value === 'object') {
|
|
1000
|
-
if ('xstate$$type' in value && value.xstate$$type ===
|
|
1001
|
+
if ('xstate$$type' in value && value.xstate$$type === createActor.$$ACTOR_TYPE) {
|
|
1001
1002
|
contextPart[key] = children[value.id];
|
|
1002
1003
|
continue;
|
|
1003
1004
|
}
|
|
@@ -1007,8 +1008,8 @@ class StateMachine {
|
|
|
1007
1008
|
}
|
|
1008
1009
|
reviveContext(restoredSnapshot.context);
|
|
1009
1010
|
if (usesInertScope) {
|
|
1010
|
-
|
|
1011
|
-
return
|
|
1011
|
+
createActor.setInertActorScopeSnapshot(resolvedActorScope, restoredSnapshot, false);
|
|
1012
|
+
return createActor.attachSnapshotActorRef(resolvedActorScope, restoredSnapshot);
|
|
1012
1013
|
}
|
|
1013
1014
|
return this._attachPureActorRef(restoredSnapshot, resolvedActorScope);
|
|
1014
1015
|
}
|
package/dist/{StateMachine-8dd1e4a0.development.esm.js → StateMachine-9da92cbf.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);
|