diff --git a/lib/mess/tree/selector.js b/lib/mess/tree/selector.js index 6d76477..6dfedaf 100644 --- a/lib/mess/tree/selector.js +++ b/lib/mess/tree/selector.js @@ -9,6 +9,13 @@ tree.Selector = function Selector(elements, filters, zoom, attachment, condition this.zoom = zoom; this.conditions = conditions; this.index = index; + this.updateID(); +}; + +tree.Selector.prototype.updateID = function() { + var filters = Object.keys(this.filters); + filters.sort(); + return this.id = (this.zoom & tree.Zoom.all) + '#' + filters.join('#'); }; tree.Selector.prototype.debug = function() { @@ -26,12 +33,6 @@ tree.Selector.prototype.debug = function() { return str; }; -tree.Selector.prototype.hash = function() { - var filters = Object.keys(this.filters); - filters.sort(); - return (this.zoom & tree.Zoom.all) + '[' + filters.join('][') + ']'; -}; - tree.Selector.prototype.sound = function() { if (!this.zoom) return false; return tree.Filter.sound(this.filters); @@ -48,6 +49,7 @@ tree.Selector.prototype.clone = function() { obj.zoom = this.zoom; obj.conditions = this.conditions; obj.index = this.index; + obj.updateID(); return obj; }; @@ -60,6 +62,7 @@ tree.Selector.prototype.merge = function(obj) { this.index = obj.index; this.zoom &= obj.zoom; this.conditions += obj.conditions; + this.updateID(); return this; }; @@ -75,7 +78,7 @@ tree.Selector.prototype.mergeOrConditions = function(obj) { if (obj.zoom != tree.Zoom.all) { var clone = this.clone(); clone.zoom &= obj.zoom; - if (clone.sound()) result[clone.hash()] = clone; + if (clone.sound()) result[clone.updateID()] = clone; var negatedZoom = ~obj.zoom; for (var id in obj.filters) { @@ -84,7 +87,7 @@ tree.Selector.prototype.mergeOrConditions = function(obj) { selector.zoom &= negatedZoom; if (selector.sound()) { tree.Filter.simplify(selector.filters); - result[selector.hash()] = selector; + result[selector.updateID()] = selector; } } } else { @@ -94,7 +97,8 @@ tree.Selector.prototype.mergeOrConditions = function(obj) { selector.filters[id] = obj.filters[id]; if (selector.sound()) { tree.Filter.simplify(selector.filters); - result[selector.hash()] = selector; + selector.updateID(); + result[selector.updateID()] = selector; } } } @@ -103,7 +107,8 @@ tree.Selector.prototype.mergeOrConditions = function(obj) { clone.zoom &= obj.zoom; if (clone.sound()) { tree.Filter.simplify(clone.filters); - result[clone.hash()] = clone; + clone.updateID(); + result[clone.updateID()] = clone; } } @@ -135,6 +140,7 @@ tree.Selector.prototype.negate = function() { obj.zoom = ~this.zoom; obj.conditions = this.conditions obj.index = this.index; + obj.updateID(); return obj; }; diff --git a/test/specificity.test.js b/test/specificity.test.js index 360f48b..1e13672 100644 --- a/test/specificity.test.js +++ b/test/specificity.test.js @@ -20,6 +20,7 @@ function cleanupItem(key, value) { else return tree.Zoom.toString(value); } else if (key === 'op') return value.value; + else if (key === 'id') return undefined; else if (key === 'val') return value.value; else if (key === 'conditions' && value == 0) return void null; else return value;