Commit d37a613b authored by Romain Courteaud's avatar Romain Courteaud

Do not try to load subgadget if not needed.

parent f245293e
...@@ -542,7 +542,7 @@ ...@@ -542,7 +542,7 @@
return RSVP.all(promise_list); return RSVP.all(promise_list);
} }
RenderJSGadget.__ready_list = [loadSubGadgetDOMDeclaration]; RenderJSGadget.__ready_list = [];
RenderJSGadget.ready = function ready(callback) { RenderJSGadget.ready = function ready(callback) {
this.__ready_list.push(callback); this.__ready_list.push(callback);
return this; return this;
...@@ -830,7 +830,7 @@ ...@@ -830,7 +830,7 @@
} }
RenderJSGadget.call(this); RenderJSGadget.call(this);
} }
RenderJSEmbeddedGadget.__ready_list = RenderJSGadget.__ready_list.slice(); RenderJSEmbeddedGadget.__ready_list = [];
RenderJSEmbeddedGadget.__service_list = RenderJSEmbeddedGadget.__service_list =
RenderJSGadget.__service_list.slice(); RenderJSGadget.__service_list.slice();
RenderJSEmbeddedGadget.ready = RenderJSEmbeddedGadget.ready =
...@@ -890,14 +890,14 @@ ...@@ -890,14 +890,14 @@
} }
RenderJSGadget.call(this); RenderJSGadget.call(this);
} }
RenderJSIframeGadget.__ready_list = RenderJSGadget.__ready_list.slice(); RenderJSIframeGadget.__ready_list = [];
RenderJSIframeGadget.ready = RenderJSIframeGadget.ready =
RenderJSGadget.ready; RenderJSGadget.ready;
RenderJSIframeGadget.setState = RenderJSIframeGadget.setState =
RenderJSGadget.setState; RenderJSGadget.setState;
RenderJSIframeGadget.onStateChange = RenderJSIframeGadget.onStateChange =
RenderJSGadget.onStateChange; RenderJSGadget.onStateChange;
RenderJSIframeGadget.__service_list = RenderJSGadget.__service_list.slice(); RenderJSIframeGadget.__service_list = [];
RenderJSIframeGadget.declareService = RenderJSIframeGadget.declareService =
RenderJSGadget.declareService; RenderJSGadget.declareService;
RenderJSIframeGadget.onEvent = RenderJSIframeGadget.onEvent =
...@@ -1257,7 +1257,7 @@ ...@@ -1257,7 +1257,7 @@
tmp_constructor = function createSuperKlass() { tmp_constructor = function createSuperKlass() {
RenderJSGadget.call(this); 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.__service_list = RenderJSGadget.__service_list.slice();
tmp_constructor.declareMethod = tmp_constructor.declareMethod =
RenderJSGadget.declareMethod; RenderJSGadget.declareMethod;
...@@ -1297,6 +1297,11 @@ ...@@ -1297,6 +1297,11 @@
tmp_constructor.prototype['__' + key] = parsed_html[key]; 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; return tmp_constructor;
} }
...@@ -1610,7 +1615,7 @@ ...@@ -1610,7 +1615,7 @@
// Create the root gadget instance and put it in the loading stack // Create the root gadget instance and put it in the loading stack
TmpConstructor = RenderJSEmbeddedGadget; TmpConstructor = RenderJSEmbeddedGadget;
TmpConstructor.__ready_list = RenderJSGadget.__ready_list.slice(); TmpConstructor.__ready_list = [];
TmpConstructor.__service_list = RenderJSGadget.__service_list.slice(); TmpConstructor.__service_list = RenderJSGadget.__service_list.slice();
TmpConstructor.prototype.__path = url; TmpConstructor.prototype.__path = url;
root_gadget = new RenderJSEmbeddedGadget(); root_gadget = new RenderJSEmbeddedGadget();
...@@ -1804,6 +1809,7 @@ ...@@ -1804,6 +1809,7 @@
}) })
.push(function waitForReadyList() { .push(function waitForReadyList() {
clearGadgetInternalParameters(root_gadget); clearGadgetInternalParameters(root_gadget);
TmpConstructor.__ready_list.unshift(loadSubGadgetDOMDeclaration);
// Trigger all ready functions // Trigger all ready functions
return triggerReadyList(TmpConstructor, root_gadget); return triggerReadyList(TmpConstructor, root_gadget);
}) })
......
...@@ -524,7 +524,7 @@ ...@@ -524,7 +524,7 @@
); );
stop(); stop();
expect(7); expect(8);
renderJS.declareGadgetKlass(url) renderJS.declareGadgetKlass(url)
.then(function (Klass) { .then(function (Klass) {
var instance; var instance;
...@@ -533,6 +533,7 @@ ...@@ -533,6 +533,7 @@
deepEqual(Klass.prototype.__acquired_method_dict, {}); deepEqual(Klass.prototype.__acquired_method_dict, {});
equal(Klass.prototype.__foo, 'bar'); equal(Klass.prototype.__foo, 'bar');
equal(Klass.__template_element.nodeType, 9); equal(Klass.__template_element.nodeType, 9);
deepEqual(Klass.__ready_list, [], 'Ready list is empty by default');
instance = new Klass(); instance = new Klass();
ok(instance instanceof RenderJSGadget); ok(instance instanceof RenderJSGadget);
...@@ -616,6 +617,27 @@ ...@@ -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 // declareJS
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
......
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