Skip to content

Use 'window' if available as 'root' in exporting #151

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

Merged
merged 1 commit into from
Jul 21, 2017

Conversation

newlukai
Copy link
Contributor

We use css-element-queries (actually only the ResizeSensor) in a Polymer based app. While we were able to use ResizeSensor in the dev environment, we weren't able to use it in the built artifact created by gulp and Polymer CLI.
The problem was that 'root' was undefined in the exporting part of the ResizeSensor. I accordingly changed ElementQueries.js, but didn't test the change.

@@ -12,7 +12,7 @@
} else {
root.ElementQueries = factory(root.ResizeSensor);
}
}(this, function (ResizeSensor) {
}(typeof window !== 'undefined' ? window : this, function (ResizeSensor) {
Copy link
Owner

Choose a reason for hiding this comment

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

@josephschmitt do you have an opinion on that?

Copy link
Contributor

Choose a reason for hiding this comment

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

The solution to this specific big report looks fine to me, but I'm curious as to why it's not working the way it's written. The implementation of root was taken right from the UMD example code, so I'd expect this to be a problem with any module using the UMD module pattern.

Any insights in your bugfinding @newlukai?

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually now that I look at it I don't think this code should go here. The way it's written it's always favoring window if it's defined, since that typeof check happens before the and or exports checks. I'd suggest moving this to inside the else statement on line 12

Copy link
Contributor

Choose a reason for hiding this comment

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

Before the amd check, not and

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've to confess that I'm pretty new to JavaScript, so I don't exactly know why this isn't working while building my app. But since ResizeSensor isn't the only lib I use, I compared your mechanism with the one of Highcharts which is working fine in our build process.

If you still need more information don't hesitate to bother me ;)

@marcj marcj merged commit 4d6469b into marcj:master Jul 21, 2017
@marcj
Copy link
Owner

marcj commented Jul 21, 2017

Thanks, we'll see how it turns out.

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.

4 participants