You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/actions.md
+15-13Lines changed: 15 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,3 @@
1
-
(actions)=
2
-
3
1
# Actions
4
2
5
3
@@ -34,6 +32,9 @@ For each defined state, you can register `on_enter_<state>` and `on_exit_<state>
34
32
35
33
-`on_exit_<state_identifier>(event_data)`
36
34
35
+
36
+
The initial {ref}`state` is entered when the machine starts and the corresponding actions `on_enter_state` or `on_enter_<state>` are called if defined.
37
+
37
38
## Event actions
38
39
39
40
For each event, you can register `before_<event>` and `after_<event>`
@@ -82,12 +83,17 @@ Actions and Guards will be executed in the following order:
82
83
-`after_transition(event_data)`
83
84
84
85
86
+
(dynamic-dispatch)=
85
87
## Dynamic dispatch
86
88
87
89
python-statemachine implements a custom dispatch mechanism on all those available Actions and
88
90
Guards, this means that you can declare an arbitrary number of `*args` and `**kwargs`, and the
89
-
library will to it's best to match your method signature of what's expect to receive with the
90
-
provided arguments.
91
+
library will match your method signature of what's expect to receive with the provided arguments.
92
+
93
+
This means that if on your `on_enter_<state>()` or `on_execute_<event>()` method, you also
94
+
need to know the `source` ({ref}`state`), or the `event` ({ref}`event`), or access a keyword
95
+
argument passed with the trigger, just add this parameter to the method and It will be passed
96
+
by the dispatch mechanics.
91
97
92
98
In other words, if you implement a method to handle an event and don't declare any parameter,
93
99
you'll be fine, if you declare an expected parameter, you'll also be covered.
@@ -110,7 +116,8 @@ For your convenience, all these parameters are available for you on any Action o
110
116
111
117
-`transition`: The {ref}`Transition` instance that was activated by the {ref}`Event`.
112
118
113
-
So, you can implement Actions and Guards like these:
119
+
So, you can implement Actions and Guards like these, but this list is not exaustive, it's only to give you a few examples... any combination of parameters will work, including extra parameters
120
+
that you may inform when triggering an {ref}`event`:
0 commit comments