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.
This commit is contained in:
parent
1b5c7aa6d8
commit
076bdadb29
|
@ -177,6 +177,14 @@ Zotero.SyncedSettings = (function () {
|
||||||
throw new Error("Value not provided");
|
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 currentValue = this.get(libraryID, setting);
|
||||||
var hasCurrentValue = currentValue !== null;
|
var hasCurrentValue = currentValue !== null;
|
||||||
|
|
||||||
|
|
|
@ -643,9 +643,11 @@ Components.utils.import("resource://gre/modules/osfile.jsm");
|
||||||
yield Zotero.Promise.each(
|
yield Zotero.Promise.each(
|
||||||
Zotero.Libraries.getAll(),
|
Zotero.Libraries.getAll(),
|
||||||
library => Zotero.Promise.coroutine(function* () {
|
library => Zotero.Promise.coroutine(function* () {
|
||||||
|
if (library.libraryType != 'feed') {
|
||||||
yield Zotero.SyncedSettings.loadAll(library.libraryID);
|
yield Zotero.SyncedSettings.loadAll(library.libraryID);
|
||||||
yield Zotero.Collections.loadAll(library.libraryID);
|
yield Zotero.Collections.loadAll(library.libraryID);
|
||||||
yield Zotero.Searches.loadAll(library.libraryID);
|
yield Zotero.Searches.loadAll(library.libraryID);
|
||||||
|
}
|
||||||
})()
|
})()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
10
test/tests/syncedSettingsTest.js
Normal file
10
test/tests/syncedSettingsTest.js
Normal 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);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user