3 Replies Latest reply on Nov 18, 2009 6:24 AM by Alex Uhlmann

    Cairngorm 3 and Commands - best practice

    Richard Butler Level 1

      Hi chaps

       

      Excellent work on CG3, it solves a lot of issues and I really like how it integrates with Parsley; definitely a step forward.

       

      About the integration lib and commands - in Cairngorm 2, it would be quite common to fire off a persistence event directly from a model, like this:

       

      public class User
      {
          public var name : String;
      
          public function save() : void
          {
              new UserEvent( UserEvent.SAVE_USER, this ).dispatch();
          }
      }
      

       

      However, using CG3, something like:

       

      -- SaveUserCommand.as
      
      public class SaveUserCommand
      {
          [Inject]
          public var delegate : IDelegate;
      
          [Command]
          public function execute( event : SaveUserEvent ) : AsyncToken
          {
              return delegate.saveUser( event.user );
          }
      }
      
      -- User.as
      
      [Event( name="saveUser", type="somepackage.event.UserEvent" )]
      
      [ManagedEvents( "saveUser" )]
      
      public class User
      {
          public var name : String;
      
          public function save() : void
          {
              dispatchEvent( new UserEvent( UserEvent.SAVE_USER, this ) );
          }
      }
      

       

      unless we do something funky here, Parsley won't know about domain classes as they are not part of the context, therefore won't pick up the [ManagedEvents] metadata. I'm fairly new to Parsley though, so there may well be a simple way of doing this.

       

      Is there a way of hooking domain classes directly to commands or, with this new architecture, should this be the responsibility of the presentation model instead - i.e. myPM.saveUser( myUser )?

       

      Thanks

      Richard