2013-05-10 27 views

回答

0

不,沒有這樣的事情。模塊不使用xhr加載。 DOM中注入JavaScript文件,並且requireJS等待腳本加載。

你可以設置一個當模塊加載,將調用回調:

require(['yourmodule'], function (module) { 
    alert('Module has loaded.'); 
} 
+0

我明白了。有沒有辦法在每個定義/要求之前/之後得到通知?我嘗試通過覆蓋window.require和window.define來掛鉤我的回調,但它不起作用。 – jichi 2013-05-10 17:36:11

+0

你想解決什麼問題? – 2013-05-10 18:04:43

0

確定。我通過覆蓋默認的require函數來實現它。 我正在使用coffeescript,代碼如下:

_root = @ 
_require = @require 
@requirehook = new class 
    constructor: -> @count = 0 
    require: => 
    @onAjaxStart?() if not @count 
    @count += 1 
    _require.apply _root, arguments 
    @count -= 1 
    @onAjaxStop?() if not @count 
    ajaxStart: (fn) => @onAjaxStart = fn 
    ajaxStop: (fn) => @onAjaxStop = fn 

@require = @requirehook.require