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: Registering Mediators within your application mediator  (Read 10841 times)
kofiaddaquay
Full Member
***
Posts: 31


View Profile Email
« on: October 19, 2008, 11:55:45 »

I have a question about registering mediators. I am pretty sure how to register mediators with

facade.registerMediator( ... );

but what if the component i am registering has other nested view components??  ???

suppose i have this

facade.registerMediator( new VideoConferenceRoom(app.videoConferenceRoom) );

now VideoConferenceRoom.mxml is composed on other custom mxml components... TextChat.mxml and VideoPublisherForm.mxml. Do i have to register these as well? if yes, how? or registering it like i have done above will include the 2 other components.  ??? ???

thanks :-\
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: October 21, 2008, 05:02:11 »

It is best to let the mediator that holds a reference to the parent view component do the registration.

Let the ApplicationMediator register the Mediators for the direct children of the Application that happen to need Mediators.

Then let those Mediators register the Mediators for the direct children of their view components.

And mind your granularity. Every view component doesn't necessarily need its own Mediator.

-=Cliff>
Logged
kofiaddaquay
Full Member
***
Posts: 31


View Profile Email
« Reply #2 on: October 21, 2008, 08:05:30 »

Makes perfect sense.. ;D

Thanks Cliff
Logged
kofiaddaquay
Full Member
***
Posts: 31


View Profile Email
« Reply #3 on: October 22, 2008, 11:34:11 »

Another question Cliff  :P [ i  hope this post isnt too confusing :'( ]

When your mediator is registering for the direct children of their view components, does it use the syntax

facade.registerMediator ?? OR would it just be something like this.registerMediator ?? where 'this' is the component name or the class.

i am confused because most of the examples have an application mediator where the main mxml file has a view stack with each view having an id. so registering is like this (for e.g)
facade.registerMediator( new ComponentClass(app.viewId) );
the app.viewId is passed to the class.

but what do i do in my case :-\ ? i have a video container class as a view component (sub component of VideoPublisherForm). within VideoPublisherFormMediator...do i just simply do

facade.registerMediator( new VideoContainer() );  // <-- not passing anything in
this.registerMediator( new VideoContainer() );  // <-- not passing anything in
OR
facade.registerMediator( videoPublisherForm.vidContainer );   
this.registerMediator( videoPublisherForm.vidContainer  ); 


i noticed ALSO my sub components use sharedobjects :'( which is a proxy...but where would i register such proxy. I was thinking in the ModelPrepCommand. is that right? can i register the proxy somewhere else or would that be bad practice?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #4 on: October 22, 2008, 08:33:57 »

Your correct syntax is:

facade.registerMediator( videoPublisherForm.vidContainer );

And yes, in the ModelPrepCommand (or StartupCommand if you combine model and view prep ) is the conspicuous  place.

-=Cliff>
Logged
kofiaddaquay
Full Member
***
Posts: 31


View Profile Email
« Reply #5 on: October 23, 2008, 08:52:18 »

Thank you thank you Cliff

K
Logged
kofiaddaquay
Full Member
***
Posts: 31


View Profile Email
« Reply #6 on: November 01, 2008, 07:01:44 »

Hi Cliff :) , i have yet another question. writing the following logic doesn't seem to work

facade.registerMediator( videoPublisherForm.vidContainer );

thing is this. vidContainer is not an MXML it is a class. so i am getting. implicit coercion of a value of type ... to an unrelated type org.puremvc.as3.interfaces:IMediator

i totally understand why this is happening. question is how do we register a view component that is entirely based on a class. i tried to extend and implement Mediator and IMediator to VideoContainer class, but i was getting all sorts of errors, because my view component also extends UIComponent :(

the above (facade.registerMediator) does make perfect sense since the Mediator is videoPublisherForm being casted in the class. but vidContainer is a Class UIComponent. how would i register this?? :( thanks for your time

Kofi
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #7 on: November 02, 2008, 05:23:00 »

Hi Kofi,

A read of the best practices doc might be a useful half hour to spend, in order to get a better understanding of the roles and responsibilities of the various actors.

The reason you are getting the exception is that you are trying to pass a view component to registerMediator instead of the mediator it expects.

The whole reason for the use of the mediator pattern within the framework is to insulate view components from any knowledge of the framework apparatus. So trying to make a view component be its own mediator really doesn't make much sense.

-=Cliff>
Logged
Pages: [1]
Print