Merge pull request #556 from mozilla/fix/clear-blocked-sites

fix race condition in resetting data, fixes #506
This commit is contained in:
monicachew 2014-04-23 17:31:13 -07:00
Родитель 51f4903fdd 5631f3f1c9
Коммит 2d83067960
2 изменённых файлов: 7 добавлений и 9 удалений

Просмотреть файл

@ -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 */ });
}
});
});