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: PrepCommand + execute  (Read 13773 times)
ceaseoleo
Newbie
*
Posts: 9


View Profile Email
« on: September 29, 2008, 04:39:16 »

In ApplicationStartupCommand, subCommands are added. 
:
addSubCommand( ModelPrepCommand );
            addSubCommand( ViewPrepCommand );

ModelPrepCommand has an execute function.  I can't seem to figure out where this execute function is called. 
This can also be found in the ViewPrepCommand. 

Looking at the addSubCommand , it just adds this class to an array. 
:
protected function addSubCommand( commandClassRef:Class ): void

{

subCommands.push(commandClassRef);

}

Where and when does execute get called ?

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



View Profile WWW Email
« Reply #1 on: September 29, 2008, 05:08:37 »

A MacroCommand calls each of its subcommands in turn when its execute method is called. Look at the source code for the framework MacroCommand class.

-=Cliff>
Logged
ceaseoleo
Newbie
*
Posts: 9


View Profile Email
« Reply #2 on: September 29, 2008, 10:45:43 »

Hi Cliff
thanks for the reply. 

I have looked at this class, I was assuming in the ApplicationStartupCommand or in the constructor of MacroCommand there would need to be an explicit call, to execute, and I can't find this anywhere. 
:
public function MacroCommand()
{
subCommands = new Array();
initializeMacroCommand();
}
In the overridden InitializeMacroCommand
:
        override protected function initializeMacroCommand() :void
        {
            addSubCommand( ModelPrepCommand );
            addSubCommand( ViewPrepCommand );
        }

I see the function that iterates through the subCommands, and so I was assuming that somewhere there would be needed this.execute or execute("startup") from some other class.
The only reference I could find is in the Controller.as that has
:
commandInstance.execute( note ); 


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



View Profile WWW Email
« Reply #3 on: September 29, 2008, 01:05:30 »

Please look at the source code for the ececute method of the framework MacroCommand class. It iterates through its children calling execute on each.

-=Cliff> 
Logged
ceaseoleo
Newbie
*
Posts: 9


View Profile Email
« Reply #4 on: September 29, 2008, 02:18:16 »

Hi Cliff

sorry if I'm not being clear, but when is the execute on the MacroCommand class being executed. 
:
public final function execute( notification:INotification ) : void
{
while ( subCommands.length > 0) {
var commandClassRef : Class = subCommands.shift();
var commandInstance : ICommand = new commandClassRef();
commandInstance.execute( notification );
}
}

I see that the MacroCommand.execute .. loops through and executes the execute function of each of each Command Object that extends SimpleCommand.  So when is the execute function of the MacroCommand called ? 

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



View Profile WWW Email
« Reply #5 on: September 29, 2008, 03:49:53 »

It is executed whenever a Notification is sent that is mapped to the MacroCommand in question.

-=Cliff>
Logged
ceaseoleo
Newbie
*
Posts: 9


View Profile Email
« Reply #6 on: September 29, 2008, 06:29:35 »

Hi Cliff

Thanks  actually now I understand, when register Command is called parameters are string, and command class
:
public function registerCommand( notificationName:String, commandClassRef:Class ):void
{
controller.registerCommand( notificationName, commandClassRef );
}

so when I call
:
registerCommand( STARTUP, ApplicationStartupCommand ); in the ApplicationFacade.as and then calls controller.registerCommand, and in this function executeCommand is called, which calls execute when the notification is triggered.

easy enough  ;D  just wanted to clarify, thanks for the help and patience.  Love the framework so far. 
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #7 on: September 29, 2008, 08:22:09 »

...Almost.

so when I call registerCommand( STARTUP, ApplicationStartupCommand ); in the ApplicationFacade.as and then calls controller.registerCommand, and in this function executeCommand is called

Controller.registerCommand does *not* call Controller.executeCommand.

It registers the concrete ICommand implementer class with the Controller, and registers a corresponding Observer with the View, which handles observer notification. That observer points to the Controller.executeCommand method.

LATER, when something (like a Proxy, Mediator or another Command) sends a Notification with the name you mapped the ICommand to in registerCommand, then the Controller is notified by having its executeCommand method called, passint the notification.

THEN, Controller.executeCommand looks at the Notification name, looks up the command to instantiate, does so and calls the new ICommand instances execute method.

-=Cliff>
Logged
ceaseoleo
Newbie
*
Posts: 9


View Profile Email
« Reply #8 on: September 29, 2008, 11:52:29 »

 ;D yes.. thanks for the clarification. 

:
view.registerObserver( notificationName, new Observer( executeCommand, this ) );
Logged
cyianite
Newbie
*
Posts: 3


View Profile Email
« Reply #9 on: October 15, 2008, 01:38:47 »

Hi Cliff,

  This is my first entry to this forum, I really love your framework , actually were using it to our big application, (I mean BIGGGG)... my question is ..

   In the MacroCommand it all multiple subcommands ('addSubCommand') right ?, after the SimpleCommand inside subCommand executes the commands, How the MacroCommand know that the command is done, does it throw a return value to the MacroCommand to execute to next subCommand?

  Hope I explained my question clearly... :)

Thanks and more power,
Cyainite
   
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #10 on: October 21, 2008, 09:27:26 »

Since Flash is single threaded, the subcommand will finish before the MacroCommand calls the next one. If the command performs an async operation, though your thread still continues.

Soon an AsyncMacroCommand  utility will be released that handles this. It was not included in the framework because the intention was for Proxies to be Async responders.

But a Command could still trigger a Proxy into an async action that you'd want to hold the execution of the MacroCommand until complete.

Duncan Hall has submitted this and it will be available around the week of MAX in mid November.

-=Cliff>
Logged
cyianite
Newbie
*
Posts: 3


View Profile Email
« Reply #11 on: October 25, 2008, 11:06:28 »

Thanks a lot Cliff .  ;)
Logged
Pages: [1]
Print