ericdrowell / KineticJS

KineticJS is an HTML5 Canvas JavaScript framework that extends the 2d context by enabling canvas interactivity for desktop and mobile applications.
http://www.kineticjs.com
3.98k stars 753 forks source link

Add findOne() convenience method on Container #1033

Closed pronebird closed 9 years ago

pronebird commented 9 years ago

There are situations when you want to find a single node by name or id. I don't see any convenient way to do this in KineticJS since Container.find() always returns array. findOne convenience method can be found from DOM API to ORM libraries, so I believe KineticJS should have one too :)

I have added a Container.findOne() convenience method and a simple test. it returns a node or undefined.

Optimized implementation should of course break the find() loop after first match found.