Мелкий рефакторинг
This commit is contained in:
@@ -205,9 +205,9 @@ class Reader extends Vue {
|
|||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
(async() => {
|
(async() => {
|
||||||
this.$refs.serverStorage.init();
|
|
||||||
await bookManager.init(this.settings);
|
await bookManager.init(this.settings);
|
||||||
await restoreOldSettings(this.settings, bookManager, this.commit);
|
await restoreOldSettings(this.settings, bookManager, this.commit);
|
||||||
|
await this.$refs.serverStorage.init();
|
||||||
|
|
||||||
if (this.$root.rootRoute == '/reader') {
|
if (this.$root.rootRoute == '/reader') {
|
||||||
if (this.routeParamUrl) {
|
if (this.routeParamUrl) {
|
||||||
|
|||||||
@@ -90,36 +90,34 @@ class ServerStorage extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async saveProfiles() {
|
async saveProfiles() {
|
||||||
if (!this.currentProfile)
|
if (!this.currentProfile || this.savingProfiles)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!this.savingProfiles) {
|
this.savingProfiles = true;
|
||||||
this.savingProfiles = true;
|
|
||||||
|
|
||||||
const diff = utils.getObjDiff(this.oldProfiles, this.profiles);
|
const diff = utils.getObjDiff(this.oldProfiles, this.profiles);
|
||||||
let result = {state: ''};
|
let result = {state: ''};
|
||||||
let tries = 0;
|
let tries = 0;
|
||||||
while (result.state != 'success' && tries < maxSetTries) {
|
while (result.state != 'success' && tries < maxSetTries) {
|
||||||
result = await this.storageSet({'profiles': {rev: this.profilesRev + 1, data: this.profiles}});
|
result = await this.storageSet({'profiles': {rev: this.profilesRev + 1, data: this.profiles}});
|
||||||
|
|
||||||
if (result.state == 'reject') {
|
if (result.state == 'reject') {
|
||||||
await this.loadProfiles();
|
await this.loadProfiles();
|
||||||
const newProfiles = utils.applyObjDiff(this.profiles, diff);
|
const newProfiles = utils.applyObjDiff(this.profiles, diff);
|
||||||
this.commit('reader/setProfiles', newProfiles);
|
this.commit('reader/setProfiles', newProfiles);
|
||||||
this.commit('reader/setProfilesRev', result.items.profiles.rev);
|
this.commit('reader/setProfilesRev', result.items.profiles.rev);
|
||||||
}
|
|
||||||
|
|
||||||
tries++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.commit('reader/setProfilesRev', this.profilesRev + 1);
|
tries++;
|
||||||
|
|
||||||
if (tries >= maxSetTries) {
|
|
||||||
throw new Error('Не удалось отправить данные на сервер');
|
|
||||||
}
|
|
||||||
|
|
||||||
this.savingProfiles = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.commit('reader/setProfilesRev', this.profilesRev + 1);
|
||||||
|
|
||||||
|
if (tries >= maxSetTries) {
|
||||||
|
throw new Error('Не удалось отправить данные на сервер');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.savingProfiles = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
generateNewServerStorageKey() {
|
generateNewServerStorageKey() {
|
||||||
|
|||||||
Reference in New Issue
Block a user