Commit ffd3d0c2 authored by Romain Courteaud's avatar Romain Courteaud

Wait for ready to be finished before setting the child gadget reference.

parent 6389d855
...@@ -1100,7 +1100,6 @@ ...@@ -1100,7 +1100,6 @@
scope_increment += 1; scope_increment += 1;
} }
} }
parent_gadget.__sub_gadget_dict[scope] = gadget_instance;
gadget_instance.element.setAttribute("data-gadget-scope", gadget_instance.element.setAttribute("data-gadget-scope",
scope); scope);
...@@ -1120,6 +1119,10 @@ ...@@ -1120,6 +1119,10 @@
if (document.contains(gadget_instance.element)) { if (document.contains(gadget_instance.element)) {
startService(gadget_instance); startService(gadget_instance);
} }
// Always set the parent reference when all ready are finished
// in case the gadget declaration is cancelled
// (and ready are not finished)
parent_gadget.__sub_gadget_dict[scope] = gadget_instance;
// Always return the gadget instance after ready function // Always return the gadget instance after ready function
return gadget_instance; return gadget_instance;
} }
......
...@@ -4190,23 +4190,26 @@ ...@@ -4190,23 +4190,26 @@
}, "<html><body></body></html>"]); }, "<html><body></body></html>"]);
stop(); stop();
expect(3); expect(6);
renderJS.declareGadgetKlass(html_url) renderJS.declareGadgetKlass(html_url)
.then(function (Klass) { .then(function (Klass) {
// Create a ready function // Create a ready function
Klass.ready(function (g) { Klass.ready(function (g) {
deepEqual(gadget.__sub_gadget_dict, {});
equal(g, this, "Context should be the gadget instance"); equal(g, this, "Context should be the gadget instance");
ready_gadget = g; ready_gadget = g;
return RSVP.delay(50).then(function () { return RSVP.delay(50).then(function () {
// Modify the value after 50ms // Modify the value after 50ms
called = true; called = true;
deepEqual(gadget.__sub_gadget_dict, {});
}); });
}); });
return gadget.declareGadget(html_url); return gadget.declareGadget(html_url, {scope: 'sub'});
}) })
.then(function (result) { .then(function (result) {
equal(result, ready_gadget, "Context should be the gadget instance"); equal(result, ready_gadget, "Context should be the gadget instance");
ok(called); ok(called);
deepEqual(gadget.__sub_gadget_dict, {'sub': result});
}) })
.fail(function (e) { .fail(function (e) {
ok(false); ok(false);
......
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