Commit ffd3d0c2 by Romain Courteaud

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

1 parent 6389d855
......@@ -1100,7 +1100,6 @@
scope_increment += 1;
}
}
parent_gadget.__sub_gadget_dict[scope] = gadget_instance;
gadget_instance.element.setAttribute("data-gadget-scope",
scope);
......@@ -1120,6 +1119,10 @@
if (document.contains(gadget_instance.element)) {
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
return gadget_instance;
}
......
......@@ -4190,23 +4190,26 @@
}, "<html><body></body></html>"]);
stop();
expect(3);
expect(6);
renderJS.declareGadgetKlass(html_url)
.then(function (Klass) {
// Create a ready function
Klass.ready(function (g) {
deepEqual(gadget.__sub_gadget_dict, {});
equal(g, this, "Context should be the gadget instance");
ready_gadget = g;
return RSVP.delay(50).then(function () {
// Modify the value after 50ms
called = true;
deepEqual(gadget.__sub_gadget_dict, {});
});
});
return gadget.declareGadget(html_url);
return gadget.declareGadget(html_url, {scope: 'sub'});
})
.then(function (result) {
equal(result, ready_gadget, "Context should be the gadget instance");
ok(called);
deepEqual(gadget.__sub_gadget_dict, {'sub': result});
})
.fail(function (e) {
ok(false);
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!