Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support matchesSelector and the like #114

Open
fabiosantoscode opened this issue Jul 23, 2014 · 1 comment
Open

Support matchesSelector and the like #114

fabiosantoscode opened this issue Jul 23, 2014 · 1 comment

Comments

@fabiosantoscode
Copy link
Contributor

When trying to find an element which matches a delegation selector, the findTarget function must select every element which matches the selector (potentially expensive), and loop that selection for each depth level in the DOM tree. It could get pretty suboptimal when the matched selection is large.

The most optimal way would be to go up in the DOM tree, calling matchesSelector once per level.

matchesSelector is a bleeding edge feature (I don't think any browser supports it without prefix yet), but Sizzle (and thus, jQuery) has it.

I propose the use of the currently available matchesSelector functions, and the addition of a setMatchesSelectorFunc function, receiving a function(selector) -> boolean. Users can use that to pass in their shims.

This does not mean that querySelector should be dropped. Just that browsers with matchesSelector will have better delegation performance.

@rvagg
Copy link
Collaborator

rvagg commented Jul 23, 2014

I'm open to a change for this, last I heard there were some concerns around the performance of matchesSelector() over alternatives but that was long ago when it was brand new. I do some heavy feature detection for matchesSelector() and query engine matches() discovery in traversty that may be of use, there would just need to be a solid fall-back where there is neither a native matchesSelector() nor a query engine plugged in with some kind of matches() support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants