PureMVC Architects Lounge

Announcements and General Discussion => Architecture => Topic started by: cturner on November 06, 2008, 11:50:54



Title: View sending notifications???
Post by: cturner on November 06, 2008, 11:50:54
I would like to know what would be considered best practice for the following situation.  I am going back and forth with allowing my views to send notifications using the puremvc framework or to have the views dispatch events to a mediator that has a registered event listener.

I know that by allowing my views to send a notification I am tying my views to pureMvc.  With that said, is it worse then having the mediators register event listeners to views?  Could there be performance or any garbage collection issues when using flex events and event listeners in the mediator. 

Personally I'd rather not rely on flex events and just let the view send a notification.  Of course this also means each view has a hook to the appfacade singleton so that i can actually send a notification.

Your thoughts??


Title: Re: View sending notifications???
Post by: Jason MacDonald on November 06, 2008, 12:13:56
The best practice is to have your Mediators handle any notifications (sending and receiving) on behalf of your view  components. The Mediator listens for events fired by your view components and then transforms those into notifications when required.

As for GC issues, your Mediators should be in charge of tearing down your view component when they are no longer needed. When you tear down a Mediator, it then tears down the view components it's managing and removes any listeners (and perhaps sends notifications that the component has been removed).

A good practice is to override the onRemove() method of your Mediators so they can handle the cleanup of your view components. This way all you need to do is call facade.removeMediator() to completely remove a mediator, its view component and any references.