Element#matches() is currently being used in a few places in the amp-story extension. The function, however, has a quirk on older browsers:
Several browsers implement this, prefixed, under the non-standard name matchesSelector().
https://developer.mozilla.org/en-US/docs/Web/API/Element/matches
Element#matches() with our matches() helper in dom.js.Bonus points:
matches() with closest or closestBySelector and switching the implementation.presubmit-checks.js that warns against usage of native matches().Fixes #11816 in the description and mention me (@choumx).If you have questions ask in this issue or on your Pull Request (if you've created one) or see the How to get help section of the Getting Started guide.
Hi, I would like to take on this issue if no one is working on this issue.
Awesome, go for it @reznord! 馃槃
@reznord Have you started working on this yet? Still interested?
Hey, sorry got busy with some office work.
Will look into this today. Is there a place (slack or discord) where I can ask for help if I am stuck at some point.
Yes, we have a Slack channel (sign up required). More details here: https://github.com/ampproject/amphtml/blob/master/CONTRIBUTING.md#ongoing-participation
Is this issue in progress or is it available please?
@sanjsanj Please take this issue since Anup seems busy. Thanks!
@choumx Cheers, I'll have a look! :)
@choumx I think I've done the basic task and would like it to be reviewed to get feedback, however I'd also like to have a go at the bonus tasks but have questions about them, should I wait til it's all done or would you like to have a look at a PR first please?
Bonus:
The first one about performance of matches() sorry maybe I'm being really dumb but I don't understand what that means, could you clarify please? I can see that matches() uses the appropriate native browser method, and that closestBySelector() can return closest() with matches() as the callback but I still don't get the question :)
I tried to run gulp presubmit before I start fiddling with the presubmit-checks but right off the bat I get quite a lot of errors, is this expected?
Let's start with the core fix in your first PR and we can follow up with another PR.
Sorry I could've phrased the bonus more clearly. Basically I think that closest() may be more performant than matches() in some cases, but I might be wrong.
I tried to run gulp presubmit before I start fiddling with the presubmit-checks but right off the bat I get quite a lot of errors, is this expected?
Shouldn't happen. Try creating your PR and I'll help take a look on the PR's build logs.
My PR is in, when you get a chance pls.
The CI is still failing because it's finding references to .matches in gulp presubmit. Did you want it replacing throughout the project or just in amp-story?
There's an issue with my matcher that I'll fix as well, it shouldn't be picking up occurrences in amp-story, but that'll have to wait until after work tomorrow. And I can act on any other feedback you have then as well.
I notice in the CI it didn't have issues with gulp presubmit but I am having them locally. I'm pretty sure it's something simple I'm missing, it's complaining about import and restricted words.