You can easily have the mediator not respond to the note if the view component isn't shown.
How? By checking the 'visible' property of the viewComponent before handling a notification in handleNotification?
Yes. Like:
override public function handleNotification( note:INotification ):void
{
if ( ! rolePanel.visible ) return;
switch ( note.getName() )
{
case ApplicationFacade.NEW_USER:
clearForm();
break;
case ApplicationFacade.ADD_ROLE_RESULT:
rolePanel.userRoles = roleProxy.getUserRoles( rolePanel.user.username );
rolePanel.reset();
break;
}
}
How would the above scheme deal with UI components which utilize a timer to continuously send out events to the mediator?
This scheme is only concerned with turning away inbound notifications, it doesn't have any intersection at all with outbound events coming from the component. Those are handled in event handlers the mediator has placed on the component. But the same scheme can apply there as well:
private function onRecurringEvent( event:Event ):void
{
if (! rolePanel.visible ) return;
roleProxy.addRoleToUser( rolePanel.user, rolePanel.selectedRole );
}
Basically you're just ignoring communications requests to or from the component when it is invisible. No biggie. If you need a more complex adaptation of mediator behavior to view component state, then you want to implement view states in the component. This is built into Flex but can be built manually in a Flash component. In any case you'd be looking at the currentState property of the component and moderating communications based on that state. This gives you more than the two states of visible/hidden.
-=Cliff>