Fix: store missing props in an object

This commit is contained in:
eight 2019-10-30 00:57:08 +08:00
parent 375c95e4a3
commit a371394fc3

View File

@ -521,6 +521,12 @@ const styleManager = (() => {
} }
function prepare() { function prepare() {
const ADD_MISSING_PROPS = {
name: style => `ID: ${style.id}`,
_id: () => uuid(),
_rev: () => Date.now()
};
return db.exec('getAll') return db.exec('getAll')
.then(event => event.target.result || []) .then(event => event.target.result || [])
.then(styleList => { .then(styleList => {
@ -545,21 +551,16 @@ const styleManager = (() => {
data: style data: style
}); });
uuidIndex.set(style._id, style.id); uuidIndex.set(style._id, style.id);
if (!style.name) {
style.name = 'ID: ' + style.id;
}
} }
}); });
function addMissingProperties(style) { function addMissingProperties(style) {
let touched = false; let touched = false;
if (!style._id) { for (const key in ADD_MISSING_PROPS) {
style._id = uuid(); if (!style[key]) {
style[key] = ADD_MISSING_PROPS[key](style);
touched = true; touched = true;
} }
if (!style._rev) {
style._rev = Date.now();
touched = true;
} }
return touched; return touched;
} }