Commit ca47096f authored by Romain Courteaud's avatar Romain Courteaud

Create monitor only when the gadget is added into the DOM.

parent b72c73a8
...@@ -447,13 +447,15 @@ ...@@ -447,13 +447,15 @@
RenderJSGadget.prototype.__required_css_list = []; RenderJSGadget.prototype.__required_css_list = [];
RenderJSGadget.prototype.__required_js_list = []; RenderJSGadget.prototype.__required_js_list = [];
function deleteGadgetMonitor(g) {
g.__monitor.cancel();
delete g.__monitor;
g.__job_list = [];
}
function createGadgetMonitor(g) { function createGadgetMonitor(g) {
if (g.__monitor !== undefined) {
g.__monitor.cancel();
}
g.__monitor = new Monitor(); g.__monitor = new Monitor();
g.__job_dict = {}; g.__job_dict = {};
g.__job_list = [];
g.__job_triggered = false; g.__job_triggered = false;
g.__monitor.fail(function handleGadgetMonitorError(error) { g.__monitor.fail(function handleGadgetMonitorError(error) {
if (!(error instanceof RSVP.CancellationError)) { if (!(error instanceof RSVP.CancellationError)) {
...@@ -465,10 +467,10 @@ ...@@ -465,10 +467,10 @@
function clearGadgetInternalParameters(gadget) { function clearGadgetInternalParameters(gadget) {
gadget.__sub_gadget_dict = {}; gadget.__sub_gadget_dict = {};
gadget.__job_list = [];
if (gadget.__json_state !== undefined) { if (gadget.__json_state !== undefined) {
gadget.state = JSON.parse(gadget.__json_state); gadget.state = JSON.parse(gadget.__json_state);
} }
createGadgetMonitor(gadget);
} }
function loadSubGadgetDOMDeclaration() { function loadSubGadgetDOMDeclaration() {
...@@ -586,6 +588,7 @@ ...@@ -586,6 +588,7 @@
} }
function startService(gadget) { function startService(gadget) {
createGadgetMonitor(gadget);
gadget.__monitor.monitor(new RSVP.Queue() gadget.__monitor.monitor(new RSVP.Queue()
.push(function monitorAllServiceList() { .push(function monitorAllServiceList() {
var i, var i,
...@@ -1495,7 +1498,7 @@ ...@@ -1495,7 +1498,7 @@
if (node.nodeType === Node.ELEMENT_NODE) { if (node.nodeType === Node.ELEMENT_NODE) {
if (node.hasAttribute("data-gadget-url") && if (node.hasAttribute("data-gadget-url") &&
(node._gadget !== undefined)) { (node._gadget !== undefined)) {
createGadgetMonitor(node._gadget); deleteGadgetMonitor(node._gadget);
} }
added_list = added_list =
node.querySelectorAll("[data-gadget-url]"); node.querySelectorAll("[data-gadget-url]");
...@@ -1503,7 +1506,7 @@ ...@@ -1503,7 +1506,7 @@
for (k = 0; k < len2; k += 1) { for (k = 0; k < len2; k += 1) {
node = added_list[k]; node = added_list[k];
if (node._gadget !== undefined) { if (node._gadget !== undefined) {
createGadgetMonitor(node._gadget); deleteGadgetMonitor(node._gadget);
} }
} }
} }
......
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