Restore implicit handleUpdate in saveStyle

This commit is contained in:
tophf 2017-03-25 05:35:54 +03:00
parent a6c3424b53
commit 8bcd7f60c5
3 changed files with 50 additions and 34 deletions

View File

@ -85,8 +85,10 @@ function importFromString(jsonString) {
stats.unchanged.ids.push(oldStyle.id); stats.unchanged.ids.push(oldStyle.id);
continue; continue;
} }
saveStyle(item, {notify: false}).then(style => { saveStyle(Object.assign(item, {
handleUpdate(style, {reason: 'import'}); reason: 'import',
notify: false,
})).then(style => {
setTimeout(proceed, 0, resolve); setTimeout(proceed, 0, resolve);
if (!oldStyle) { if (!oldStyle) {
stats.added.names.push(style.name); stats.added.names.push(style.name);
@ -160,11 +162,12 @@ function importFromString(jsonString) {
} }
const id = newIds[index++]; const id = newIds[index++];
deleteStyle(id, {notify: false}).then(id => { deleteStyle(id, {notify: false}).then(id => {
handleDelete(id);
const oldStyle = oldStylesById.get(id); const oldStyle = oldStylesById.get(id);
if (oldStyle) { if (oldStyle) {
saveStyle(Object.assign(oldStyle, {reason: 'undoImport'}), {notify: false}) saveStyle(Object.assign(oldStyle, {
.then(handleUpdate) reason: 'undoImport',
notify: false,
}))
.then(() => setTimeout(undoNextId, 0, resolve)); .then(() => setTimeout(undoNextId, 0, resolve));
} else { } else {
setTimeout(undoNextId, 0, resolve); setTimeout(undoNextId, 0, resolve);

View File

@ -215,14 +215,13 @@ class EntryOnClick {
} }
static update(event) { static update(event) {
const element = getClickedStyleElement(event); const updatedCode = getClickedStyleElement(event).updatedCode;
const updatedCode = element.updatedCode;
// update everything but name // update everything but name
delete updatedCode.name; saveStyle(Object.assign(updatedCode, {
updatedCode.id = element.styleId; id: element.styleId,
updatedCode.reason = 'update'; name: null,
saveStyle(updatedCode) reason: 'update',
.then(style => handleUpdate(style, {reason: 'update'})); }));
} }
static delete(event) { static delete(event) {

View File

@ -250,7 +250,7 @@ function cleanupCachedFilters({force = false} = {}) {
} }
function saveStyle(style, {notify = true} = {}) { function saveStyle(style) {
return new Promise(resolve => { return new Promise(resolve => {
getDatabase(db => { getDatabase(db => {
const tx = db.transaction(['styles'], 'readwrite'); const tx = db.transaction(['styles'], 'readwrite');
@ -258,8 +258,13 @@ function saveStyle(style, {notify = true} = {}) {
const id = style.id !== undefined && style.id !== null ? Number(style.id) : null; const id = style.id !== undefined && style.id !== null ? Number(style.id) : null;
const reason = style.reason; const reason = style.reason;
const notify = style.notify !== false;
delete style.method; delete style.method;
delete style.reason; delete style.reason;
delete style.notify;
if (!style.name) {
delete style.name;
}
// Update // Update
if (id != null) { if (id != null) {
@ -279,6 +284,9 @@ function saveStyle(style, {notify = true} = {}) {
style, codeIsUpdated, reason, style, codeIsUpdated, reason,
}); });
} }
if (typeof handleUpdate != 'undefined') {
handleUpdate(style, {reason});
}
resolve(style); resolve(style);
}; };
}; };
@ -303,6 +311,9 @@ function saveStyle(style, {notify = true} = {}) {
if (notify) { if (notify) {
notifyAllTabs({method: 'styleAdded', style, reason}); notifyAllTabs({method: 'styleAdded', style, reason});
} }
if (typeof handleUpdate != 'undefined') {
handleUpdate(style, {reason});
}
resolve(style); resolve(style);
}; };
}); });
@ -336,6 +347,9 @@ function deleteStyle(id, {notify = true} = {}) {
invalidateCache(notify, {deletedId: id}); invalidateCache(notify, {deletedId: id});
if (notify) { if (notify) {
notifyAllTabs({method: 'styleDeleted', id}); notifyAllTabs({method: 'styleDeleted', id});
}
if (typeof handleDelete != 'undefined') {
handleDelete(id);
} }
resolve(id); resolve(id);
}; };