Commit acd9abbf authored by Romain Courteaud's avatar Romain Courteaud

Load gadget dependencies in the right order.

parent 2a499e62
......@@ -213,8 +213,6 @@
// };
gadget.chan.bind("declareMethod", function (trans, method_name) {
console.log("Receive declaration " + method_name + " on " +
gadget.path);
gadget[method_name] = function () {
var dfr = $.Deferred();
gadget.chan.call({
......@@ -233,7 +231,6 @@
// Wait for the iframe to be loaded before continuing
gadget.chan.bind("ready", function (trans) {
console.log(gadget.path + " is ready");
next_loading_gadget_deferred.resolve(gadget);
});
gadget.chan.bind("failed", function (trans) {
......@@ -279,12 +276,32 @@
// Load dependencies if needed
$.when(gadget.getRequiredJSList(), gadget.getRequiredCSSList())
.done(function (js_list, css_list) {
var result_list = [];
var result_list = [],
first_deferred = $.Deferred(),
first_promise = first_deferred.promise();
gadget_loading_klass = Klass;
// Load all JS and CSS
$.each(js_list, function (i, required_url) {
result_list.push(renderJS.declareJS(required_url));
// Load JS and follow the dependency declaration defined in the
// head
function next(next_js_list) {
var next_js = next_js_list.shift();
if (next_js === undefined) {
first_deferred.resolve();
} else {
renderJS.declareJS(next_js)
.done(function () {
next(next_js_list);
})
.fail(function () {
first_deferred.reject.apply(
first_deferred,
arguments
);
});
}
}
next(js_list);
result_list.push(first_promise);
// Load CSS
$.each(css_list, function (i, required_url) {
result_list.push(renderJS.declareCSS(required_url));
});
......
......@@ -1323,6 +1323,14 @@
server.respond();
});
// test('load dependency in the right order', function () {
// // Check that JS dependencies are loaded in the right order
// // Can be reproduce with real loading (http):
// // * enormous 1 js
// // * second small js which require the 1 one to be loaded
// // How to mock the loading time?
// });
test('Fail if klass can not be loaded', function () {
// Check that gadget is not created if klass is can not be loaded
var gadget = new RenderJSGadget(),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment