views:

156

answers:

2

Currently I am working on flex using puremvc framework. Actually my question is related to where to register mediator in puremvc framework. One of my colleague is registering mediator in views(components) creationComplete method only (inside view). While my preference is send some notification from creationComplete method which could be handle by some command and command will register mediator. So which one is better approach in terms of best practice ?

+1  A: 

Views by themselves can't register mediators. Mediators can register mediators instead. E.g. you have a Panel and a PanelMediator. If you have a ListA and ListB in this panel your PanelMediator can add creation complete event listeners to ListA and ListB. In these listeners you can register mediators like ListAMediator/ListBMediator.

The goal is to make components reusable, so your Views should deal with UI and not with your application core.

mico
A: 

I would register your mediators in Commands.

From Best Practices...

To communicate and interact with other parts of the system, Commands may:

  • Register, remove or check for the existing registration of Mediators, Proxies, and Commands.
  • Send Notifications to be responded to by other Commands or Mediators.
  • Retrieve and Proxies and Mediators and manipulate them directly.

As mico mentioned, View's should not register their own mediators, and Proxy's should stay tied to their data sources they interface with and nothing else.

Thomas