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: Proxies or ValueObjects  (Read 7184 times)
Helmut Granda
Full Member
***
Posts: 47

Flash Developer.


View Profile WWW Email
« on: May 06, 2009, 02:19:31 »

So far i have been using the value objects to hold data that a proxy can retrieve and dispatch an event when the update has been completed. I have a small dilema. I have to keep somehow the state of the application, the application can have 3 positions and i need to keep track of the position of when it changes or when it has been changed. In this case do I need to write a Proxy that will wrap a VO with this information?
   
It might look like a lot of work at first just to keep track of onee property but I want to be able to do it right with small items to be ready when I need to apply the same concept to a larger scale.
Logged
Helmut Granda
Full Member
***
Posts: 47

Flash Developer.


View Profile WWW Email
« Reply #1 on: May 06, 2009, 03:36:10 »

disregard my question, I am looking at pages 34-46 from the Best Practices document and I believe that explains what I need to know perfectly.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #2 on: May 06, 2009, 03:41:25 »

Sounds like you need to have a look at the StateMachine utility. StateMachine is specifically for keeping the state of your application and controlling the transitions between states. Although the view can be affected by the actions of the StateMachine, it is not just for controlling View states (use Flex for that).

Search and read in forums, and check out the 'Get your FSM on!' article in the news section. The utility is evolving, though with care not to break backward compatibility. Note that the existing demo (StopWatch) works but is not indicative of the appropriate usage yet.

A recent real-world app done using the latest version is http://seaofarrows.com. Check out the implementation at http://seaofarrows.com/srcview.

The Sea of Arrows Music Player illustrates the use of PureMVC MultiCore, Pipes and StateMachine.

In it, the Main App/Shell talks bidirectionally via Pipes to a PlaylistModule, which in turn talks bidirectionally to a VisualsModule.

For a demonstration of how the StateMachine can be used to control the states of your application, go check out the Shell Module. Start by looking in its controller package for the InjectFSMCommand. This file defines the Finite State Machine for the Shell. You can see that it defines several states and the valid transitions away from those states.

:
<fsm initial={ShellFacade.STARTING}>

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

       <transition action={ShellFacade.STARTED}
           target={ShellFacade.PLUMBING}/>

       <transition action={ShellFacade.STARTUP_FAILED}
           target={ShellFacade.FAILING}/>
</state>

<!-- PLUMB THE CORES -->
<state name={ShellFacade.PLUMBING} changed={ShellFacade.PLUMB}>

       <transition action={ShellFacade.PLUMBED}
           target={ShellFacade.CONFIGURING}/>
       
       <transition action={ShellFacade.PLUMB_FAILED}
           target={ShellFacade.FAILING}/>

</state>

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

       <transition action={ShellFacade.CONFIGURED}
           target={ShellFacade.ASSEMBLING}/>
       
       <transition action={ShellFacade.CONFIG_FAILED}
           target={ShellFacade.FAILING}/>

</state>

<!-- ASSEMBLE THE VIEW -->
<state name={ShellFacade.ASSEMBLING} changed={ShellFacade.ASSEMBLE}>

       <transition action={ShellFacade.ASSEMBLED}
           target={ShellFacade.NAVIGATING}/>
       
       <transition action={ShellFacade.ASSEMBLY_FAILED}
           target={ShellFacade.FAILING}/>

</state>

<!-- READY TO ACCEPT BROWSER OR USER NAVIGATION -->
<state name={ShellFacade.NAVIGATING} changed={ShellFacade.NAVIGATE}/>

<!-- REPORT FAILURE FROM ANY STATE -->
<state name={ShellFacade.FAILING} changed={ShellFacade.FAIL}/>

</fsm>;

A really nice thing about a StateMachine definition like the one above is that you can immediately get an understanding of the application that you couldn't get without it.

It similar to our life in the plane of the galaxy; our perspective lends the idea that the universe around us is this incredible, uniformly random cloud of stars. But if we could fly up out of the plane of the ecliptic, tangential to it and far away from the galaxy, then we'd see an order. We'd see the arms of the galaxy, the hub, the thin parts, etc.

Within a normal PureMVC app, you see the notifications that are mapped to various commands and mediators are interested in some and you can see that you kick off some domino effect at the view, and an event will trigger a mediator to send a note that a command will pick up and talk to a Proxy, etc. And there are many of these paths all interwoven in an app. You just have to pick a thread and start following it to see what calls what and what happens then.

But with a quick read of the FSM above, you now have a high-level understanding of the life-cycle of this module. Now, within any given state, you may find that all sorts of activity has to happen, including async calls to remote services, etc. But rest assured, the StateMachine will not budge. Until it hears one of the valid actions that trigger transitions to other valid states, the current state will be held.

Note that the other modules could have their own StateMachines giving us the ability to have sub-states, although this app doesn't - yet. I'm considering making another module called Sequencer and refactoring the playback functionality into it, and it would likely have a StateMachine to keep track of ready, playing, paused states and how to respond to them when new tracks are selected or previous/next is requested, etc.

-=Cliff>
Logged
Helmut Granda
Full Member
***
Posts: 47

Flash Developer.


View Profile WWW Email
« Reply #3 on: May 08, 2009, 02:41:06 »

Cliff,

Thank you for taking the time to explain in such detail the idea behind of what the StateMachine , and for giving me the references to items that I can use as reference to "fix" my dilemma.

I am going to try to implement the StateMachine in the best of my abilities and hope that I am able to do it right. Some how coming from a non-technical background makes it difficult to grasp all the concepts at once.

I hope one day I can integrate analogies as you have done to my explanations to make it easier for people to grasp the concepts.

Logged
Pages: [1]
Print