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: PureMVC Vs parsley  (Read 14790 times)
Meg41
Newbie
*
Posts: 4


View Profile Email
« on: April 12, 2011, 01:25:29 »

We currently use PureMVC for our flex app. I am comparing PureMVC and Parsley at the moment. Any thoughts?

Also, I am facing an issue where I want to re-use my view and mediator. Should I go about inherting my mediator or creating another intsance of the same mediator by injecting a different name for it? If so, I will have branch my code in every function to check what name it is to make tweaks to code, if any.

Also, as our app is growing I am registering new commands, mediators and proxies, hereby making my startup command really big...any thoughts on this.

Help is appreciated.

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



View Profile WWW Email
« Reply #1 on: April 13, 2011, 08:07:19 »

We currently use PureMVC for our flex app. I am comparing PureMVC and Parsley at the moment. Any thoughts?
A project that I'm working on right now uses the Parsley Task library to launch SequentialTaskGroups that may have async tasks mixed in. This seems to work pretty well. I'm not a major fan of Parsley for dependency injection, though. Another project I worked on was attempting Parsley DI with Cairngorm, and I was wildly under-impressed with the bang-for-your-buck. It's just a different philosophy altogether.

Also, I am facing an issue where I want to re-use my view and mediator. Should I go about inherting my mediator or creating another intsance of the same mediator by injecting a different name for it? If so, I will have branch my code in every function to check what name it is to make tweaks to code, if any.
Are you retrieving this mediator and acting upon it? That's the only reason I can imagine you'd have problems coping with it having a unique name for each instance of your view component. The best practices doc urges you to avoid this practice and instead send notifications to your mediator to get things done instead. For one thing, this decouples the sender of the note from the Mediator, and secondly, it avoids problems where you need to know the specific mediator's name.

Also, as our app is growing I am registering new commands, mediators and proxies, hereby making my startup command really big...any thoughts on this.
Well your commands should be being registered in your concrete Facade's initializeController method. As for the Proxy and Mediator registrations, I suggest making your StartupCommand be a MacroCommand with two SubCommands PrepareModelCommand and PrepareViewCommand, into which you'll move your Proxy and Mediator registrations respectively.

-=Cliff>
Logged
Meg41
Newbie
*
Posts: 4


View Profile Email
« Reply #2 on: April 13, 2011, 09:46:34 »

Cliff,

Thanks for your response. I have more follow up questions:


1)
I am doing the following when I register my mediator:

facade.registerMediator(new MyMediator(myView));

and say the following to retrieve it...
myMediator = MyMediator(facade.retrieveMediator(MyMediator.NAME));

Now I want to use the existing view and mediator by creating another instance of it, how do I handle this.

2)
Yes, my commands are in the concrete Facade's initializeController method, but this is growing over time. Any suggestions here...thanks
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: April 15, 2011, 07:25:57 »

and say the following to retrieve it...
myMediator = MyMediator(facade.retrieveMediator(MyMediator.NAME));
Is it possible that you could send a notification to this mediator instead of retrieving it and invoking methods or setting properties on it? Its best if you can.

Now I want to use the existing view and mediator by creating another instance of it, how do I handle this.
Your mediator must have a unique name if it is to be registered multiple times. Usually, I concatenate the canonical mediator name with the id of the view component.

:
         public static const NAME:String = "MyViewMediator";

         public function MyViewMediator( viewComponent:MyView )
         {
            super( NAME+"/"+viewComponent.id, viewComponent );
         }

Now, in order to retrieve that mediator from elsewhere, you need to be able to construct that unique name. So, you might push the name construction into a static method:

:
         public static const NAME:String = "MyViewMediator";

         public function MyViewMediator( viewComponent:MyView )
         {
            super( getMediatorNameForID( viewComponent.id ), viewComponent );
         }
       
         public static function getMediatorNameForID( string:id ):String
         {
            return NAME+"/"+id;
         }

Then elsewhere, when you need to retrieve that mediator:

:
var myViewMediator:MyViewMediator;
myViewMediator = MyViewMediator( facade.retrieveMediator( MyViewMediator.getMediatorNameForID( id ) ) );

-=Cliff>
Logged
Meg41
Newbie
*
Posts: 4


