I was trying to connect the state machine with some unit testing (Fluint and FUnit) and came to the following problem: whenever i want to see if a given state was 'changed' I allways see the previous state. Here is my code:
<state name={STATE_REGISTERING} changed={REGISTER_TRY}>
<transition action={ACTION_REGISTER_OK} target={STATE_REGISTERED}/>
</state>
So I make a listener for REGISTER_TRY and in that function I want to check the state if it's STATE_REGISTERED. But it's not, and the reason is that in StateMachine class:
// Send the notification configured to be sent when this specific state becomes current
if ( nextState.changed ) sendNotification( currentState.changed, data );
// Notify the app generally that the state changed and what the new state is
sendNotification( CHANGED, currentState, currentState.name );
In my code the CHANGED notification upadtes the status variable(I listen for this in a Mediator)
So you see, the notification with my data is coming sooner, and the notification of the state changed is coming later, so my status variable is changing later, so I allways see the previous state first.
So what I did, I replaced the 2 lines with each other, and now my state changes first, then comes my notification where I can check the state...
// Notify the app generally that the state changed and what the new state is
sendNotification( CHANGED, currentState, currentState.name );
// Send the notification configured to be sent when this specific state becomes current
if ( nextState.changed ) sendNotification( currentState.changed, data );
Is it an error or am I doing something the wrong way?