MutationEvents are fired by document host, when anything inside the
document hierarchy has been subjected to any CRUD operation. Any dom
node or attribute.

Our "imaginary" "$ listeners" are actually better described as
"mutation listeners". they will be receiving MutationEvents only when
w3c dom level 2 spec, says they should be fired. Which is *only* when
and if some CRUD operation is changing the state of the document tree.

So ...

$.ajax({
   url: "data.xml",
   dataType: ($.browser.msie) ? "text" : "xml",
   success: function(data){
     var xml;
     if (typeof data == "string") {
       xml = new ActiveXObject("Microsoft.XMLDOM");
       xml.async = false;
       xml.loadXML(data);
     } else {
       xml = data;
     }
     // Returned data available in object "xml"
   }
 });

Above does not affect document tree in any way and is not going to
provoke MutationEvent-s firing.

var div = document.createElement('div'); $(div)...

is also *not* mutating the current document in any way . until one
does (for example) this :

$(div).appendTo( document.body )

At which moment jQuery future "mutator" receives the request to append
the div to the document.body, does it and then signals all the
registered $ "listeners" with MutationEvent objects as specified by
the DOM Level 2 spec.

When time allows, I think I should make a small demo page which will
do this with "normal"  javascript, , while "inside"  CHROME ...

How much is this "breaking the new ground" or not, I do not know. But
it solves a whole category of issues which are (or have been)
"overlooked" in todays "single page app".

--DBJ


On Dec 17, 4:25 am, John Arrowwood <jarro...@gmail.com> wrote:
> And what would this mean in the case where I have downloaded an XML document
> via $.ajax()?  That $ will not be an observer of the $(document) instance,
> will it?
>
> Or if I create fragments that are not yet in the DOM, such as
>
> var foo = document.createElement('div');
> $(foo)...
>
> That instance should not be a listener, should it?
>
>
>
> On Thu, Dec 17, 2009 at 12:50 AM, DBJDBJ <dbj...@gmail.com> wrote:
> > MutationEvents are fired whenever and wherever any CRUD operation is
> > done on the document tree.
> > To do this, one needs to redesign jQuery to follow an Observer
> > pattern.
> > Where observable is a single instance of jQ 'mutator'. Imagine that
> > instead of this (currently in core.js )
>
> > // Handle $(""), $(null), or $(undefined)
> > if ( !selector ) {      return this;  }
>
> > We do this (and a lot more) :
>
> > // Handle $(""), $(null), or $(undefined)
> > if ( !selector ) {      return rootjQuery ;  }
>
> > Now we have rootjQuery (aka $(document) ) as an single observable
> > which sends MutationEvents to 'observers', which are all the other $
> > instances.
> > So every $(selector,context) is *also* an observer of the rootjQuery
> > (aka 'mutator'). rootjQuery  publishes (fires) MutationEvents to which
> > all the other '$' are subscribed.
> > In that (imaginary) context, every  '$' is an 'client' of the
> > rootjQuery which is a single 'mutator'. The only one who deals with
> > DOM.
> > The 'others' are just sending it commands to be executed on the
> > document tree, by rootjQuery. Which does it and signals back to all
> > the registered listeners, by publishing to all the subcribers,
> > appropriate MutationEvent objects.
>
> > Important moment here: "to ALL the subscribers". If one '$' removes a
> > node, all the other '$' are sent a MutationEvent about the removal.
>
> > All of this would apply to jQ 'mutator' in every browser host.
> > Regardless of if the browser implements MutationEvents natively or
> > not. For the ones that do not, some internal MutationEvents mechanism
> > will be implemented. Much like Sizzle implements querySelectorAll() if
> > host is not having it.
>
> > This obviously is a "non trivial" change to how jQ works today. Or any
> > other glow, dojo, moo, extjs, fusejs or prototype I know of.
> > But, is the only legal way, to have 2 or more simultaneous dom
> > document tree users.
> > Same applies (conceptually) to any situation with 2 or more users of a
> > single persistent structure.
>
> > --DBJ
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "jQuery Development" group.
> > To post to this group, send email to jquery-...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > jquery-dev+unsubscr...@googlegroups.com<jquery-dev%2bunsubscr...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/jquery-dev?hl=en.
>
> --
> John Arrowwood
> John (at) Irie (dash) Inc (dot) com
> John (at) Arrowwood Photography (dot) com
> John (at) Hanlons Razor (dot) com
> --http://arrowwood.blogspot.com
> Mike Ditka <http://www.brainyquote.com/quotes/authors/m/mike_ditka.html>  -
> "If God had wanted man to play soccer, he wouldn't have given us arms."

--

You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-...@googlegroups.com.
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en.


Reply via email to