Merge pull request #99 from Deedone/render_speed

Improve long list rendering time
This commit is contained in:
Preston 2020-08-24 17:44:05 -04:00 committed by GitHub
commit 8b52a61353
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 85 additions and 27 deletions

5
package-lock.json generated
View File

@ -18872,6 +18872,11 @@
"vue-style-loader": "^4.1.0" "vue-style-loader": "^4.1.0"
} }
}, },
"vue-observe-visibility": {
"version": "0.4.6",
"resolved": "https://registry.npmjs.org/vue-observe-visibility/-/vue-observe-visibility-0.4.6.tgz",
"integrity": "sha512-xo0CEVdkjSjhJoDdLSvoZoQrw/H2BlzB5jrCBKGZNXN2zdZgMuZ9BKrxXDjNP2AxlcCoKc8OahI3F3r3JGLv2Q=="
},
"vue-router": { "vue-router": {
"version": "3.4.3", "version": "3.4.3",
"resolved": "https://registry.npmjs.org/vue-router/-/vue-router-3.4.3.tgz", "resolved": "https://registry.npmjs.org/vue-router/-/vue-router-3.4.3.tgz",

View File

@ -33,6 +33,7 @@
"vue": "^2.6.12", "vue": "^2.6.12",
"vue-electron": "^1.0.6", "vue-electron": "^1.0.6",
"vue-i18n": "^8.21.0", "vue-i18n": "^8.21.0",
"vue-observe-visibility": "^0.4.6",
"vue-router": "^3.4.3", "vue-router": "^3.4.3",
"vuex": "^3.5.1", "vuex": "^3.5.1",
"xml2json": "^0.12.0", "xml2json": "^0.12.0",

View File

@ -1,4 +1,5 @@
import Vue from 'vue' import Vue from 'vue'
import { ObserveVisibility } from 'vue-observe-visibility'
import TopNav from './components/top-nav/top-nav.vue' import TopNav from './components/top-nav/top-nav.vue'
import SideNav from './components/side-nav/side-nav.vue' import SideNav from './components/side-nav/side-nav.vue'
import FtToast from './components/ft-toast/ft-toast.vue' import FtToast from './components/ft-toast/ft-toast.vue'
@ -7,6 +8,8 @@ import $ from 'jquery'
let useElectron let useElectron
let shell let shell
Vue.directive('observe-visibility', ObserveVisibility)
if (window && window.process && window.process.type === 'renderer') { if (window && window.process && window.process.type === 'renderer') {
/* eslint-disable-next-line */ /* eslint-disable-next-line */
shell = require('electron').shell shell = require('electron').shell

View File

@ -1,18 +1,14 @@
import Vue from 'vue' import Vue from 'vue'
import FtFlexBox from '../ft-flex-box/ft-flex-box.vue' import FtFlexBox from '../ft-flex-box/ft-flex-box.vue'
import FtAutoGrid from '../ft-auto-grid/ft-auto-grid.vue' import FtAutoGrid from '../ft-auto-grid/ft-auto-grid.vue'
import FtListVideo from '../ft-list-video/ft-list-video.vue' import FtListLazyWrapper from '../ft-list-lazy-wrapper/ft-list-lazy-wrapper.vue'
import FtListChannel from '../ft-list-channel/ft-list-channel.vue'
import FtListPlaylist from '../ft-list-playlist/ft-list-playlist.vue'
export default Vue.extend({ export default Vue.extend({
name: 'FtElementList', name: 'FtElementList',
components: { components: {
'ft-flex-box': FtFlexBox, 'ft-flex-box': FtFlexBox,
'ft-auto-grid': FtAutoGrid, 'ft-auto-grid': FtAutoGrid,
'ft-list-video': FtListVideo, 'ft-list-lazy-wrapper': FtListLazyWrapper
'ft-list-channel': FtListChannel,
'ft-list-playlist': FtListPlaylist
}, },
props: { props: {
data: { data: {

View File

@ -2,28 +2,13 @@
<ft-auto-grid <ft-auto-grid
:grid="listType !== 'list'" :grid="listType !== 'list'"
> >
<template <ft-list-lazy-wrapper
v-for="(result, index) in data" v-for="(result, index) in data"
>
<ft-list-channel
v-if="result.type === 'channel'"
:key="index" :key="index"
appearance="result" appearance="result"
:data="result" :data="result"
:first-screen="index < 16"
/> />
<ft-list-video
v-if="result.type === 'video' || result.type === 'shortVideo'"
:key="index"
appearance="result"
:data="result"
/>
<ft-list-playlist
v-if="result.type === 'playlist'"
:key="index"
appearance="result"
:data="result"
/>
</template>
</ft-auto-grid> </ft-auto-grid>
</template> </template>

View File

@ -0,0 +1,3 @@
.lazyWrapper {
min-height: 264px;
}

View File

@ -0,0 +1,37 @@
import Vue from 'vue'
import FtListVideo from '../ft-list-video/ft-list-video.vue'
import FtListChannel from '../ft-list-channel/ft-list-channel.vue'
import FtListPlaylist from '../ft-list-playlist/ft-list-playlist.vue'
export default Vue.extend({
name: 'FtListLazyWrapper',
components: {
'ft-list-video': FtListVideo,
'ft-list-channel': FtListChannel,
'ft-list-playlist': FtListPlaylist
},
props: {
data: {
type: Object,
required: true
},
appearance: {
type: String,
required: true
},
firstScreen: {
type: Boolean,
required: true
}
},
data: function () {
return {
visible: this.firstScreen
}
},
methods: {
onVisibilityChanged: function (visible) {
this.visible = visible
}
}
})

View File

@ -0,0 +1,28 @@
<template>
<div
v-observe-visibility="firstScreen ? false : {
callback: onVisibilityChanged,
once: true,
}"
class="lazyWrapper"
>
<ft-list-channel
v-if="data.type === 'channel' && visible"
:appearance="appearance"
:data="data"
/>
<ft-list-video
v-if="(data.type === 'video' || data.type === 'shortVideo') && visible"
:appearance="appearance"
:data="data"
/>
<ft-list-playlist
v-if="data.type === 'playlist' && visilbe"
:appearance="appearance"
:data="data"
/>
</div>
</template>
<script src="./ft-list-lazy-wrapper.js" />
<style scoped src="./ft-list-lazy-wrapper.css" />