From 9e296231d9aff90e66e05904bfbb71600eea7409 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Fri, 20 Sep 2019 16:54:03 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=B1=D0=B0=D0=B3=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Reader/ServerStorage/ServerStorage.vue | 48 ++++++++++--------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/client/components/Reader/ServerStorage/ServerStorage.vue b/client/components/Reader/ServerStorage/ServerStorage.vue index 1daa7680..13e42559 100644 --- a/client/components/Reader/ServerStorage/ServerStorage.vue +++ b/client/components/Reader/ServerStorage/ServerStorage.vue @@ -72,8 +72,19 @@ class ServerStorage extends Vue { async bookManagerEvent(eventName, itemKey) { if (eventName == 'recent-changed') { - if (itemKey) + if (itemKey) { + if (!this.recentDeltaInited) { + this.warning('Функции сохранения на сервер пока недоступны'); + return; + } + + if (!this.recentDelta) + this.recentDelta = {}; + + this.recentDelta[itemKey] = _.cloneDeep(bookManager.recent[itemKey]); + this.debouncedSaveRecent(itemKey); + } } } @@ -394,7 +405,7 @@ class ServerStorage extends Vue { this.recentDelta = recentDelta.data; } else { newRecent = recent.data; - this.recentDelta = null; + this.recentDelta = {}; } this.recentDeltaInited = true; @@ -420,30 +431,21 @@ class ServerStorage extends Vue { const bm = bookManager; - if (!this.recentDeltaInited) { - this.warning('Функции сохранения на сервер пока недоступны'); - return; - } - - if (!this.recentDelta) - this.recentDelta = {}; - - this.recentDelta[itemKey] = _.cloneDeep(bm.recent[itemKey]); - //вычисление критерия сохранения целиком let forceSaveRecent = false; - if (!forceSaveRecent && itemKey) { - if (!this.sameKeyCount) - this.sameKeyCount = 0; - if (this.prevItemKey == itemKey) - this.sameKeyCount++; - - forceSaveRecent = this.sameKeyCount > 5 && (Object.keys(this.recentDelta).length > 1); - - this.sameKeyCount = (!forceSaveRecent ? this.sameKeyCount : 0); - this.prevItemKey = itemKey; + if (!this.sameKeyCount) + this.sameKeyCount = 0; + if (this.prevItemKey == itemKey) { + this.sameKeyCount++; + } else { + this.sameKeyCount = 0; } + forceSaveRecent = this.sameKeyCount > 5 && (Object.keys(this.recentDelta).length > 1); + + this.sameKeyCount = (!forceSaveRecent ? this.sameKeyCount : 0); + this.prevItemKey = itemKey; + this.savingRecent = true; try { if (forceSaveRecent) {//сохраняем recent целиком @@ -460,6 +462,7 @@ class ServerStorage extends Vue { this.warning(`Последние изменения отменены. Данные синхронизированы с сервером.`); if (!recurse) { this.savingRecent = false; + this.recentDelta[itemKey] = _.cloneDeep(bm.recent[itemKey]); this.saveRecent(itemKey, true); return; } @@ -482,6 +485,7 @@ class ServerStorage extends Vue { this.warning(`Последние изменения отменены. Данные синхронизированы с сервером.`); if (!recurse) { this.savingRecent = false; + this.recentDelta[itemKey] = _.cloneDeep(bm.recent[itemKey]); this.saveRecent(itemKey, true); return; }