Comments (5)
AMD support is close to landing in Backbone.js.
from backbone-mootools.
Here's how jQuery hooks up its module definition:
// Expose jQuery to the global object
window.jQuery = window.$ = jQuery;
// Expose jQuery as an AMD module, but only for AMD loaders that
// understand the issues with loading multiple versions of jQuery
// in a page that all might call define(). The loader will indicate
// they have special allowances for multiple jQuery versions by
// specifying define.amd.jQuery = true. Register as a named module,
// since jQuery can be concatenated with other files that may use define,
// but not use a proper concatenation script that understands anonymous
// AMD modules. A named AMD is safest and most robust way to register.
// Lowercase jquery is used because AMD module names are derived from
// file names, and jQuery is normally delivered in a lowercase file name.
// Do this after creating the global so that if an AMD module wants to call
// noConflict to hide this version of jQuery, it will work.
if ( typeof define === "function" && define.amd && define.amd.jQuery ) {
define( "jquery", [], function () { return jQuery; } );
}
from backbone-mootools.
Some more background: here are some notes about updating libraries for AMD.
For this particular library, I can see this form of code working. Perhaps something like this so it works in cases that do not use an AMD loader:
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
// In the AMD loader, the developer maps
// mootools-core to the mootools-core-1.4.1.js file
define(['mootools-core'], function () {
factory(root);
});
} else {
// Browser globals
factory(root);
// Hijack the jQuery variable to patch into Backbone if a jQuery object doesn't
// exist.
if (!root.jQuery) jQuery = root.$;
}
}(this, function (root) {
//root in here is window. Do the backbone
//adapter work in here.
}));
from backbone-mootools.
A pull request is always welcome. I'll take a look at this later today as well.
from backbone-mootools.
I took a look at this and decided not to land any changes until Backbone lands AMD support as well. I want to be able to test our AMD changes with Backbone and ensure they work together. If this is is something pressing for you, feel free to send in a pull request as mentioned above.
from backbone-mootools.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from backbone-mootools.