Commit d37a613b by Romain Courteaud

Do not try to load subgadget if not needed.

1 parent f245293e
......@@ -542,7 +542,7 @@
return RSVP.all(promise_list);
}
RenderJSGadget.__ready_list = [loadSubGadgetDOMDeclaration];
RenderJSGadget.__ready_list = [];
RenderJSGadget.ready = function ready(callback) {
this.__ready_list.push(callback);
return this;
......@@ -830,7 +830,7 @@
}
RenderJSGadget.call(this);
}
RenderJSEmbeddedGadget.__ready_list = RenderJSGadget.__ready_list.slice();
RenderJSEmbeddedGadget.__ready_list = [];
RenderJSEmbeddedGadget.__service_list =
RenderJSGadget.__service_list.slice();
RenderJSEmbeddedGadget.ready =
......@@ -890,14 +890,14 @@
}
RenderJSGadget.call(this);
}
RenderJSIframeGadget.__ready_list = RenderJSGadget.__ready_list.slice();
RenderJSIframeGadget.__ready_list = [];
RenderJSIframeGadget.ready =
RenderJSGadget.ready;
RenderJSIframeGadget.setState =
RenderJSGadget.setState;
RenderJSIframeGadget.onStateChange =
RenderJSGadget.onStateChange;
RenderJSIframeGadget.__service_list = RenderJSGadget.__service_list.slice();
RenderJSIframeGadget.__service_list = [];
RenderJSIframeGadget.declareService =
RenderJSGadget.declareService;
RenderJSIframeGadget.onEvent =
......@@ -1257,7 +1257,7 @@
tmp_constructor = function createSuperKlass() {
RenderJSGadget.call(this);
};
tmp_constructor.__ready_list = RenderJSGadget.__ready_list.slice();
tmp_constructor.__ready_list = [];
tmp_constructor.__service_list = RenderJSGadget.__service_list.slice();
tmp_constructor.declareMethod =
RenderJSGadget.declareMethod;
......@@ -1297,6 +1297,11 @@
tmp_constructor.prototype['__' + key] = parsed_html[key];
}
}
// Check if there is a HTML declared subgadget
if (tmp_constructor.__template_element
.querySelectorAll('[data-gadget-url]').length) {
tmp_constructor.__ready_list.push(loadSubGadgetDOMDeclaration);
}
return tmp_constructor;
}
......@@ -1610,7 +1615,7 @@
// Create the root gadget instance and put it in the loading stack
TmpConstructor = RenderJSEmbeddedGadget;
TmpConstructor.__ready_list = RenderJSGadget.__ready_list.slice();
TmpConstructor.__ready_list = [];
TmpConstructor.__service_list = RenderJSGadget.__service_list.slice();
TmpConstructor.prototype.__path = url;
root_gadget = new RenderJSEmbeddedGadget();
......@@ -1804,6 +1809,7 @@
})
.push(function waitForReadyList() {
clearGadgetInternalParameters(root_gadget);
TmpConstructor.__ready_list.unshift(loadSubGadgetDOMDeclaration);
// Trigger all ready functions
return triggerReadyList(TmpConstructor, root_gadget);
})
......
......@@ -524,7 +524,7 @@
);
stop();
expect(7);
expect(8);
renderJS.declareGadgetKlass(url)
.then(function (Klass) {
var instance;
......@@ -533,6 +533,7 @@
deepEqual(Klass.prototype.__acquired_method_dict, {});
equal(Klass.prototype.__foo, 'bar');
equal(Klass.__template_element.nodeType, 9);
deepEqual(Klass.__ready_list, [], 'Ready list is empty by default');
instance = new Klass();
ok(instance instanceof RenderJSGadget);
......@@ -616,6 +617,27 @@
});
});
test('Ready list length is one if HTML sub gadget', function () {
var url = 'https://example.org/files/qunittest/test';
this.server.respondWith("GET", url, [200, {
"Content-Type": "text/html; charset=utf-8"
}, "<html><body><div data-gadget-url='foo'></div></body></html>"]);
stop();
expect(1);
renderJS.declareGadgetKlass(url)
.then(function (Klass) {
equal(Klass.__ready_list.length, 1);
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
/////////////////////////////////////////////////////////////////
// declareJS
/////////////////////////////////////////////////////////////////
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!