mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-08 13:52:06 -05:00
Clean up Item#name code.
This commit is contained in:
parent
16ab461fde
commit
a9fbc41e15
1 changed files with 11 additions and 16 deletions
|
@ -45,12 +45,12 @@ var Item = this.Item = Base.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
_removeFromNamed: function() {
|
_removeFromNamed: function() {
|
||||||
var children = this._parent._children;
|
var children = this._parent._children,
|
||||||
var namedChildren = this._parent._namedChildren;
|
namedChildren = this._parent._namedChildren,
|
||||||
var name = this._name;
|
name = this._name,
|
||||||
|
namedArray = namedChildren[name];
|
||||||
if (children[name] = this)
|
if (children[name] = this)
|
||||||
delete children[name];
|
delete children[name];
|
||||||
var namedArray = namedChildren[name];
|
|
||||||
namedArray.splice(namedArray.indexOf(this), 1);
|
namedArray.splice(namedArray.indexOf(this), 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]
|
||||||
|
@ -66,29 +66,24 @@ var Item = this.Item = Base.extend({
|
||||||
* The name of the item.
|
* The name of the item.
|
||||||
*/
|
*/
|
||||||
getName: function() {
|
getName: function() {
|
||||||
if (this._name)
|
|
||||||
return this._name;
|
return this._name;
|
||||||
},
|
},
|
||||||
|
|
||||||
setName: function(name) {
|
setName: function(name) {
|
||||||
var children = this._parent.children;
|
var children = this._parent._children,
|
||||||
var namedChildren = this._parent._namedChildren;
|
namedChildren = this._parent._namedChildren;
|
||||||
if (name != this.name) {
|
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 ? name : undefined;
|
this._name = name || undefined;
|
||||||
}
|
}
|
||||||
if (name) {
|
if (name) {
|
||||||
if (!namedChildren[name]) {
|
(namedChildren[name] = namedChildren[name] || []).push(this);
|
||||||
namedChildren[name] = [this];
|
|
||||||
} else {
|
|
||||||
namedChildren[name].push(this);
|
|
||||||
}
|
|
||||||
children[name] = this;
|
children[name] = this;
|
||||||
} else {
|
} else {
|
||||||
children[name] = undefined;
|
delete children[name];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue