views:

108

answers:

2

Is it possible to implement an undo/redo engine with JavascriptMVC?

+1  A: 

Probably. While I've never worked with JavascriptMVC, here is the principle how undo works:

  1. Instead of directly changing anything, you put the code to change something in a "command" object. The command object has two methods: undo() and redo().

  2. When an operation is executed, you create the necessary command objects, invoke redo() on them and add them to a list (the "undo stack").

  3. For undo, pop items off the list and invoke undo() on them and push them on the "redo stack".

  4. For redo, pop from the "redo stack", invoke redo() and push the item on the undo stack.

It doesn't matter whether you do this on the server or on the client but I suggest that you chose one side and stick with it.

Aaron Digulla
A: 

What are you going to use it for? Instead of using undo/redo, can you use it's history plugin? That way undo/redo will work with the forward and back buttons.

Justin Meyer