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
|
|
|
Show Posts
|
Pages: [1]
|
2
|
Announcements and General Discussion / Getting Started / Re: Merging/combining commands?
|
on: January 08, 2010, 05:20:34
|
When you merge multiple commands, those commands could also be UndoableCommands ?
And if you plan to merge them at runtime, how do you plan to store the information about which commands merge with what ? If you override initializeMacroCommand that won't help ? You can't use notification's body to find out the subcommands you want to run ?
Also, do you want to run the commands sequentially or in parallel ?
|
|
|
3
|
Announcements and General Discussion / Architecture / Re: Implementing Undoable commands in PureMVC
|
on: January 12, 2009, 11:33:45
|
Richard, I'm not sure if I got it right, but I'm wondering why would you need an UndoSetPropertyCommand, if you already have SetPropertyCommand. Can't you undo SetPropertyCommand with SetPropertyCommand ?
In my projects I do something like this: 1. I have an UpdateCommand that undos itself, so the registered undo command is also UpdateCommand 2. When I call that command I send the updated state of the object I want to change into the body of the note. I.e. note.getBody() would be an instance of ItemVO, let's call it 'newProperties' 3. When I execute the command, I save a snapshot with the object I am about to change, so I retrieve a copy of ItemVO, let's call it 'originalProperties' 3. I perform the changes in the model so that the view updates properly according to the 'newProperties' 4. I copy the snapshot 'originalProperties' into the note's body because this is the information I need to call undo. 5. Calling undo/redo it will simply switch 'newProperties' with 'originalProperties'.
I don't know if this can be applied to your case though.
|
|
|
10
|
Announcements and General Discussion / Architecture / Re: Implementing Undoable commands in PureMVC
|
on: November 30, 2007, 05:05:45
|
Hi,
I got inspired from your ideas and I thought I should post mine, just to continue the discussion you initiated. These days I had to implement an undo/redo system into an application and this is how I did it:
1. I created an UndoableCommandBase class that extends SimpleCommand. UndoableCommandBase is a superclass for any command within the application that must be undoable. I added 4 more methods. a. registerUndoCommand – registers the command that needs to be called on undo
/** * Registers the undo command * @param cmdClass The class to be executed on undo */ public function registerUndoCommand( cmdClass:Class ):void { undoCmdClass = cmdClass; }
b. executeCommand – method that needs to be overridden in the sub class
/** * This method must be overridden in the super class. * Post here the code the be executed by the command. */ public function executeCommand():void { throw new Error("The undoable command does not have 'executeCommand' method implemented."); }
c. redo – recalls executeCommand
public function redo():void { executeCommand(); }
d. undo – creates an instance of the undoCommand (registered at point 1) and executes it
public function undo():void { if ( undoCmdClass == null ) throw new Error("Undo command not set. Could not undo. Use 'registerUndoCommand' to register an undo command"); /** The type of the notification is used as a flag, * indicating whether to save the command into the history, or not. * The undo command, should not be recorded into the history, * and its notification type is set to <code>UndoableCommandEnum.NON_RECORDABLE_COMMAND</code> **/ var oldType:String = _note.getType(); _note.setType( UndoableCommandEnum.NON_RECORDABLE_COMMAND ); try { var commandInstance : ICommand = new undoCmdClass(); commandInstance.execute( _note ); } catch ( err:Error ) { trace("Could not call undo on " + this + ". " + err.getStackTrace() ); } _note.setType( oldType ); }
e. execute – this method saves the command into the history and calls executeCommand method
/** * Saves the command into the CommandHistoryProxy class * ( if <code>note.getType() == UndoableCommandEnum.RECORDABLE_COMMAND</code> ) * and calls the <code>executeCommand</code> method. * * @param note The Notification instance */ override public function execute(note:INotification):void { _note = note; executeCommand(); if ( note.getType() == UndoableCommandEnum.RECORDABLE_COMMAND ) { var historyProxy:CommandHistoryProxy = facade.retrieveProxy( CommandHistoryProxy.NAME ) as CommandHistoryProxy; historyProxy.putCommand( this ); } }
2. I created command classes by extending UndoableCommandBase with 2 methods:
a. override public function execute(note:INotification) - that calls the super.execute( note ) in order to record the command into the history, and calls registerUndoCommand in order to save the command that will be used for undo b. override public function executeCommand()- method that actually does what is needed inside the command
Here is a sample of how the class looks like :
public class AddItemCommand extends UndoableCommandBase { override public function execute(note:INotification):void { super.execute( note ); registerUndoCommand( RemoveItemCommand ); } override public function executeCommand():void { var itemsProxy:ItemsProxy = facade.retrieveProxy( ItemsProxy.NAME ) as ItemsProxy; itemsProxy.addItem( _note.getBody() as ItemVO ); } }
If you have better ideas I’m looking forward in seeing them. Also, for people that are interested in this solution, I can share the sources of a sample application.
Dragos
PS- Cliff, thanks for sharing with us your work. I discovered pureMVC 2 weeks ago and I already started to use it with my entire team. We’re very exited of this “world”. We’re hoping to have a better scalable and maintainable product at the end, using your solution.
|
|
|
|
|
|