W3C home > Mailing lists > Public > whatwg@whatwg.org > September 2011

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

From: Ryosuke Niwa <rniwa@webkit.org>
Date: Mon, 12 Sep 2011 23:05:16 -0700
Message-ID: <CABNRm63iGYaZDkSgo7cgopLW_0+twv_w8yLsteVSZS+DZExwfQ@mail.gmail.com>
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
Received on Monday, 12 September 2011 23:05:16 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:36 UTC