Prechádzať zdrojové kódy

Мелкий рефакторинг

Book Pauk 6 rokov pred
rodič
commit
e800dfe796

+ 1 - 1
client/components/Reader/Reader.vue

@@ -205,9 +205,9 @@ class Reader extends Vue {
 
     mounted() {
         (async() => {
-            this.$refs.serverStorage.init();
             await bookManager.init(this.settings);
             await restoreOldSettings(this.settings, bookManager, this.commit);
+            await this.$refs.serverStorage.init();
 
             if (this.$root.rootRoute == '/reader') {
                 if (this.routeParamUrl) {

+ 19 - 21
client/components/Reader/ServerStorage/ServerStorage.vue

@@ -90,36 +90,34 @@ class ServerStorage extends Vue {
     }
 
     async saveProfiles() {
-        if (!this.currentProfile)
+        if (!this.currentProfile || this.savingProfiles)
             return;
 
-        if (!this.savingProfiles) {
-            this.savingProfiles = true;
-
-            const diff = utils.getObjDiff(this.oldProfiles, this.profiles);
-            let result = {state: ''};
-            let tries = 0;
-            while (result.state != 'success' && tries < maxSetTries) {
-                result = await this.storageSet({'profiles': {rev: this.profilesRev + 1, data: this.profiles}});
+        this.savingProfiles = true;
 
-                if (result.state == 'reject') {
-                    await this.loadProfiles();
-                    const newProfiles = utils.applyObjDiff(this.profiles, diff);
-                    this.commit('reader/setProfiles', newProfiles);
-                    this.commit('reader/setProfilesRev', result.items.profiles.rev);
-                }
+        const diff = utils.getObjDiff(this.oldProfiles, this.profiles);
+        let result = {state: ''};
+        let tries = 0;
+        while (result.state != 'success' && tries < maxSetTries) {
+            result = await this.storageSet({'profiles': {rev: this.profilesRev + 1, data: this.profiles}});
 
-                tries++;
+            if (result.state == 'reject') {
+                await this.loadProfiles();
+                const newProfiles = utils.applyObjDiff(this.profiles, diff);
+                this.commit('reader/setProfiles', newProfiles);
+                this.commit('reader/setProfilesRev', result.items.profiles.rev);
             }
 
-            this.commit('reader/setProfilesRev', this.profilesRev + 1);
+            tries++;
+        }
 
-            if (tries >= maxSetTries) {
-                throw new Error('Не удалось отправить данные на сервер');
-            }
+        this.commit('reader/setProfilesRev', this.profilesRev + 1);
 
-            this.savingProfiles = false;
+        if (tries >= maxSetTries) {
+            throw new Error('Не удалось отправить данные на сервер');
         }
+
+        this.savingProfiles = false;
     }
 
     generateNewServerStorageKey() {