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

Fix CommonJS issues for contexts without module global #63

Merged
merged 2 commits into from
Aug 11, 2014

Conversation

mroderick
Copy link
Owner

This pull request fixes issues #49 and #51 in CommonJS contexts that doesn't provide the module global by implementing a slightly tweaked version of https://github.com/umdjs/umd/blob/master/commonjsStrictGlobal.js

The adjustments made are just to pass in the expected root to still allow the jQuery version to work.

This pull request fixes issues for CommonJS contexts that doesn't provide the `module` global by implementing a slightly tweaked version of https://github.com/umdjs/umd/blob/master/commonjsStrictGlobal.js

The adjustments made are just to pass in the expected `root` to still allow the jQuery version to work.
if (typeof define === 'function' && define.amd){
// AMD. Register as an anonymous module.
define(['exports'], function (exports, b){
factory((root.PubSub = exports), b);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not following theses changes, doesn't this mean that you're also exporting the PubSub object as a global here. Also why is the "exports" module needed? Is this something supported by all AMD implementations?

What was wrong with the factory returning the PubSub object?

Copy link
Owner Author

Choose a reason for hiding this comment

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

doesn't this mean that you're also exporting the PubSub object as a global here.

It does

Also why is the "exports" module needed? Is this something supported by all AMD implementations?

That's a good question. It's supported by RequireJS, don't know about others.

What was wrong with the factory returning the PubSub object?

Just consistency, since for some environments, the return value was not used

Copy link
Collaborator

Choose a reason for hiding this comment

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

doesn't this mean that you're also exporting the PubSub object as a global here.
It does

I think that goes against the idea of AMD allowing you to keep the global namespace clean. What's the rationale behind this? If someone wants a global they can always export it themselves? But this could cause problems in places where AMD is used to avoid polluting the global namespaces, extensions and bookmarklets lets being a good example.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Copy link
Owner Author

Choose a reason for hiding this comment

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

I think that goes against the idea of AMD allowing you to keep the global namespace clean. What's the rationale behind this? If someone wants a global they can always export it themselves? But this could cause problems in places where AMD is used to avoid polluting the global namespaces, extensions and bookmarklets lets being a good example.

My work was based on https://github.com/umdjs/umd/blob/master/commonjsStrictGlobal.js ... I'll update it to use https://github.com/umdjs/umd/blob/master/commonjsStrict.js

Use the [commonjsStrict](https://github.com/umdjs/umd/blob/master/commonjsStrict.js) pattern instead of [commonjsStrictGlobal](https://github.com/umdjs/umd/blob/master/commonjsStrictGlobal.js), so we don't introduce a new global.
@mroderick
Copy link
Owner Author

@aron let's try this again :)

@aron
Copy link
Collaborator

aron commented Aug 11, 2014

aron added a commit that referenced this pull request Aug 11, 2014
Fix CommonJS issues for contexts without `module` global
@aron aron merged commit a38ff7f into master Aug 11, 2014
@aron aron deleted the fix-49-51-commonjs-strict branch August 11, 2014 08:52
@mroderick
Copy link
Owner Author

Cheers

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.

2 participants