handle null response from API in chromeSync

This commit is contained in:
tophf 2017-08-28 13:53:10 +03:00
parent 5330db11af
commit 37bff1c5c9

View File

@ -55,12 +55,16 @@ var chromeSync = {
}); });
}, },
getLZValue(key) { getLZValue(key) {
return chromeSync.get(key).then(data => tryJSONparse(LZString.decompressFromUTF16(data[key]))); return chromeSync.getLZValues([key]).then(data => data[key]);
}, },
getLZValues(keys) { getLZValues(keys) {
return chromeSync.get(keys).then(data => return chromeSync.get(keys).then((data = {}) => {
Object.assign({}, ...keys.map(key => for (const key of keys) {
({[key]: tryJSONparse(LZString.decompressFromUTF16(data[key]))})))); const value = data[key];
data[key] = value && tryJSONparse(LZString.decompressFromUTF16(value));
}
return data;
});
}, },
setLZValue(key, value) { setLZValue(key, value) {
return chromeSync.set({[key]: LZString.compressToUTF16(JSON.stringify(value))}); return chromeSync.set({[key]: LZString.compressToUTF16(JSON.stringify(value))});