PureMVC Architects Lounge

Announcements and General Discussion => Architecture => Topic started by: joe on February 26, 2008, 02:11:40



Title: Question about multiple instances of a component.
Post by: joe on February 26, 2008, 02:11:40
I am using PureMVC and I have some components (with mediators/proxies) that I would like to have multiple instances of at once but i am unsure how to do this.  I have not seen any examples of doing this in PureMVC as all components in examples are concrete single instances.

EDIT: Just to clarify I want to have multiple instances of the same View component, as I understand you can have multiple different views and a single mediator.

So basically I have:

[Component A ]
[ textbox        ]
[ textbox        ]
[ datagrid       ]

and also Proxy A and Mediator A that takes Component A as the argument in the constructor.  The issue is that I need many Component A's active in the application at any one time.  Obviously following any of the examples and best use cases the view is just duplicated in every instance as they share the same mediator/proxy.

Thanks.


Title: Re: Question about multiple instances of a component.
Post by: puremvc on February 26, 2008, 03:31:47
Check out the HelloFlash demo.

-=Cliff>


Title: Re: Question about multiple instances of a component.
Post by: joe on February 26, 2008, 07:04:12
Cliff,

Thanks a lot I went through the Flash demo and I understand how best to have multiple views and mediators and this technique will work well.  I do have one other quick question regarding proxies.

The majority of these shared components actually use the same data and it is just filtered differently to the view by the mediator, but some of them may need different proxies.  Do you have a best practice for this as well?  If I need multiple copies of the same view/mediator (like in the HelloFlash) but with their own model proxies?


Title: Re: Question about multiple instances of a component.
Post by: puremvc on February 27, 2008, 06:50:55
There isn't a demo showing it, but multiple Proxy instances work the same.give them a unique name.

If a mediator and proxy need to be tied together, say a document editor with a proxy and mediator pair for each new document in an editor, then let the mediator know the name of its proxy, perhaps with a constructor param that it saves in a private var.

Have the proxy sen its name as the type param for notifications it sends.

Have the mediator check in its handleNotification switch/case for the notes that come from that proxy to see if the type param is equal to its proxy's name. If not, disregard the note.

-=Cliff>