【发布时间】:2014-03-05 21:50:43
【问题描述】:
我正在构建一个包含 50 多个模块的应用程序。使用 require 函数动态加载控制器+路由器是个好主意吗?以下是我与 require.js 和 marionette 一起使用的 app.js 文件中的 sudo 代码
app.on("initialize:after", function(){
if(Backbone.history){
Backbone.history.start();
/* For now I am considering the app with have only single
level routing, something like http://localhost#module and
app will always call list method from controller */
var moduleName = Backbone.history.fragment;
var controllerFile = "app/controller/" + moduleName + "controller";
require([controllerFile], function() {
app.trigger( moduleName + ':' + 'list');
}
}
})
我的控制器文件包含路由器,它会在初始化必要的模型后直接调用视图。我看到使用这种方法的唯一风险可能是在控制器文件完全加载之前调用 require 函数。我没有在代码中添加任何保护措施,当我了解这是否是一个好方法时,我会这样做。
【问题讨论】:
标签: backbone.js requirejs marionette