[Catalyst] Use Undo on A List Apart

Matthieu Codron matthieu at codron.org
Sat Jul 28 12:00:14 GMT 2007


Hi,

Le 26 juil. 07 à 08:55, Bill Moseley a écrit :

> There's a recent article titled "Never Use a Warning When you Mean
> Undo" at http://alistapart.com/articles/neveruseawarning.
>
> I'm wondering about the implementation.
>

I read that too. Interesting, but from what I see undo is not so easy  
to implement.

> One option is to create actions for every possible undo operation.
> That would mean that each undo operation would generate a specific
> link, including request parameters to identify the item that needed to
> be, well, undone.
>
> Another possibility would be to generate the code for the undo action
> and place it in the session so that there's just an /undo link.  /undo
> fetches the code and evals/executes it.  The /undo link would only be
> available for a single request after displaying the undo link.

I like more the idea of a generic undo request. This could be part of  
a plugin providing this action and the necessary infrastructure to  
implement the "un-doing" of the action.
This plugin could implement a simple version of the classic Memento  
pattern (http://en.wikipedia.org/wiki/Memento_pattern)

Then you could declare undoable actions like this:

sub delete : Local Undoable {
     my ($self, $c) = @_;
     ...

     $c->save_undo( $object );
}

# Actual undo action
sub undo_delete : Private {
   my ($self, $c, $restored_object) = @_;
   ...
   # recreate object from $restored_object
}

The generic undo action would then forward to the above declared  
undo_delete action, restoring the saved object.
This would even perhaps allow multi-level undo.


> If the undo link is part of the server response the back button might
> lead to a stale undo link.  If that's a problem I suppose could do an
> AJAX request to fetch the link to prevent it showing up if using the
> back button.
>

Could be in the plugin too, I guess.

-- 
Matthieu Codron
matthieu at codron.org


More information about the Catalyst mailing list