Fix a bug where after renaming items, old name references where still laying around.

This commit is contained in:
Jürg Lehni 2011-06-17 13:29:47 +01:00
parent 5f48d4e4a9
commit 30087d046a

View file

@ -85,21 +85,22 @@ var Item = this.Item = Base.extend({
}, },
setName: function(name) { setName: function(name) {
// Empty name '' is stored as undefined internally
if ((name || '') === (this._name || ''))
return;
var children = this._parent._children, var children = this._parent._children,
namedChildren = this._parent._namedChildren; namedChildren = this._parent._namedChildren;
if (name != this._name) { // If the item already had a name,
// If the item already had a name, // remove its property from the parent's children object:
// remove its property from the parent's children object: if (this._name)
if (this._name) this._removeFromNamed();
this._removeFromNamed();
this._name = name || undefined;
}
if (name) { if (name) {
(namedChildren[name] = namedChildren[name] || []).push(this); (namedChildren[name] = namedChildren[name] || []).push(this);
children[name] = this; children[name] = this;
} else { } else if (this._name) {
delete children[name]; delete children[this._name];
} }
this._name = name || undefined;
}, },
/** /**