Fix issue with #setName() introduced in recent commit.

This commit is contained in:
Jürg Lehni 2011-06-17 16:32:47 +01:00
parent 503a031bdf
commit 38de43c612

View file

@ -85,22 +85,22 @@ var Item = this.Item = Base.extend({
}, },
setName: function(name) { setName: function(name) {
// Empty name '' is stored as undefined internally // Note: Don't check if the name has changed and bail out if it has not,
if ((name || '') === (this._name || '')) // because setName is used internally also to update internal structures
return; // when an item is moved from one parent to another.
var children = this._parent._children,
namedChildren = this._parent._namedChildren; // If the item already had a name, remove the reference to it from the
// If the item already had a name, // 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) {
var children = this._parent._children,
namedChildren = this._parent._namedChildren;
(namedChildren[name] = namedChildren[name] || []).push(this); (namedChildren[name] = namedChildren[name] || []).push(this);
children[name] = this; children[name] = this;
} else if (this._name) {
delete children[this._name];
} }
this._name = name || undefined; this._changed(ChangeFlags.ATTRIBUTE);
}, },
/** /**
@ -508,10 +508,15 @@ var Item = this.Item = Base.extend({
var children = this._parent._children, var children = this._parent._children,
namedChildren = this._parent._namedChildren, namedChildren = this._parent._namedChildren,
name = this._name, name = this._name,
namedArray = namedChildren[name]; namedArray = namedChildren[name],
if (children[name] = this) index = namedArray ? namedArray.indexOf(this) : -1;
if (index == -1)
return;
// Remove the named reference
if (children[name] == this)
delete children[name]; delete children[name];
namedArray.splice(namedArray.indexOf(this), 1); // Remove this entry
namedArray.splice(index, 1);
// If there are any items left in the named array, set // If there are any items left in the named array, set
// the last of them to be this.parent.children[this.name] // the last of them to be this.parent.children[this.name]
if (namedArray.length) { if (namedArray.length) {