statemachine icon indicating copy to clipboard operation
statemachine copied to clipboard

Enhancement: Extension method to return state that handled event

Open prlaba opened this issue 7 years ago • 2 comments

Appccelerate’s base extension methods are a great debugging tool. I use them all the time to help debug new state machines or state machines being modified or enhanced.

In a hierarchical state machine with deeply nested substates, it can be quite difficult to debug issues where multiple substates respond to the same event (with or without guards).

For example, suppose C is a substate of B, B is a substate of A, and all have an event handler with guard for event E. If E is fired from state C and C’s guard fails, then B’s E event handler is called. If B’s guard fails, then A’s E event handler is called.

Because each state’s event handler guard can be based on different conditions, and result in different actions/transitions when the guard succeeds, it can be difficult to trace the state machine’s behavior in response to event E.

It would be valuable if you could provide a new base extension method, HandledIn (or some suitably named method), that returns the state that ultimately handled the most recently fired event. In the above example, if event E is fired from state C, and state C and B’s event handlers’ guards failed, but state A’s event handler’s guard succeeded, then HandledIn would return state A. If state A’s event handler’s guard also failed, then HandledIn would return null (unhandled event).

Thanks,

Paul

prlaba avatar May 06 '18 15:05 prlaba

Hi Paul

Nice idea. Maybe it would be better to add this information in the transition context passed to the extension method, or as a new parameter to this method. I'll have to see how it applies in the code.

Cheers, Urs

ursenzler avatar May 08 '18 11:05 ursenzler

Thanks Urs, whatever implementation works best to identify the state that handled the event is fine by me.

Paul

prlaba avatar May 08 '18 11:05 prlaba