Skip to content

Instantly share code, notes, and snippets.

@iros
Created November 12, 2011 17:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save iros/1360856 to your computer and use it in GitHub Desktop.
Save iros/1360856 to your computer and use it in GitHub Desktop.
BackboneTraining-require.js
// Define whatever global space vars you might need.
var mbta = {
// application configuration parameters
app : {
server : "http://backbonetraining.bocoup.com:8000"
},
// application data
data : {
// station collection
lines : null
}
};
// Require.js allows us to configure shortcut aliases
require.config({
paths: {
jQuery: '../libs/jquery',
underscore: '../libs/underscore',
Backbone: '../libs/backbone'
}
});
// First make sure all dependancies are loaded - in order!
require(['order!jQuery', 'order!underscore', 'order!Backbone'], function($, _, Backbone){
var applicationModules = [
"modules/lines",
"modules/predictions",
"modules/stations",
"utils"
];
// Then require all our internal modules.
require(applicationModules, function(Lines, Predictions, Stations, Utils) {
jQuery(function($) {
// Start your main application router that
// has a "" route
var router = new ApplicationRouter();
// Start backbone.history tracking.
Backbone.history.start();
});
});
});
<!doctype html>
<html lang=en>
<head>
<meta charset=utf-8>
<meta http-equiv=X-UA-Compatible content=IE=edge,chrome=1>
<title>My Application</title>
<!-- Load require.js.
specify the main application requirement specification file
and the location of the require.js file.
-->
<script data-main="assets/js/src/application.js" src="assets/js/libs/require.js>
</script>
</head>
<body>
</body>
</html>
// assets/js/src/modules/line.js
(function() {
// What are the required modules for this module?
var modules = [ "jquery","underscore", "Backbone", "modules/stations", "modules/predictions"];
define(modules, function($, _, Backbone, Stations, Predictions) {
// Define the line model
Line.Model = Backbone.Model.extend({
});
// Define the line collection
Line.Collection = Backbone.Collection.extend({
model: Line.Model
});
// Return the object this module represents...
return Line;
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment