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: Standards for removing event listeners and unwatch bindings  (Read 3423 times)
Meg41
Newbie
*
Posts: 4


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



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