commit 076bdadb2919da0811bc8b6270ca4149e9b62ba5
parent 1b5c7aa6d843449c9d5909ac18a1cffff1339806
Author: Adomas Ven <adomas.ven@gmail.com>
Date: Tue, 16 Aug 2016 10:03:42 +0300
Fixes feed sync bugs after conflicts. (#1074)
SyncedSettings.set() caches values. If an object passed to set() is
modified after the call then get() returns that modified object.
Diffstat:
3 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/chrome/content/zotero/xpcom/syncedSettings.js b/chrome/content/zotero/xpcom/syncedSettings.js
@@ -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;
diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js
@@ -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);
+ }
})()
);
}
diff --git a/test/tests/syncedSettingsTest.js b/test/tests/syncedSettingsTest.js
@@ -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);
+ });
+});