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: Call functions and hold references from other ViewComponents allowed?  (Read 8458 times)
Oscar
Jr. Member
**
Posts: 12


View Profile Email
« 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?   

Logged
Joel Hooks
Courseware Beta
Sr. Member
***
Posts: 146


baby steps

 - 46288188  - passport@provinsal.com  - joeltuff
View Profile WWW Email
« Reply #1 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?
Logged

http://joelhooks.com - my ramblings about developing with actionscript and python using pureMVC and django respectively.
Oscar
Jr. Member
**
Posts: 12


View Profile Email
« Reply #2 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. 
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 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>
Logged
Joel Hooks
Courseware Beta
Sr. Member
***
Posts: 146


baby steps

 - 46288188  - passport@provinsal.com  - joeltuff
View Profile WWW Email
« Reply #4 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.
Logged

http://joelhooks.com - my ramblings about developing with actionscript and python using pureMVC and django respectively.
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #5 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>
Logged
Pages: [1]
Print