PureMVC Architects Lounge

Announcements and General Discussion => Getting Started => Topic started by: akmansoor on November 06, 2008, 08:02:23



Title: Where is the best place to declare a global variable
Post by: akmansoor on November 06, 2008, 08:02:23
I would like to declare a global variable where I can access it anywhere, this global variable reading data from an xml file. In puremvc where should I declare this global variable so that I can access it in mediators, command and proxy classes


Title: Re: Where is the best place to declare a global variable
Post by: Joel Hooks on November 06, 2008, 09:19:24
I would access the XML in a proxy and then access that proxy in your mediators, commands and other proxies.


Title: Re: Where is the best place to declare a global variable
Post by: akmansoor on November 06, 2008, 11:42:56
Thanks,

each time the this proxy is retrieved is it going to load xml data? Do we need to make it singleton to avoid that, if so how to make proxy singleton


Mansoor


Title: Re: Where is the best place to declare a global variable
Post by: Jason MacDonald on November 06, 2008, 12:06:06
You use the facade (singleton) to retrieve the proxy and place your variable on a public property of the Proxy. The facade is accessible from all Mediators, Commands and Proxies.

:
// Get your proxy
var myProxy:MyProxy = facade.retriveProxy(MyProxy.NAME) as MyProxy;

// access your variable.
myProxy.myGlobalVariable;

Proxies are "cached" within the facade and therefore do not have a short lifespan like a Command, unless you removeProxy();


Title: Re: Where is the best place to declare a global variable
Post by: akmansoor on November 06, 2008, 01:52:24
Thanks, really apreciate.

One more doubt on this.
Is it okey to declare global variable in ApplicationFacade
and  get the data through proxy and use facade to get the global variable.

ApplicationFacade
{
    public var myGlobalVariable;

   ApplicationFacade( ){
     var myProxy:MyProxy = facade.retriveProxy(MyProxy.NAME) as MyProxy;
     myGlobalVariable =  myProxy.retrieveGlobalVariables();
   }
}
[/color]
and then access the global variable using facade

Thanks,
Mansoor


Title: Re: Where is the best place to declare a global variable
Post by: Joel Hooks on November 06, 2008, 02:03:37
Thanks, really apreciate.

One more doubt on this.
Is it okey to declare global variable in ApplicationFacade
and  get the data through proxy and use facade to get the global variable.

ApplicationFacade
{
    public var myGlobalVariable;

   ApplicationFacade( ){
     var myProxy:MyProxy = facade.retriveProxy(MyProxy.NAME) as MyProxy;
     myGlobalVariable =  myProxy.retrieveGlobalVariables();
   }
}
[/color]
and then access the global variable using facade

Thanks,
Mansoor

There is 100% no reason to do this as any mediator, command, or proxy can access the proxy by calling facade.retrieveProxy(MyProxy.NAME)

I recommend removing 'global variable' from your vocabulary in terms of PureMVC applications. ;)


Title: Re: Where is the best place to declare a global variable
Post by: Jason MacDonald on November 06, 2008, 02:43:06

I recommend removing 'global variable' from your vocabulary in terms of PureMVC applications. ;)

Haha, I was think the same thing. Global variable is a dirty word, especially in AS3/OOP. ;)


Title: Re: Where is the best place to declare a global variable
Post by: puremvc on November 06, 2008, 04:37:52
Take a look at the Deployment Config utility. This is specifically for reading XML configuration and exposing it to your app.

-=Cliff>