Re: [dom] MutationObserver with querySelector for elements (#77)

So I was looking at http://www.w3.org/2008/webapps/wiki/MutationReplacement#NodeWatch_.28A_Microsoft_Proposal.29 again, and discussing with zbraniecki and I think one possible option here is to have a way to observe mutations, without actually creating the MutationRecords.
Then one can know that there is some mutation in DOM tree, and use querySelectorAll and effectively implement NodeWatch in JS. One could for example schedule querySelectorAll to run using rAF if there is a DOM mutation. In this l10n case, all the elements which have been handled could be marked with some attribute, say l10nHandled="true" and the selector would skip such elements.

var pending = false;
var mo = new MutationObserver(
  function() {
    if (pending) return;
    pending = true;
    window.requestAnimationFrame(function() {
      pending = false;
      var qa = document.querySelectorAll("<some clever selector>");
      translate(qa);
    }
  }
);
mo.observe(document, {childList: true, subtree: true, attributes: true, noRecordDelivery: true; });
That would effectively just optimize out tons of record objects (and engines wouldn't need to create bunch of js wrappers for the native nodes either). A question is that whether we need to optimize the records out, or can engines deal with that garbage well enough. noRecordDelivery would be rather trivial change so perhaps it is worth to add.

---
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/77#issuecomment-147543173

Received on Monday, 12 October 2015 22:52:57 UTC