PureMVC Architects Lounge

Announcements and General Discussion => Getting Started => Topic started by: creynders on May 20, 2008, 05:37:59



Title: deferred mediator registration
Post by: creynders on May 20, 2008, 05:37:59
I don't know if anybody'll have any use for this, but I wrote a small function which defers the registration of the mediator until the view component it mediates is created.
(I hope it doesn't sin against the best practices ??)

Place this in ApplicationFacade:
:
public function deferMediatorRegistration( mediatorClass : Class, viewComponent : UIComponent ) : void{
var facade : ApplicationFacade = this;
var listener : Function = function( event : FlexEvent ) : void {
facade.registerMediator( new mediatorClass( event.target ) );
}
viewComponent.addEventListener( FlexEvent.CREATION_COMPLETE, listener );
}
to use it (in, for instance, ApplicationMediator )
:
ApplicationFacade.getInstance().deferMediatorCreation( MyCustomMediator, app.myCustomComponent );


Title: Re: deferred mediator registration
Post by: puremvc on May 20, 2008, 08:17:59
The only problem is it wouldn't be portable to somewhere other than Flex/AIR, since it depends on a FlexEvent.

-=Cliff>


Title: Re: deferred mediator registration
Post by: creynders on May 21, 2008, 12:19:01
Ah, yes, should've mentioned it can only be used in Flex.