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: Structural Advice and Un-registering Mediators.  (Read 7082 times)
paulc
Newbie
*
Posts: 2


View Profile WWW Email
« on: August 05, 2008, 04:02:50 »

Hi, let me prefix all of this by saying that I'm very new to using the framework but I quite like the way it works.  I'm having a bit of trouble deciding how to go about implementing something and so I'm looking for some advice.  I'm also wondering about managing references to mediators for later cleanup.  Here's where I'm at...

I'm building an application where I've got a layer that displays information windows as an overlay over the whole app (like loading progress bars, etc).  I've built a mediator for the overlay container (just a Sprite) which listens for NEW_INFO_WINDOW notifications and builds a new view in the container and then sends a notification REGISTER_INFO_WINDOW with the new view as the notification body.  I have a command mapped to trigger on REGISTER_INFO_WINDOW that creates a new mediator for the view passed along (InfoWindowMediator).

First of all, is this a good way to do things?  Some of my information windows will be non-interactive so I wonder if there's even a point to registering a mediator for them.  However, some will be interactive like confirmation dialogs.

Secondly, this is going to, over the course of the applications life, create a large number of InfoWindowMediators.  I really don't like having orphaned objects that won't get garbage collected so I've been struggling with a way to keep account of the mediators and un-register them when the information window they mediate is destroyed and removed.  Any suggestions there?

I hope that all makes sense.  Thanks in advance!
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: August 06, 2008, 10:21:58 »

It is a sound setup.

Take the simple expedient of naming the mediator instance the same as the id of the window it mediates.

Then, have the mediator for the application (or which ever one removes the component from the display) also remove the mediator named the same as the view component's id.
-=Cliff>
Logged
paulc
Newbie
*
Posts: 2


View Profile WWW Email
« Reply #2 on: August 06, 2008, 12:40:33 »

Cliff, thanks for the reply.

I suppose I should have added the disclaimer that I'm not working in Flex so I don't have IDs for my windows "out of the box" so to speak.  I suppose I'll implement this and assign IDs to windows when they're created and use your suggestion of using this value for the mediator.  Of course if I had multiple windows going at once that had the same IDs, could there be name collisions (when removing or registering)?

Finally, thanks for all your work on the framework and your ongoing support here :)
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: August 06, 2008, 01:25:25 »

You definitely want unique ids for each window / mediator. See the HelloFlash demo for how to handle this. The HelloSprite and HelloSpriteMediator do this.

-=Cliff>
Logged
Pages: [1]
Print