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: Place for commands  (Read 8391 times)
kidsday
Newbie
*
Posts: 2


View Profile Email
« on: November 11, 2011, 06:22:09 »

Hello everyone,

I am quite new to the PureMVC framework and have a question about placing the commands:

When I register a command to interact between the view and model - where should I place the code to preserve the consistency of the PureMVC pattern? Do I have to register all the commands in the ApplicationStartupCommand file, or can I register the commands to the facade right out of mediator or proxy?

Thanks in advance,

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



View Profile WWW Email
« Reply #1 on: November 11, 2011, 08:01:22 »

Unless you have very special application needs, you should register all your commands at once. There are a couple of places you can do this.

1) ApplicationFacade.initializeController()

If you do them here be sure to call super.initializeController first...
:
package com.me.myapp
{
import com.me.myapp.controller.command.StartupCommand;
import com.me.myapp.controller.command.ThisCommand ;
import com.me.myapp.controller.command.ThatCommand ;
import com.me.myapp.controller.command.TheOtherCommand ;
import com.me.myapp.controller.constant.AppConstants;

import org.puremvc.as3.patterns.facade.Facade;

public class ApplicationFacade extends Facade
{

/**
* The singleton instance factory method.
*/
public static function getInstance( ) : ApplicationFacade
{
if ( instance == null ) instance = new ApplicationFacade( );
return instance as ApplicationFacade;
}

override protected function initializeController():void
{
super.initializeController();

registerCommand( AppConstants.STARTUP, StartupCommand );
registerCommand( AppConstants.THIS, ThisCommand );
registerCommand( AppConstants.THAT, ThatCommand );
registerCommand( AppConstants.THE_OTHER, TheOtherCommand );
}

/**
* A convenience method for starting up the PureMVC
* apparatus from the application.
*/
public function startup( app:MyApp ):void
{
registerCommand( AppConstants.STARTUP, StartupCommand );
sendNotification( AppConstants.STARTUP, app );
}
}
}

2) In your StartupCommand, *before* registering Proxies and Mediators.

Of course your StartupCommand itself will need to be registered in the ApplicationFacade, or it could never be triggered. But you can now move it down into the startup convenience method just before sending the STARTUP note.
:
package com.me.myapp
{
import com.me.myapp.controller.command.StartupCommand;
import com.me.myapp.controller.constant.AppConstants;

import org.puremvc.as3.patterns.facade.Facade;

public class ApplicationFacade extends Facade
{

/**
* The singleton instance factory method.
*/
public static function getInstance( ) : ApplicationFacade
{
if ( instance == null ) instance = new ApplicationFacade( );
return instance as ApplicationFacade;
}

/**
* A convenience method for starting up the PureMVC
* apparatus from the application.
*/
public function startup( app:MyApp ):void
{
registerCommand( AppConstants.STARTUP, StartupCommand );
sendNotification( AppConstants.STARTUP, app );
}
}
}
:
package com.me.myapp.command
{
import com.me.myapp.controller.command.ThisCommand ;
import com.me.myapp.controller.command.ThatCommand ;
import com.me.myapp.controller.command.TheOtherCommand ;
import com.me.myapp.controller.constant.AppConstants;

import com.me.myapp.controller.model.proxy.SomeProxy;
import com.me.myapp.controller.model.proxy.AProxy;

import com.me.myapp.controller.view.mediator.ApplicationMediator;

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

public class StartupCommand extends SimpleCommand
{
override public function execute(note:INotification):void
{
// Prepare the Controller
facade.registerCommand( AppConstants.STARTUP, StartupCommand );
facade.registerCommand( AppConstants.THIS, ThisCommand );
facade.registerCommand( AppConstants.THAT, ThatCommand );
facade.registerCommand( AppConstants.THE_OTHER, TheOtherCommand );

// Prepare the Model
facade.registerProxy( new SomeProxy() );
facade.registerProxy( new AProxy() );

// Prepare the View
var app:MyApp= note.getBody() as MyApp;
facade.registerMediator( new ApplicationMediator( app ) );

}
}
}

-=Cliff>
« Last Edit: November 11, 2011, 09:44:02 by puremvc » Logged
kidsday
Newbie
*
Posts: 2


View Profile Email
« Reply #2 on: November 11, 2011, 08:20:35 »

Thank You very much, Cliff! That really helped me out!
Logged
Pages: [1]
Print