Some minor fixes in new #getItems() code.

This commit is contained in:
Jürg Lehni 2015-12-27 14:49:53 +01:00
parent f2a44a5832
commit f2f34c3b75
2 changed files with 13 additions and 16 deletions

View file

@ -1877,6 +1877,7 @@ var Item = Base.extend(Emitter, /** @lends Item# */{
if (name.hasOwnProperty(key) && !this.matches(key, name[key]))
return false;
}
return true;
} else if (type === 'function') {
return name(this);
} else if (name === 'match') {
@ -1892,13 +1893,11 @@ var Item = Base.extend(Emitter, /** @lends Item# */{
: name === 'type'
? Base.hyphenate(this._class)
: this[name];
if (/^(constructor|class)$/.test(name)) {
if (typeof compare === 'function') {
if (name === 'class') {
if (typeof compare === 'function')
return this instanceof compare;
} else {
// Compare further with the _class property value instead.
value = this._class;
}
// Compare further with the _class property value instead.
value = this._class;
}
if (compare instanceof RegExp) {
return compare.test(value);
@ -1906,11 +1905,9 @@ var Item = Base.extend(Emitter, /** @lends Item# */{
return !!compare(value);
} else if (Base.isPlainObject(compare)) {
return matchObject(compare, value);
} else if (!Base.equals(value, compare)) {
return false;
}
return Base.equals(value, compare);
}
return true;
},
/**

View file

@ -46,7 +46,7 @@ test('Project#getItems()', function() {
var layer = new Layer();
var matches = paper.project.getItems({
type: 'layer'
class: Layer
});
equals(function() {
return matches.length == 1 && matches[0] == layer;
@ -61,20 +61,20 @@ test('Project#getItems()', function() {
var path = new Path();
var matches = paper.project.getItems({
type: 'path'
class: Path
});
equals(function() {
return matches.length == 1 && matches[0] == path;
}, true);
var group = new Group();
var matches = paper.project.getItems({
constructor: Path
className: 'Group'
});
equals(function() {
return matches.length == 1 && matches[0] === path;
return matches.length == 1 && matches[0] === group
}, true);
var group = new Group();
var matches = paper.project.getItems({
type: 'group'
});
@ -84,7 +84,7 @@ test('Project#getItems()', function() {
var raster = new Raster();
var matches = paper.project.getItems({
type: 'raster'
class: Raster
});
equals(function() {
return matches.length == 1 && matches[0] === raster
@ -107,7 +107,7 @@ test('Project#getItems()', function() {
equals(function() {
return paper.project.getItems({
selected: true,
type: 'raster'
class: Raster
}).length;
}, 1);
});