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

Issue/209 #231

Merged
merged 2 commits into from
Aug 24, 2017
Merged

Issue/209 #231

merged 2 commits into from
Aug 24, 2017

Conversation

p2kmgcl
Copy link
Contributor

@p2kmgcl p2kmgcl commented Apr 30, 2017

These commits solve the report described con #209, however, there are three things pending before finishing:

  • I only have passed the tests on latest Chrome and Firefox (for Linux). Checking the MDN documentation I have found that DOMException is a common type of exception implemented by Chrome, Firefox, Edge and IE (links below), buy I have no information about Safari implementation.
  • I thought about another way of implementing hasClassWithNative_, and it's returning false if the given className has an space (same than hasClassWithoutNative_). Personally I prefer relying on the native implementation and then catching the error, but I am not sure what kind of behaviour you prefer.
  • For checking the coverage, I temporary inverted the "has native implementation", because I have no browser without a native implementation. Maybe you have some kind of browserstack for the testing.

MDN DOMException docs: https://developer.mozilla.org/en-US/docs/Web/API/DOMException
MSDN DOMException docs: https://msdn.microsoft.com/es-es/library/ff974354(v=vs.85).aspx

@@ -340,7 +340,18 @@ export function hasClass(element, className) {
* @private
*/
function hasClassWithNative_(element, className) {
return element.classList.contains(className);
try {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try/catch won't be optimized in browsers, would be better to check for presence of element.classList.

@p2kmgcl
Copy link
Contributor Author

p2kmgcl commented May 1, 2017

Ok, I have updated my PR and:

@jbalsas
Copy link
Contributor

jbalsas commented Aug 22, 2017

Hey @Robert-Frampton, this should be good to go. Care to take a look and merge if all seems fine?

Thanks! ☺️

@robframpton
Copy link

robframpton commented Aug 22, 2017

@p2kmgcl

Why not remove the try catch block and check for whitespace in _hasClassWithNative like you are in _hasClassWithoutNative?

function hasClassWithNative_(element, className) {
	return className.indexOf(' ') < 0 && element.classList.contains(className);
}

That way there is no error to catch.

@p2kmgcl
Copy link
Contributor Author

p2kmgcl commented Aug 23, 2017

@Robert-Frampton you are totally right. I will modify the PR and notify you in a couple of days. Thanks for the correction :)

Pablo Molina added 2 commits August 24, 2017 13:02
Now the pass the given test. For the case of hasClassWithNative_, it
tries to use the native methods, but catches a dom exception with
the text "contains HTML space characters", other exceptions are thrown.
@p2kmgcl
Copy link
Contributor Author

p2kmgcl commented Aug 24, 2017

@Robert-Frampton ready to go

@robframpton
Copy link

LGTM.

@robframpton robframpton merged commit 8176b78 into metal:master Aug 24, 2017
@p2kmgcl p2kmgcl deleted the issue/209 branch August 25, 2017 06:58
@brunobasto
Copy link

Hey guys, should we close #209 as well?

@jbalsas
Copy link
Contributor

jbalsas commented Sep 13, 2017

Yeah, done! 😉

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

Successfully merging this pull request may close these issues.

5 participants