PureMVC Architects Lounge

Announcements and General Discussion => General Discussion => Topic started by: Oscar on October 15, 2008, 06:24:28



Title: Call functions and hold references from other ViewComponents allowed?
Post by: Oscar on October 15, 2008, 06:24:28
Hi,   

for example:

Let's say we have a Image Gallery.
The Image Gallery has a 'ThumbnailOverview' Component. The corresponding Mediator is 'ThumbnailOverviewMediator'. 

There is also a 'ThumbnailItem' Component with the corresponding Mediator called 'ThumbnailItemMediator'.

The ThumbnailOverview and Mediator creates and hold the ThumbnailItems:

:

// ThumbNailOverviewMediator

//....

public function makeThumbnails():void
{
    for(var i:int = 0;i<10000; i++)
    {
        var thumbNail:ThumbnailItem = new ThumbNailItem();
        _facade.registerMediator(new ThumbnailItemMediator(thumbNail));
 
       thumbNailOverview.insertThumbNail(thumbNail);
    }


The 'ThumbnailOverview' then could look something like this:

:

// ThumbnailOverview ViewComponent

//.....

public function insertThumbNail(thumbNail:ThumbNailItem):void
{
   addChild(thumbNail);
   listOfThumbNails.push(thumbnail); // Array which hold all the Thumbnail Items
   thumbNail.addEventListener(ThumbNailItem.REMOVED, thumbNailRemoved);
   thumbNail.testFunction();
}


Would this ok, that the 'ThumbnailOverview' hold references to ThumbNailItems, add itself as an Listener and also called Functions on the ThumbNailItem?   



Title: Re: Call functions and hold references from other ViewComponents allowed?
Post by: Joel Hooks on October 15, 2008, 08:57:54
I've personally been trying to get into the habit of using my mediators more for this type of functionality. Usually I will build the component, do as you have done, and then pull it out into the appropriate mediators to leave the viewComponents as light as possible.

There is nothing wrong with what you are doing though, the viewComponents are still oblivious to the framework and just going about their business. I'd probably keep the listOfThumbnails on a proxy myself, but that too wouldn't be strictly necessary.

Just out of curiosity, why does your mediator access facade as _facade?


Title: Re: Call functions and hold references from other ViewComponents allowed?
Post by: Oscar on October 16, 2008, 04:51:39
thanks a lot for your answer.   

:
Just out of curiosity, why does your mediator access facade as _facade?
You're right. The var name is facade not _facade.
I forgot to mention, that it was just more pseudo/example Code. So i don't looked to much into it. 


Title: Re: Call functions and hold references from other ViewComponents allowed?
Post by: puremvc on October 18, 2008, 07:50:19
Its perfectly normal to have a view component relationship such as you have described between ThumbnailOverview and ThumbnailItem.

However you may not need the level of granularity where there are mediators for every thumbnail. It debends on the amount of system and user interaction involved with a thumbnail. If it is complex, then you may basically be set here.

But if a thumbnail only raises one or two events, and the overview itself is simple enough, then the ThumbnailOverview mediator may be enough.

For instance, to remove a thumbnail as a result of some user gesture upon it, you can send a bubbling event from the thumbnail, and rather than listen for it in the ThumbnailOverview, have the ThumbnailOverviewMediator listen to the ThumbnailOverview for it. Since it you will send a bubbling event, the mediator will get it, tell its view component to remove it, and also send any notification that the rest of the system might need to hear about the removal.

@Joel, Proxies (denizens of the Model region) are not conceptually a good place to store view components.

-=Cliff>


Title: Re: Call functions and hold references from other ViewComponents allowed?
Post by: Joel Hooks on October 18, 2008, 09:39:24

@Joel, Proxies (denizens of the Model region) are not conceptually a good place to store view components.

-=Cliff>

I assumed (didn't read closely enough) that an ArrayCollection would be thumbnail value objects and not the components/renderers.


Title: Re: Call functions and hold references from other ViewComponents allowed?
Post by: puremvc on October 19, 2008, 07:45:33
Ah, then certainly that would be the place. I thought it was view components that were being referred to.

-=Cliff>