add an id to selectors

This commit is contained in:
Konstantin Käfer 2011-01-27 22:10:31 -05:00
parent 4e0fee38b4
commit c2931d8983
2 changed files with 17 additions and 10 deletions

View File

@ -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;
};

View File

@ -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;