Fixes feed sync bugs after conflicts. ()

SyncedSettings.set() caches values. If an object passed to set() is
modified after the call then get() returns that modified object.
This commit is contained in:
Adomas Ven 2016-08-16 10:03:42 +03:00 committed by Dan Stillman
parent 1b5c7aa6d8
commit 076bdadb29
3 changed files with 23 additions and 3 deletions
chrome/content/zotero/xpcom
test/tests

View File

@ -177,6 +177,14 @@ Zotero.SyncedSettings = (function () {
throw new Error("Value not provided");
}
// Prevents a whole bunch of headache if you continue modifying the object after calling #set()
if (value instanceof Array) {
value = Array.from(value);
}
else if (typeof value == 'object') {
value = Object.assign({}, value);
}
var currentValue = this.get(libraryID, setting);
var hasCurrentValue = currentValue !== null;

View File

@ -643,9 +643,11 @@ Components.utils.import("resource://gre/modules/osfile.jsm");
yield Zotero.Promise.each(
Zotero.Libraries.getAll(),
library => Zotero.Promise.coroutine(function* () {
yield Zotero.SyncedSettings.loadAll(library.libraryID);
yield Zotero.Collections.loadAll(library.libraryID);
yield Zotero.Searches.loadAll(library.libraryID);
if (library.libraryType != 'feed') {
yield Zotero.SyncedSettings.loadAll(library.libraryID);
yield Zotero.Collections.loadAll(library.libraryID);
yield Zotero.Searches.loadAll(library.libraryID);
}
})()
);
}

View File

@ -0,0 +1,10 @@
describe('Zotero.SyncedSettings', function() {
it('should not affect cached value when modifying the setting after #set() call', function* () {
let setting = {athing: 1};
yield Zotero.SyncedSettings.set(Zotero.Libraries.userLibraryID, 'setting', setting);
setting.athing = 2;
let storedSetting = Zotero.SyncedSettings.get(Zotero.Libraries.userLibraryID, 'setting');
assert.notDeepEqual(setting, storedSetting);
});
});