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: Application Mediator for tabNavigator  (Read 5506 times)
gkf
Jr. Member
**
Posts: 10


View Profile Email
« on: November 17, 2009, 02:10:37 »

I have seen this post http://forums.puremvc.org/index.php?topic=842.0
and this demo http://puremvc.org/pages/demos/AS3/Demo_AS3_Flex_Slacker/srcview/

I have created an ApplicationMediator listening to my application which has a tabNavigator.

My main application fires and event each time selected tab changes (I use change event of the tabNavigator). Events are SHOW_TAB1, SHOW_TAB2, etc. ApplicationMediator listens to those events.
When SHOW_TABx is fired, ApplicationMediator removes mediators linked to over tabs and registers mediators linked to the one selected.

onRemove method of all my mediators removes listeners linked to the mediator removed.

Is it a good way to manage registration of mediators linked to tabs of a tabNavigator ?
Logged
Helmut Granda
Full Member
***
Posts: 47

Flash Developer.


View Profile WWW Email
« Reply #1 on: November 17, 2009, 03:05:53 »

I don't have the answer to your question but would like to make a suggestion. Instead of sending a notification as SHOW_TABx you can have one notification and you can pass an id with it.

sendNotification ( SHOW_TAB, {id:x});

This will help in the future if you were to have 100 tabs (exaggerated to make a point), then you just add the ID to the notification instead of having to create 100 constants.
Logged
gkf
Jr. Member
**
Posts: 10


View Profile Email
« Reply #2 on: November 17, 2009, 03:18:25 »

There's no notifications in my management of tabNavigator ;)
The application catches tab changes and fires events using dispatchEvent.

ApplicationMediator adds event listeners, listening to those events in its onRegister method.

Each method called by on of those listeners, registers mediators and removes others.
Logged
Helmut Granda
Full Member
***
Posts: 47

Flash Developer.


View Profile WWW Email
« Reply #3 on: November 17, 2009, 03:32:57 »

I see, the "SHOW_TABx" is the instance name of your tabs! I misunderstood your setup.
Logged
gkf
Jr. Member
**
Posts: 10


View Profile Email
« Reply #4 on: November 17, 2009, 11:24:31 »

SHOW_TAB1, SHOW_TAB2, etc (SHOW_TABx) are names of events fired by the application.

I have read once again Slaker demo comments http://puremvc.org/content/view/92/1/.

I understood that tabNavigator has a default creation policy set to auto to improve application startup speed.

I said that my ApplicationMediator adds and removes mediators linked to tabs depending on selected tab.

Is it usefull to remove mediators ?
Does tabNavigator remove view components when they are not needed for a long time ?

If removing is useless, I just have to create and register needed mediators the first time user selects a tab.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #5 on: November 18, 2009, 09:21:57 »

You don't need to remove the mediator unless you remove the view component. Flex's deferred instantiation simply delays creation of children other than the first shown until you navigate to it. It doesn't remove the component once you navigate away.

However Flex States to remove view components and add them back as you move from state to state, so it is possible that you will need to register and remove mediators (if you have them) for transient subcomponents of components with Flex States.

-=Cliff>
Logged
gkf
Jr. Member
**
Posts: 10


View Profile Email
« Reply #6 on: November 18, 2009, 10:20:36 »

Thanks. I will only create and register mediators when needed if they are not yet registered.

I have created the following method in my ApplicationMediator.

:
private function checkForMediator(mediator:Class, view:Object):void
{
if (!facade.hasMediator(mediator.NAME))
{
facade.registerMediator(new mediator(view));
}
}
« Last Edit: November 18, 2009, 10:41:19 by gkf » Logged
Pages: [1]
Print