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

Show Posts

| * |

  Show Posts
Pages: [1]
1  Announcements and General Discussion / General Discussion / How can I trace the Transition Action called during a state machine transition? on: August 08, 2009, 07:42:24
Take the following state machine code example
:
<state name={STATE_ONE}
entering={ENTER_STATE_ONE}
exiting={EXIT_STATE_ONE}
changed={CHANGED_STATE_TWO}>
<transition action={ACTION_FOO} target={STATE_TWO}/>
</state>

<state name={STATE_TWO}
entering={ENTER_STATE_TWO}
exiting={EXIT_STATE_TWO}
changed={CHANGED_STATE_TWO}>
<transition action={ACTION_BAR} target={STATE_TWO}/>
</state>


How can I trace specifically which transition action caused the state transition?

In other, words how can find out if it was ACTION_FOO or ACTION_BAR that caused a transition to STATE_TWO?

Another way of putting it. Assume ENTER_STATE_TWO is mapped to the following command:

:
package com.app.controller
{
import com.app.ApplicationFacade;

import org.puremvc.as3.interfaces.INotification;
import org.puremvc.as3.patterns.command.SimpleCommand;

public class EnteringStateTwoCommand extends SimpleCommand
{
override public function execute(note:INotification):void
{
                    // Entering guard code goes here
}
}
}

Assume somewhere in my code there are the following notifications sent:
:
sendNotification(StateMachine.ACTION, null, ACTION_FOO);

...

sendNotification(StateMachine.ACTION, null, ACTION_BAR);



How can I query which specific ACTION brought me to this state when I am in the EnteringStateTwoCommand command? Or anywhere else in the state machine event chain for that matter. Theoretically it could be either ACTION_FOO or ACTION_BAR in the above command.

Maybe I overlooked something but what is the syntax to get the actual value of the transition action itself during a state machine notification? Is it

:
note.getType()
Maybe it isn't possible to get the ACTION in this command? Where and when can I find out about the transition action? I am trying to debug the logic flow in my app's state machine implementation.
2  Announcements and General Discussion / General Discussion / Strongly Typed Notifications and Commands? on: August 06, 2009, 09:39:44
If there a useful convention around this or any modules that would enable this?

The idea is as follows. I use the Notifications to shuttle various data objects (VOs) around the app. Sometimes I kind of use the command as a traditional function. I provide an input data object and then return a certain result or open a specific view. The kind of data doesn't seem to logically fit in a Proxy because it is very fleeting. It only really needs exist temporarily so it makes sense to pass the data structure around the app using Notifications. However, it would be nice to get some code hinting when I construct my sendNotification() calls in Flex Builder. And apart from that I would like to have a consistent way of formulating my commands to either return an error notification if the command note.getBody() receives the wrong type of object or else complete successfully.

Perhaps in the Facade there should be a way to register a specific data type that a command can receive in note body parameter.

Are there any common guidelines around this? Am I just not thinking deeply enough about the Proxy pattern?
3  Announcements and General Discussion / Architecture / Asynchronous and State Machine on: August 04, 2009, 02:02:41
I am having a difficult time getting my head around asynchronous remote service calls.

I think I just need a simple code demo to really get the point. I have reviewed many if not all the Actionscript code samples and haven't found a clear example.

This is the behavior I am looking for

Click a button in a view, trigger an action and notification that calls a proxy and generates a remote service call.

Once the remote service call result event returns, send data back to the application and change one or more views including the view where I clicked the button.

Other variations, on the theme:

Click button --> Make Service Call --> Receive Data back --> Transition to different and updated view.

If no data is returned then provide an alert and don't transition to new view.

And finally, I should add one more requirement. In some cases the service call should be a blocking call. In that while the service is communicating with the server, the view should not be interactive. Perhaps, even display a "processing" view while waiting for the remote service to complete.

Is this best handled by a service proxy and then use the state machine to manage the transitions between views in the app? Is there any any code examples that clearly demonstrate passing around data with the StateMachine?

I have looked at the async command but that doesn't seem to do what I want.

