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: View sending notifications???  (Read 6623 times)
cturner
Newbie
*
Posts: 2


View Profile Email
« 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??
Logged
Jason MacDonald
Sr. Member
****
Posts: 243


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