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: [ DEFUSED ] Register more Simple commands to same events  (Read 10710 times)
gabon
Jr. Member
**
Posts: 14


View Profile Email
« on: February 25, 2008, 10:19:13 »

I encountered an expected behaviour while registering more simple commands to the same event. I found out, also watching the code, that registering another command to an event where another command was registered, SHOULD override and leave the latter registered. What is happening though is that correctly the first command is not registered anymore, but the second is registered twice  (it gets fired twice).
It sounds to big to be a bug, what am I missing?

Cheers, chr
« Last Edit: February 26, 2008, 05:07:35 by puremvc » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: February 25, 2008, 10:47:45 »

Christian,

Would you mind checking that you have the latest version of PureMVC? This was actually addressed one or 2 revs back.

Before, the Controller's registerCommand method created an Observer and stored the Command Class in the commandMap as the value for the Notification name key. If you were overwriting a preexisting mapping, an extra Observer got generated.

The code in registerCommand currently checks to see if the commandMap already has a Command associated with the Notification name passed in. Only if the value is null for that key does it create an Observer. Since all Observers created for Commands are the same (they point to the Controller's executeCommand method), then whatever your new Command was, it got called twice.

Please let me know if replacing your PureMVC.swc (or the source code if you're using flash) fixes this.

BTW, from 2.0 on, all swc files will have a version number as part of the filename, since you can't tell what version you have by looking at it.  We learn as we go with this stuff folks :)

-=Cliff>

« Last Edit: February 25, 2008, 10:51:02 by puremvc » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #2 on: February 26, 2008, 05:06:54 »

Christian

I'm assuming that you were using an old version of PureMVC before the fix was made that I described.

To be sure since I don't have a specific unit test for this, I did a quick test in the project I'm working on. See the attached image.

 * I've set a breakpoint in my ApplicationFacade.initializeController method.

 * Before the breakpoint I:
    > Registered and re-registered the same two notification names multiple times to the wrong commands
    > Finally re-registered the same 2 note names to the correct Commands

 * At the breakpoint, inspecting the facade variables, we can see:
    > We only have 2 commands mapped, and correctly
    > The observer lists for each notification only have one observer each
 
BTW, I will add a unit test for Command re-registration in 2.0 for sure.

-=Cliff>
Logged
gabon
Jr. Member
**
Posts: 14


View Profile Email
« Reply #3 on: February 28, 2008, 03:20:57 »

Hi Cliff, you are right, with the new version it seems to work as expected. It's strange just because I downloaded it less than a month ago.

Thanks a lot, chr
Logged
Pages: [1]
Print