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

Re: [UndoManager] Re-introduce DOMTransaction interface?

From: Yuval Sadan <sadan.yuval@gmail.com>
Date: Fri, 6 Jul 2012 00:49:54 +0300
Message-ID: <CAJaqjSpRDDfz8jhNrqeiqRG4NwqtMA3HfasZ0QEfD9_K12GNQQ@mail.gmail.com>
To: Ryosuke Niwa <rniwa@webkit.org>
Cc: public-webapps <public-webapps@w3.org>, James Graham <jgraham@opera.com>
>
>
> > To sum up, as an author I vote for--
> > var t = undoManager.transact("foo");
> > t.onundo = function() { ... };
> > OR t.setUndo(function() { .... });
>
> How do you envision it should work with an automatic transaction?
>
> We need some mechanism to tell the UA "record DOM mutations while I'm
> calling this function".
>
My preliminary thought is that transactions should be automatic unless
otherwise stated. Following that rationale, perhaps

var t;
// performs automatic transaction, no undo or redo needs specifying
t = undoManager.transact("foo", function() { ... });
t.execute();

t = undoManager.transact("bar", function() { ... });
t.onundo = function() { /* custom undo */ };
t.execute();

t = undoManager.transact("foobar", function() { ... });
t.onredo = function() { /* custom redo */ };
t.execute();

Whether onundo/onredo are assigned upon execute() is well defined, so
basing behavior on that is clear enough for me. Plus, I wonder - what is a
non-automatic transaction without an undo? A freak?

Some more ideas -- besides the other more verbose solutions (having
executeAutomatic(), a special property e.g. isAutomatic), you might extend
the vocabulary of UndoManager: either offer an additional argument for
transact (e.g. transact("foo", function() { ... }, true) ), or better imho,
have transact() specify a custom transaction and introduce record() (just
to avoid autoTransact()) which will specify an automatic transaction, thus
having:

t = undoManager.transact("lala", function() { });
t.execute(); // error, transact() with no undo()

t = undoManager.record("baba", function() {});
t.onundo = function() { }; // will be ignored/error thrown, since we're on
record()
t.execute();
Received on Thursday, 5 July 2012 21:50:43 GMT

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