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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ElementQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;)


/**
*
Expand Down
2 changes: 1 addition & 1 deletion src/ResizeSensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
} else {
root.ResizeSensor = factory();
}
}(this, function () {
}(typeof window !== 'undefined' ? window : this, function () {

// Make sure it does not throw in a SSR (Server Side Rendering) situation
if (typeof window === "undefined") {
Expand Down