Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Welcome, Guest. Please login or register.
December 12, 2017, 08:30:38 PM
Home Help Search Login Register
News: Please DM @puremvc on Twitter to gain forum access. Spambots are why we can't have nice things.
Pages: [1]
Print
Author Topic: Listen for component events inside mediator  (Read 2300 times)
arend
Newbie
*
Posts: 3


View Profile
« on: January 14, 2009, 11:49:39 PM »

Hi all,

I have a Flex MXML navigation component with a couple of simple buttons inside, that has a mediator.

There are two options:
1
Setup event listeners for the buttons inside the MXML component and dispatch custom events for the mediator to be picked up.

2
Add event listeners inside the mediator, directly on the buttons inside the MXML component.
Like this: mainMenu.mainMenuButtonHelp.addEventListener(MouseEvent.CLICK, onHelpButtonClicked);

Does it break the view components encapsulation if I register for events from inside the mediator ?

It seems a bit redundant to dispatch custom events in the MXML component and then listen for those events inside the mediator.
Logged
arend
Newbie
*
Posts: 3


View Profile
« Reply #1 on: January 15, 2009, 07:06:40 AM »

After reading the Implementation Idioms and Best Practices once again I came to following conclusion:
Despite the seemingly redundant event handling in both the mediator and the MXML component it's probably better to dispatch custom events from the MXML component.

Especially possible later changes in the component won't necessarily force a change in the mediator.

Thanks goes to Cliff Hall for his excellent documentation.
Logged
Joel Hooks
Courseware Beta
Sr. Member
***
Posts: 146


baby steps

46288188 passport@provinsal.com joeltuff
View Profile WWW
« Reply #2 on: January 15, 2009, 07:37:09 PM »

After reading the Implementation Idioms and Best Practices once again I came to following conclusion:
Despite the seemingly redundant event handling in both the mediator and the MXML component it's probably better to dispatch custom events from the MXML component.

Especially possible later changes in the component won't necessarily force a change in the mediator.

Thanks goes to Cliff Hall for his excellent documentation.

When I first started using PMVC I went for option 1. It is mess. Option 2 gives a lot more freedom, versatility, portability, and overall system knowledge.
Logged

http://joelhooks.com - my ramblings about developing with actionscript and python using pureMVC and django respectively.
Pages: [1]
Print
Jump to: