Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Welcome, Guest. Please login or register.
August 19, 2017, 08:01:51 AM
Home Help Search Login Register
News: Please DM @puremvc on Twitter to gain forum access. Spambots are why we can't have nice things.
Pages: [1]
Print
Author Topic: Need some State Machine advice  (Read 3838 times)
Bonky
Newbie
*
Posts: 3


View Profile Email
« on: May 09, 2013, 03:23:47 PM »

Background:
I am using Haxe PureMVC with State Machine to build a web application (deployed to JavaScript). I am integrating it with a government-mandated UI framework that uses a JQuery-powered tabbed interface. The application has 4 tabs and I have created an application state for each of these tabs. The tab interface (EasyTabs) has a built-in event system which helps the integration. Clicking a tab fires an event, and if the handler for the event (in my Haxe app) returns true, only then will the tab view change.

Problem:
I want that handler to send a StateMachine.CHANGE notification and let the "Entering" command for the next tab state to do the necessary checks that ultimately cancel or approve the state transition. I'm just not sure how to send the notification and use the results of that action to return true or false so that EasyTabs gets the Boolean it requires.

Here's my current code:
Code:
var tabs=new JQuery("#theTabs");
tabs.bind("easytabs:before",tabHooksHandler); //setup the handler for the tab event

private function tabHooksHandler(e:Dynamic,clicked:Dynamic,targetPanel:Dynamic,settings:Dynamic):Bool{
switch(targetPanel.selector){
case"#tab1":
                    sendNotification ( StateMachine.ACTION, null, Main.ACTION_GOTO_FILE );
case"#tab2":
                    sendNotification ( StateMachine.ACTION, null, Main.ACTION_GOTO_TREES );
case"#tab3":
                    sendNotification ( StateMachine.ACTION, null, Main.ACTION_GOTO_MAP );
case"#tab4":
                    sendNotification ( StateMachine.ACTION, null, Main.ACTION_GOTO_CALCULATOR );
}
return true; //this lets EasyTabs complete the switch of tabs. If the StateMachine does a cancel, I would want this to return false.
}
So, could I use a callback somehow? Suggestions would be appreciated, thanks!
Logged
Bonky
Newbie
*
Posts: 3


View Profile Email
« Reply #1 on: May 09, 2013, 03:48:32 PM »

I think if I check the active state right before I do the return it will work. Didn't know this would be that easy. Smiley I already have an ApplicationStateProxy I am using.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2870



View Profile WWW
« Reply #2 on: May 10, 2013, 07:04:41 AM »

With the State Machine utility, state is a running thing that is announced. Actors don't generally 'check' the state, but instead respond to state changes as they are sent. If you are persisting the application state represented by the state machine in a proxy, then you should rethink your design. Things should never be confused about the application state, but instead always be organized to represent the current state.

To your point with canceling the tabs, you could likely capture the event, cancel it, and dispatch a different event that your mediator hears and sends off the notification to the state machine. That would trigger the guard logic that may cancel the action. Or it might let the action go through and a CHANGED note goes out that the mediator hears and it changes the tab.

-=Cliff>

Logged
Pages: [1]
Print
Jump to: