зеркало из https://github.com/mozilla/lightbeam.git
Merge pull request #556 from mozilla/fix/clear-blocked-sites
fix race condition in resetting data, fixes #506
This commit is contained in:
Коммит
2d83067960
|
@ -30,7 +30,7 @@ aggregate.edgemap = {};
|
|||
|
||||
function resetData() {
|
||||
console.log('aggregate::resetData');
|
||||
aggregate.getBlockedDomains().filter(function (domain) {
|
||||
aggregate.getBlockedDomains().forEach(function (domain) {
|
||||
console.log("deleting", domain);
|
||||
delete userSettings[domain];
|
||||
});
|
||||
|
@ -48,13 +48,6 @@ aggregate.on('reset', resetData);
|
|||
|
||||
aggregate.getBlockedDomains = function () {
|
||||
return Object.keys(userSettings).filter(function (domain) {
|
||||
// ignore domains already known
|
||||
var nodes = aggregate.nodes;
|
||||
for (var i = nodes.length - 1; i >= 0; i--) {
|
||||
if (nodes[i].name == domain) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return userSettings[domain] == 'block';
|
||||
});
|
||||
}
|
||||
|
|
|
@ -156,7 +156,12 @@ document.querySelector('.reset-data').addEventListener('click', function () {
|
|||
allConnections = [];
|
||||
global.self.port.emit('reset');
|
||||
aggregate.emit('reset');
|
||||
location.reload(); // reload page
|
||||
// WARNING: this is a race condition. Since the event emitters are
|
||||
// async, we were running into the situation where the page was reloaded
|
||||
// before aggregate::resetData was finished, resulting in #506
|
||||
//
|
||||
// TODO: using a short timeout for now, would be better to use a Promise
|
||||
setTimeout(500, function () { location.reload(); /* reload page */ });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче