PureMVC Architects Lounge

Announcements and General Discussion => General Discussion => Topic started by: boliz on November 11, 2009, 03:21:34



Title: Remove and Add Notifications Interests after registeration
Post by: boliz on November 11, 2009, 03:21:34
Hi,

i was wondering if there is a way to add and remove notifications from the list notifications on runtime?
it is obvious that this may cause performance issues if there is no way to do that.
when in event system i can do add and remove events, abut here i only list the notification on registration.
this may cause allot of functions to be registered and do nothing...
i think that this is not reasonable solution from performance point of view, and i would like to know what is the best way or if there is a way to add and remove notifications interests on run time? 

Thank you
Boaz


Title: Re: Remove and Add Notifications Interests after registeration
Post by: puremvc on November 12, 2009, 08:38:03
1) The Mediator's interests are generally static across its lifetime, so just be sure to remove them when they're no longer needed. A call to facade.removeMediator(mediatorName) removes a Mediator and all its interests. Be sure to null its view component in onRemove.

2) If a Command is no longer needed its notification mapping can be removed. You can do this as a group, removing a bunch at a go, or if a command is known to be a 'one-shot', you can always make its final statement be to remove itself. A call to facade.removeCommand(notificationName) removes a command to notification mapping.

-=Cliff>


Title: Re: Remove and Add Notifications Interests after registeration
Post by: boliz on November 12, 2009, 09:15:02
Thank you,
i am creating an Open Source Video Player based on Pure MVC and on OSMF,
because this is a Player my view components and mediators are mostly never removed,
i think it will be smart to add some kind of functionality to add and remove registration of
certen notifications inside the mediators like you do with commands.
10x again,
Boaz


Title: Re: Remove and Add Notifications Interests after registeration
Post by: hesten on November 27, 2009, 04:22:45
I think my thoughts on it would be;

If you alter the notification interests at runtime you're essentially maintaining some form of state logic in your mediator. If the main purpose of a mediator is a view components "plug" into the system, then you don't want that kind of logic there.
Your meditator only mediates messages to and from the system, and if some notification is irrelevant under certain circumstances then that could be handled easily by a statefull view component, right?

This way the mediator is "clean", meaning it has no view relevant logic, and your view component continues its lifespan with states.


Title: Re: Remove and Add Notifications Interests after registeration
Post by: puremvc on November 27, 2009, 07:51:17
@hesten, that's about the size of it.

The Mediator really is a tempting area to put a lot of smarts. But the view component needs to encapsulate its own behavior including its internal states. The Mediator's interests shouldn't vary, but the way the component behaves when it is in one mode or another certainly can.

-=Cliff>