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: Only one command per notification...why?  (Read 7184 times)
schickm
Newbie
*
Posts: 9


View Profile Email
« on: July 20, 2008, 08:48:32 »

I realized today that if I use registerCommand() multiple times with the same notification it only chooses the last one.  I'm at a loss as to why this is because it seems to me that it would be great to hook up multiple commands to the same notification and just write them with the understanding that they should not be dependent on the order that they are executed. 

What I'm doing now as a replacement is declaring a constant like LOAD_PIECES, and then doing:

:
registerCommand( LOAD_PIECES, LoadPiecesCommand );

Which is fine for one or two, but when you've got 10 things to load you end up with a whole bunch of constants that are pretty repetitive.  But, I'd say I've got a pretty low tolerance for code that is long and very explicit since I've been coding in ruby and lisp.  So I should probably learn to embrace the verbosity required to code in as31.
 
However like most things puremvc, I'm sure there is a very logical reason why a notification can only have one registered command.   Would someone mind explaining said reason so that I stop coding things wrong?  Is the same true for mediators: if one mediator has the same constant in listNotificationInterests() as another, does only the later executed mediator get the notification?

1 I'm not ripping on as3 for being verbose. I drives me nuts when people argue the merits of a symbolic language like ruby and lisp vs.  a more verbose language like as3 or java.  And verbose is probably not the proper word to describe that family of languages, but I wasn't a CS major so I hope people get what I mean.
« Last Edit: July 20, 2008, 09:11:51 by schickm » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: July 20, 2008, 10:22:26 »

Try using a MacroCommand.

The reason for one Command per Notification has to do with the mechanism used for executing Commands.

The Controller is registered as the observer for the note, and when its ececute method is called, it looks up the class to instantiate as in a map keyed by note name.

Now it could maintain its own observer list and all that like the view does for Mediators but it isn't really worth the complexity. MacroCommands are generally an acceptable solution. 
And no, Mediators do not share this limitation. You may have any number interested in the same note.

-=Cliff>
PS: to be 'less verbose' I was going to leave it at the first sentence, but thought it might be rude.:)

The challenge is to use as much verbosity as clarity demands, but no more.
Logged
schickm
Newbie
*
Posts: 9


View Profile Email
« Reply #2 on: July 20, 2008, 04:09:16 »

Ah yes, the MacroCommand!  Completely forgot about that little guy.

thanks Cliff!  You are the pasta in my bowl. 

Logged
Pages: [1]
Print