Skip to content

Commit

Permalink
fix: _closed guard
Browse files Browse the repository at this point in the history
  • Loading branch information
pooya parsa committed Apr 24, 2019
1 parent 4f8811e commit b7f3b3e
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion app/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,21 @@ export default {
methods: {
onWSData(data) {
if (this._closed) {
return
}
// We have data from ws. Delay timeout!
this.setTimeout()
this.onData(data)
},
async fetchData() {
if (this._closed) {
return
}
// Prevent any fetch happening during fetch
this.clearTimeout()
Expand All @@ -108,12 +116,16 @@ export default {
},
setTimeout() {
if (this._closed) {
return
}
this.clearTimeout()
this._fetchTimeout = setTimeout(() => this.fetchData(), 1000)
},
onData(data) {
if (!data || !data.states) {
if (!data || !data.states || this._closed) {
return
}
Expand Down Expand Up @@ -150,6 +162,11 @@ export default {
},
async showNuxtApp() {
if (this._closed) {
return
}
this._closed = true
// Stop timers
this.clearTimeout()
Expand Down

0 comments on commit b7f3b3e

Please sign in to comment.