-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
AMD boilerplate still defines jQuery as a dependency #3074
Comments
Shimming messes up the build tool IIRC. The commonjs solution is to assign Opinions on killing the jquery require for AMD? |
Both scenarios seem pretty crappy:
Am I missing a clever third solution? Option 1 seems more correct in that the whole point of #3003 was to no longer require jQuery, so may as well reflect that in the defined dependency tree. |
I do not have all the context, but either Backbone depends on jQuery or it doesn't. All module systems, AMD, CommonJS/Node, even ES6 are based on a similar principle for dependencies. I believe this sort of issue came up for the Node pathway in Backbone too. Perhaps if there are parts of Backbone that need jQuery that should be broken out as a separate module/file/addon. But I do not have enough context to suggest a final pathway, best that the folks in the Backbone community sort it out. |
I don't mind setting up Backbone.$ on the application setup, but that's just my opinion. One solution in the AMD scenario is catching the error for not finding jquery. Though it's ugly to do that. |
Have an open PR: |
Nope. As the docs state, Backbone's only hard dependency is Underscore. It has a "light dependency" on jQuery that can be overridden. One of the many advantages of a late-binding language like JS is rewriting dependencies or exposed modules on the fly, which is particularly useful for scenarios like this where the code remains functionally similar but has large underlying portions replaced.
Also nope. Backbone shouldn't need to use AMD to manage internal code.
Not in the node pathway, the Browserify pathway. Browserify was choking on a try-catch wrapped around the commonjs I'm not hugely opposed to making the dev set |
I think @jrburke means that a light dependency is not a dependency, which is the consensus regarding commonjs as well.
Pedantically, it's commonjs in both cases. Regardless, it's precedent we should heed.
👍 |
They're both commonjs, but the difference is runtime lookup vs a precompile step. The former you can use a I've seen projects use |
Sorry if my previous answer was a bit to short, some more follow up: ES modules will work like AMD as far as behavior of specifying dependencies: they need to be specified more declaratively, up front. A dynamic dependency can be loaded via This is different from Node's commonjs-like system because they have synchronous file access, so they can support a dynamically fetched require('jquery') and throw. That is a very bad practice in the browser though, so it does not carry forward to ES6. End result: deciding now how Backbone would like to express its dependencies for AMD will mean it has solved its solution for ES6 modules, whatever that solution is, even if it is "do nothing". If you wanted to keep "jquery" as a specified dependency, for AMD projects that did not want to use any DOM library helper, then instructing AMD users to do the following after their config setup would allow that to work: // Showing requirejs config call here, but same holds for any AMD
// loader config call.
requirejs.config({
// normal config here
});
// Seed the module loader with an empty jQuery dependency. Just
// do this before starting main app loading
define('jquery', function(){});
// Now do app loading
require(['app/main']); The other option is to just save that My impression is that most Backbone users using Backbone in the browser will be using it with a DOM helper library (zepto/ender can be supported via an AMD loader map config that points 'jquery' to those providers). If that is true, then I would bias the dependency expression to mention 'jquery' and suggest the pathways mentioned above for AMD users that do not want a DOM helper library with Backbone, but you all know your community better. |
Sounds good to me. @jrburke knows best ;) |
👍 to setting an empty jquery object. |
@akre54 so the actionable item here would be to keep jQuery as a dep in the AMD definition, then change Backbone's AMD test definition to setup a blank jQuery object if I am reading correctly? |
I must say it would feel strange if someone wants to use a library other than jQuery in Backbone.$ and having to create a jquery file/definition.Cumprimentos, On Wed, Mar 19, 2014 at 5:31 PM, Ryan Eastridge notifications@github.com
|
@magalhas I agree. I already primarily use zepto, and seems a little strange |
Agreed with @magalhas. All seem like crap solutions. |
@akre54 so is it simple enough to say that there are only two reasonable solutions:
Does this capture the conversation to date correctly? @jrburke thanks for your input on this. All hail Lord Require =) |
Oh and if it's #3075 let's make it a minor release and not a patch release. 1.1.2 blew up in our faces in a way that I would not have expected a patch release to have. |
I kind of prefer #3075 (dependency removal) and also this way it works the same way as CJS module definition do. As said the downside is for newbies that won't know that Backbone.$ needs to be defined in order to have views and routers working properly, though that should be overcome with documentation. This will break the current "interface" so a minor release would be proper in my opinion. |
Also on a side note, we could have a default Backbone.$ implementation that throws an error stating that a library should be "plugged in", that would help out people that doesn't read documentation at all :) UPDATE Though things like |
Reopening as it seems that this will require more discussion. |
@jrburke says to just shim |
@akre54 I'm trying to get NativeView to play nicely with Handlebones. Non AMD tests are all passing. Hoorah!
The current AMD setup in backbone.js still defines jQuery as a hard dependency:
https://github.com/jashkenas/backbone/blob/master/backbone.js#L12
Which will cause my AMD build to blow up when I try to test it. Any suggestions as to how this can be handled by Backbone? I'm sure there was much strife over the AMD boilerplate and getting it in, but boy I wish it wasn't there at all. There was nothing wrong with shimming it IMHO.
The text was updated successfully, but these errors were encountered: