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] 2
1  PureMVC Manifold / Demos and Utils / Re: StateMachine - A PureMVC / AS3 Utility on: March 05, 2009, 02:18:38
Don't hold your breath on the demo. I'm steaming on a project that you'll all hear much more about very soon. I will be working on something, but spare time is low right now.

Hey everyone, I just pushed up a demo utilizing these new changes in StateMachine to github.  Please check it out there until Cliff moves it into a demo page here (if he thinks its worthy)  ;)

http://github.com/gjastrab/puremvc-statemachine-1.1-login-demo/tree/master
2  PureMVC Manifold / Demos and Utils / Re: StateMachine - A PureMVC / AS3 Utility on: January 15, 2009, 03:08:25
Yea, I don't really seen any value in passing the State in the body, but that may just be because I haven't found the need to use it yet.

Why don't you introduce a new class:

StateMachineNotificationBody or something like that?
:
public class StateMachineNotificationBody {

  public var body:Object;

  public var state:State;

}
3  PureMVC Manifold / Demos and Utils / Re: StateMachine - A PureMVC / AS3 Utility on: January 15, 2009, 02:27:48
Precisely, if you could pass a body w/ a StateMachine.ACTION that would be available in the notifications that StateMachine sends out, that would save me from a bunch of code that doesn't belong in certain places (if I want to send a body into an event in response to a CHANGED notification, I currently have to throw that onto a Mediator somewhere.
4  PureMVC Manifold / Demos and Utils / Re: StateMachine - A PureMVC / AS3 Utility on: January 14, 2009, 01:27:17
Before recommending that I'd like to think through the problem a bit more.  (Sorry for not attaching code yet, I will if it makes it easier, but hopefully talking through it will be enough first)

If anyone would like to throw out example scenarios here that use subclasses and arguments for it, please do.
Here is a simple usage example for a case that, in the current version of the utility, is difficultannoying to implement:

I want to pair StateMachine w/ AsyncCommand that will attempt to login to a service.  The login form will be changed when the login request is outstanding, and either change back if failed or faded and the main view is to be displayed if login was successful.

This uses my practice of making the Command an IResponder - which I know has been discussed to be bad practice in PureMVC.  However, I think the usefulness of doing this (especially with an AsyncMacroCommand) outweighs the "bad practice" argument.  I'm willing to be swayed, but this has been my practice since using PureMVC which is why I'm still going with it.  In this example, we're not using an AsyncMacroCommand, but I'll make the DoLoginCommand extend AsyncCommand anyway, for argument's sake.

So, my FSM:

LOGIN -> TRY_LOGIN
TRY_LOGIN -> LOGIN (transition to occur on a failed login)
TRY_LOGIN -> MAIN (transition to occur on a successful login)

If we dispatch an event from the Login form that will get picked up by a mediator, which will send a notification with the username/password information.  However, we don't want the login service to be called until we are actually in the TRY_LOGIN state.

This currently requires us to send a LOGIN notification w/ the username/password.  A command will extract this information from the notification and store it on a LoginProxy.  It will then
:
sendNotification(StateMachine.ACTION, null, TRY_LOGIN)
Now in the mediator on ENTER_TRY_LOGIN we can disable the Login button and the input fields and display a message "Logging in...".  However, cannot execute the service until the state machine has changed into TRY_LOGIN.  So we have to listen on a mediator for StateMachine.CHANGED, and:
:
if(note.getBody().name == TRY_LOGIN) { // (body of note is a State)
  // now run login service
  sendNotification(DO_LOGIN); // (registered to DoLoginCommand)
}

DoLoginCommand
:
public class DoLoginCommand extends AsyncCommand implements IResponder {
  override public function execute(note:INotification):void {
    var loginProxy:LoginProxy = facade.retrieveProxy(LoginProxy.NAME) as LoginProxy;
    loginProxy.login(this); // LoginProxy will execute an HTTPService call and add this command as a responder to the token
  }

  public function fault(info:Object):void {
    sendNotification(StateMachine.ACTION, null, AppFacade.LOGIN) // go back to login
  }

  public function result(data:Object):void {
    /* pseudo code here */
    if( data.result) { // (login successful)
      sendNotification(StateMachine.ACTION, null, AppFacade.MAIN); // go to main
    }
    else { // (invalid credentials)
      fault(null);
    }
  }
}

I love using StateMachine to enforce what state your application is in, but the shortcoming for me right now is not being able to trigger a state change from the login event and pass that event object to the notification that will initiate the state change, but have that be accessible in the ENTER notification for the target state.  Thus, the current need to wait for CHANGED on a mediator before doing the actual login.

To be clear, I would like to be able to:
:
var evt:LoginEvent = ... // this has been retrieved from the mediator, and has username & password properties
sendNotification(StateMachine.ACTION, evt, AppFacade.TRY_LOGIN);

ENTER_TRY_LOGIN will be registered w/ the DoLoginCommand.
Ideal DoLoginCommand:
:
...
override public function execute(note:INotification) {
  var state:State = note.getBody();
  state.body // (the LoginEvent sent as the body of the TRY_LOGIN action notification)
}
5  Announcements and General Discussion / General Discussion / Re: How to properly manage application states 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.
6  PureMVC Manifold / Demos and Utils / Re: StateMachine - A PureMVC / AS3 Utility on: January 12, 2009, 09:35:37
Awesome work Darshan, that's slick and elegant!
7  PureMVC Manifold / Demos and Utils / Re: StateMachine - A PureMVC / AS3 Utility on: January 07, 2009, 01:30:21
Hm, that does complicate things if it relies on interpreting meaning from slashes in a notification name in Fabrication.

