PureMVC Architects Lounge

PureMVC Manifold => Standard Version => Topic started by: mikebritton on November 20, 2008, 06:07:05



Title: Registering Mediators Dynamically
Post by: mikebritton on November 20, 2008, 06:07:05
I have an app that has two modes, "default" and "custom".  Default mode means views use a standard set of components; custom mode means views have been customized and should load images for their UI.

Because of this, my views differ significantly enough to warrant creating a mediator for each.  The alternative would introduce a lot of messy conditional logic to the views, which is something I want to keep at a minimum.

So here goes: I have a command that registers these mediators based on boolean flags set in my proxies.  These booleans tell the app whether certain views are "custom" or "default".  How do I refer to the base app, where the views have been instantiated, from my command?

One approach is to store a reference to the main application on the facade, and fire a method on the facade when I'm ready to set the mediators dynamically.

In ApplicationFacade:

:
public function startup( app:VODPlayer ):void
{
this.app = app;
sendNotification( STARTUP, app );
}

public function get app():VODPlayer { return __app; }
public function set app(value:VODPlayer):void { __app = value; }

In the Command:

:
var app:VODPlayer = ApplicationFacade(facade).app;

This doesn't feel like a good technique.  Has anyone come up something more elegant?  Am I missing something simple and obvious?


Title: Re: Registering Mediators Dynamically
Post by: puremvc on November 20, 2008, 10:26:37
Why are you stashing a ref to the app on the facade rather than passing it to an ApplicationMediator?

-=Cliff>


Title: Re: Registering Mediators Dynamically
Post by: mikebritton on November 20, 2008, 11:37:54
Uh....

Because I didn't think of that.  Maybe I should avoid coding when I haven't had my coffee.

Thanks Cliff!