Title: Command Registration questions Post by: puremvc on December 13, 2007, 10:04:20 Thomas asked:
- What should happen when the same command is registered for the same notification string multiple times? Currently, in the AS3 version, when the same Command is registered for the same notification string multiple times, in the Controller we store only one reference to the registration, the previous commandMap key is overwritten. However, we do register a new observer regardless of whether there was already a Command registered by that name: public function registerCommand( notificationName : String, commandClassRef : Class ) : void This was based on the assumption that registration of commands will happen in one place and its easy to see if you've duplicated yourself. It hasn't been a problem, but it should be handled more like this: public function registerCommand( notificationName : String, commandClassRef : Class ) : void Once a key is registered for a given notification, subsequent attempts to register a Command to that notification should be disregarded. -=Cliff> Title: Re: Command Registration questions Post by: arasoft on December 14, 2007, 04:25:32 Since the documentation states that the command registered last should be the one used, we propose a different implementation which in our Java port currently looks like this:
public void registerCommand( String notificationName, Class commandClassRef ) { if (null != this.commandMap.put( notificationName, commandClassRef )) return; this.view.registerObserver( notificationName, new Observer( new IFunction() { public void onNotification( INotification notification ) { executeCommand( notification ); } }, this ) ); } We replace the command if one was registered before, but do not add another observer. Okay with you? Title: Re: Command Registration questions Post by: puremvc on December 14, 2007, 01:20:09 Yes, since the observer will point to the same place, the controller's executeCommand method. I agree.
-=Cliff> |