Bug 999756 - Delay sending "HomePanels:RefreshDataset" message to Java. r=lucasr

This commit is contained in:
Margaret Leibovic 2014-05-13 09:13:31 +01:00
parent 3f0e522c57
commit bc4085e122

View File

@ -284,6 +284,31 @@ function validateItem(datasetId, item) {
}
}
var gRefreshTimers = {};
/**
* Sends a message to Java to refresh the given dataset. Delays sending
* messages to avoid successive refreshes, which can result in flashing views.
*/
function refreshDataset(datasetId) {
// Bail if there's already a refresh timer waiting to fire
if (gRefreshTimers[datasetId]) {
return;
}
let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
timer.initWithCallback(function(timer) {
delete gRefreshTimers[datasetId];
sendMessageToJava({
type: "HomePanels:RefreshDataset",
datasetId: datasetId
});
}, 100, Ci.nsITimer.TYPE_ONE_SHOT);
gRefreshTimers[datasetId] = timer;
}
HomeStorage.prototype = {
/**
* Saves data rows to the DB.
@ -325,10 +350,7 @@ HomeStorage.prototype = {
yield db.close();
}
sendMessageToJava({
type: "HomePanels:RefreshDataset",
datasetId: this.datasetId,
});
refreshDataset(this.datasetId);
}.bind(this));
},
@ -348,10 +370,7 @@ HomeStorage.prototype = {
yield db.close();
}
sendMessageToJava({
type: "HomePanels:RefreshDataset",
datasetId: this.datasetId,
});
refreshDataset(this.datasetId);
}.bind(this));
}
};