RE: Surface JavaScript APIs for selector match changes

± var sel = new Selector(".foo", document)
± sel.onchange  = function(event) { } instead.
± ~TJ

FWIW, I like the idea of having a Selector object. Then we can start imagining other useful functions like helpers to compare the relative priority of two selectors, or whether a selector depends on features X or Y.

Just because the conversation is there, I wanted to mention I made a prollyfill for Selectors Observers in the past, that works in that way:

    querySelectorLive("h2~p", {
        onadded: function(e) {
            console.log("h2~p added:");
        onremoved: function(e) {
            console.log("h2~p removed:");

The polyfill is sufficiently good (performance-wise) to be used on real websites while we wait for a standard approach. 

Regarding the idea of sending an array of elements being removed/added, I believe it would be more efficient because much less functions calls need to be done (for loops are cheap), but at the same time it makes the code a bit less elegant, I think. 

Received on Tuesday, 15 April 2014 12:11:44 UTC