fgmacedo / python-statemachine

Python Finite State Machines made easy.
MIT License
858 stars 84 forks source link

A small question about docs of `Actions` #377

Closed iamgodot closed 1 year ago

iamgodot commented 1 year ago

From here:

This means that if on your onenter() or onexecute() method

What does it mean by on_execute_<event>? Is it a typo or referring to something else?

fgmacedo commented 1 year ago

I tried to say that this is a dynamic name interpolated with the event name.

For each action type you have a generic one, and other that is based or in the event name or in the state name.

For example, given that you have an event named finish and and state completed, something like this finish = pending.to(completed).

You can implement generic or named actions:

  1. on_transition (generic that will be called every time any transition occurs)
  2. on_finish (the on_<event> just for the finish event)
  3. on_enter_state (generic that will be called every time any state is entered)
  4. on_enter_completed ( the on_enter_<state.id> just for the completed state).
iamgodot commented 1 year ago

I tried to say that this is a dynamic name interpolated with the event name.

For each action type you have a generic one, and other that is based or in the event name or in the state name.

For example, given that you have an event named finish and and state completed, something like this finish = pending.to(completed).

You can implement generic or named actions:

  1. on_transition (generic that will be called every time any transition occurs)
  2. on_finish (the on_<event> just for the finish event)
  3. on_enter_state (generic that will be called every time any state is entered)
  4. on_enter_completed ( the on_enter_<state.id> just for the completed state).

Totally, thanks for the explanation. And I suppose it's better to use on_<event>() instead of on_execute_<event>, just like here, to keep things consistently. Let me know if you want this small update on the doc.

fgmacedo commented 1 year ago

Oh, now I see 😃, it is a typo. Yes, thanks!

iamgodot commented 1 year ago

Oh, now I see 😃, it is a typo. Yes, thanks!

You're welcome :)