stateless icon indicating copy to clipboard operation
stateless copied to clipboard

What are internal transitions?

Open lexuzieel opened this issue 1 year ago • 3 comments

In the code there are mentions of "internal" transitions as well as of an "initial" transition which supposedly adds an internal transition to the machine. What is the purpose of this and how and when to use them? The README just tells how to define them in code without any examples on how to actually use them.

lexuzieel avatar Jul 22 '22 20:07 lexuzieel

Hi @avixFF, internal transitions are standard state machine concepts, nothing specific to this library. From wikipedia:

Very commonly, an event causes only some internal actions to execute but does not lead to a change of state (state transition). In this case, all actions executed comprise the internal transition. For example, when one types on a keyboard, it responds by generating different character codes. However, unless the Caps Lock key is pressed, the state of the keyboard does not change (no state transition occurs). -- https://en.wikipedia.org/wiki/UML_state_machine#Internal_transitions

You have some examples in example_test.go:

https://github.com/qmuntal/stateless/blob/491b43867de630ac46cfdd5701276f06a51dd60f/example_test.go#L52-L63

qmuntal avatar Jul 24 '22 18:07 qmuntal

Ah yes, I see. So in the context of this library does this mean that internal transitions is basically a way to define multiple independent events with different logic for the same state?

lexuzieel avatar Jul 26 '22 16:07 lexuzieel

internal transitions is basically a way to define multiple independent events with different logic for the same state?

Yep, and those events don't trigger any state transition.

qmuntal avatar Jul 26 '22 17:07 qmuntal