Created
July 23, 2012 07:09
-
-
Save maletor/3162378 to your computer and use it in GitHub Desktop.
Bootstrap data using RequireJS and Backbone
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
require(['userAttributes', 'backbone', 'user_router'], function (config, Backbone, UserRouter) { | |
var userRouter = new UserRouter() { | |
userAttributes: userAttributes | |
}; | |
return router; | |
}); |
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> | |
<title>Page</title> | |
<script data-main="app" src="require.js"></script> | |
<script> | |
require('userAttributes', function() { | |
return { | |
val1: 'hello', | |
val2: 'world' | |
}; | |
}); | |
require('colleagues', function() { | |
return { | |
val1: 'memcache', | |
val2: 'is your friend' | |
}; | |
}); | |
require('publications', function() { | |
return { | |
val1: 'memcache', | |
val2: 'is your friend' | |
}; | |
}); | |
</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
define(['backbone', 'view'], function(Backbone, View) { | |
var view = Backbone.Router.extend({ | |
routes: { | |
'*index': 'index' | |
}, | |
index: function() { | |
new View({ | |
first: userAttributes.val1, | |
second: userAttributes.val2 | |
}).render(); | |
} | |
}); | |
return view; | |
}); |
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(['backbone'], function(Backbone) { | |
var view = Backbone.View.extend({ | |
render: function() { | |
console.log(this.first + ', ' + this.second); | |
} | |
}); | |
return view; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment