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: Purpose of registerMediator? Also, how to handle multiple mediator instances?  (Read 6773 times)
hang
Newbie
*
Posts: 4


View Profile Email
« 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.
Logged
hang
Newbie
*
Posts: 4


View Profile Email
« Reply #1 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.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #2 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>
Logged
Pages: [1]
Print