-
-
Notifications
You must be signed in to change notification settings - Fork 157
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
Check if window is available before using it #104
Conversation
Some JavaScript platforms break because of the use of window. Below are some platforms I can think of. https://www.nativescript.org/ http://www.appcelerator.com/mobile-app-development-products/ https://facebook.github.io/react-native/ (Possibly)
lib/loglevel.js
Outdated
window.document.cookie = | ||
encodeURIComponent(storageKey) + "=" + levelName + ";"; | ||
} catch (ignore) {} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, this is reasonable. I'd rather flip it and add a guard clause though, rather than indenting the whole function. Can you convert both of these into something like the below instead?
if (typeof window === undefinedType) return;
[...rest of the function...]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
Sorry, JSHint actually doesn't like that example, so the build broke. I disagree though, so I just went and added a quick patch to relax that, and then there was an actual bug, so I fixed that while I was there too. Anyway, all looks good to me now, merging! Thanks for contributing 😃 |
@thomasconner Hmm, wait actually. Looking closer at this, I'm not sure why it's required. The following lines that access Are you fixing this because this causes an actual issue you can reproduce somewhere? |
Yes. When I was using I will try and put a project that reproduces the issue. |
Some JavaScript platforms break because of the use of window. Below are some platforms I can think of.
https://www.nativescript.org/
http://www.appcelerator.com/mobile-app-development-products/
https://facebook.github.io/react-native/ (Possibly)