Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: StateMachine Global Transitions  (Read 6180 times)
orensol
Newbie
*
Posts: 6


View Profile Email
« on: February 07, 2010, 04:41:15 »

Hi all,

I stumbled upon a use case where a global transition in the StateMachine would be useful, but I think there's no way to implement it right now other than hardcoding the same transition to each and every state individually.

For example, if I have an "APPLICATION_EXCEPTION" state, to which I want to be able to make a transition from all states.

I'd like to know if there's a way to do it which I am missing, and if there's no way to do it, it might be useful in an upcoming version...

Thanks,
Oren
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: February 07, 2010, 10:25:21 »

Currently there is only one way, and that is to define it in all the states that use it. I agree it would be useful to have another way of handling 'global' transitions.

From the standpoint of the utility, there are two ways I can think of at the moment for dealing with it.

1) We could modify the StateMachine itself, adding some new logic and/or action type. 
2) We could modify the FSMInjector and the FSM xml schema.

I think the latter might be the best way of handling it. No reason to monkey with what works in the StateMachine itself. Instead, if we had a way of expressing to the FSMInjector 'by the way, put *this* transition inside every state' we'd be duplicating what we can already do manually but consider laborious.

So an FSM definition might look like:

:
            var fsm:XML =
            <fsm initial={FSMConstants.STARTING}>
           
                <!-- GLOBAL TRANSITIONS (added to every state) -->
                <global>
                    <transition action={FSMConstants.FAILED} target={FSMConstants.FAILING}/>
                </global>

                <!-- STARTUP THE SHELL -->
                <state name={FSMConstants.STARTING}>

                   <transition action={FSMConstants.STARTED}
                                  target={FSMConstants.PLUMBING}/>
                </state>
               
                <!-- PLUMB THE CORES -->                               
                <state name={FSMConstants.PLUMBING} changed={FSMConstants.PLUMB}>

                   <transition action={FSMConstants.PLUMBED}
                                  target={FSMConstants.CONFIGURING}/>
                </state>

                <!-- RETRIEVE, DISTRIBUTE and PARSE CONFIGURATION -->
                <state name={FSMConstants.CONFIGURING} changed={FSMConstants.CONFIGURE}>

                   <transition action={FSMConstants.CONFIGURED}
                                  target={FSMConstants.ASSEMBLING}/>
                   
                </state>
               
                <!-- ASSEMBLE THE VIEW -->
                <state name={FSMConstants.ASSEMBLING} changed={FSMConstants.ASSEMBLE}>

                   <transition action={ShellFacade.ASSEMBLED}
                                  target={FSMConstants.NAVIGATING}/>
                   
                </state>

                <!-- READY TO ACCEPT BROWSER OR USER NAVIGATION -->
                <state name={FSMConstants.NAVIGATING} changed={FSMConstants.NAVIGATE}/>
               
                <!-- REPORT FAILURE FROM ANY STATE -->
                <state name={FSMConstants.FAILING} changed={FSMConstants.FAIL}/>

            </fsm>;

Will put this on the todo list. Or Neil, if you have the time, and would like to take a crack at it?

-=Cliff>
Logged
Pages: [1]
Print