[whatwg] Fixing undo on the Web - UndoManager and Transaction

Ryosuke Niwa rniwa at webkit.org
Mon Sep 12 23:05:16 PDT 2011

I must say that I'm a little sad about the fact I have to tie transactions
so closely with undo manager.

In my original proposal where we have AbstractTransaction interface and two
derived interfaces for automatic and manual transactions, I tried to
decouple the concepts of undomanager and transactions so that they can work
independently of each other in the future.

In this ideal world, AbstractTransaction will have pure-virtual apply,
unapply, reapply methods, and undomanager will simply invoke them regardless
of whether a transaction is automatic or not.  UAs will simply supply
unapply and reapply methods to AutomaticTransaction internally.  So in the
future, we could expose those unapply & reapply methods automatically added
by UAs. This will be useful in apps where you want to apply, unapply,
reapply DOM changes without making them user interactive (i.e. without
modifying UndoManager).  e.g. readonly mode of Etherpad can make use of this

- Ryosuke

On Mon, Sep 12, 2011 at 6:06 PM, Ryosuke Niwa <rniwa at webkit.org> wrote:

> On Mon, Sep 12, 2011 at 5:19 PM, Jonas Sicking <jonas at sicking.cc> wrote:
>> Could you please supply an example where the apply/reapply split leads
>> to cleaner or otherwise better code than using a boolean argument?
> apply: function() {
>   // modify dom
>   // send data back to server
> },
> unapply: function() {
>   // ask server what I should do for undo
>   // modify dom
> },
> reapply: function() {
>   // ask sever what I should do for redo
>   // modify dom
> }
> I can't give you a code from existing apps because such apps do not use
> undoManager API.
> Having slightly different signatures for the apply function on both
>> transaction feels like a much smaller problem. Either we can rename
>> 'apply' on automatic transactions, or we can give it a boolean
>> argument too which is passed 'false'. It's easy enough to ignore
>> arguments in JS, simply don't put them in your function signature.
> I'm fine with adding a boolean argument if we're splitting the interface
> for automatic and manual transactions because then we don't need to have
> boolean argument in automatic transaction's apply.
> - Ryosuke

More information about the whatwg mailing list