Change: make prefs.set return a promise
This commit is contained in:
parent
4666fe493a
commit
a051e21ce4
18
js/prefs.js
18
js/prefs.js
|
@ -210,10 +210,10 @@ const prefs = (() => {
|
||||||
}
|
}
|
||||||
values[key] = value;
|
values[key] = value;
|
||||||
emitChange(key, value);
|
emitChange(key, value);
|
||||||
if (synced || timer) {
|
if (!synced && !timer) {
|
||||||
return;
|
timer = syncPrefsLater();
|
||||||
}
|
}
|
||||||
timer = setTimeout(syncPrefs);
|
return timer;
|
||||||
}
|
}
|
||||||
|
|
||||||
function emitChange(key, value) {
|
function emitChange(key, value) {
|
||||||
|
@ -230,10 +230,14 @@ const prefs = (() => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function syncPrefs() {
|
function syncPrefsLater() {
|
||||||
// FIXME: we always set the entire object? Ideally, this should only use `changes`.
|
return new Promise((resolve, reject) => {
|
||||||
chrome.storage.sync.set({settings: values});
|
setTimeout(() => {
|
||||||
timer = null;
|
timer = null;
|
||||||
|
chrome.storage.sync.set({settings: values})
|
||||||
|
.then(resolve, reject);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function equal(a, b) {
|
function equal(a, b) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user