I think fleecie's right and now that the PureMVC community/tools are growing it's going to be interesting and important to see how to better tie things together to ensure they play nicely.

+1 on being interested to see if Cliff has anything cooking in this area yet...
8  PureMVC Manifold / Demos and Utils / Re: StateMachine - A PureMVC / AS3 Utility on: January 07, 2009, 11:38:23
Of course, I wasn't criticizing your post, but just suggesting that the problem should be addressed at the root cause in order to prevent the same thing from occurring elsewhere (people using slashes in their constants), rather than changing the way state machine names its constants.
9  PureMVC Manifold / Demos and Utils / Re: StateMachine - A PureMVC / AS3 Utility on: January 07, 2009, 11:26:27
Wouldn't this be an issue to take up w/ the Fabrication utility and not StateMachine?  What if someone uses the convention of putting slashes in their constants out of preference (I have begun doing this for all of my Facade constants).

I haven't used Fabrication yet, so I'm not sure how that works, but it seem that Fabrication should perhaps detect and trim out bad characters, replacing them with empty space, or underscores or something when trying to call respondTo*...
10  PureMVC Manifold / Demos and Utils / Re: StateMachine - A PureMVC / AS3 Utility on: December 26, 2008, 01:31:25
oh, and merry xmas

And merry xmas to everyone as well.
11  PureMVC Manifold / Demos and Utils / Re: StateMachine - A PureMVC / AS3 Utility on: December 26, 2008, 01:30:19
I don't have a particular need to subclass state, but was just exploring how this would be done in response to the bullet in the release notes I originally quoted.

If there was a body Object on the State that would allow me to pass data into the notification that is initiating an ACTION to another State, then the problem of having to send the StateMachine.ACTION notification, and then respond later after an ENTERING or CHANGED notification to send data would be solved.  That is the primary feature request I have right now for this utility.
12  PureMVC Manifold / Demos and Utils / Re: StateMachine - A PureMVC / AS3 Utility on: December 24, 2008, 12:11:43
Hm, wasn't thinking about having to port when suggesting that, but would it really be that difficult?  I was just concerned w/ having to re-enter the potentially long namespace for the subclassed State multiple times.  I much prefer the first method, and parsing it is easy!

Using the following XML:
:
var fsm:XML = <fsm xmlns:sub1="com.SubState1" xmlns:sub2="com.SubState2">
  <state name="Normal State" />
  <sub1:state name="Sub Classed 1" />
  <sub2:state name="Sub Classed 2" />
</fsm>

Parsing:
:
var namespaces:Array = fsm.namespaceDeclarations();
for each(var ns:Namespace in namespaces) {
  // get class reference for ns.uri
  // store it in a hash under key ns.prefix
  trace("Prefix '" + ns.prefix + "' is for class => " + ns.uri);
}

for each( var state:XML in fsm.children() ) {
  var stateNS:Namespace = state.namespace();
  if(stateNS == null) { /* USE regular State class */ }
  else {
    trace("Need to use class w/ NS: " + stateNS.prefix);
    // something like
    var stateClass:Class = stateRefs[stateNS.prefix];
    state = new stateClass();
  }
}
13  PureMVC Manifold / Demos and Utils / Re: StateMachine - A PureMVC / AS3 Utility on: December 24, 2008, 10:38:19
In the release notes under the State Representation section one of the points is:

The entering notification for a State carries a reference in the body to the state we are entering as well, in case you've sub-classed State to pass data.

Do you have an example of how this would be done?  How would you get your new state class to be registered, by overriding FSMInjector::createState to instantiate your class instead of StateMachine's State class?

This would be my top feature request: an elegant way to specify subclasses for individual states w/o needing to override createState (maybe a user doesn't want all of the states to be represented by the extended State class, only certain ones).  Perhaps something could be cleverly done w/ XML namespaces to specify the class to use...

(abbreviated fsm example)
:
<fsm xmlns:sub="com.my.namespace.to.state.class.ExtendedStateClass">
  <state name="Normal State">...</state>
  <sub:state name="Extended State 1">...</sub:state>
  <sub:state name="Extended State 2">...</sub:state>
</fsm>

This way you wouldn't have to type out the entire state class multiple times:
More Verbose Way
:
<fsm>
  <state name="Normal State">...</state>
  <state name="Extended State 1" stateClass="com.my.namespace.to.state.class.ExtendedStateClass">...</state>
  <state name="Extended State 2" stateClass="com.my.namespace.to.state.class.ExtendedStateClass">...</state>
</fsm>
14  Announcements and General Discussion / Public Demos, Tools and Applications / Re: PureMVC AS Code Generator - PureMVCGen on: December 18, 2008, 03:36:50
I just pushed the 0.1.1 release of the generator, so it will now properly work on Windows.  I also moved the events directory into the views, as suggested by Cliff.  (There are no generation tasks that do anything with events yet, but that's in the pipeline).

Since I just pushed it isn't showing up yet on rubyforge, but if you run

gem search -r puremvc-gen

once it is listing puremvc-gen (0.1.1, 0.1.0) it will be ready for you to install.

If you've already installed it then run:

gem update puremvc-gem

to update to 0.1.1, otherwise if you just

gem install puremvc-gem

you should get the 0.1.1 version.
15  Announcements and General Discussion / Public Demos, Tools and Applications / Re: PureMVC AS Code Generator - PureMVCGen on: December 10, 2008, 01:34:18
Thanks for confirming ghostmonk.  It's weird 'cause it correctly told me that ANT wasn't installed when I tried to run it after installing just the generator, but once I installed ANT, nothing gets output.  I'll try to get it figured out ASAP.
Pages: [1] 2