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 [2] 3 4
Print
Author Topic: Loadup - A PureMVC AS3 Utility  (Read 38565 times)
philipSe
Sr. Member
****
Posts: 139


View Profile Email
« Reply #15 on: August 28, 2009, 10:20:04 »

Just 2 alternatives to consider.
1. you could drop PROJECTS_RETRIEVED, just use PROJECTS_LOADED in the LoginMediator, use the body (i.e. the proxy name) to retrieve the project proxy and use that to get the data property.
2. use of 'app.appView.selectedIndex = 2' in a mediator might be considered too closely coupled to the internals of the viewcomponent - I think the slacker demo has an example of mediator/component interaction where the component contains a view stack - see MainDisplay.mxml and MainDisplayMediator.
----Philip
Logged
bestbuyernc
Full Member
***
Posts: 21


View Profile Email
« Reply #16 on: October 01, 2009, 02:58:00 »

Hi. Been away for a while. But thank you for responding.  The following gives me a null proxy object.  The facade isn't able to find it based on the name.  Am I doing something wrong?
:
                [b]Project Proxy[/b]
// setting the name
public static const NAME:String = "ProjectProxy";

        // set the proxy's data to be retrieved
setData( projects );

// send the project's loaded notification.  mediators can get its data from the facade using the NAME passed in the body
sendNotification( ApplicationFacade.PROJECTS_LOADED, ProjectProxy.NAME );

                [b]LoginMediator[/b]
            case ApplicationFacade.PROJECTS_LOADED:
            projectProxy = facade.retrieveProxy( body as String ) as ProjectProxy;
            loginForm.domainSource = ( projectProxy.getData() as Array );
            break;
Logged
philipSe
Sr. Member
****
Posts: 139


View Profile Email
« Reply #17 on: October 02, 2009, 02:20:19 »

Have you registered the proxy? - must be registered before it can be retrieved.
----Philip
Logged
bestbuyernc
Full Member
***
Posts: 21


View Profile Email
« Reply #18 on: October 02, 2009, 06:33:54 »

Yes.  It is the ILoadupProxy.  I am setting its data with results from the remote call.  I can see where the data is populated.  However, trying to retrieve it from the mediator by the name is giving me a null exception.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #19 on: October 02, 2009, 06:41:57 »

Sounds as if the Proxy isn't registered.

By the way, you should define the notification constant on the Proxy so that the Proxy isn't bound to the ApplicationFacade. The Proxy can then be reused in other applications without relying on a constant that it depends on to be defined elsewhere.

-=Cliff>
Logged
bestbuyernc
Full Member
***
Posts: 21


View Profile Email
« Reply #20 on: October 02, 2009, 07:21:17 »

Sounds as if the Proxy isn't registered.

By the way, you should define the notification constant on the Proxy so that the Proxy isn't bound to the ApplicationFacade. The Proxy can then be reused in other applications without relying on a constant that it depends on to be defined elsewhere.

-=Cliff>

Thank you. I registered the ProjectProxy in the LoadResourcesCommand

:
public class LoadResourcesCommand extends SimpleCommand implements ICommand
{
private var monitor:LoadupMonitorProxy;

public override function execute( note:INotification ):void {
facade.registerProxy( new LoadupMonitorProxy() );
this.monitor = facade.retrieveProxy( LoadupMonitorProxy.NAME ) as LoadupMonitorProxy;

var projectProxy:ILoadupProxy = new ProjectProxy();
facade.registerProxy( projectProxy );

makeAndRegisterLoadupResource( ProjectProxy.NAME, projectProxy);
this.monitor.loadResources();
}

private function makeAndRegisterLoadupResource( proxyName :String, appResourceProxy:ILoadupProxy ):LoadupResourceProxy {
var r:LoadupResourceProxy = new LoadupResourceProxy( proxyName, appResourceProxy );
facade.registerProxy( r );
monitor.addResource( r );
return r;
}
}

I did what you said and defined the notification constant in the ProjectProxy.

:
        public function loaded( asToken:Object=null ):void {       
        var projects:Array = [];
        for each ( var item:Object in asToken.result ) {
        projects.push( { label: item.domain, data: item.domain } );
        sendNotification( ApplicationFacade.LOADING_STEP, asToken.result.length / projects.length * 100 );
        }
        // set the proxy's data to be retrieved from interested mediators
setData( projects );

// send the project's loaded notification.  mediators can get its data from the facade using the NAME passed in the body
sendNotification( ProjectProxy.PROJECTS_RETRIEVED, ProjectProxy.NAME );
        }

... and then to get the data ...
:
            case ProjectProxy.PROJECTS_RETRIEVED:
            var projects:Array = facade.retrieveProxy( body as String ).getData() as Array;
            loginForm.domainSource = ( projects );
            break;

but the projects is still null.
Logged
philipSe
Sr. Member
****
Posts: 139


View Profile Email
« Reply #21 on: October 05, 2009, 04:44:41 »

You seem to be using the same proxy name for the ProjectProxy instance and for the corresponding LoadupResourceProxy instance.  So, when the latter is registered, it supersedes the former.  So, when you retrieve the proxy, it is the LoadupResourceProxy you are retrieving.
----Philip
Logged
bestbuyernc
Full Member
***
Posts: 21


