Skip to content

Commit

Permalink
Convert to "CommonJS style" AMD
Browse files Browse the repository at this point in the history
ReWrite the `define` factory functions to accept an argument named
`require`, and use it as though it synchronously loaded modules (just
like in CommonJS). This makes modules slightly more maintainable since
dependencies may be added and removed without the need to synchronize
two separate-but-related lists.
  • Loading branch information
jugglinmike committed Sep 8, 2014
1 parent 6628840 commit 04ade31
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
define(['modules/photo', 'modules/view'], function(Photo, PhotoView) {
define(function(require) {
'use strict';
var Photo = require('modules/photo');
var PhotoView = require('modules/view');

var me = new Photo({
id : 19
Expand Down
3 changes: 2 additions & 1 deletion src/modules/photo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
define(['backbone'], function(Backbone) {
define(function(require) {
'use strict';
var Backbone = require('backbone');

var Photo = Backbone.Model.extend({
urlRoot : function() {
Expand Down
5 changes: 4 additions & 1 deletion src/modules/view.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
define(['backbone', 'jquery', 'underscore'], function(Backbone, $, _) {
define(function(require) {
'use strict';
var Backbone = require('backbone');
var $ = require('jquery');
var _ = require('underscore');

var PhotoView = Backbone.View.extend({

Expand Down

0 comments on commit 04ade31

Please sign in to comment.