Skip to content

Instantly share code, notes, and snippets.

@fernandofleury
Created October 4, 2013 14:27
Show Gist options
  • Save fernandofleury/6826824 to your computer and use it in GitHub Desktop.
Save fernandofleury/6826824 to your computer and use it in GitHub Desktop.
// festival.js
(function(){
'use strict';
var FestivalView = Backbone.View.extend({
el: '.content',
render: function(){
var template = 'text';
this.$el.html(template);
}
});
var festivalView = new FestivalView();
return festivalView
})();
// router.js
(function(){
'use strict';
var Router = Backbone.Router.extend({
routes: {
"festival": "festival"
}
});
var router = new Router();
router.on('route:festival', function() {
require(['view/festival'], function(festivalView){
festivalView.render();
});
});
Backbone.history.start();
return router
})();
@diogoreus
Copy link

main.js - Modulo principal do require

'use strict';
require.config({
shim: {
underscore: {
exports: '_'
},
backbone: {
deps: [
'underscore',
'jquery'
],
exports: 'Backbone'
}
...
},

paths: {
    jquery: '../bower_components/jquery/jquery',
    backbone: '../bower_components/backbone/backbone',
    underscore: '../bower_components/underscore/underscore',
    ...    
}    

});

view fica algo assim:
define([
'jquery',
'underscore',
'backbone',
], function ($, _, Backbone, JST, Mustache) {
'use strict';
var FestivalView = Backbone.View.extend({
el: '.content',

    render: function(){
        var template = 'text';
        this.$el.html(template);
    }
});

var festivalView = new FestivalView();

return festivalView;

});

define([
'jquery',
'backbone'
'view/festival'
], function ($, Backbone, festivalView) {
'use strict';

var Router = Backbone.Router.extend({
routes: {
"festival": "festival"
}
});

    festival: function() {
          festivalView.render();
}       
});

return router;

});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment