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

Multiple define calls ignored. #716

Closed
LukeChannings opened this issue Aug 22, 2014 · 1 comment
Closed

Multiple define calls ignored. #716

LukeChannings opened this issue Aug 22, 2014 · 1 comment

Comments

@LukeChannings
Copy link

Hi James,

I have noticed that r.js will skip transforming define calls if it detects more than one,
this is presumably because it's assumed if there is more than one define then the file's already
been pre-processed and has named define calls. (Or not please correct me.)

The issue I'm having is with Velocity, which legitimately has two define calls for the same module here:

if (window.Velocity) {
    define("velocity", factory);
} else {
    define("velocity", [ "jquery" ], factory)
}

This is to test for a jQuery shim, and alternately require jQuery or not, depending on whether the shim exists.
The define calls were named due to r.js not transforming the calls with a name, the calls should be:

if (window.Velocity) {
    define(factory);
} else {
    define([ "jquery" ], factory)
}

But r.js should ideally transform that into the first block, or whatever velocity happens to be named in the configuration.

Do you have any insight on this? Is it non-breaking for r.js to be changed to write multiple named define calls? Is it possible to detect if the define calls are in a condition like this?

Thanks!

@jrburke
Copy link
Member

jrburke commented Sep 7, 2014

The expectation is that there is just one define() call in the file. This sort of dynamic alternate setup will not be possible in ES6 modules, so I suggest that the project just choose one definition and stick with that. I suggest choosing the one that does not require jQuery if it can operate without jQuery anyway.

Perhaps the library could move to a model where if some other code attaches velocity.$ to it, it would do extra jQuery things, but not have a hard dependency on it.

Closing as a discussion ticket. Feel free to continue discussion here.

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

No branches or pull requests

2 participants