Рефакторинг

This commit is contained in:
Book Pauk
2019-02-15 23:22:36 +07:00
parent 16edc85e39
commit abdd6d4142

View File

@@ -117,15 +117,19 @@ class TextPage extends Vue {
}, 50); }, 50);
this.debouncedUpdatePage = _.debounce(async(lines) => { this.debouncedUpdatePage = _.debounce(async(lines) => {
if (!this.toggleLayout) if (!this.pageChangeAnimation)
this.toggleLayout = !this.toggleLayout;
else {
this.page2 = this.page1;
this.toggleLayout = true;
}
if (this.toggleLayout)
this.page1 = this.drawHelper.drawPage(lines); this.page1 = this.drawHelper.drawPage(lines);
else else
this.page2 = this.drawHelper.drawPage(lines); this.page2 = this.drawHelper.drawPage(lines);
await this.doPageAnimation(); await this.doPageAnimation();
if (!this.inAnimation)
this.toggleLayout = !this.toggleLayout;
}, 10); }, 10);
this.$root.$on('resize', () => {this.$nextTick(this.onResize)}); this.$root.$on('resize', () => {this.$nextTick(this.onResize)});
@@ -302,16 +306,10 @@ class TextPage extends Vue {
// шрифты хрен знает когда подгружаются в div, поэтому // шрифты хрен знает когда подгружаются в div, поэтому
const parsed = this.parsed; const parsed = this.parsed;
if (!parsed.force) { await sleep(5000);
let i = 0; if (this.parsed === parsed) {
parsed.force = true; parsed.force = true;
while (i < 10) { this.draw();
await sleep(1000);
if (this.parsed != parsed)
break;
this.draw();
i++;
}
parsed.force = false; parsed.force = false;
} }
} }
@@ -553,11 +551,10 @@ class TextPage extends Vue {
} }
//fast draw prepared //fast draw prepared
if (!this.inAnimation && !this.currentAnimation && this.pageChangeDirectionDown && this.pagePrepared && this.bookPos == this.bookPosPrepared) { if (!this.pageChangeAnimation && this.pageChangeDirectionDown && this.pagePrepared && this.bookPos == this.bookPosPrepared) {
this.toggleLayout = !this.toggleLayout; this.toggleLayout = !this.toggleLayout;
this.linesDown = this.linesDownNext; this.linesDown = this.linesDownNext;
this.linesUp = this.linesUpNext; this.linesUp = this.linesUpNext;
this.doPageAnimation();
} else {//normal debounced draw } else {//normal debounced draw
const lines = this.getLines(this.bookPos); const lines = this.getLines(this.bookPos);
this.linesDown = lines.linesDown; this.linesDown = lines.linesDown;
@@ -566,7 +563,7 @@ class TextPage extends Vue {
} }
this.pagePrepared = false; this.pagePrepared = false;
if (!this.inAnimation && !this.currentAnimation) if (!this.pageChangeAnimation)
this.debouncedPrepareNextPage(); this.debouncedPrepareNextPage();
this.debouncedDrawStatusBar(); this.debouncedDrawStatusBar();
@@ -615,12 +612,8 @@ class TextPage extends Vue {
}; };
const duration = Math.round(3000*(1 - this.pageChangeAnimationSpeed/100)); const duration = Math.round(3000*(1 - this.pageChangeAnimationSpeed/100));
let page1 = this.$refs.scrollingPage2; let page1 = this.$refs.scrollingPage1;
let page2 = this.$refs.scrollingPage1; let page2 = this.$refs.scrollingPage2;
if (!this.toggleLayout) {
[page1, page2] = [page2, page1];
[animation1Finish, animation2Finish] = [animation2Finish, animation1Finish];
}
switch (this.currentAnimation) { switch (this.currentAnimation) {
case 'thaw': case 'thaw':
@@ -635,15 +628,16 @@ class TextPage extends Vue {
this.resolveAnimation1Finish = null; this.resolveAnimation1Finish = null;
this.resolveAnimation2Finish = null; this.resolveAnimation2Finish = null;
this.inAnimation = false;
this.stopAnimation = false;
page1.style.animation = ''; page1.style.animation = '';
page2.style.animation = ''; page2.style.animation = '';
}
this.currentAnimation = ''; this.currentAnimation = '';
this.pageChangeDirectionDown = false;//true только если PgDown this.pageChangeDirectionDown = false;//true только если PgDown
this.inAnimation = false;
this.stopAnimation = false;
}
} }
getLines(bookPos) { getLines(bookPos) {