View Profile Email
« Reply #22 on: October 05, 2009, 06:45:54 »

I don't understand.  I am doing what is being done in the LoadUpAsOrdered demo.  In the LoadResourcesCommand,  a customer proxy is created as an ILoadupProxy and then registered with the facade.  That same proxy reference is passed to the makeAndRegisterLoadupResource method to create a LoadupResourceProxy.  The only difference I can see is that no data is actually being passed in the mediator to the notification.  Is it that my scenario is not the right one for the loadup utility?  Or maybe i am just lost  ???
Logged
philipSe
Sr. Member
****
Posts: 139


View Profile Email
« Reply #23 on: October 05, 2009, 10:12:14 »

In the case you mention, from LoadUpAsOrdered demo, the line of code is
:
var rCus :LoadupResourceProxy = makeAndRegisterLoadupResource( CustomerProxy.SRNAME, cusPx );
Note the first argument is CustomerProxy.SRNAME as opposed to CustomerProxy.NAME.  That's what I mean.
----Philip
Logged
bestbuyernc
Full Member
***
Posts: 21


View Profile Email
« Reply #24 on: October 05, 2009, 01:05:46 »

Thanks Phillip... Unfortunately, I tried that also but get the same results.  I have just elected to just get the projects after PureMVC starts up and use a notification to send the data to my login view and just pop a database down message to the user if the projects cant be loaded.  I may not have had the best scenario for the utility.  Maybe somewhere down the line i will retry it.  I have learned a lot however, just be trying to implement it though.  Thanks for the help!
Logged
jts
Newbie
*
Posts: 3


View Profile Email
« Reply #25 on: November 16, 2009, 11:48:52 »

Let's assume that I have a ProductProxy that is responsible for retreiving products from the server. ProductProxy.data contains an object named ProductCatalog that stores all of the products that have been loaded onto the client. When my app starts I will call a method on the proxy named loadProductCatalog() which will get some basic info about each product. When a product is selected I will call another method on the proxy named loadProductDetails(prodId:int) that will be responsible for loading the details and merging them into the ProductCatalog(ProductProxy.data) structure.

I want to use the LoadUp utility in my system and am trying to figure out the best way to refactor this proxy to work with the Loadup.

First I believe I can simply rename loadProductCatalog() to load() and conceptially they will be the same thing. The  Product Proxy will be loading the products when load is called. So this naturally works. The point of confusion is how to handle other methods within my proxy. For the LoadProductDetails call, would I be best to to create a new proxy named ProdudDetailsProxy. This proxy would then contain only one method named load which would do the same thing as my old method named loadProductDetails. Then when this proxy loads the data, it would retreive the default instance of the ProductProxy and merge the just retreived ProductDetails into the ProductCatalog(ProductProxy.data) structure. So really my ProductDetails proxy would only be a short lived object since I only need it to load the data and merge it into my ProductProxy. Going with this pattern, it seems I would need a new proxy type for every load operation i plan to do on my model. I though it would be nice to keep load operations grouped within one proxy. For instance all operations related to a product would go inside a ProductProxy. What do you all think?

Thanks!!
« Last Edit: November 16, 2009, 11:58:22 by jts » Logged
jts
Newbie
*
Posts: 3


View Profile Email
« Reply #26 on: November 16, 2009, 01:56:55 »

I want to us the same LoadupMonitorProxy in different use cases but am having trouble identifying which use case was was being performed when the command attached to LoadupMonitorProxy.LOADING_COMPLETE fires. Maybe I need to track which state I am in with the state machine and check the state in my command and send the appropriate notification?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #27 on: November 16, 2009, 02:27:35 »

That would be my suggestion.

-=Cliff>
Logged
jts
Newbie
*
Posts: 3


View Profile Email
« Reply #28 on: November 16, 2009, 04:41:54 »

That would be my suggestion.

-=Cliff>

This may not be so easy as it looks like there is not a good way to get the current state out of the state machine. This is the general command I am attempting to use to attach to LoadupMonitorProxy.LOADING_COMPLETE notes that I want to be able to handler all use cases. Then in this command I can check my app state to know how to handle. Note that my CustomSimpleCommand grabs a ref to StateMachine from the facade. Is their a way to get the current state from state machine without having to track outside of state machine?

:
public class LoadingCompleteCommand extends CustomSimpleCommand
{
public override function execute(note:INotification):void
{
//if we are in the starting command we can move out of the state into the configuring commadn
if (this.stateMachine.currentState.name == StateNames.STARTING)
{
this.sendNotification(StateMachine.ACTION, null, StateNames.CONFIGURING_PRODUCT);
}
}
}
Logged
philipSe
Sr. Member
****
Posts: 139


View Profile Email
« Reply #29 on: November 17, 2009, 05:14:52 »

This is not a response to the state machine query, just a comment regarding LoadupMonitorProxy.

If I understand correctly, it seems that there are separate Loadup sessions - one for the ProductCatalog load and one for each Product load - but using the one LoadupMonitorProxy instance.  Instead, if you use separate instances of LoadMonitorProxy for these, then
- you can have concurrent retrieval of more than one product
- the loading complete notification will have the instance name in the type, hence differentiating the different contexts.

However, I well recognise the role the state machine can have in overall management of this.
----Philip
Logged
Pages: 1 [2] 3 4
Print