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: multiple commands mapped to one notification  (Read 3569 times)
tjiddy
Jr. Member
**
Posts: 10


View Profile Email
« on: April 21, 2008, 02:39:54 »

So I wrote up a test app, and if I do this in my facade

:
registerCommand(EVENT1, HelloCommand);
registerCommand(EVENT1, WorldCommand);

Only the WorldCommand gets executed.  Is this by design? 
I would think I could map a plethora of commands to the same notification. 

I'm sure I'm missing something....
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: April 21, 2008, 03:18:56 »

Nope. Notification name to Command relationship is one to one. Multiple mediators may respond to create a self-ordering View, but only one Command may respond to a given Notification. The reason is you can't guarantee order of execution of the Commands or of the Observers in the queue, particularly if you register and unregister Commands and Mediators based on system state.

To solve this problem, use a MacroCommand which executes a list of Commands, if need be. That allows you to control the order of the commands, and to programatically choose which Commands will be included based on system state in the initializeMacroCommand method.

For instance, based on a given application context, you might be in 'edit mode' and so when the user clicks and drags an object, they're moving its position on its canvas. But if you're not in edit mode, clicking and dragging might mean something different. like panning the viewport.

Rather than registering and unregistering commands based on application state, you can have the MacroCommand execute one set of Simple(or Macro)Commands in one mode and a different set in a different mode. This allows the handler for a general gesture to control its runtime context-sensitive behavior dynamically based upon system state.

Hope this helps,
-=Cliff>
« Last Edit: April 21, 2008, 03:20:27 by puremvc » Logged
tjiddy
Jr. Member
**
Posts: 10


View Profile Email
« Reply #2 on: April 21, 2008, 03:33:35 »

yea, that makes perfect sense.  Thanks for the clarification.  In my case, I don't care what order things are executed in, as long as they are executed after a specific notification.  Maybe I'll randomize them in my MacroCommand every time just for fun :)
Logged
Pages: [1]
Print