From 98fd921f9806da4b9e723a800688bc535d58033f Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Sat, 2 Feb 2019 18:39:38 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=BA=D0=B8=20debouncedPosChange?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/components/Reader/Reader.vue | 17 +++++++++++++---- client/components/Reader/TextPage/TextPage.vue | 6 +----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/client/components/Reader/Reader.vue b/client/components/Reader/Reader.vue index d73cba8c..49200eeb 100644 --- a/client/components/Reader/Reader.vue +++ b/client/components/Reader/Reader.vue @@ -81,6 +81,7 @@ import SettingsPage from './SettingsPage/SettingsPage.vue'; import bookManager from './share/bookManager'; import readerApi from '../../api/reader'; +import _ from 'lodash'; import {sleep} from '../../share/utils'; export default @Component({ @@ -101,9 +102,7 @@ export default @Component({ if (textPage.bookPos != newValue) { textPage.bookPos = newValue; } - if (this.lastOpenedBook && this.lastOpenedBook.bookPos != newValue) { - this.commit('reader/setOpenedBook', Object.assign({}, this.lastOpenedBook, {bookPos: newValue, bookPosSeen: this.bookPosSeen})); - } + this.debouncedCommitOpenedBook(newValue); } }, routeParamPos: function(newValue) { @@ -147,6 +146,16 @@ class Reader extends Vue { this.lastActivePage = false; + this.debouncedUpdateRoute = _.debounce(() => { + this.updateRoute(); + }, 1000); + + this.debouncedCommitOpenedBook = _.debounce((newValue) => { + if (this.lastOpenedBook && this.lastOpenedBook.bookPos != newValue) { + this.commit('reader/setOpenedBook', Object.assign({}, this.lastOpenedBook, {bookPos: newValue, bookPosSeen: this.bookPosSeen})); + } + }, 500); + document.addEventListener('fullscreenchange', () => { this.fullScreenActive = (document.fullscreenElement !== null); }); @@ -205,7 +214,7 @@ class Reader extends Vue { if (event.bookPosSeen !== undefined) this.bookPosSeen = event.bookPosSeen; this.bookPos = event.bookPos; - this.updateRoute(); + this.debouncedUpdateRoute(); } get toolBarActive() { diff --git a/client/components/Reader/TextPage/TextPage.vue b/client/components/Reader/TextPage/TextPage.vue index 99116f87..0a18f85a 100644 --- a/client/components/Reader/TextPage/TextPage.vue +++ b/client/components/Reader/TextPage/TextPage.vue @@ -44,7 +44,7 @@ const minLayoutWidth = 100; export default @Component({ watch: { bookPos: function(newValue) { - this.debouncedEmitPosChange(newValue); + this.$emit('book-pos-changed', {bookPos: newValue, bookPosSeen: this.bookPosSeen}); this.draw(); }, settings: function() { @@ -79,10 +79,6 @@ class TextPage extends Vue { this.config = this.$store.state.config; this.reader = this.$store.state.reader; - this.debouncedEmitPosChange = _.debounce((newValue) => { - this.$emit('book-pos-changed', {bookPos: newValue, bookPosSeen: this.bookPosSeen}); - }, 1000); - this.debouncedStartClickRepeat = _.debounce((x, y) => { this.startClickRepeat(x, y); }, 800);