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: which part the mediator was registered?  (Read 8974 times)
j4m35bond
Newbie
*
Posts: 6


View Profile Email
« on: March 15, 2009, 06:48:30 »

Hi,
Allow me to post a simple question here but I need to make things clear before dig further.
Take for example, EmployeeAdmin project. I see the EmployeeAdmin.mxml create a facade and run its startup method, which in turn sendnotification "startup".
How does it work that register all mediators with their interest notification?

In the [view] forlder I noticed there are 3 mediators.as. Is it when startup notification sent, all class in view component will be registered automatically?

Thanks

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



View Profile WWW Email
« Reply #1 on: March 15, 2009, 08:19:18 »

Notice that the ApplicationFacade class registers some command mappings, in particular the StarupCommand is mapped to the notification name STARTUP. This happens when the ApplicationFacade is instantiated in the MXML where a facade variable is initialized from the getInstance method.

Later, when the mxml creation is complete, we invok a startup method on the facade instance which sends the STARTUP notification, triggering the StartupCommand. There, the ApplicationMediator is registered, the sole actor that will retain a reference to the mxml app.

I'm on a phone right now without easy access to the code, so I'll describe the  two possibilities for where the remaining mediators are registered.

The most likely is that the ApplicationMediator registers the remaining mediators since it is the actor responsible for mediation of communication with the mxml application including registering any mediators needed for its immediate children.

The other possibility in a super simple app or demo is that the StartupCommand registers the ApplicationMediator and its those for the application's immediate children for expediency and clarity.

This latter method is usually not adequate because in reality the view hierarchy may be many levels deep and child creation is often deferred, so registration of all mediators at startup isn't possible and must be delegated to the Mediators of the components whose mediated children will have their creation deferred.

Hope this helps,
-=Cliff>
Logged
j4m35bond
Newbie
*
Posts: 6


View Profile Email
« Reply #2 on: March 15, 2009, 09:38:22 »

Hi,
Sorry I am still not very clear with the explanation.
Take for example:
the viewcomponent: UserForm.mxml
Is it fixed that the correspond mediator AS filename must have the format like: vcomponent name follow by "Mediator"  => UserFormMediator.as ?
Is it we have to name the mediator follow that way in order for the startup command to "know" what  mediator(s) should be registered in the application facade?
Or the facade registered all mediator under [view] folder?
Logged
Tekool
Sr. Member
****
Posts: 192


View Profile WWW Email
« Reply #3 on: March 15, 2009, 10:17:43 »

It's not an automatic mechanism, you have to register mediators in a command or in mediators itself as Cliff explains it in the previous post. Mediators of the EmployeeAdmin demo are registered within the StartupCommand :

:
    public class StartupCommand extends SimpleCommand implements ICommand
    {
        /**
         * Register the Proxies and Mediators.
         *
         * Get the View Components for the Mediators from the app,
         * which passed a reference to itself on the notification.
         */
        override public function execute( note:INotification ) : void   
        {
            facade.registerProxy( new UserProxy() );
            facade.registerProxy( new RoleProxy() );
           
            var app:EmployeeAdmin = note.getBody() as EmployeeAdmin;
            facade.registerMediator( new UserFormMediator( app.userForm ) );
            facade.registerMediator( new UserListMediator( app.userList ) );
            facade.registerMediator( new RolePanelMediator( app.rolePanel ) );
        }
    }
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #4 on: March 15, 2009, 10:17:57 »

No need to name it the same as the view component plus 'Mediator', it just makes sense to. Ad no there is no facility for registering an entire folder automatically. As I mentioned above, generally the mediator for the main app, which in turn registers any mediators needed for its direct children. Those mediators may in turn register mediators for their components direct children and so on.   
-=Cliff>
Logged
Pages: [1]
Print