xstate 6.0.0-alpha.12 → 6.0.0-alpha.13
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-8a9e6cb4.development.esm.js → StateMachine-193c2d4d.development.esm.js} +42 -1
- package/dist/{StateMachine-7af634f9.cjs.js → StateMachine-1b26c5de.cjs.js} +42 -1
- package/dist/{StateMachine-c7e1996c.development.cjs.js → StateMachine-3120a7ff.development.cjs.js} +42 -1
- package/dist/{StateMachine-97ef0e5e.esm.js → StateMachine-614c0f36.esm.js} +42 -1
- package/dist/declarations/src/StateMachine.d.ts +1 -0
- package/dist/declarations/src/fsm.d.ts +74 -0
- package/dist/declarations/src/index.d.ts +1 -0
- package/dist/declarations/src/setup.d.ts +29 -10
- package/dist/declarations/src/types.d.ts +9 -3
- package/dist/declarations/src/types.v6.d.ts +5 -5
- package/dist/{index-3d018b1e.development.cjs.js → index-08d86676.development.cjs.js} +21 -15
- package/dist/{index-698a3320.cjs.js → index-32631949.cjs.js} +21 -15
- package/dist/{index-45856a94.esm.js → index-603c1cda.esm.js} +18 -16
- package/dist/{index-be3d4c2d.development.esm.js → index-7081e0c9.development.esm.js} +18 -16
- package/dist/xstate-actors.cjs.js +1 -1
- package/dist/xstate-actors.development.cjs.js +1 -1
- package/dist/xstate-actors.development.esm.js +1 -1
- package/dist/xstate-actors.esm.js +1 -1
- package/dist/xstate-graph.cjs.js +2 -2
- package/dist/xstate-graph.development.cjs.js +2 -2
- package/dist/xstate-graph.development.esm.js +2 -2
- package/dist/xstate-graph.esm.js +2 -2
- package/dist/xstate-graph.umd.min.js +1 -1
- package/dist/xstate-graph.umd.min.js.map +1 -1
- package/dist/xstate.cjs.js +336 -2
- package/dist/xstate.cjs.mjs +1 -0
- package/dist/xstate.development.cjs.js +336 -2
- package/dist/xstate.development.cjs.mjs +1 -0
- package/dist/xstate.development.esm.js +339 -6
- package/dist/xstate.esm.js +339 -6
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/package.json +1 -1
package/dist/{StateMachine-8a9e6cb4.development.esm.js → StateMachine-193c2d4d.development.esm.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as ProcessingStatus,
|
|
1
|
+
import { P as ProcessingStatus, G as resolveReferencedActor, d as createActor, S as STATE_DELIMITER, H as mapValues, t as toArray, I as createInvokeId, J as getDelayedTransitions, K as evaluateCandidate, L as formatTransition, N as NULL_EVENT, M as toTransitionConfigArray, O as createInvokeTimeoutEvent, Q as getCandidates, R as formatRouteTransitions, U as resolveStateValue, V as getAllStateNodes, k as getStateNodes, W as createMachineSnapshot, Y as isInFinalState, e as macrostep, Z as cloneMachineSnapshot, _ as transitionNode, m as matchesEventDescriptor, r as resolveActionsWithContext, f as createInitEvent, g as initialMicrostep, $ as toStatePath, a0 as isStateId, a1 as getStateNodeByPath, a2 as getPersistedSnapshot, a3 as $$ACTOR_TYPE } from './index-7081e0c9.development.esm.js';
|
|
2
2
|
|
|
3
3
|
function createSpawner(actorScope, {
|
|
4
4
|
machine,
|
|
@@ -526,12 +526,53 @@ class StateMachine {
|
|
|
526
526
|
* @param event The received event
|
|
527
527
|
*/
|
|
528
528
|
transition(snapshot, event, actorScope) {
|
|
529
|
+
const fastSnapshot = this._transitionFast(snapshot, event, actorScope);
|
|
530
|
+
if (fastSnapshot) {
|
|
531
|
+
return [fastSnapshot, []];
|
|
532
|
+
}
|
|
529
533
|
const {
|
|
530
534
|
snapshot: nextSnapshot,
|
|
531
535
|
microsteps
|
|
532
536
|
} = macrostep(snapshot, event, actorScope, []);
|
|
533
537
|
return [nextSnapshot, microsteps.flatMap(([, actions]) => actions)];
|
|
534
538
|
}
|
|
539
|
+
_transitionFast(snapshot, event, actorScope) {
|
|
540
|
+
if (snapshot.status !== 'active' || typeof snapshot.value !== 'string' || this.root.always?.length) {
|
|
541
|
+
return undefined;
|
|
542
|
+
}
|
|
543
|
+
const sourceNode = this.root.states[snapshot.value];
|
|
544
|
+
if (!sourceNode || sourceNode.type !== 'atomic' || sourceNode.exit || sourceNode.invoke.length || sourceNode.always?.length || sourceNode.after?.length) {
|
|
545
|
+
return undefined;
|
|
546
|
+
}
|
|
547
|
+
const transitions = sourceNode.transitions.get(event.type);
|
|
548
|
+
if (transitions?.length !== 1) {
|
|
549
|
+
return undefined;
|
|
550
|
+
}
|
|
551
|
+
const selected = transitions[0];
|
|
552
|
+
if (selected.guard || selected.actions || selected.to || selected.reenter || selected.input || typeof selected.context === 'function' || selected.target && selected.target.length !== 1) {
|
|
553
|
+
return undefined;
|
|
554
|
+
}
|
|
555
|
+
const targetNode = selected.target?.[0] ?? sourceNode;
|
|
556
|
+
const stateChanged = targetNode !== sourceNode;
|
|
557
|
+
if (targetNode.parent !== this.root || targetNode.type !== 'atomic' || stateChanged && (targetNode.entry || targetNode.invoke.length || targetNode.always?.length || targetNode.after?.length)) {
|
|
558
|
+
return undefined;
|
|
559
|
+
}
|
|
560
|
+
const context = selected.context !== undefined ? {
|
|
561
|
+
...snapshot.context,
|
|
562
|
+
...selected.context
|
|
563
|
+
} : snapshot.context;
|
|
564
|
+
const collectedMicrosteps = actorScope.self._collectedMicrosteps || [];
|
|
565
|
+
collectedMicrosteps.push(selected);
|
|
566
|
+
actorScope.self._collectedMicrosteps = collectedMicrosteps;
|
|
567
|
+
return cloneMachineSnapshot(snapshot, {
|
|
568
|
+
...(context !== snapshot.context ? {
|
|
569
|
+
context
|
|
570
|
+
} : {}),
|
|
571
|
+
...(stateChanged ? {
|
|
572
|
+
_nodes: [this.root, targetNode]
|
|
573
|
+
} : {})
|
|
574
|
+
});
|
|
575
|
+
}
|
|
535
576
|
|
|
536
577
|
/**
|
|
537
578
|
* Determines the next state given the current `state` and `event`. Calculates
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var dist_xstateActors = require('./index-
|
|
3
|
+
var dist_xstateActors = require('./index-32631949.cjs.js');
|
|
4
4
|
|
|
5
5
|
function createSpawner(actorScope, {
|
|
6
6
|
machine,
|
|
@@ -514,12 +514,53 @@ class StateMachine {
|
|
|
514
514
|
* @param event The received event
|
|
515
515
|
*/
|
|
516
516
|
transition(snapshot, event, actorScope) {
|
|
517
|
+
const fastSnapshot = this._transitionFast(snapshot, event, actorScope);
|
|
518
|
+
if (fastSnapshot) {
|
|
519
|
+
return [fastSnapshot, []];
|
|
520
|
+
}
|
|
517
521
|
const {
|
|
518
522
|
snapshot: nextSnapshot,
|
|
519
523
|
microsteps
|
|
520
524
|
} = dist_xstateActors.macrostep(snapshot, event, actorScope, []);
|
|
521
525
|
return [nextSnapshot, microsteps.flatMap(([, actions]) => actions)];
|
|
522
526
|
}
|
|
527
|
+
_transitionFast(snapshot, event, actorScope) {
|
|
528
|
+
if (snapshot.status !== 'active' || typeof snapshot.value !== 'string' || this.root.always?.length) {
|
|
529
|
+
return undefined;
|
|
530
|
+
}
|
|
531
|
+
const sourceNode = this.root.states[snapshot.value];
|
|
532
|
+
if (!sourceNode || sourceNode.type !== 'atomic' || sourceNode.exit || sourceNode.invoke.length || sourceNode.always?.length || sourceNode.after?.length) {
|
|
533
|
+
return undefined;
|
|
534
|
+
}
|
|
535
|
+
const transitions = sourceNode.transitions.get(event.type);
|
|
536
|
+
if (transitions?.length !== 1) {
|
|
537
|
+
return undefined;
|
|
538
|
+
}
|
|
539
|
+
const selected = transitions[0];
|
|
540
|
+
if (selected.guard || selected.actions || selected.to || selected.reenter || selected.input || typeof selected.context === 'function' || selected.target && selected.target.length !== 1) {
|
|
541
|
+
return undefined;
|
|
542
|
+
}
|
|
543
|
+
const targetNode = selected.target?.[0] ?? sourceNode;
|
|
544
|
+
const stateChanged = targetNode !== sourceNode;
|
|
545
|
+
if (targetNode.parent !== this.root || targetNode.type !== 'atomic' || stateChanged && (targetNode.entry || targetNode.invoke.length || targetNode.always?.length || targetNode.after?.length)) {
|
|
546
|
+
return undefined;
|
|
547
|
+
}
|
|
548
|
+
const context = selected.context !== undefined ? {
|
|
549
|
+
...snapshot.context,
|
|
550
|
+
...selected.context
|
|
551
|
+
} : snapshot.context;
|
|
552
|
+
const collectedMicrosteps = actorScope.self._collectedMicrosteps || [];
|
|
553
|
+
collectedMicrosteps.push(selected);
|
|
554
|
+
actorScope.self._collectedMicrosteps = collectedMicrosteps;
|
|
555
|
+
return dist_xstateActors.cloneMachineSnapshot(snapshot, {
|
|
556
|
+
...(context !== snapshot.context ? {
|
|
557
|
+
context
|
|
558
|
+
} : {}),
|
|
559
|
+
...(stateChanged ? {
|
|
560
|
+
_nodes: [this.root, targetNode]
|
|
561
|
+
} : {})
|
|
562
|
+
});
|
|
563
|
+
}
|
|
523
564
|
|
|
524
565
|
/**
|
|
525
566
|
* Determines the next state given the current `state` and `event`. Calculates
|
package/dist/{StateMachine-c7e1996c.development.cjs.js → StateMachine-3120a7ff.development.cjs.js}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var dist_xstateActors = require('./index-
|
|
3
|
+
var dist_xstateActors = require('./index-08d86676.development.cjs.js');
|
|
4
4
|
|
|
5
5
|
function createSpawner(actorScope, {
|
|
6
6
|
machine,
|
|
@@ -528,12 +528,53 @@ class StateMachine {
|
|
|
528
528
|
* @param event The received event
|
|
529
529
|
*/
|
|
530
530
|
transition(snapshot, event, actorScope) {
|
|
531
|
+
const fastSnapshot = this._transitionFast(snapshot, event, actorScope);
|
|
532
|
+
if (fastSnapshot) {
|
|
533
|
+
return [fastSnapshot, []];
|
|
534
|
+
}
|
|
531
535
|
const {
|
|
532
536
|
snapshot: nextSnapshot,
|
|
533
537
|
microsteps
|
|
534
538
|
} = dist_xstateActors.macrostep(snapshot, event, actorScope, []);
|
|
535
539
|
return [nextSnapshot, microsteps.flatMap(([, actions]) => actions)];
|
|
536
540
|
}
|
|
541
|
+
_transitionFast(snapshot, event, actorScope) {
|
|
542
|
+
if (snapshot.status !== 'active' || typeof snapshot.value !== 'string' || this.root.always?.length) {
|
|
543
|
+
return undefined;
|
|
544
|
+
}
|
|
545
|
+
const sourceNode = this.root.states[snapshot.value];
|
|
546
|
+
if (!sourceNode || sourceNode.type !== 'atomic' || sourceNode.exit || sourceNode.invoke.length || sourceNode.always?.length || sourceNode.after?.length) {
|
|
547
|
+
return undefined;
|
|
548
|
+
}
|
|
549
|
+
const transitions = sourceNode.transitions.get(event.type);
|
|
550
|
+
if (transitions?.length !== 1) {
|
|
551
|
+
return undefined;
|
|
552
|
+
}
|
|
553
|
+
const selected = transitions[0];
|
|
554
|
+
if (selected.guard || selected.actions || selected.to || selected.reenter || selected.input || typeof selected.context === 'function' || selected.target && selected.target.length !== 1) {
|
|
555
|
+
return undefined;
|
|
556
|
+
}
|
|
557
|
+
const targetNode = selected.target?.[0] ?? sourceNode;
|
|
558
|
+
const stateChanged = targetNode !== sourceNode;
|
|
559
|
+
if (targetNode.parent !== this.root || targetNode.type !== 'atomic' || stateChanged && (targetNode.entry || targetNode.invoke.length || targetNode.always?.length || targetNode.after?.length)) {
|
|
560
|
+
return undefined;
|
|
561
|
+
}
|
|
562
|
+
const context = selected.context !== undefined ? {
|
|
563
|
+
...snapshot.context,
|
|
564
|
+
...selected.context
|
|
565
|
+
} : snapshot.context;
|
|
566
|
+
const collectedMicrosteps = actorScope.self._collectedMicrosteps || [];
|
|
567
|
+
collectedMicrosteps.push(selected);
|
|
568
|
+
actorScope.self._collectedMicrosteps = collectedMicrosteps;
|
|
569
|
+
return dist_xstateActors.cloneMachineSnapshot(snapshot, {
|
|
570
|
+
...(context !== snapshot.context ? {
|
|
571
|
+
context
|
|
572
|
+
} : {}),
|
|
573
|
+
...(stateChanged ? {
|
|
574
|
+
_nodes: [this.root, targetNode]
|
|
575
|
+
} : {})
|
|
576
|
+
});
|
|
577
|
+
}
|
|
537
578
|
|
|
538
579
|
/**
|
|
539
580
|
* Determines the next state given the current `state` and `event`. Calculates
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as ProcessingStatus,
|
|
1
|
+
import { P as ProcessingStatus, G as resolveReferencedActor, d as createActor, S as STATE_DELIMITER, H as mapValues, t as toArray, I as createInvokeId, J as getDelayedTransitions, K as evaluateCandidate, L as formatTransition, N as NULL_EVENT, M as toTransitionConfigArray, O as createInvokeTimeoutEvent, Q as getCandidates, R as formatRouteTransitions, U as resolveStateValue, V as getAllStateNodes, k as getStateNodes, W as createMachineSnapshot, Y as isInFinalState, e as macrostep, Z as cloneMachineSnapshot, _ as transitionNode, m as matchesEventDescriptor, r as resolveActionsWithContext, f as createInitEvent, g as initialMicrostep, $ as toStatePath, a0 as isStateId, a1 as getStateNodeByPath, a2 as getPersistedSnapshot, a3 as $$ACTOR_TYPE } from './index-603c1cda.esm.js';
|
|
2
2
|
|
|
3
3
|
function createSpawner(actorScope, {
|
|
4
4
|
machine,
|
|
@@ -512,12 +512,53 @@ class StateMachine {
|
|
|
512
512
|
* @param event The received event
|
|
513
513
|
*/
|
|
514
514
|
transition(snapshot, event, actorScope) {
|
|
515
|
+
const fastSnapshot = this._transitionFast(snapshot, event, actorScope);
|
|
516
|
+
if (fastSnapshot) {
|
|
517
|
+
return [fastSnapshot, []];
|
|
518
|
+
}
|
|
515
519
|
const {
|
|
516
520
|
snapshot: nextSnapshot,
|
|
517
521
|
microsteps
|
|
518
522
|
} = macrostep(snapshot, event, actorScope, []);
|
|
519
523
|
return [nextSnapshot, microsteps.flatMap(([, actions]) => actions)];
|
|
520
524
|
}
|
|
525
|
+
_transitionFast(snapshot, event, actorScope) {
|
|
526
|
+
if (snapshot.status !== 'active' || typeof snapshot.value !== 'string' || this.root.always?.length) {
|
|
527
|
+
return undefined;
|
|
528
|
+
}
|
|
529
|
+
const sourceNode = this.root.states[snapshot.value];
|
|
530
|
+
if (!sourceNode || sourceNode.type !== 'atomic' || sourceNode.exit || sourceNode.invoke.length || sourceNode.always?.length || sourceNode.after?.length) {
|
|
531
|
+
return undefined;
|
|
532
|
+
}
|
|
533
|
+
const transitions = sourceNode.transitions.get(event.type);
|
|
534
|
+
if (transitions?.length !== 1) {
|
|
535
|
+
return undefined;
|
|
536
|
+
}
|
|
537
|
+
const selected = transitions[0];
|
|
538
|
+
if (selected.guard || selected.actions || selected.to || selected.reenter || selected.input || typeof selected.context === 'function' || selected.target && selected.target.length !== 1) {
|
|
539
|
+
return undefined;
|
|
540
|
+
}
|
|
541
|
+
const targetNode = selected.target?.[0] ?? sourceNode;
|
|
542
|
+
const stateChanged = targetNode !== sourceNode;
|
|
543
|
+
if (targetNode.parent !== this.root || targetNode.type !== 'atomic' || stateChanged && (targetNode.entry || targetNode.invoke.length || targetNode.always?.length || targetNode.after?.length)) {
|
|
544
|
+
return undefined;
|
|
545
|
+
}
|
|
546
|
+
const context = selected.context !== undefined ? {
|
|
547
|
+
...snapshot.context,
|
|
548
|
+
...selected.context
|
|
549
|
+
} : snapshot.context;
|
|
550
|
+
const collectedMicrosteps = actorScope.self._collectedMicrosteps || [];
|
|
551
|
+
collectedMicrosteps.push(selected);
|
|
552
|
+
actorScope.self._collectedMicrosteps = collectedMicrosteps;
|
|
553
|
+
return cloneMachineSnapshot(snapshot, {
|
|
554
|
+
...(context !== snapshot.context ? {
|
|
555
|
+
context
|
|
556
|
+
} : {}),
|
|
557
|
+
...(stateChanged ? {
|
|
558
|
+
_nodes: [this.root, targetNode]
|
|
559
|
+
} : {})
|
|
560
|
+
});
|
|
561
|
+
}
|
|
521
562
|
|
|
522
563
|
/**
|
|
523
564
|
* Determines the next state given the current `state` and `event`. Calculates
|
|
@@ -63,6 +63,7 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
|
|
|
63
63
|
* @param event The received event
|
|
64
64
|
*/
|
|
65
65
|
transition(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, event: TEvent, actorScope: ActorScope<typeof snapshot, TEvent, AnyActorSystem, TEmitted>): ActorLogicTransitionResult<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, ExecutableActionObjectFromLogic<this>>;
|
|
66
|
+
private _transitionFast;
|
|
66
67
|
/**
|
|
67
68
|
* Determines the next state given the current `state` and `event`. Calculates
|
|
68
69
|
* a microstep.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { createTransitionEnqueue } from "./transitionActions.js";
|
|
2
|
+
import type { ActorLogic, EventObject, MachineContext, NonReducibleUnknown, Snapshot } from "./types.js";
|
|
3
|
+
export type FSMSnapshot<TContext extends MachineContext, TState extends string, TInput = unknown> = Snapshot<undefined> & {
|
|
4
|
+
value: TState;
|
|
5
|
+
context: TContext;
|
|
6
|
+
input: TInput | undefined;
|
|
7
|
+
children: {};
|
|
8
|
+
_stateInput: Record<string, unknown> | undefined;
|
|
9
|
+
machine: {
|
|
10
|
+
id: string;
|
|
11
|
+
implementations: {
|
|
12
|
+
actions: {};
|
|
13
|
+
actorSources: {};
|
|
14
|
+
guards: {};
|
|
15
|
+
delays: {};
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
type FSMArgs<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TInput> = {
|
|
20
|
+
context: TContext;
|
|
21
|
+
event: TEvent;
|
|
22
|
+
input: TInput | undefined;
|
|
23
|
+
value: TState;
|
|
24
|
+
self: any;
|
|
25
|
+
system: any;
|
|
26
|
+
parent: any;
|
|
27
|
+
children: {};
|
|
28
|
+
};
|
|
29
|
+
type FSMAction<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TInput> = (args: FSMArgs<TContext, TEvent, TState, TInput> & {
|
|
30
|
+
input: Record<string, unknown> | undefined;
|
|
31
|
+
}, enq: ReturnType<typeof createTransitionEnqueue>) => void | {
|
|
32
|
+
context?: FSMContextPatch<TContext>;
|
|
33
|
+
};
|
|
34
|
+
type FSMGuard<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TInput> = (args: FSMArgs<TContext, TEvent, TState, TInput>) => boolean;
|
|
35
|
+
type FSMContextPatch<TContext extends MachineContext> = Partial<TContext> & {
|
|
36
|
+
call?: never;
|
|
37
|
+
apply?: never;
|
|
38
|
+
bind?: never;
|
|
39
|
+
};
|
|
40
|
+
type FSMContextMapper<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TInput> = (args: FSMArgs<TContext, TEvent, TState, TInput>) => FSMContextPatch<TContext>;
|
|
41
|
+
type FSMTarget<TContext extends MachineContext> = {
|
|
42
|
+
target?: string;
|
|
43
|
+
context?: FSMContextPatch<TContext>;
|
|
44
|
+
input?: Record<string, unknown> | ((args: {
|
|
45
|
+
context: TContext;
|
|
46
|
+
event: EventObject;
|
|
47
|
+
}) => Record<string, unknown>);
|
|
48
|
+
};
|
|
49
|
+
type FSMObjectTarget<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TInput> = Omit<FSMTarget<TContext>, 'context'> & {
|
|
50
|
+
context?: FSMContextPatch<TContext> | FSMContextMapper<TContext, TEvent, TState, TInput>;
|
|
51
|
+
};
|
|
52
|
+
type FSMTransitionFunction<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TInput> = (args: FSMArgs<TContext, TEvent, TState, TInput>, enq: ReturnType<typeof createTransitionEnqueue>) => void | false | FSMTarget<TContext>;
|
|
53
|
+
type FSMTransition<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TInput> = FSMObjectTarget<TContext, TEvent, TState, TInput> | (FSMObjectTarget<TContext, TEvent, TState, TInput> & {
|
|
54
|
+
guard?: FSMGuard<TContext, TEvent, TState, TInput>;
|
|
55
|
+
actions?: FSMAction<TContext, TEvent, TState, TInput> | Array<FSMAction<TContext, TEvent, TState, TInput>>;
|
|
56
|
+
}) | FSMTransitionFunction<TContext, TEvent, TState, TInput>;
|
|
57
|
+
type FSMStateConfig<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TInput> = {
|
|
58
|
+
entry?: FSMAction<TContext, TEvent, TState, TInput> | Array<FSMAction<TContext, TEvent, TState, TInput>>;
|
|
59
|
+
exit?: FSMAction<TContext, TEvent, TState, TInput> | Array<FSMAction<TContext, TEvent, TState, TInput>>;
|
|
60
|
+
on?: Record<string, FSMTransition<TContext, TEvent, TState, TInput> | Array<FSMTransition<TContext, TEvent, TState, TInput>>>;
|
|
61
|
+
};
|
|
62
|
+
export type FSMConfig<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TInput = NonReducibleUnknown> = {
|
|
63
|
+
id?: string;
|
|
64
|
+
initial: TState;
|
|
65
|
+
context?: TContext | ((args: {
|
|
66
|
+
input: TInput;
|
|
67
|
+
}) => TContext);
|
|
68
|
+
states: Record<TState, FSMStateConfig<TContext, TEvent, TState, TInput>>;
|
|
69
|
+
};
|
|
70
|
+
export type FSMActorLogic<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TInput> = ActorLogic<FSMSnapshot<TContext, TState, TInput>, TEvent, TInput, any, EventObject> & {
|
|
71
|
+
id?: string;
|
|
72
|
+
};
|
|
73
|
+
export declare function createFSM<TContext extends MachineContext, TEvent extends EventObject, TInput = NonReducibleUnknown>(config: FSMConfig<TContext, TEvent, string, TInput>): FSMActorLogic<TContext, TEvent, string, TInput>;
|
|
74
|
+
export {};
|
|
@@ -2,6 +2,7 @@ export * from "./actors/index.js";
|
|
|
2
2
|
export { assertEvent } from "./assert.js";
|
|
3
3
|
export { Actor, createActor, type RequiredActorOptionsKeys as RequiredActorOptionsKeys } from "./createActor.js";
|
|
4
4
|
export { createMachine, createStateConfig } from "./createMachine.js";
|
|
5
|
+
export { createFSM, type FSMActorLogic, type FSMConfig, type FSMSnapshot } from "./fsm.js";
|
|
5
6
|
export { createMachineFromConfig } from "./createMachineFromConfig.js";
|
|
6
7
|
export type { ActionJSON, GuardJSON, InvokeJSON, MachineJSON, StateNodeJSON, TransitionJSON } from "./createMachineFromConfig.js";
|
|
7
8
|
export { machineConfigToJSON, serializeMachine, type CodeExpression } from "./serialize.js";
|
|
@@ -242,12 +242,12 @@ type StateNodeConfigWithNestedInput<TSiblingStateSchemas extends Record<string,
|
|
|
242
242
|
type StateTransitions<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry> = {
|
|
243
243
|
[K in EventDescriptor<TEvent>]?: StateTransitionConfigOrTarget<TStateSchemas, TContext, TContextShape, ExtractEvent<TEvent, K>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
244
244
|
};
|
|
245
|
-
type StateTransitionConfigOrTarget<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry> = undefined | StateTransitionObjectConfig<TStateSchemas, TContext, TContextShape, TExpressionEvent, TMeta> | StateTransitionFunction<TStateSchemas, TContext, TContextShape, TExpressionEvent, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
246
|
-
type StateTransitionObjectConfig<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TExpressionEvent extends EventObject, TMeta extends MetaObject> = (StateTransitionResult<TStateSchemas, TContext, TContextShape, TMeta> & {
|
|
245
|
+
type StateTransitionConfigOrTarget<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry> = undefined | StateTransitionObjectConfig<TStateSchemas, TContext, TContextShape, TExpressionEvent, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry> | StateTransitionFunction<TStateSchemas, TContext, TContextShape, TExpressionEvent, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
246
|
+
type StateTransitionObjectConfig<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TExpressionEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry> = (StateTransitionResult<TStateSchemas, TContext, TContextShape, TMeta, TExpressionEvent, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, true> & {
|
|
247
247
|
description?: string;
|
|
248
248
|
}) | {
|
|
249
249
|
target: SetupStateTarget<TStateSchemas>[];
|
|
250
|
-
context?:
|
|
250
|
+
context?: StateTransitionContext<true, TContext, TContextShape, TContextShape, TContext, TExpressionEvent, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
251
251
|
description?: string;
|
|
252
252
|
reenter?: boolean;
|
|
253
253
|
meta?: TMeta;
|
|
@@ -256,6 +256,21 @@ type StateTransitionObjectConfig<TStateSchemas extends Record<string, SetupState
|
|
|
256
256
|
event: TExpressionEvent;
|
|
257
257
|
} & OutputArg<TExpressionEvent>) => Record<string, unknown>);
|
|
258
258
|
};
|
|
259
|
+
type StateTransitionContextMapper<TContext extends MachineContext, TContextShape, TTargetContextShape, TResolvedTargetContext extends MachineContext, TExpressionEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry> = (args: {
|
|
260
|
+
context: TContext;
|
|
261
|
+
event: TExpressionEvent;
|
|
262
|
+
self: AnyActorRef;
|
|
263
|
+
parent: AnyActorRef | undefined;
|
|
264
|
+
value: StateValue;
|
|
265
|
+
children: TChildren;
|
|
266
|
+
system: SystemRuntime<TSystemRegistry>;
|
|
267
|
+
actions: TActionMap;
|
|
268
|
+
actorSources: TActorMap;
|
|
269
|
+
guards: TGuardMap;
|
|
270
|
+
delays: TDelayMap;
|
|
271
|
+
} & OutputArg<TExpressionEvent>) => ContextPatch<TContextShape, TTargetContextShape, TResolvedTargetContext>;
|
|
272
|
+
type StateTransitionContextOrMapper<TContext extends MachineContext, TContextShape, TTargetContextShape, TResolvedTargetContext extends MachineContext, TExpressionEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry> = ContextPatch<TContextShape, TTargetContextShape, TResolvedTargetContext> | StateTransitionContextMapper<TContext, TContextShape, TTargetContextShape, TResolvedTargetContext, TExpressionEvent, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
273
|
+
type StateTransitionContext<TAllowMapper extends boolean, TContext extends MachineContext, TContextShape, TTargetContextShape, TResolvedTargetContext extends MachineContext, TExpressionEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry> = TAllowMapper extends true ? StateTransitionContextOrMapper<TContext, TContextShape, TTargetContextShape, TResolvedTargetContext, TExpressionEvent, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry> : ContextPatch<TContextShape, TTargetContextShape, TResolvedTargetContext>;
|
|
259
274
|
type StateTransitionFunction<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry> = (args: {
|
|
260
275
|
context: TContext;
|
|
261
276
|
event: TExpressionEvent;
|
|
@@ -268,10 +283,10 @@ type StateTransitionFunction<TStateSchemas extends Record<string, SetupStateSche
|
|
|
268
283
|
actorSources: TActorMap;
|
|
269
284
|
guards: TGuardMap;
|
|
270
285
|
delays: TDelayMap;
|
|
271
|
-
} & OutputArg<TExpressionEvent>, enq: EnqueueObject<TEvent, TEmitted, TSystemRegistry>) => StateTransitionResult<TStateSchemas, TContext, TContextShape, TMeta> | void;
|
|
272
|
-
type StateTransitionResult<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TMeta extends MetaObject> = {
|
|
286
|
+
} & OutputArg<TExpressionEvent>, enq: EnqueueObject<TEvent, TEmitted, TSystemRegistry>) => StateTransitionResult<TStateSchemas, TContext, TContextShape, TMeta, TExpressionEvent, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, false> | void;
|
|
287
|
+
type StateTransitionResult<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TMeta extends MetaObject, TExpressionEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry, TAllowContextMapper extends boolean> = {
|
|
273
288
|
target?: never;
|
|
274
|
-
context?:
|
|
289
|
+
context?: StateTransitionContext<TAllowContextMapper, TContext, TContextShape, TContextShape, TContext, TExpressionEvent, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
275
290
|
reenter?: boolean;
|
|
276
291
|
meta?: TMeta;
|
|
277
292
|
} | {
|
|
@@ -286,17 +301,21 @@ type StateTransitionResult<TStateSchemas extends Record<string, SetupStateSchema
|
|
|
286
301
|
} & ([TContextShape] extends [
|
|
287
302
|
StateContextShape<TStateSchemas[K], TContextShape>
|
|
288
303
|
] ? {
|
|
289
|
-
context?:
|
|
304
|
+
context?: StateTransitionContext<TAllowContextMapper, TContext, TContextShape, StateContextShape<TStateSchemas[K], TContextShape>, StateContext<TStateSchemas[K], TContext>, TExpressionEvent, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
290
305
|
} : {
|
|
291
|
-
context:
|
|
306
|
+
context: StateTransitionContext<TAllowContextMapper, TContext, TContextShape, StateContextShape<TStateSchemas[K], TContextShape>, StateContext<TStateSchemas[K], TContext>, TExpressionEvent, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
292
307
|
});
|
|
293
308
|
}[keyof TStateSchemas & string] | {
|
|
294
309
|
target: Exclude<SetupStateTarget<TStateSchemas>, keyof TStateSchemas & string>;
|
|
295
|
-
context?:
|
|
310
|
+
context?: StateTransitionContext<TAllowContextMapper, TContext, TContextShape, TContextShape, TContext, TExpressionEvent, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
296
311
|
reenter?: boolean;
|
|
297
312
|
meta?: TMeta;
|
|
298
313
|
};
|
|
299
|
-
type ContextPatch<TCurrentContext, TTargetContext, TResolvedTargetContext extends MachineContext> = Compute<Partial<TResolvedTargetContext> & Pick<TResolvedTargetContext, Extract<RequiredContextKeys<TCurrentContext, TTargetContext>, string
|
|
314
|
+
type ContextPatch<TCurrentContext, TTargetContext, TResolvedTargetContext extends MachineContext> = Compute<Partial<TResolvedTargetContext> & Pick<TResolvedTargetContext, Extract<RequiredContextKeys<TCurrentContext, TTargetContext>, string>> & {
|
|
315
|
+
call?: never;
|
|
316
|
+
apply?: never;
|
|
317
|
+
bind?: never;
|
|
318
|
+
}>;
|
|
300
319
|
type RequiredContextKeys<TCurrentContext, TTargetContext> = {
|
|
301
320
|
[K in keyof TTargetContext]-?: K extends keyof TCurrentContext ? [TCurrentContext[K]] extends [TTargetContext[K]] ? never : K : K;
|
|
302
321
|
}[keyof TTargetContext];
|
|
@@ -130,12 +130,18 @@ export interface StateValueMap {
|
|
|
130
130
|
*/
|
|
131
131
|
export type StateValue = string | StateValueMap;
|
|
132
132
|
export type TransitionTarget = SingleOrArray<string>;
|
|
133
|
+
export type TransitionContextPatch<TContext extends MachineContext> = Partial<TContext> & {
|
|
134
|
+
call?: never;
|
|
135
|
+
apply?: never;
|
|
136
|
+
bind?: never;
|
|
137
|
+
};
|
|
138
|
+
export type TransitionContextMapper<TContext extends MachineContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], _TCtx extends MachineContext = [TContext] extends [never] ? any : TContext> = (args: TransitionFunctionArgs<_TCtx, TCurrentEvent, TEvent, TActionMap, TActorMap, TGuardMap, TDelayMap>) => TransitionContextPatch<_TCtx>;
|
|
133
139
|
export interface TransitionConfig<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> {
|
|
134
140
|
actions?: never;
|
|
135
141
|
guard?: unknown;
|
|
136
142
|
reenter?: boolean;
|
|
137
143
|
target?: TransitionTarget | undefined;
|
|
138
|
-
context?:
|
|
144
|
+
context?: TransitionContextPatch<TContext> | TransitionContextMapper<TContext, TExpressionEvent, TEvent, TActionMap, TActorMap, TGuardMap, TDelayMap>;
|
|
139
145
|
to?: TransitionConfigFunction<TContext, TExpressionEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
140
146
|
meta?: TMeta;
|
|
141
147
|
description?: string;
|
|
@@ -198,9 +204,9 @@ export type StateNodesConfig<TContext extends MachineContext, TEvent extends Eve
|
|
|
198
204
|
};
|
|
199
205
|
export type TransitionConfigTarget = string | undefined;
|
|
200
206
|
export type TransitionConfigOrTarget<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = SingleOrArray<TransitionConfigTarget | TransitionConfig<TContext, TExpressionEvent, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap> | TransitionConfigFunction<TContext, TExpressionEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>>;
|
|
201
|
-
export type TransitionConfigFunction<TContext extends MachineContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject, _TCtx = [TContext] extends [never] ? any : TContext> = (args: TransitionFunctionArgs<_TCtx, TCurrentEvent, TEvent, TActionMap, TActorMap, TGuardMap, TDelayMap>, enq: EnqueueObject<TEvent, TEmitted>) => {
|
|
207
|
+
export type TransitionConfigFunction<TContext extends MachineContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject, _TCtx extends MachineContext = [TContext] extends [never] ? any : TContext> = (args: TransitionFunctionArgs<_TCtx, TCurrentEvent, TEvent, TActionMap, TActorMap, TGuardMap, TDelayMap>, enq: EnqueueObject<TEvent, TEmitted>) => {
|
|
202
208
|
target?: string | string[];
|
|
203
|
-
context?:
|
|
209
|
+
context?: TransitionContextPatch<_TCtx>;
|
|
204
210
|
reenter?: boolean;
|
|
205
211
|
meta?: TMeta;
|
|
206
212
|
} | void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from "./schema.types.js";
|
|
2
2
|
import { MachineSnapshot } from "./State.js";
|
|
3
|
-
import { Action, ActorLogic, ActorRef, ActorRefFromLogic, ActorSelf, AnyActorLogic, AnyActorRef, Compute, DoneActorEvent, DoNotInfer, EventDescriptor, EventObject, ExtractEvent, InitialContext, InputFrom, IsNever, MetaObject, NonReducibleUnknown, OutputFrom, SingleOrArray, SnapshotEvent, StateValue, TODO, TransitionConfigFunction, Values, AnyStateNode, SystemRegistry } from "./types.js";
|
|
3
|
+
import { Action, ActorLogic, ActorRef, ActorRefFromLogic, ActorSelf, AnyActorLogic, AnyActorRef, Compute, DoneActorEvent, DoNotInfer, EventDescriptor, EventObject, ExtractEvent, InitialContext, InputFrom, IsNever, MetaObject, NonReducibleUnknown, OutputFrom, SingleOrArray, SnapshotEvent, StateValue, TODO, TransitionContextMapper, TransitionContextPatch, TransitionConfigFunction, Values, AnyStateNode, SystemRegistry } from "./types.js";
|
|
4
4
|
import { MachineContext, Mapper } from "./types.js";
|
|
5
5
|
import { LowInfer } from "./types.js";
|
|
6
6
|
import { DoneStateEvent } from "./types.js";
|
|
@@ -229,7 +229,7 @@ type Next_ChoiceTarget<TMeta extends MetaObject> = {
|
|
|
229
229
|
event: any;
|
|
230
230
|
}) => Record<string, unknown>);
|
|
231
231
|
};
|
|
232
|
-
type Next_ChoiceArgs<TContext extends MachineContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], _TCtx = [TContext] extends [never] ? any : TContext> = Parameters<TransitionConfigFunction<TContext, TCurrentEvent, TEvent, EventObject, TActionMap, TActorMap, TGuardMap, TDelayMap, MetaObject, _TCtx>>[0];
|
|
232
|
+
type Next_ChoiceArgs<TContext extends MachineContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], _TCtx extends MachineContext = [TContext] extends [never] ? any : TContext> = Parameters<TransitionConfigFunction<TContext, TCurrentEvent, TEvent, EventObject, TActionMap, TActorMap, TGuardMap, TDelayMap, MetaObject, _TCtx>>[0];
|
|
233
233
|
/**
|
|
234
234
|
* Route config: either a static config object, or a transition-style function
|
|
235
235
|
* that acts as the route's guard and resolver — returning `undefined`/`false`
|
|
@@ -256,7 +256,7 @@ type Next_RouteConfig<TContext extends MachineContext, TEvent extends EventObjec
|
|
|
256
256
|
event: any;
|
|
257
257
|
}) => Record<string, unknown>);
|
|
258
258
|
});
|
|
259
|
-
type Next_ChoiceConfigFunction<TContext extends MachineContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject, _TCtx = [TContext] extends [never] ? any : TContext> = (args: Next_ChoiceArgs<TContext, TCurrentEvent, TEvent, TActionMap, TActorMap, TGuardMap, TDelayMap, _TCtx>) => Next_ChoiceTarget<TMeta>;
|
|
259
|
+
type Next_ChoiceConfigFunction<TContext extends MachineContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject, _TCtx extends MachineContext = [TContext] extends [never] ? any : TContext> = (args: Next_ChoiceArgs<TContext, TCurrentEvent, TEvent, TActionMap, TActorMap, TGuardMap, TDelayMap, _TCtx>) => Next_ChoiceTarget<TMeta>;
|
|
260
260
|
export type Next_StateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TDelays extends string, TTag extends string, _TOutput, TEmitted extends EventObject, TMeta extends MetaObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TInput = Record<string, unknown> | undefined, TInputMap extends Record<string, unknown> = Record<string, unknown>, TSystemRegistry extends SystemRegistry = SystemRegistry, TChildOutput = unknown> = Next_RegularStateNodeConfig<TContext, TEvent, TDelays, TTag, _TOutput, TEmitted, TMeta, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TInput, TInputMap, TSystemRegistry, TChildOutput> | Next_ChoiceStateNodeConfig<TContext, TEvent, TTag, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>;
|
|
261
261
|
interface Next_ChoiceStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TTag extends string, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> {
|
|
262
262
|
contextSchema?: StandardSchemaV1;
|
|
@@ -409,7 +409,7 @@ interface Next_RegularStateNodeConfig<TContext extends MachineContext, TEvent ex
|
|
|
409
409
|
}
|
|
410
410
|
export type Next_TransitionConfigOrTarget<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject> = undefined | {
|
|
411
411
|
target?: string | string[];
|
|
412
|
-
context?:
|
|
412
|
+
context?: TransitionContextPatch<TContext> | TransitionContextMapper<TContext, TExpressionEvent, TEvent, TActionMap, TActorMap, TGuardMap, TDelayMap>;
|
|
413
413
|
description?: string;
|
|
414
414
|
reenter?: boolean;
|
|
415
415
|
meta?: TMeta;
|
|
@@ -419,7 +419,7 @@ export type Next_TransitionConfigOrTarget<TContext extends MachineContext, TExpr
|
|
|
419
419
|
}) => Record<string, unknown>);
|
|
420
420
|
} | {
|
|
421
421
|
to?: TransitionConfigFunction<TContext, TExpressionEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
422
|
-
context?:
|
|
422
|
+
context?: TransitionContextPatch<TContext> | TransitionContextMapper<TContext, TExpressionEvent, TEvent, TActionMap, TActorMap, TGuardMap, TDelayMap>;
|
|
423
423
|
description?: string;
|
|
424
424
|
reenter?: boolean;
|
|
425
425
|
meta?: TMeta;
|
|
@@ -1710,24 +1710,25 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
1710
1710
|
* transition.
|
|
1711
1711
|
*/
|
|
1712
1712
|
function getTransitionResult(transition, snapshot, event, actorScope, options) {
|
|
1713
|
+
const transitionArgs = {
|
|
1714
|
+
context: snapshot.context,
|
|
1715
|
+
event,
|
|
1716
|
+
output: getEventOutput(event),
|
|
1717
|
+
value: snapshot.value,
|
|
1718
|
+
children: snapshot.children,
|
|
1719
|
+
system: actorScope.system,
|
|
1720
|
+
parent: actorScope.self._parent,
|
|
1721
|
+
self: actorScope.self,
|
|
1722
|
+
actions: snapshot.machine.implementations.actions,
|
|
1723
|
+
actorSources: snapshot.machine.implementations.actorSources,
|
|
1724
|
+
guards: snapshot.machine.implementations.guards,
|
|
1725
|
+
delays: snapshot.machine.implementations.delays
|
|
1726
|
+
};
|
|
1713
1727
|
if (transition.to) {
|
|
1714
1728
|
const actions = [];
|
|
1715
1729
|
const internalEvents = [];
|
|
1716
1730
|
const enqueue = createTransitionEnqueue(actorScope, actions, internalEvents, false, options?.resolveActions ?? true);
|
|
1717
|
-
const res = transition.to(
|
|
1718
|
-
context: snapshot.context,
|
|
1719
|
-
event,
|
|
1720
|
-
output: getEventOutput(event),
|
|
1721
|
-
value: snapshot.value,
|
|
1722
|
-
children: snapshot.children,
|
|
1723
|
-
system: actorScope.system,
|
|
1724
|
-
parent: actorScope.self._parent,
|
|
1725
|
-
self: actorScope.self,
|
|
1726
|
-
actions: snapshot.machine.implementations.actions,
|
|
1727
|
-
actorSources: snapshot.machine.implementations.actorSources,
|
|
1728
|
-
guards: snapshot.machine.implementations.guards,
|
|
1729
|
-
delays: snapshot.machine.implementations.delays
|
|
1730
|
-
}, enqueue);
|
|
1731
|
+
const res = transition.to(transitionArgs, enqueue);
|
|
1731
1732
|
const targets = res?.target ? resolveTarget(transition.source, toArray(res.target)) : undefined;
|
|
1732
1733
|
// Resolve input for .to transitions
|
|
1733
1734
|
const resolvedInput = typeof transition.input === 'function' ? transition.input({
|
|
@@ -1751,9 +1752,10 @@ function getTransitionResult(transition, snapshot, event, actorScope, options) {
|
|
|
1751
1752
|
event,
|
|
1752
1753
|
output: getEventOutput(event)
|
|
1753
1754
|
}) : transition.input;
|
|
1755
|
+
const resolvedContext = typeof transition.context === 'function' ? transition.context(transitionArgs) : transition.context;
|
|
1754
1756
|
return {
|
|
1755
1757
|
targets: transition.target,
|
|
1756
|
-
context:
|
|
1758
|
+
context: resolvedContext,
|
|
1757
1759
|
reenter: transition.reenter,
|
|
1758
1760
|
actions: undefined,
|
|
1759
1761
|
internalEvents: undefined,
|
|
@@ -4442,7 +4444,10 @@ exports.ProcessingStatus = ProcessingStatus;
|
|
|
4442
4444
|
exports.STATE_DELIMITER = STATE_DELIMITER;
|
|
4443
4445
|
exports.TimeoutError = TimeoutError;
|
|
4444
4446
|
exports.XSTATE_INIT = XSTATE_INIT;
|
|
4447
|
+
exports.XSTATE_STOP = XSTATE_STOP;
|
|
4448
|
+
exports.builtInActions = builtInActions;
|
|
4445
4449
|
exports.checkStateIn = checkStateIn;
|
|
4450
|
+
exports.cloneMachineSnapshot = cloneMachineSnapshot;
|
|
4446
4451
|
exports.createActor = createActor;
|
|
4447
4452
|
exports.createAsyncLogic = createAsyncLogic;
|
|
4448
4453
|
exports.createCallbackLogic = createCallbackLogic;
|
|
@@ -4456,6 +4461,7 @@ exports.createLogic = createLogic;
|
|
|
4456
4461
|
exports.createMachineSnapshot = createMachineSnapshot;
|
|
4457
4462
|
exports.createObservableLogic = createObservableLogic;
|
|
4458
4463
|
exports.createSubscriptionLogic = createSubscriptionLogic;
|
|
4464
|
+
exports.createTransitionEnqueue = createTransitionEnqueue;
|
|
4459
4465
|
exports.evaluateCandidate = evaluateCandidate;
|
|
4460
4466
|
exports.formatRouteTransitions = formatRouteTransitions;
|
|
4461
4467
|
exports.formatTransition = formatTransition;
|