From 30fa9671c8171d8e0e9bef34cb8fea54d50d1726 Mon Sep 17 00:00:00 2001 From: tophf Date: Sun, 10 Dec 2017 06:02:25 +0300 Subject: [PATCH] debounce autosave more, prevent re-entry see #298 --- manage/config-dialog.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/manage/config-dialog.js b/manage/config-dialog.js index b6c13d5e..c609d436 100644 --- a/manage/config-dialog.js +++ b/manage/config-dialog.js @@ -3,6 +3,8 @@ function configDialog(style) { const AUTOSAVE_DELAY = 500; + let saving = false; + const data = style.usercssData; const varsHash = deepCopy(data.vars) || {}; const varNames = Object.keys(varsHash); @@ -88,7 +90,7 @@ function configDialog(style) { if (va) { va.dirty = varsInitial[va.name] !== (isDefault(va) ? va.default : va.value); if (prefs.get('config.autosave') && !justSaved) { - debounce(save, 0, {anyChangeIsDirty: true}); + debounce(save, 100, {anyChangeIsDirty: true}); return; } renderValueState(va); @@ -106,6 +108,10 @@ function configDialog(style) { } function save({anyChangeIsDirty = false} = {}) { + if (saving) { + debounce(save, 0, ...arguments); + return; + } if (!vars.length || !vars.some(va => va.dirty || anyChangeIsDirty && va.value !== va.savedValue)) { return; @@ -157,6 +163,7 @@ function configDialog(style) { if (!numValid) { return; } + saving = true; return BG.usercssHelper.save(style) .then(saved => { varsInitial = getInitialValues(deepCopy(saved.usercssData.vars)); @@ -169,6 +176,9 @@ function configDialog(style) { const el = $('.config-error', messageBox.element) || $('#message-box-buttons').insertAdjacentElement('afterbegin', $create('.config-error')); el.textContent = el.title = Array.isArray(errors) ? errors.join('\n') : errors; + }) + .then(() => { + saving = false; }); }