PureMVC Architects Lounge

Announcements and General Discussion => General Discussion => Topic started by: hang on November 01, 2008, 05:18:15



Title: Purpose of registerMediator? Also, how to handle multiple mediator instances?
Post by: hang on November 01, 2008, 05:18:15
What is the purpose of registerMediator other than to keep a reference to the mediator so it doesn't get garbage collected?

Also, I have a situation where my application generates a popup window and I attach a mediator to each of those popup windows.  Do each of these mediators need an unique name?  If not, what happens when I call removeMediator when the user closes the popup window?  It seems uniqueness in name is necessary.  However, since the popup creation is going to be done by a command, it's hard to ensure that each popup mediator has an unique name.

Is a command the wrong place to do this?  I figured that a command is the right thing because there can be many different situations when the application would want to invoke the popup window.  Furthermore, I can see there being a series of necessary steps to take prior to showing the popup window such as fetching some data first.

Thanks.


Title: Re: Purpose of registerMediator? Also, how to handle multiple mediator instances?
Post by: hang on November 01, 2008, 05:24:57
Another thing I've been considering is to make the mediator able to monitor multiple instances of the popup window, effectively making it a singleton.  This does get around the multiple instances problem but I'm still curious as to how one can handle that case should it ever arise.


Title: Re: Purpose of registerMediator? Also, how to handle multiple mediator instances?
Post by: puremvc on November 01, 2008, 07:07:06
Yes, you can give each mediator a unique name. 80% or more of mediators you write will only need to have one instance, so you can register an instance with a NAME constant, which makes it easy to retrieve. See the HelloSpriteMediator in the HelloFlash demo for a mediator with positive multiplicity.

As for the function of registerMediator (or any method) the best way to find out is to look at the source code.

The framework interrogates the mediator on registration about its notification interests and sets up Observers for them.

-=Cliff>