From 9753681651927eacf197874f180eb0697c9c3470 Mon Sep 17 00:00:00 2001 From: kkapsner Date: Tue, 17 Jul 2018 12:54:10 +0200 Subject: [PATCH] Return storage promise from settings.set(). --- lib/lists.js | 7 +++++-- lib/settings.js | 10 ++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/lists.js b/lib/lists.js index 6e87232..bc7b77a 100644 --- a/lib/lists.js +++ b/lib/lists.js @@ -68,6 +68,7 @@ value = settings[type + "List"]; } lists[type] = getDomainRegExpList(value); + return lists[type]; } Object.keys(lists).forEach(function(type){ settings.on(type + "List", function({newValue}){ @@ -107,8 +108,10 @@ return lists[type]; }; scope.appendTo = function appendToList(type, entry){ - settings[type + "List"] += (settings[type + "List"]? ",": "") + entry; - updateList(type); + var oldValue = settings[type + "List"]; + return settings.set(type + "List", oldValue + (oldValue? ",": "") + entry).then(function(){ + return updateList(type); + }); }; scope.update = updateList; scope.updateAll = function updateAllLists(){ diff --git a/lib/settings.js b/lib/settings.js index f1d2ebf..b22a4ad 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -144,11 +144,13 @@ if (!settingDefinition.transient){ var storeObject = {}; storeObject[name] = newValue; - browser.storage.local.set(storeObject).then(function(){ + var promise = browser.storage.local.set(storeObject); + promise.then(function(){ logging.verbose("New value stored for %s:", name, newValue); }, function(err){ logging.warning("Unable to store new value for %s:", name, newValue, err); }); + return promise; } else { logging.warning("Transient setting %s cannot be stored.", name); @@ -171,10 +173,10 @@ matching = [newEntry]; } matching[0][settingDefinition.name] = newValue; - urlContainer.set(urlContainerValue); + return urlContainer.set(urlContainerValue); } else { - storeValue(newValue); + return storeValue(newValue); } } else{ @@ -186,7 +188,7 @@ return function setValue(newValue){ logging.verbose("New value for %s:", name, newValue); if (isValid(newValue)){ - storeValue(newValue); + return storeValue(newValue); } else{ logging.warning("Invalid value for %s:", name, newValue);