Hi guys,
I just started using the FMS utility, wich I think it´s a incredible utility, and I already got some questions.
I´m making a simple remote login app. The FMS xml is as follow
<fsm initial={App.STATE_READY}>
<state name={App.STATE_READY} entering={LoginPanelMediator.RESET} exiting= LoginPanelMediator.LOGIN_TRY}>
<transition action={LoginPanelMediator.VALID_LOGIN_FORM} target={App.STATE_TRY_LOGIN}/>
</state>
<state name={App.STATE_TRY_LOGIN} entering={ApplicationFacade.CMD_LOGIN}>
<transition action={UserProxy.ACTION_LOGIN_OK} target={App.STATE_USER_HOME}/>
<transition action={UserProxy.ACTION_LOGIN_FAIL} target={App.STATE_READY}/>
</state>
<state name={App.STATE_USER_HOME} >
<transition action={App.ACTION_LOGOUT} target={App.STATE_READY}/>
</state>
</fsm>;
The idea is that simple: Initial state presents the Login Panel. When the user click on button "Log me in!" the app changes to the "Trying to Login" State that shows a wait message. The login is validated on a PHP remote server. If the response is a valid login, change the app state to the "User Home State" wich shows the user´s home screen. If not valid login, goes back to initial state showing the error message sent by the server. The only action that is avaiable on User Home state is the Logout wich brings the user back to the initial state of the app.
Well, that didn´t work as I expected. In fact, I found my self traped in a mase of notifications and actions and commands. And the timming and flow of them.
The problem was that the remote response was being faster that the FSM could change state. In detail: the UserProxy executes the login() method, the response is instantaneous, so it send the UserProxy.ACTION_LOGIN_* notification. But, the app is still in STATE_READY that doesn´t know how to process the action, so the app stops working.
To fix that, I just changed the StateMachine.as, transitionTo() method like this:
// Enter the next State
currentState = nextState;
if ( nextState.entering ) sendNotification( nextState.entering, nextState );
//currentState = nextState;
I don´t know if this right but ... what do you guys think? I really don´t feel confortable changing the Utilitys source but other fixes would need much more coding.
Looking foward for you solutions and comments.