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
For small state machines the current API Design works good, but in my case I has 8 States and ~15 Transitions that all need some sort of transitions guards/validation and hooks (pre/after).
This bloats the state machine class extremely to an unreadable state. It needs way to much if clauses to check $from and $to for all the possibilities.
Proposal
I introduced classes per Transition to help organise all the logic. Each class defines for which state machines, from states and to states its applicable. These classes are registered to the state machine which selects the first applicable Transition class for the transition to be run.
The transition class itself has methods for validation, pre-hook and a post-hook.
The StateMachine class it self needs just a little modifications an supports the 'old' way of managing transitions as well.
The main points are the transitionClasses array and some additions to the transitionTo method, which now selects the first applicable Transition class and runs its hooks after the main StateMachine hooks.
Summary
For small state machines the current API Design works good, but in my case I has 8 States and ~15 Transitions that all need some sort of transitions guards/validation and hooks (pre/after).
This bloats the state machine class extremely to an unreadable state. It needs way to much if clauses to check $from and $to for all the possibilities.
Proposal
I introduced classes per Transition to help organise all the logic. Each class defines for which state machines, from states and to states its applicable. These classes are registered to the state machine which selects the first applicable
Transition
class for the transition to be run.The transition class itself has methods for validation, pre-hook and a post-hook.
The
StateMachine
class it self needs just a little modifications an supports the 'old' way of managing transitions as well.The main points are the
transitionClasses
array and some additions to thetransitionTo
method, which now selects the first applicableTransition
class and runs its hooks after the mainStateMachine
hooks.If there is interest in this kind of feature I could provide a PR
The text was updated successfully, but these errors were encountered: