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] 2
Print
Author Topic: How to properly manage application states  (Read 17927 times)
sinosoidal
Jr. Member
**
Posts: 15


View Profile Email
« on: January 09, 2009, 08:28:15 »

Hi,

I'm building a complex application in flex with puremvc which envolves the managment of several sections with subsections, etc.

For example, when I want to switch between sections I need to have sure that the actual section has nothing to save.

Other case is for example when I'm in a following section and I use data of that section as input of the target section and then i want to get back to the original section.

Basicly what i need is somekind of state manager to handle confirm dialogs and switch between sections.

This must be a very common problem so I would love to hear the best way of doing this taking advantages of the pure mvc framework.

Thanks in advance,

With my best regards,

Nuno Santos
Logged
Jason MacDonald
Sr. Member
****
Posts: 243


View Profile Email
« Reply #1 on: January 09, 2009, 10:49:01 »

Try this http://forums.puremvc.org/index.php?topic=859.0
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #2 on: January 09, 2009, 04:37:58 »

I didn't follow jasonmac's link on my phone, so not sure if this is redundant, but look at the StateMachine utility. There's a writup on the front page about it at the moment.

-=Cliff>
Logged
Jason MacDonald
Sr. Member
****
Posts: 243


View Profile Email
« Reply #3 on: January 09, 2009, 08:31:43 »

I didn't follow jasonmac's link on my phone, so not sure if this is redundant, but look at the StateMachine utility. There's a writup on the front page about it at the moment.

-=Cliff>
That's what I linked to;)
« Last Edit: January 13, 2009, 07:22:09 by Jason MacDonald » Logged
sinosoidal
Jr. Member
**
Posts: 15


View Profile Email
« Reply #4 on: January 12, 2009, 11:48:53 »

Hi,

I have tried the State Machine and it's seems a powerfull and unviesal way of defining states. Now i have the following question:

I have 8 sections which represent 8 possible main states. When i'm in a state i can go to other 7. This is at least something like 56 possible states.

What I want to know is if there is any way of bypassing the description of some basic transitions.

Example:

I have the Section 1, 2 and 3. From section one i can go to section 2 and 3. If i'm in section 2, i can go to section 1 and 3, etc.

Thanks,

Nuno
Logged
Neil Manuell
Courseware Beta
Sr. Member
***
Posts: 109


View Profile Email
« Reply #5 on: January 12, 2009, 12:14:00 »

Have a look at this post:
http://revisual.co.uk/?p=237
This was my original version of the StateMachine, it is linear, and so is probably more what you are looking for, though you won't be able to cancel your transitions in it.

My advise is that you'ld be better off using the current version (hosted here in the manifold), and declare the seven different actions for each state, as you will have more control, and better future-proofing (you will only have to type it out once, after all).

cheers:~)
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #6 on: January 12, 2009, 03:50:08 »

Sounds like the job of a design tool that could create the states and let you visually connect them. You might have a 'connect to all button'.

A nice addition for Nick Collins' PureMVC Studio perhaps... (wink, wink, nudge, nudge)

Are you sure these sections are discrete states? If, for instance, they are sections of a catalog, then perhaps they aren't all discrete states at all. Perhaps they are all the same state and in that state, you display the items for sale in the current category, and though the window dressing may be different, the state 'shopping' is the same. And perhaps shopping can transition to itself. and going frome one section to another merely has a transition from shopping to shopping. The exiting for shopping hides the current category and the entering displays the ne category.

This reentrance may be prohibited due to the design of the StateMachine to prevent feedback. I'll have to check.if so we may want to rev the StateMachine to allow this.

-=Cliff>
Logged
Neil Manuell
Courseware Beta
Sr. Member
***
Posts: 109


View Profile Email
« Reply #7 on: January 13, 2009, 02:45:35 »

at the moment, a transition to self is not accepted, and will fail silently.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #8 on: January 13, 2009, 08:28:11 »

What do you think about this Neil? I think we should we allow self re-entrant states. In fact it may be my fault that it doesn't currently. I do remember hovering on that part, flipping and flopping on whether it would be good or bad. I don't remember if I added the check for it or not :) If I did, oops, my bad. Otherwise, I vote for its removal.

-=Cliff>
Logged
sinosoidal
Jr. Member
**
Posts: 15


View Profile Email
« Reply #9 on: January 14, 2009, 04:55:53 »

Hi guys,

Thanks for your support.

I don't have a concrete position about transitions to the same state. However I have a new question:

Imagine the following situation. I'm in state A and I want to go to state B. On the exiting actions of A I have a method that verify if there is something to save. If so, a dialog appears asking user input.

I don't want to go to state B while the user has not given its input.

For that i had to cancel the transition by the time of the exiting notification handling. But I don't have a way of resuming the transition without an external hack.

Is there any clean way of doing this?

Thank you very much,

With my best regards,

Nuno Santos
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #10 on: January 14, 2009, 07:12:10 »

You should be able to have that exiting note trigger an AsyncMacroCommand that doesn't complete until the data is collected. This should hold off the state change.

Keep in mind, this *should* work. I've been meaning to fiddle with these two utils in conjunction but have been too swamped.I hope to investigate this scenario and others in a demo soon. Keep me in the loop on your findings.

-=Cliff>
Logged
sinosoidal
Jr. Member
**
Posts: 15


View Profile Email
« Reply #11 on: January 14, 2009, 07:15:27 »

Hi Cliff,

Thanks for you reply.

I have never used AsyncMacroCommand. Can you give a quick example on how to achieve it?

In the meanwhile i'll try to sort it out by myself.

And yes, I'll keep you updated.

Thanks,

Nuno

Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #12 on: January 14, 2009, 07:48:15 »

Have a look at the Sequential demo. It shows how a mix of normal ICommands and IAsyncCommands as subcommands of an AsyncMacroCommand.

It uses a timer to simulate the async activities.

-=Cliff>
Logged
sinosoidal
Jr. Member
**
Posts: 15


View Profile Email
« Reply #13 on: January 14, 2009, 10:45:16 »

Hi Cliff,

I have tried the AsyncCommand but this is not solving the problem as the transition is being executed. Please check what i'm doing:

In facade:

registerCommand(EFFECT_SAVE_CONFIRM, EffectSaveConfirmAsyncCommand);

In EffectSaveConfirmAsyncCommand definition

:
{
    public static const CANCEL_EFFECT:String = 'EffectSaveConfirmAsyncCommand.cancelEffect';
    public static const SAVE_EFFECT:String = 'EffectSaveConfirmAsyncCommand.saveEffect';
    public static const LOAD_EFFECT:String = 'EffectSaveConfirmAsyncCommand.loadEffect';
   
        override public function execute ( note:INotification ) : void
        {
        var confirmPopUpMediator:ConfirmPopUpMediator = PopUpManager.openPopUpWindow(ConfirmPopUp,ConfirmPopUpMediator) as ConfirmPopUpMediator;
                confirmPopUpMediator.confirmPopUp.type = ConfirmPopUp.CANCELNOYES;
                confirmPopUpMediator.confirmPopUp.title = 'SAVE EFFECT';               
                confirmPopUpMediator.confirmPopUp.message = "Current effect has been changed. Do you want to save the changes?";
                confirmPopUpMediator.confirmPopUp.closeHandler = closeHandler;
               
           
        }
       
        private function closeHandler(event:EventWithParameter):void
        {
            if (event.data == ConfirmPopUp.YES)
            {         
                sendNotification(SAVE_EFFECT);
            }
            else if (event.data == ConfirmPopUp.CANCEL)
            {
                sendNotification(CANCEL_EFFECT);                                           
            }
            else
            {
                sendNotification(LOAD_EFFECT);                                     
            }

            // commandComplete();    this gives error if not commented
         }
    }

In FSM definition:

<state name={Main.STATE_EFFECT_EDITOR} entering={ApplicationMediator.SHOW_EFFECT_EDITOR} exiting={ApplicationFacade.EFFECT_SAVE_CONFIRM}>
                   <transition action={EffectEditor.RETURN_TO_EFFECTS_WORKBENCH} target={Main.STATE_EFFECTS_WORKBENCH}/>
                   <transition action={EffectEditor.RETURN_TO_TIMELINE_EDITOR} target={Main.STATE_TIMELINE_EDITOR}/>
               </state>

Thanks,

With my best regards,

Nuno Santos

Logged
gjastrab
Jr. Member
**
Posts: 18



View Profile WWW Email
« Reply #14 on: January 14, 2009, 12:55:47 »

Could use seeing more of your code to comment on the issue, Nuno.  commandComplete should not be causing an error if the EffectSaveConfirmAsyncCommand extends AsyncCommand.

Cliff, I don't think this is going to hold off the state change...  The scope of the EffectSaveConfirmAsyncCommand::execute() function is going to complete and let state machine fall through before the user has done something to cause the closeHandler to be fired.
Logged
Pages: [1] 2
Print