Commit a8eb5043 authored by Romain Courteaud's avatar Romain Courteaud

Start service after ready

parent 5fc0961f
......@@ -620,8 +620,9 @@
}
function startService(gadget) {
if ((gadget.constructor.__service_list.length === 0) &&
(!gadget.constructor.__job_declared)) {
if (((gadget.constructor.__service_list.length === 0) &&
(!gadget.constructor.__job_declared)) ||
(gadget.hasOwnProperty('__monitor'))) {
return;
}
createGadgetMonitor(gadget);
......@@ -906,7 +907,6 @@
gadget_instance.element.appendChild(fragment);
setAqParent(gadget_instance, parent_gadget);
clearGadgetInternalParameters(gadget_instance);
gadget_instance.element._gadget = gadget_instance;
if (old_element !== undefined) {
// Add gadget to the DOM if needed
// Do it when all DOM modifications are done
......@@ -999,7 +999,6 @@
gadget_instance.state = {};
options.element.appendChild(iframe);
clearGadgetInternalParameters(gadget_instance);
gadget_instance.element._gadget = gadget_instance;
// Add gadget to the DOM if needed
// Do it when all DOM modifications are done
old_element.parentNode.replaceChild(options.element,
......@@ -1116,7 +1115,11 @@
// Always set the parent reference when all ready are finished
// in case the gadget declaration is cancelled
// (and ready are not finished)
gadget_instance.element._gadget = gadget_instance;
parent_gadget.__sub_gadget_dict[scope] = gadget_instance;
if (document.contains(gadget_instance.element)) {
startService(gadget_instance);
}
// Always return the gadget instance after ready function
return gadget_instance;
}
......
......@@ -2337,6 +2337,52 @@
});
});
test('service started after ready is finished', function () {
// couscous romain xxxxxxxxx
// Subclass RenderJSGadget to not pollute its namespace
var gadget = new RenderJSGadget(),
html_url = 'https://example.org/files/qunittest/test5011.html',
defer = RSVP.defer();
gadget.__sub_gadget_dict = {};
this.server.respondWith("GET", html_url, [200, {
"Content-Type": "text/html"
}, "<html><body></body></html>"]);
document.getElementById('qunit-fixture').innerHTML = "<div></div>";
stop();
expect(1);
renderJS.declareGadgetKlass(html_url)
.then(function (Klass) {
Klass.declareService(function () {
defer.reject('Triggered before ready');
});
Klass.ready(function () {
return RSVP.delay(500)
.then(function () {
defer.resolve('Triggered before service');
});
});
return gadget.declareGadget(
html_url,
{element: document.getElementById('qunit-fixture')
.querySelector("div")}
);
})
.then(function () {
return defer.promise;
})
.then(function (result) {
equal(result, 'Triggered before service');
})
.fail(function (e) {
ok(false, e);
})
.always(function () {
start();
});
});
test('service started when gadget element added in DOM', function () {
// Subclass RenderJSGadget to not pollute its namespace
var service1 = {},
......
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