PureMVC Architects Lounge

Announcements and General Discussion => General Discussion => Topic started by: Meg41 on April 12, 2011, 01:30:22



Title: Standards for removing event listeners and unwatch bindings
Post by: Meg41 on April 12, 2011, 01:30:22
I would like to know the inbuilt standards in puremvc to remove event listeners and unwatch the binding on all mediators, proxies and views which are not going to be in use any more coz of switch of views in the app.

Who should initiate the remove event listeners - obviously the event which switches the view. But where should this code sit... in a mediator?

There are multiple mediators involved and should we call a method removeEventListeners on all these mediators, which inturn should remove event listeners on their respective views and proxies.

Help appreciated. Thanks!


Title: Re: Standards for removing event listeners and unwatch bindings
Post by: puremvc on April 13, 2011, 07:57:07
I would like to know the inbuilt standards in puremvc to remove event listeners and unwatch the binding on all mediators, proxies and views which are not going to be in use any more coz of switch of views in the app.
There shouldn't be any bindings to Mediators or Proxies. They are retrieved as needed from the View and Model respectively and should not be referenced by view components or binding therein.

As for when to remove event listeners, that's up to you and the lifecycle of your component. However, it is typical that if a view component may be removed from the display list, that you set a listener in onRegister which listens for an event from the component indicating it has been removed. If you're using Flash, this would be Event.REMOVED_FROM_STAGE. In your handler for that, you may simply have the Mediator remove itself.

-=Cliff>