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: deferred mediator registration  (Read 5724 times)
creynders
Jr. Member
**
Posts: 18


View Profile Email
« 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 );
« Last Edit: May 20, 2008, 05:39:52 by creynders » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 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>
Logged
creynders
Jr. Member
**
Posts: 18


View Profile Email
« Reply #2 on: May 21, 2008, 12:19:01 »

Ah, yes, should've mentioned it can only be used in Flex.
Logged
Pages: [1]
Print