From fc7793453c90d400b3dd838a3ba7b461cb8646da Mon Sep 17 00:00:00 2001 From: tophf Date: Fri, 21 Apr 2017 13:57:01 +0300 Subject: [PATCH] code cosmetics: simplify import::undo --- backup/fileSaveLoad.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/backup/fileSaveLoad.js b/backup/fileSaveLoad.js index ce5f2032..33c75eb5 100644 --- a/backup/fileSaveLoad.js +++ b/backup/fileSaveLoad.js @@ -194,15 +194,18 @@ function importFromString(jsonString) { ...stats.codeOnly.ids, ...stats.added.ids, ]; + let resolve; index = 0; - return new Promise(undoNextId) - .then(BG.refreshAllTabs) + return new Promise(resolve_ => { + resolve = resolve_; + undoNextId(); + }).then(BG.refreshAllTabs) .then(() => messageBox({ title: t('importReportUndoneTitle'), contents: newIds.length + ' ' + t('importReportUndone'), buttons: [t('confirmOK')], })); - function undoNextId(resolve) { + function undoNextId() { if (index == newIds.length) { resolve(); return; @@ -211,13 +214,10 @@ function importFromString(jsonString) { deleteStyleSafe({id, notify: false}).then(id => { const oldStyle = oldStylesById.get(id); if (oldStyle) { - saveStyleSafe(Object.assign(oldStyle, { - reason: 'import', - notify: false, - })).then(() => - setTimeout(undoNextId, 0, resolve)); + saveStyleSafe(Object.assign(oldStyle, SAVE_OPTIONS)) + .then(undoNextId); } else { - setTimeout(undoNextId, 0, resolve); + undoNextId(); } }); }