I feel like I have a good grasp of the other features of pureMVC, it is just this asynchronous data transfer that is tripping me up.
4  Announcements and General Discussion / Architecture / State Machine and circular references on: August 04, 2009, 01:18:09
Hi, first time post. Been trying to wrap my head around the state machine module.

My question involves circular references within a state machine.

Is the following state machine code valid?

:
var fsm:XML =
<fsm initial={STATE_ONE}>
<state name={STATE_ONE}
entering={ENTER_STATE_ONE}
exiting={EXIT_STATE_ONE}
changed={CHANGED_STATE_ONE}>
<transition action={ACTION_MOVE_TO_STATE_TWO} target={STATE_TWO}/>
</state>

<state name={STATE_TWO}
entering={ENTER_STATE_TWO}
exiting={EXIT_STATE_TWO}
changed={CHANGED_STATE_TWO}>
<transition action={ACTION_MOVE_TO_STATE_ONE} target={STATE_ONE}/>
<transition action={ACTION_MOVE_TO_STATE_TWO} target={STATE_TWO}/>
<transition action={ACTION_MOVE_TO_STATE_THREE} target={STATE_THREE}/>
</state>

<state name={STATE_THREE}
entering={ENTER_STATE_THREE}
exiting={EXIT_STATE_THREE}
changed={CHANGED_STATE_THREE}>
<transition action={ACTION_MOVE_TO_STATE_TWO} target={STATE_TWO}/>
</state>

</fsm>;

The key point being that any state can transition to STATE_TWO, even when you are in State two. I have duplicated the transition action to STATE_TWO across all three states. The idea here as that you can go into STATE_TWO from anywhere, but certain trajectories require STATE_TWO. For example, if I understand this correctly the above state machine would prohibit a direct jump from STATE_ONE to STATE_THREE, without first passing through STATE_TWO.

The context here is something like a modal view in my application. Imagine STATE_TWO being a modal dialog of some sort that can be transitioned in and out of, from anywhere in the application.

Is there any problems with my logic here? Does duplicating action ACTION_MOVE_TO_STATE_TWO introduce any ambiguities or unanticipated gotchas?

Would it be better to not duplicate the actions at all?

For example would the following code be better from a best practices point of view?

:
var fsm:XML =
<fsm initial={STATE_ONE}>
<state name={STATE_ONE}
entering={ENTER_STATE_ONE}
exiting={EXIT_STATE_ONE}
changed={CHANGED_STATE_ONE}>
<transition action={ACTION_MOVE_TO_STATE_TWO_FROM_ONE} target={STATE_TWO}/>
</state>

<state name={STATE_TWO}
entering={ENTER_STATE_TWO}
exiting={EXIT_STATE_TWO}
changed={CHANGED_STATE_TWO}>
<transition action={ACTION_MOVE_TO_STATE_ONE_FROM_TWO} target={STATE_ONE}/>
<transition action={ACTION_MOVE_TO_STATE_TWO_FROM_TWO} target={STATE_TWO}/>
<transition action={ACTION_MOVE_TO_STATE_THREE_FROM_TWO} target={STATE_THREE}/>
</state>

<state name={STATE_THREE}
entering={ENTER_STATE_THREE}
exiting={EXIT_STATE_THREE}
changed={CHANGED_STATE_THREE}>
<transition action={ACTION_MOVE_TO_STATE_TWO_FROM_THREE} target={STATE_TWO}/>
</state>

</fsm>;

Note that now there is no duplication of the transition actions. In someways the the first variation seems simpler, because I can have a small listing of transitions that are redundant but clear meaning of intention.

ACTION_MOVE_TO_STATE_TWO

always means what it says no matter what state I am in.

In the latter state machine I would have to determine ahead of time in my code and pick from three possible transitions

ACTION_MOVE_TO_STATE_TWO_FROM_ONE
ACTION_MOVE_TO_STATE_TWO_FROM_TWO
ACTION_MOVE_TO_STATE_TWO_FROM_THREE

depending on what state I was in.

Hopefully my question is clear. Any thoughts, or guidance?

By the way, thanks Cliff for all the work you have put into pureMVC. It has been a useful tool.
Pages: [1]