Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
feat: 🎸 Showcase: Add setTimeoutLoop()
Browse files Browse the repository at this point in the history
  • Loading branch information
ilharp committed Oct 31, 2019
1 parent bda8107 commit 07864bc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
15 changes: 12 additions & 3 deletions packages/superspider-showcase/pages/sc/dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,13 @@ export default {
tr: ''
},
started: false,
interval: false,
timer: false,
status: ''
}
},
beforeDestroy() {
if (this.timer) clearTimeout(this.timer)
},
async mounted() {
if (this.$route.query.roomid) {
this.form.room = this.$route.query.roomid
Expand All @@ -156,12 +159,18 @@ export default {
async startFetchData() {
await this.fetchData()
if (this.started === this.form.room) return
if (this.interval) clearInterval(this.interval)
this.interval = setInterval(async () => {
if (this.timer) clearTimeout(this.timer)
this.timer = this.setTimeoutLoop(async () => {
await this.fetchData()
}, 8000)
this.started = this.form.room
},
setTimeoutLoop(call, time) {
this.timer = setTimeout(async function fn() {
await call()
this.timer = setTimeout(fn, time)
}, time)
},
async fetchData() {
if (
!this.form.room ||
Expand Down
15 changes: 12 additions & 3 deletions packages/superspider-showcase/pages/sc/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export default {
scData: [],
room: '',
started: false,
interval: false,
timer: false,
showTimeNative: true,
showKanaNative: true,
showGiftNative: true,
Expand Down Expand Up @@ -282,16 +282,25 @@ export default {
}
)
},
beforeDestroy() {
if (this.timer) clearTimeout(this.timer)
},
async startFetchData() {
if (!this.room) return
await this.fetchData()
if (this.started === this.room) return
if (this.interval) clearInterval(this.interval)
this.interval = setInterval(async () => {
if (this.timer) clearTimeout(this.timer)
this.timer = this.setTimeoutLoop(async () => {
await this.fetchData()
}, 8000)
this.started = this.room
},
setTimeoutLoop(call, time) {
this.timer = setTimeout(async function fn() {
await call()
this.timer = setTimeout(fn, time)
}, time)
},
async fetchData() {
if (!this.room || isNaN(Number(this.room)) || this.room === '') return
let err = false
Expand Down

0 comments on commit 07864bc

Please sign in to comment.