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

Re: Mutation events replacement

From: David Flanagan <dflanagan@mozilla.com>
Date: Fri, 01 Jul 2011 15:25:22 -0700
Message-ID: <4E0E4952.70300@mozilla.com>
To: Olli@pettay.fi
CC: Olli Pettay <Olli.Pettay@helsinki.fi>, Rafael Weinstein <rafaelw@google.com>, Boris Zbarsky <bzbarsky@mit.edu>, public-webapps <public-webapps@w3.org>
On 7/1/11 3:06 PM, Olli Pettay wrote:
> On 07/02/2011 12:59 AM, David Flanagan wrote:
>> But, and I think this is an interesting but, what happens if a node is
>> removed from the document, has its attributes or data or children
>> changed and is then re-inserted into the document? If the node has no
>> parent when it is changed, no mutation events will be generated, will
>> they?
> Sure they are. If the node has listeners, they will get called.
I'm assuming the listeners are further up the tree.

To give a concrete example, to a mutation event listener (under Rafael's 
proposal, but maybe yours, too?) on the document, these two sequences of 
operations will be indistinguishable:

// Generates one event for removing the title text from the <head> and 
another for
// inserting it into the <body>.  (Assume 
document.head.firstChild.firstChild is the text node inside
// the <title> tag.

// Here we generate the same sequence of mutation events
var titletext = document.head.firstChild.firstChild.
titletext.parentNode.removeChild(titletext);  // Generates a remove event
titletext.data = "foobar";                               // Generates a 
mutation event no one sees
document.body.appendChild(titletext);         // Generates an insert event

I claim that it is useful to be able to distinguish these two cases with 
some sort of move event.  If moves are treated as remove/insert pairs, 
then listeners have to assume that arbitrary changes could have taken 
place between the two.

Received on Friday, 1 July 2011 22:26:00 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 18:13:22 UTC