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: Multiple Views of the same components  (Read 13585 times)
mycroft
Newbie
*
Posts: 7


View Profile Email
« on: November 30, 2007, 11:30:34 »

Hi Cliff,

Maybe this is a stupid question but bleh, here it is :)

Ok, so I have this AIR application which acts as a main container for a SuperTabNavigator. Tabs to the nav are being added dynamically depending on what the user selects.

In the scenario of:

Tab 1 : Home
Tab 2 : UserForm for userA
Tab 3 : UserForm for userB

UserForm is using a Mediator calling other Proxies used to retrieve remote data and then in turn they update the view from the Mediator. The data is updated on an 5 sec interval for each UserForm tab. Would these Proxies interfere with each other and if yes, how could I go around it? (i.e when Tab 3 is opened, the data in the proxies for Tab2 will change with info for userB)
« Last Edit: December 01, 2007, 01:02:23 by mycroft » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: December 01, 2007, 10:02:06 »

Hi Mycroft,

I'm guessing the conflict you're expecting to arise comes from having multiple instances of the same Proxy and Mediator for each UserForm.

One Proxy is sending Notifications that userA data is available and the other  is sending Notifications that userB data is available. But both instances of this UserProxy are sending Notifications with the same name like USER_SERVICE_SUCCESS or something to that effect.

On the view side of the fence, you've got multiple instances of a UserFormMediator listening for this USER_SERVICE_SUCCESS message, and expecting to take the UserVO passed in the Notification body and set it into the view component.

So (I think) your question is: How does the Mediator for the UserForm displaying User A keep from responding to the USER_SERVICE_SUCCESS Notification from the UserProxy that just receieved User B's data?

The answer: Use the Notification's type property as a discriminator. Have the UserProxy set the type property (third argument to sendNotification) to the user_id. Then in the handleNofitications method of the UserFormMediator, in the switch case where you've identified the Notification as USER_SERVICE_SUCCESS, check the type (notification.getType()) and compare it to the user_id property you've exposed on your UserForm. If not equal then break, ignoring the message in that Mediator instance.

-=Cliff>
Logged
mycroft
Newbie
*
Posts: 7


View Profile Email
« Reply #2 on: December 01, 2007, 11:31:28 »

Thanks Cliff, that's exactly what I was looking for!!
Logged
MacObelix
Courseware Beta
Newbie
***
Posts: 3


View Profile Email
« Reply #3 on: January 17, 2008, 08:34:32 »

Hi Cliff and Mycroft,

I am working on a similar project, using a SuperTabNavigator to add tabs at runtime, depending on user actions.

These tabs can also be closed by the user.  My question is the following: How can I make sure the mediator will no longer be looking for closed viewComponents ?  What needs to be done in order to severe the link between a viewComponent and its Mediator ?

Simple removing the mediator is not an option as othe -still open- viewComponents may depend on them.

Thanks in advance for your answer.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #4 on: January 17, 2008, 10:13:34 »

The mediator is bound to one view component and should be removed when its child is removed.

There should not be any other view components dependant on the Mediator unless you are saying you are using one Mediator for the SuperTabNav in which case you need to be more granular (mediator per tab) or make the API your SuperTabNav exposes to its Mediator deal with inbound requests for non existent tabs gracefully.

-=Cliff>
Logged
MacObelix
Courseware Beta
Newbie
***
Posts: 3


View Profile Email
« Reply #5 on: January 17, 2008, 11:33:03 »

Hi Cliff,

Currently, each 'tabComponent' (=a view component that can be added as a tab to the SuperTab), has its own Mediator, which is registered when the tabComponent is created (at runtime) and then added to the SuperTab.

The SuperTab itself has a very limited Mediator, not interfering with the adding process.

When 2 tabComponents of the same type (e.g. UserForm) are called, they both will register UserFormMediator.  In debug mode, the facade only shows one UserFormMediator registered, mediating both userForms.

Do I understand correctly that you advise to have one separate Mediator for all tabs (regardless is they are from the same type), and that these uniquly linked mediators are to be removed when the tab is closed ?

If yes, can you point me to an example of how to register separate mediators for the same view component type ?

Again, thanks in advance.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #6 on: January 17, 2008, 01:44:24 »

Yes, you want a separate mediator instance for each tab. For an example see the HelloFlash demo where each HelloSprite(colored square) has its own HelloSpriteMediator.
The key is that the mediator instance's name must be unique.

-=Cliff>
Logged
MacObelix
Courseware Beta
Newbie
***
Posts: 3


View Profile Email
« Reply #7 on: January 17, 2008, 01:50:00 »

Thanks for the clarification ! Your input is highly appreciated.
Logged
sjackson
Newbie
*
Posts: 2


View Profile Email
« Reply #8 on: January 28, 2008, 01:50:41 »

Hello,

I have a related question.  We are building an application that needs to support an X number of simultaneous Forms created as needed by the user. Each of the Forms are exactly the same and require the exact same Mediator.  For instance, you could have two "Person" forms open at the same time. The Forms also need to be destroyed after use. The removeMediator() method only takes a static Mediator string name so it doesn't appear that it supports creating two of the same entity at the same time.

How would one go about supporting this and also be able to clean up after the used mediators?

Warmest regards,

- Jackson
Logged
Oscar
Jr. Member
**
Posts: 12


View Profile Email
« Reply #9 on: January 29, 2008, 07:44:52 »

Take a look at the "HelloFlash" Example.

In this example you can see, how to make the Mediator name dynamically.
Logged
sjackson
Newbie
*
Posts: 2


View Profile Email
« Reply #10 on: January 29, 2008, 08:49:29 »

Well, I guess it is always the simple solutions that evade us.  Tragic thing is that I have reviewed this sample before and failed to notice the way the mediators are named.

For those that don't want to open the example, essentially the getMediatorName() method returns a reference to a unique key on the viewComponent it mediates for. 

Thanks for pointing me back to this example for a closer look, Oscar.

- Jackson
Logged
Pages: [1]
Print