View Full Version : Ext.Queryable - child and down function warnings when more than 1 match

28 Jan 2014, 8:51 AM
Ext.Queryable exposes ComponentQuery support on components.

When using child and down you are looking for the first descendant child.

In the case where you are exclusively looking for only one child to match the selector it would be really nice if the implementation checked the size of the result array and output a warning (in dev mode) when more than 1 match is made.

This is super useful when developing for finding problems both in your selectors and in finding unrecovered views, etc.

It would be nice if there was a global flag on the Queryable mixin, say 'useStrict', just like Ext.Date that turned on a 'strict' mode for down and child...and if more than one item matches a warning or error is output to the log...a bit like.

A similar check should be made in the Controller's getRef implementation.

What do people think?
Is this a valid enhancement request?

28 Jan 2014, 12:43 PM
Just because you're asking it to match the first item doesn't mean there can't be multiple matches.

I could be asking for:


Asking for one doesn't preclude there being others that match. I can see some value if you're matching by itemId, but I think it will end up with a whole lot of false positives.

28 Jan 2014, 12:46 PM
Right...that's why I'm asking for an optional flag like useStrict to enable log warnings.

There are zero uses of down in the current large application I'm working on - all selectors are targeted to guarantee a single item response...anything else is a programming error of some sort.

I'd be interested to see use cases of when child is used with such an un-targeted selector and question whether query would be better in those cases.

28 Jan 2014, 1:27 PM
A few (fictitious) cases spring to mind:

panel.down(':focusable').focus(); // Find the first focusable item, focus it
toolbar.down([enabled=true]).highlight(); // Grab the first enabled button and have it give off a little glow

28 Jan 2014, 1:30 PM
I guess I'd critque your code by asking which field are you focusing and which button are you modifying?

What happens when I work on your project and add a field in at the top and a button to the left.

Those selectors suck.

But I'll close out my query - I'm done.