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: Several small questions  (Read 7770 times)
joao.saleiro
Newbie
*
Posts: 6


View Profile Email
« on: June 17, 2008, 05:21:06 »

Hello,

I have several small questions on best-practices using PureMVC on a Flex/AS3 Application.
I am posting them on the same topic, but if you prefer next time I can create a topic for each of them.

1.
There are views that are only added to stage later, so I can't register their mediator on the StartupCommand. In this case, where do you recommend making the facade.registerMediator ?

2.
If I have views inside other views, I am doing this to register the mediators on the StartupCommand:

         facade.registerMediator(new LocalesModuleMediator(app))
         facade.registerMediator(new LocalesManagerMediator(app.localesManager));
         facade.registerMediator(new LocaleEditorMediator(app.localesManager.localeEditor));
[...]

Is this the best approach?

3.
On the sendNotification method, what the purpose of the third argument (type) ?

4.
I have a view with several components (buttons, etc). I have a button that will change the current section on the application. What's the best approach:
a) The view registers for the click event of the button, and it's handler will dispach an event that the mediator should listen an react to change the application state
b) The mediator registers for the click of the button on the view, so everything is handled on the mediator

5.
The mediator should act only as a gateway between the views and the framework, or it is supposed to act also as a ViewHelper? In another words, imagine that I have a button that when clicked, it changes the currentState of the view. There is no need to access the framework, since everything needed is accessible on the view. The code to react to the click and change the currentState should be put inside the view component (the mxml file) or on the mediator? When should I make "reaction" code on the mediator?

6.
On the multicore version of PureMVC the facade is only available on the mediator after the call to the initializeNotifier. Where should I put the "addEventListeners" for the components on the view: on the constructor of the mediator, or on the initializeNotifier method?

Thank you! BTW, we are loving the PureMVC multicore. ;)

João Saleiro
« Last Edit: June 17, 2008, 05:23:46 by joao.saleiro » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: June 18, 2008, 06:16:10 »

Hi João,

Yes, next time it would be best if you could break your questions up. If it takes a long time to answer, it'll be deferred until there's adequate time to answer.

The answers to most of these questions can be found by reading the Best Practices document, coupled with searches in this forum. Yes, a FAQ is coming so you won't have to do so much digging, but for now, do treat it as a resource. The signal to noise ratio is pretty good here.

1. Search this forum for 'deferred instantiation'
2. You are placing too much knowledge about the internals of the view component in the command.
3. From Best Practices and Implementation Idioms:
Notifications also have an optional ‘type’ that can be used by the Notification recipient as a discriminator. For instance, in a document editor application, there may be a Proxy instance for each document that is opened and a corresponding Mediator for the View Component used to edit the document. The Proxy and Mediator might share a unique key that the Proxy passes as the Notification type. All the Mediator instances registered for that Proxy’s Notifications will be notified, but will use the type property to determine if they should act upon it or not.
4. Either: A)Make the event from the button have bubbles=true. Then have the mediator place the listener on the view component containing the button. The view component itself doesn't have to listen or dispatch. OR B) Make the component listen for the click and dispatch a different event that the mediator is listening for.
5. The mediator should mediate. It should not hold state or perform complex logic that could be contained in the black box of the view component.
6. Place the listeners on the view components in the constructor, but wait until onRegister (in MultiCore or Standard) to do facade manipulation as a best practice. It's necessary to wait at least until initializeNotifier for facade manipulation in MultiCore, but the reason you should really wait until onRegister in all cases for facade activity is that a Proxy or Mediator should be registered and ready before taking any action that could begin a conversation with other actors.

-=Cliff>


Logged
joao.saleiro
Newbie
*
Posts: 6


View Profile Email
« Reply #2 on: June 18, 2008, 06:41:46 »

Cliff,

thank you a lot, once again. :)
All is clear, except number 2:

>2.
>If I have views inside other views, I am doing this to register the mediators on the StartupCommand:
>
>         facade.registerMediator(new LocalesModuleMediator(app))
>         facade.registerMediator(new LocalesManagerMediator(app.localesManager));
>         facade.registerMediator(new LocaleEditorMediator(app.localesManager.localeEditor));

>> 2. You are placing too much knowledge about the internals of the view component in the command.

So what do you propose? I don't see another way...

Thanks,

João Saleiro
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: August 16, 2008, 04:17:51 »

Here's a link to the new FAQ entry for the deferred instantiation issue:

http://puremvc.org/content/view/91/185/

-=Cliff>
Logged
Pages: [1]
Print