W3C home > Mailing lists > Public > public-webapps@w3.org > July to September 2012

Re: [UndoManager] Re-introduce DOMTransaction interface?

From: Olli Pettay <Olli.Pettay@helsinki.fi>
Date: Thu, 05 Jul 2012 21:07:00 +0300
Message-ID: <4FF5D7C4.5040208@helsinki.fi>
To: Ryosuke Niwa <rniwa@webkit.org>
CC: public-webapps <public-webapps@w3.org>, Ojan Vafai <ojan@chromium.org>, Jonas Sicking <jonas@sicking.cc>, Ehsan Akhgari <ehsan@mozilla.com>, Erik Arvidsson <arv@chromium.org>, Adam Barth <w3c@adambarth.com>, Sukolsak Sakshuwong <sukolsak@gmail.com>, Aryeh Gregor <ayg@aryeh.name>
Btw, is there something unique with UndoManager which causes implementation problems in WebKit?
There are plenty of other APIs not using eventlisteners which take JS callbacks: setTimeout, requestAnimationFrame,
Google's File System API, PeerConnection ... Why aren't those causing problems?

We shouldn't change the UndoManager API because of implementation issues, but if event based API ends up being better.



On 07/05/2012 01:38 AM, Ryosuke Niwa wrote:
> Hi all,
>
> Sukolsak has been implementing the Undo Manager API in WebKit but the fact undoManager.transact() takes a pure JS object with callback functions is
> making it very challenging.  The problem is that this object needs to be kept alive by either JS reference or DOM but doesn't have a backing C++
> object.  Also, as far as we've looked, there are no other specification that uses the same mechanism.
>
> Since I want to make the API consistent with the rest of the platform and the implementation maintainable in WebKit, I propose the following changes:
>
>   * Re-introduce DOMTransaction interface so that scripts can instantiate new DOMTransaction().
>   * Introduce AutomaticDOMTransaction that inherits from DOMTransaction and has a constructor that takes two arguments: a function and an optional label
>
> After this change, authors can write:
> scope.undoManager.transact(new AutomaticDOMTransaction{function () {
>      scope.appendChild("foo");
> }, 'append "foo"'));
>
> instead of:
>
> scope.undoManager.transact({executeAutomatic: function () {
>      scope.appendChild("foo");
> }, label: 'append "foo"'});
>
> And
>
> document.undoManager.transact(new DOMTransaction({function () {
>          // Draw a line on canvas
>      }, function () {
>          // Undraw a line
>      }, function () { this.execute(); },
>      'Draw a line'
> }));
>
> instead of:
>
> document.undoManager.transact({ execute: function () {
>          // Draw a line on canvas
>      }, undo: function () {
>          // Undraw a line
>      }, redo: function () { this.execute(); },
>      label: 'Draw a line'
> });
>
> Best,
> Ryosuke Niwa
> Software Engineer
> Google Inc.
>
Received on Thursday, 5 July 2012 18:07:40 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:53 GMT