From f2f34c3b75eb70479bd9c9aca01effdd870c3e04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sun, 27 Dec 2015 14:49:53 +0100 Subject: [PATCH] Some minor fixes in new #getItems() code. --- src/item/Item.js | 15 ++++++--------- test/tests/Item_Getting.js | 14 +++++++------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/item/Item.js b/src/item/Item.js index 8a8dad44..e7ccf8b7 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -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; }, /** diff --git a/test/tests/Item_Getting.js b/test/tests/Item_Getting.js index 86d9f477..d3cfe40f 100644 --- a/test/tests/Item_Getting.js +++ b/test/tests/Item_Getting.js @@ -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); });