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: Apps with multiple instances of proxies (and mediators)  (Read 7760 times)
bwise
Newbie
*
Posts: 1


View Profile Email
« on: February 05, 2008, 06:49:25 »

So, we have been using the framework here for a little while now. As applications get complex things are getting interesting and I am wondering how some other people are solving this problem...

- You have an application that makes multiple instances of a ui widget
- The ui widget has a corresponding Proxy to save its data (multiple instances of proxy, one for each ui widget)

-the problem: following the puremvc practice of poxies sending notifications, every widget will hear the notification of one proxies save and load and error notifications.

Imagine an app like TextEdit, with multiple documents open. If you load a window(or reload) You don't want EVERY window to update with the new loaded text.

The only way I see out of this is having the proxy send an event, not a notification.The mediator(which is instanced with the ui component) will hold a reference to the proxy so this is easy. This doesn't seem recommended in PMVC, is there a more framework friendly solution?

I feel like the whole framework breaks down a bit if things aren't as simple as one proxy matching up with one instance of ui components that care about its data. I hope im wrong!

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



View Profile WWW Email
« Reply #1 on: February 05, 2008, 09:19:05 »

For an example of multiple instances of a view component / mediator pair see the HelloFlash demo. In that application HelloSprite is the view component, and it has a HelloSpriteMediator. Also, in that particular case, when you scroll the wheel on the mouse, the notification is sent to all HelloSpriteMediators, who scale their HelloSprite accordingly.

In the case you describe you have multiple instances of the same view component/Mediator pair associated with multiple instances of the same Proxy. When a given Proxy sends certain Notifications, we want only the specific Mediator instance that's displaying this Proxy's data to respond.

   * The Proxy needs to be named in a similar manner, a unique id is used instead of the NAME constant.
   * Each unique Mediator instance needs to be given (or be able to extrapolate) the name of the Proxy instance it is specifically interested in.
   * The Proxy instance sets the type parameter of the Notification to its unique name before sending.
   * All Mediators interested in this Notification name are notified, but they use the type property of the Notification to disambiguate and determine if this is a Notification that this particular Mediator instance needs to act upon.


Hope this helps,
-=Cliff>
Logged
Pages: [1]
Print