-
Notifications
You must be signed in to change notification settings - Fork 1
Transitions
Transition is the way to change state of State Machine.
In general, Transition consists of:
- Trigger, type of Event that activates Transition,
- Source, a State that transition is coming from,
- Target, a State that transition is coming to,
- Guard, logic that decides if Transition should happen,
- Effect, logic that is run when Transition happens.
There are three types of Transitions:
- 'Regular' Transition that moves from one State to another,
- Internal Transition that has no Target State,
- Default Transition that has no explicit Trigger Event.
Transitions are always defined on the level of Source State.
Single State can have multiple Transitions triggered by various Event types. Moreover, there can be multiple Transitions triggered by the same Event type.
UML notation of Transition:
stateDiagram-v2
Source --> Target : Trigger [Guard] / Effect
Equivalent Stateflows notation of Transition:
/* fragment of State Machine definition */
.AddState("Source", b => b
.AddTransition<Trigger>("Target", b => b
.AddGuard(async c => true)
.AddEffect(async c => {})
)
)
.AddState("Target")
Using lambda style means that logic parts within Transition (Guard, Effect) are implemented directly in State Machine as lambdas.
/* fragment of State Machine definition */
.AddState<Source>(b => b
.AddTransition<Trigger, TriggerTransition, Target>()
)
.AddState<Target>()
Using typed style means that logic parts within Transition (Guard, Effect) are implemented as separate classes and referenced using typed overloads of
Add*
methods.
There are two places where logic can be injected into Transition of any type, both optional:
-
Guard:
- determines if Transition should happen,
- must return bool value,
- lack of Guard on Transition means that there is an implicit true-returning Guard,
- should not cause any side effect,
- can be called multiple times on multiple Transitions, even the ones which won't eventually happen.
-
Effect:
- is called when Transition happens, after OnExit of Source State and before OnEntry of Target State,
- can cause side effects.
The way of adding logic to Transition varies depending on used declaration style. For more details, refer to Guards or Effects, respectively.
Topic is explained in Evaluation of Transitions.
Home page Support Code licensed under an MIT-style License. Documentation licensed under CC BY 4.0. © by Mikołaj Milewski, 2025
Overview
Installation
Behaviors
State Machines
Building blocks
States
State
Composite State
Orthogonal State
Final State
Pseudostates
Choice
Junction
Fork
Join
Transitions
Transition
Default Transition
Internal Transition
Concepts
Evaluation of Transitions
Activities
Building blocks
Nodes
Action Node
Decision Node
Merge Node
Initial Node
Final Node
Input Node
Output Node
Fork Node
Join Node
Accept Event Action Node
Send Event Action Node
Data Store Node
Structured Activity Node
Iterative Activity Node
Parallel Activity Node
Flows
Data Flow
Control Flow
Concepts
Implicit fork and join
Actions