2
我們如何處理路由之間的啓動/停止模塊,而不必明確告訴路由的控制器方法來啓動/停止每個模塊。啓動/停止Marionette模塊和路由
var AppRouterController = {
index: function() {
// Start only modules I need for this route here
// in this case, HomeApp only
App.module('HomeApp').start();
// Stop all modules that should not be running for this route
// The idea, being that not everyone has to come to the index route first
// They could have been to many other routes with many different modules starting at each route before here
App.module('Module1').stop();
App.module('ModuleInfinity').stop();
// ...
// ...
// This could get tedious, expensive, and there has to be a better way.
},
someOtherRouteMethod: function() {
// Do it all over again
}
}
我知道我在這裏做錯了什麼,希望不是根本,但請讓我知道是否有更好的方法。由於它將主要在平板設備上運行,所以模塊管理將成爲該項目的關鍵。
這是一個奇妙的答案。也許,我正在考慮如何錯誤地處理我的模塊。我的印象是這樣的,這只是有道理的。畢竟,爲什麼要在HomeApp中運行3次點擊模塊?如果這是最好的方法,我一定會使用這種方法。是否有充分的理由不考慮僅僅因爲實際需要啓動模塊? – Jarrod
根據我的經驗,有選擇地啓動模塊對於幾個不同的事情是有用的。 1.你有單獨的腳本不屬於你的主要應用程序,但你需要在一些頁面上。一個很好的例子就像一個使用d3.js的圖形庫,您只需要該應用程序特定部分的代碼和周圍的模塊。 2.您的模塊負責大部分不相關的啓動代碼。例如,像一個現場演示頁面,在開始時會產生大量假數據。 –