Permalink
Browse files

Add findOne() convenience method on Container

  • Loading branch information...
pronebird committed Oct 23, 2014
1 parent 7f853dd commit 41e0466286373a861a4ecb78f11b275ab5cf605a
Showing with 18 additions and 0 deletions.
  1. +3 −0 src/Container.js
  2. +15 −0 test/unit/Container-test.js
View
@@ -179,6 +179,9 @@
return Kinetic.Collection.toCollection(retArr);
},
findOne: function(selector) {
return this.find(selector)[0];
},
_getNodeById: function(key) {
var node = Kinetic.ids[key];
@@ -1024,6 +1024,21 @@ suite('Container', function() {
layer.draw();
});
// ======================================================
test('test findOne() selector by quering existing and non-existing nodes by name', function () {
var stage = addStage();
var layer = new Kinetic.Layer();
var rect = new Kinetic.Rect({
name: 'rect'
});
layer.add(rect);
assert.equal(layer.findOne('.rect'), rect, 'findOne() on existing node must return a single node.');
assert.equal(layer.findOne('.doesNotExist'), undefined, 'findOne() on non-existing node must return undefined.');
});
// ======================================================
test('add layer then shape', function() {
var stage = addStage();

0 comments on commit 41e0466

Please sign in to comment.