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: Mediator removal anti-pattern?  (Read 10409 times)
sasuke
Full Member
***
Posts: 29


View Profile Email
« on: August 20, 2009, 07:21:20 »

Hi all, a puremvc beginner here.

A really quick question; is it a wrong thing or a bad practice to remove a mediator or de-register it from within itself?

The big picture: In my application, all my views implement a common interface 'IViewComponent' which has a cleanup method. As soon as the view needs to be swapped out, the parent mediator invokes the cleanup method on the view, which in turn sends an event to the mediator which in turn does all the cleanup [typically this involves clearing the form fields, grounding all VOs, re-setting page state and finally unregistering the mediator].

I could have avoided this by:
- removing the mediator in the parent mediator itself
- retrieved the reference to the facade in the view [Facade.get...] and then removed the mediator
- fired off a command to do the removal; but this kinda makes the the 'resetting the page state' part difficult to handle [clearing the view from the command doesn't seem like a good idea]

Any suggestions or thoughts would be really appreciated.

-sasuke
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: August 20, 2009, 07:46:24 »

is it a wrong thing or a bad practice to remove a mediator or de-register it from within itself?

Nope. In fact that's the easiest way to deal with the mediators of transient view objects. Have the mediator listen to the view object for an event sent when it is removed. In the handler for that event just have the mediator remove itself. Also, there (or in the mediator's onRemove method), null the mediator's reference to the view component for good measure with a setViewComponent(null).

-=Cliff>
Logged
sasuke
Full Member
***
Posts: 29


View Profile Email
« Reply #2 on: August 27, 2009, 12:12:48 »

is it a wrong thing or a bad practice to remove a mediator or de-register it from within itself?

Nope. In fact that's the easiest way to deal with the mediators of transient view objects. Have the mediator listen to the view object for an event sent when it is removed. In the handler for that event just have the mediator remove itself. Also, there (or in the mediator's onRemove method), null the mediator's reference to the view component for good measure with a setViewComponent(null).

-=Cliff>
Hi Cliff,

Thanks for the response. I was kinda hesitant in doing since it seemed so much like suicide. :-)

Anyways, regarding de-registration of PureMVC actors, is it really necessary to de-register proxies, mediators, commands when removing a core? Or does removing the core do all this automagically?

Are there any anti-patterns in general regarding the removal or de-registration of core actors? Something like "would it be wrong if the facade was removed when the control is in the mediator" or "Never de-register any actor from a Proxy" etc.?

TIA,
sasuke
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: August 28, 2009, 10:33:17 »

If all your notification activity has stopped in a core, and you remove it from the outside, you theoretically shouldn't have to remove all the mediators and proxies. However if the proxy uses a service and there are outstanding calls, you need to cancel them first. And on RTMP channels, you really have to destroy everything to make them go away. Channelsets and all. And if the mediated view components in a module are plugged into another core's view hierarchy, you may need to remove the mediator, and unhook the view compoent.

-=Cliff>
Logged
Pages: [1]
Print