View Profile Email
« Reply #4 on: April 15, 2011, 01:24:01 »

Thank you Cliff.

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



View Profile WWW Email
« Reply #5 on: August 28, 2011, 01:41:17 »

PS: My wife says with PureMVC, you'll never have to worry that bunnies will eat your framework. :)
Logged
openoli
Full Member
***
Posts: 44


View Profile Email
« Reply #6 on: September 01, 2011, 02:55:37 »

Hey Cliff,
one question regarding your eyample above:
I've a Collection Proxy that get it's data from a remote server.
The proxy data object is an ArrayCollection.
Now I'd like to get different extracts of the data object e.g. by using the method getMyCollectionByStatus(id:String) and also re-load a part of the data object by using e.g. the method loadMyCollectionByStatusService(id:String). In the first case the id is passed to the method and will be forwarded to the notification.
But what should I do in the second case if I invoke an server side method asynchronous?

Many thanks in advance
Olaf


:
public class MyCollectionProxy extends Proxy
{
public static const NAME:String = 'MyCollectionProxy';

public function MyCollectionProxy(proxyName:String)
{
super(proxyName);
}

override public function onRegister() : void
    {
                        //...
    }


public function getMyCollectionByName(id:String):ArrayCollection
{
                        var data:ArrayCollection;

                        // ...
                        // ... get data by Name
                        // ...
sendNotification(ApplicationFacade.LOAD_DATA_SUCCESS, data, id);
}

public function getMyCollectionByStatus(id:String):ArrayCollection
{
                        var data:ArrayCollection;
                        // ...
                        // ... get data by Status
                        // ...
sendNotification(ApplicationFacade.LOAD_DATA_SUCCESS, data, id);
}


public function loadMyCollectionByStatusService(id:String):void
{
                        // ...what should we do with the passed id?
                        //

var delegate:MyService = new MyService( new Responder( onLoadDataService, onLoginFaultService ) );
delegate.loadDataByStatus();
CursorManager.setBusyCursor();
}

public function onLoadMyCollectionByStatusService(event:ResultEvent):void
{
                       
CursorManager.removeBusyCursor();
var result:ArrayCollection= event.result as ArrayCollection;
                        setData(result);

                        //
                        // ...where should we get the id
                        //

sendNotification(ApplicationFacade.LOAD_DATA_SUCCESS, result, id);
}
}

:
         public static const NAME:String = "MyViewMediator";

         public function MyViewMediator( viewComponent:MyView )
         {
            super( getMediatorNameForID( viewComponent.id ), viewComponent );
         }

         public function getDataByStatus():void
         {
            // this will call the registered Command (inside the Command we invoke the proxy remote call)
            sendNotification(ApplicationFacade.LOAD_DATA_BY_STATUS, false, id);
         }
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #7 on: September 01, 2011, 08:13:30 »

Use the Asynchronous Token.

The delegate.loadDataByStatus() method will make a service call. Don't ignore the result of that call; instead return it to the Delegate's caller. It is an AsyncToken object. You can set any values you want on it and then in the result handler, the token will present on the ResultEvent and contain those values.

:
public function loadMyCollectionByStatusService(id:String):void
{
var delegate:MyService = new MyService( new Responder( onLoadDataService, onLoginFaultService ) );
CursorManager.setBusyCursor();

// Set the id on the AsyncToken
var token:AsyncToken = delegate.loadDataByStatus();
token.id = id;
}

public function onLoadMyCollectionByStatusService(event:ResultEvent):void
{
                        
CursorManager.removeBusyCursor();
var result:ArrayCollection= event.result as ArrayCollection;
                        setData(result);

// Get the id from the AsyncToken
var token:AsyncToken = event.token;
                        var id:String = token.id;

sendNotification(ApplicationFacade.LOAD_DATA_SUCCESS, result, id);
}
}

-=Cliff>
« Last Edit: September 01, 2011, 08:15:13 by puremvc » Logged
openoli
Full Member
***
Posts: 44


View Profile Email
« Reply #8 on: September 06, 2011, 06:45:57 »

Many thanks Cliff!!!
Your support is still unbelivable, I really appreciate it.

Olaf
Logged
Pages: [1]
Print