2012-11-11 82 views
0

我有一個Mediator-Sandbox庫和一個構建在此庫頂部的路由器擴展。要求映射:映射擴展時獲取模塊超時

庫建成這樣的:

(function(window) { 

    var MedSan = {}; 

    window.MedSan = MedSan; 

})(this); 

擴展看起來是這樣的:

(function(_, Backbone, MedSan) { 

    MedSan.Router = {}; 

})(_, Backbone, MedSan); 

的需要配置加載擴展看起來是這樣的:

require.config({ 

    baseUrl: "javascripts", 

    shim: { 
     "jquery": { 
      exports: "$" 
     }, 
     "underscore": { 
      exports: "_" 
     }, 
     "backbone": { 
      deps: ['jquery', 'underscore'], 
      exports: "Backbone" 
     }, 
     "Distribution": { 
      exports: "Distribution" 
     }, 
     "Distribution.Router": { 
      deps: ['underscore', 'backbone', 'Distribution'], 
      exports: "Distribution" 
     } 
    }, 

    /* 
    map: { 
     "*": { 
      "Distribution": "Distribution.Router" 
     }   
    }, 
    */ 


    paths: { 
     "jquery": "Vendors/jquery", 
     "underscore": "Vendors/underscore", 
     "backbone": "Vendors/backbone", 

     "Distribution": "Distribution/Distribution", 
     "Distribution.Router": "Distribution/Plugins/Router" 
    } 

}); 

我現在可以使用我的完整庫:

require(['Distribution.Router'], function(Distribution) {}); 

當我取消了地圖配置,這樣我就可以使用滿載模塊路由器擴展這種方式:

require(['Distribution'], function(Distribution) {}); 

比我得到一個模塊超時。

我在做什麼錯?

回答

1

當你映射到DistributionDistribution.Router,你要創建一個循環依賴,因爲Distribution.Router還取決於Distribution

爲了解決這個問題只需要添加另一條線路覆蓋地圖的DistributionDistribution.Router

map: { 
    "*": { 
     "Distribution": "Distribution.Router" 
    }, 
    "Distribution.Router": { 
     "Distribution": "Distribution" 
    } 
}