-
-
Save tbranyen/1362351 to your computer and use it in GitHub Desktop.
BackboneTraining-require.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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