From 076bdadb2919da0811bc8b6270ca4149e9b62ba5 Mon Sep 17 00:00:00 2001 From: Adomas Ven Date: Tue, 16 Aug 2016 10:03:42 +0300 Subject: [PATCH] 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. --- chrome/content/zotero/xpcom/syncedSettings.js | 8 ++++++++ chrome/content/zotero/xpcom/zotero.js | 8 +++++--- test/tests/syncedSettingsTest.js | 10 ++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 test/tests/syncedSettingsTest.js diff --git a/chrome/content/zotero/xpcom/syncedSettings.js b/chrome/content/zotero/xpcom/syncedSettings.js index 64fce7fcc..30d26037a 100644 --- 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 index 9912f362c..88bd76234 100644 --- 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 new file mode 100644 index 000000000..ed286c1f6 --- /dev/null +++ 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); + }); +});