PureMVC Architects Lounge

Announcements and General Discussion => General Discussion => Topic started by: diegovolpe on September 11, 2007, 02:16:35



Title: Mediators Sequence/Priority
Post by: diegovolpe on September 11, 2007, 02:16:35
Cliff,

Firstly, congrats on sharing this excellent project.

I need to enable/disable mediators without using register/remove in order to keep their creation sequence/priority.
The mediators must work much like interceptors, keeping their sequence (data and transformation dependency)
Imagine the following scenario: I have 3 Mediators, registered to the same view, to Analyze, Record and Broadcast user interactions:
1) GestureAnalyzerMediator
2) GestureRecorderMediator
3) GestureBroadcasterMediator

How can I disable/enable only the GestureRecorderMediator without using removeMediator/registerMediator?
Is there a different approach to keep the registered priority/sequence using those methods? (How about override facade.notifyObservers in order to filter the notifications to the mediators that are flagged to enable)

Thanks.


Title: Re: Mediators Sequence/Priority
Post by: puremvc on September 11, 2007, 04:20:45
Hi Diego,

Interesting question.

Overriding Facade.notifyObservers wouldn't work in this case, as it just passes through the notification to the View.notifyObservers method. And, since the the other Mediators still need to be notified, you'd still need to send every notification. Taking this tack, you'd have to override the View.notifyObservers method, AND you'd need to give the View a list of disabled mediators to skip. AND you'd need some extra methods to manage that list AND some Commands to make it all happen.

I believe the direction I would take is:

1) Give the Mediator a Boolean 'enabled' property.
2) Whenever you need to enable or disable this Mediator, send a special Notification (i.e. DISABLE_GESTURE_RECORDER or ENABLE_GESTURE_RECORDER) that only the GestureRecorderMediator has interest in, and to which it responds by setting its own enabled property accordingly.
3) In the handleNotification method of the GestureRecorderMediator, before your switch statement, return immediately if the Mediator is disabled.

That ought to do it.

Sounds like you're doing some interesting stuff there, just from the Mediator names. Let us know what you're up to if it's not top secret.

-=Cliff>


Title: Re: Mediators Sequence/Priority
Post by: diegovolpe on September 11, 2007, 08:53:42
Hey Cliff,

You're absolutely right. The observerMap lives in the view.
I think your suggestion is much more consistent and less intrusive (the Mediator itself holds the filter logic). Thanks.

The classes I've mentioned before are just the tip of the iceberg. We have a working Flex "Class Builder", a sort of online Powerpoint integrated with a huge multimedia database (videos, animations, simulators, etc).
The Educational Company I've been working for wouldn't allow me to share the code, but I'll try to setup some "generic" examples demonstrating how PureMVC and other useful patterns were used.

I have other questions like instance Mediators using UIID, ProxyFactory combined with Inversion of Control, ChainCommands simulating workflow, TypedServices combined with Proxys, and so on, but I'll mature these doubts before starting a discussion.

Thanks again.